prithivMLmods/Coder-Stat huggingface dataset:
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  int min = 1000;
  for (int i = 0; i < 7; i++) {
    if (abs(753 - stoi(S.substr(i, 3))) < min) {

      min = abs(753 - stoi(S.substr(i, 3)));
    }
  }

  cout << min;
}

Fixed submission:
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  int min = 1000;
  for (int i = 0; i < S.size() - 2; i++) {
    if (abs(753 - stoi(S.substr(i, 3))) < min) {

      min = abs(753 - stoi(S.substr(i, 3)));
    }
  }

  cout << min;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  string S;
  cin >> S;

  int n = S.length();
  int Snum = stoi(S);
  int ans = 999;
  for (int i = 0; i < n - 2; i++) {
    int M = abs(Snum % 1000 - 753);
    ans = min(M, ans);
    if (ans == 0)
      break;
    Snum = Snum / 10;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  string S;
  cin >> S;

  int n = S.length();
  ll Snum = stoll(S);
  int ans = 999;
  for (int i = 0; i < n - 2; i++) {
    int M = abs(Snum % 1000 - 753);
    ans = min(M, ans);
    if (ans == 0)
      break;
    Snum = Snum / 10;
  }
  cout << ans << endl;
  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 1000;
  for (int i = 0; s.size() - 2; i++) {
    int num = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
    ans = min(ans, abs(num - 753));
  }
  cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 1000;
  for (int i = 0; i < s.size() - 2; i++) {
    int num = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
    ans = min(ans, abs(num - 753));
  }
  cout << ans << endl;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  string S;
  cin >> S;
  int jud, min = 1000, a;
  for (int i = 0; i < S.length(); i++) {
    for (int t = S.length() - i; t > 0; t--) {
      a = stoi(S.substr(i, t));
      if (753 - a >= 0)
        jud = 753 - a;
      else
        jud = a - 753;
      if (jud <= min)
        min = jud;
    }
  }
  cout << min;
}


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

int main(void) {
  string S;
  cin >> S;
  int jud, min = 1000, a;
  for (int i = 0; i <= S.length() - 2; i++) {
    a = stoi(S.substr(i, 3));
    if (753 - a >= 0)
      jud = 753 - a;
    else
      jud = a - 753;
    if (jud <= min)
      min = jud;
  }
  cout << min;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
  char s[11];
  scanf("%s", s);

  int tmp = 2, min = 1000;
  while (s[tmp] != '\n') {
    int n;
    n = 100 * (s[tmp - 2] - '0') + 10 * (s[tmp - 1] - '0') + (s[tmp] - '0');
    if (abs(n - 753) < min)
      min = abs(n - 753);
    tmp++;
  }

  printf("%d\n", min);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
  char s[11];
  scanf("%s", s);

  int tmp = 2, min = 1000;
  while (s[tmp] != '\0') {
    int n;
    n = 100 * (s[tmp - 2] - '0') + 10 * (s[tmp - 1] - '0') + (s[tmp] - '0');
    if (abs(n - 753) < min)
      min = abs(n - 753);
    tmp++;
  }

  printf("%d\n", min);

  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, spart;
  cin >> s;
  int min = 999;
  int tmp = 0;
  for (int i = 0; i < s.length() - 2; i++) {
    spart = s[i] + s[i + 1] + s[i + 2];
    tmp = stoi(spart);
    if (min > abs(tmp - 753))
      min = abs(tmp - 753);
  }
  cout << min << endl;
  return 0;
}

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

int main() {
  string s, spart;
  cin >> s;
  int min = 999;
  int tmp = 0;
  for (int i = 0; i < s.length() - 2; i++) {
    spart = s.substr(i, 3);
    tmp = stoi(spart);
    if (min > abs(tmp - 753))
      min = abs(tmp - 753);
  }
  cout << min << endl;
  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  cin >> S;
  int a = 1000;
  for (int i = 0; i < S.size() - 2; i++) {
    a = min(abs(753 - ((S.at(i) - '0') * 100 + (S.at(i + 1) - '0') * 10 +
                       S.at(i - 2) - '0')),
            a);
  }
  cout << a << endl;
}

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

int main() {
  string S;
  cin >> S;
  int a = 1000;
  for (int i = 0; i < S.size() - 2; i++) {
    a = min(abs(753 - ((S.at(i) - '0') * 100 + (S.at(i + 1) - '0') * 10 +
                       S.at(i + 2) - '0')),
            a);
  }
  cout << a << endl;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  string s;
  cin >> s;
  int u = stoi(s);
  vector<int> a(s.size());
  for (int i = 0; i < s.size(); i++) {
    a[i] = u % 10;
    u = u / 10;
  }
  reverse(a.begin(), a.end());

  int minV = 1000;
  for (int i = 0; i < s.size() - 2; i++) {
    minV = min(minV, abs(753 - (a[i] * 100 + a[i + 1] * 10 + a[i + 2])));
  }

  cout << minV << endl;

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  ll u = stol(s);
  vector<int> a(s.size());
  for (int i = 0; i < s.size(); i++) {
    a[i] = u % 10;
    u = u / 10;
  }
  reverse(a.begin(), a.end());

  int minV = 1000;
  for (int i = 0; i < s.size() - 2; i++) {
    minV = min(minV, abs(753 - (a[i] * 100 + a[i + 1] * 10 + a[i + 2])));
  }

  cout << minV << endl;

  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string x;
  int z, result = 1000;
  cin >> x;
  for (int i = 0; i < 9; i++) {
    string s = x.substr(i, 3);
    z = abs(stoi(s) - 753);
    result = min(result, z);
  }
  cout << result << endl;
}

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

int main() {
  string x;
  int z, result = 1000;
  cin >> x;
  for (int i = 0; i < x.length() - 2; i++) {
    string s = x.substr(i, 3);
    z = abs(stoi(s) - 753);
    result = min(result, z);
  }
  cout << result << endl;
}
Problem p03211 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

signed main() {
  int S;
  cin >> S;
  int ans = 114514;
  for (; S >= 100; S / 10) {
    int a = abs(S % 1000 - 753);
    if (abs(S % 1000 - 753) < ans)
      ans = a;
  }
  cout << ans << endl;
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

signed main() {
  int S;
  cin >> S;
  int ans = 114514;
  for (; S >= 100; S /= 10) {
    int a = abs(S % 1000 - 753);
    if (abs(S % 1000 - 753) < ans)
      ans = a;
  }
  cout << ans << endl;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  vector<int> a(S.length() - 2);
  for (int i = 0; i < S.length() - 2; i++) {
    a[i] = abs(753 - stoi(S.substr(i, 3)));
  }
  sort(a.begin(), a.end());
  cout << a[0] << endl;
}

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

int main() {
  string S;
  cin >> S;
  vector<int> a(S.length() - 2);
  for (int i = 0; i < S.length() - 2; i++) {
    a[i] = abs(753 - stoi(S.substr(i, 3)));
  }
  sort(a.begin(), a.end());
  cout << a[0] << endl;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  string S;
  cin >> S;

  int ret = stoi(S);
  for (auto i = 0u; i < S.size() - 2; ++i) {
    auto s = S.substr(i, 3);
    ret = min(ret, abs(753 - stoi(s)));
  }
  cout << ret << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  string S;
  cin >> S;

  int ret = 1000;
  for (auto i = 0u; i < S.size() - 2; ++i) {
    auto s = S.substr(i, 3);
    ret = min(ret, abs(753 - stoi(s)));
  }
  cout << ret << endl;
  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int abs(int a, int b) {
  if (a >= b) {
    return a - b;
  } else {
    return b - a;
  }
}

int main() {
  string S;
  cin >> S;
  int s = (int)S.size();
  vector<int> T;
  for (int i = 0; i < s; i++) {
    T[i] = S[i] - '0';
  }

  int min_diff = 1e4;

  for (int i = 0; i <= s - 3; i++) {
    int x = 100 * T[i] + 10 * T[i + 1] + T[i + 2];
    min_diff = min(min_diff, abs(753, x));
  }

  cout << min_diff << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int abs(int a, int b) {
  if (a >= b) {
    return a - b;
  } else {
    return b - a;
  }
}

int main() {
  string S;
  cin >> S;
  int s = (int)S.size();
  vector<int> T(s);
  for (int i = 0; i < s; i++) {
    T[i] = S[i] - '0';
  }

  int min_diff = 1e4;

  for (int i = 0; i <= s - 3; i++) {
    int x = 100 * T[i] + 10 * T[i + 1] + T[i + 2];
    min_diff = min(min_diff, abs(753, x));
  }

  cout << min_diff << endl;

  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string vec;
  cin >> vec;
  ll b = 1000;
  for (ll i = 0; i < 7; i++) {
    ll c, d, e;
    c = vec.at(i) - '0';
    d = vec.at(i + 1) - '0';
    e = vec.at(i + 2) - '0';
    b = min(b, abs(100 * c + 10 * d + e - 753));
  }
  cout << b << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string vec;
  cin >> vec;
  ll b = 1000;
  ll x = vec.size();
  for (ll i = 0; i < vec.size() - 2; i++) {
    ll c, d, e;
    c = vec.at(i) - '0';
    d = vec.at(i + 1) - '0';
    e = vec.at(i + 2) - '0';
    b = min(b, abs(100 * c + 10 * d + e - 753));
  }
  cout << b << endl;
  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pf(n) printf("%d\n", n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

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

  int org = stoi(s);
  vector<int> ket(s.size());
  int t = s.size();
  for (int i = 0; i < t; i++) {
    ket[i] = org % 10;
    org /= 10;
  }
  reverse(ket.begin(), ket.end());
  int ans = 999;
  for (int i = 0; i < t - 2; i++) {
    int num = 100 * ket[i] + 10 * ket[i + 1] + ket[i + 2];
    ans = min(ans, abs(753 - num));
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pf(n) printf("%d\n", n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
  string s;
  cin >> s;
  int n = s.length();
  int ans = INF;
  for (int i = 0; i <= n - 3; i++) {
    int x = (s[i] - '0');
    int y = (s[i + 1] - '0');
    int z = (s[i + 2] - '0');
    int a = 100 * x + 10 * y + z;
    ans = min(ans, abs(753 - a));
  }
  cout << ans << endl;

  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int counter = 10000;
  int n = stoi(s);
  deque<int> a;
  while (n > 0) {
    a.push_front(n % 10);
    n = n / 10;
  }
  for (int i = 0; i < a.size() - 2; i++) {
    counter =
        min(counter, abs(a.at(i) * 100 + a.at(i + 1) * 10 + a.at(i + 2) - 753));
  }
  cout << counter << endl;
}


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

int main() {
  string s;
  cin >> s;
  int counter = 10000;
  long long n = stoll(s);
  deque<int> a;
  while (n > 0) {
    a.push_front(n % 10);
    n = n / 10;
  }
  for (int i = 0; i < a.size() - 2; i++) {
    counter =
        min(counter, abs(a.at(i) * 100 + a.at(i + 1) * 10 + a.at(i + 2) - 753));
  }
  cout << counter << endl;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  string S;
  cin >> S;
  int diff = 753, t = 753;
  int s = stoi(S);
  int length = S.size();
  cout << s << endl;
  for (int i = 0; i < S.size() - 3; i++) {
    diff = 753 - s / (int)pow(10, length - 3);
    cout << s / (int)pow(10, length - 3) << endl;
    if (abs(diff) <= t) {
      t = abs(diff);
    }
    s = s % (int)pow(10, length - 1);
    length -= 1;
    cout << s << " " << length << endl;
  }
  cout << t;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  int diff, t = 753;
  for (int i = 0; i < s.size() - 2; i++) {
    diff = 753 - (s[i] - '0') * 100 - (s[i + 1] - '0') * 10 - (s[i + 2] - '0');
    t = min(t, abs(diff));
  }
  cout << t;

  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, ans;
  cin >> a;
  ans = abs(a % 1000 - 753);
  for (int i = 10; i < 10000000000000; i = i * 10) {
    if (abs((a % (i * 1000) / i) - 753) < ans) {
      ans = abs((a % (i * 1000) / i) - 753);
    }
    if (a / (i * 1000) == 0) {
      break;
    }
  }
  cout << ans << endl;
}

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

int main() {
  long long a, ans;
  cin >> a;
  ans = abs(a % 1000 - 753);
  for (long long i = 10; i < 10000000000000; i = i * 10) {
    if (abs((a % (i * 1000) / i) - 753) < ans) {
      ans = abs((a % (i * 1000) / i) - 753);
    }
    if (a / (i * 1000) == 0) {
      break;
    }
  }
  cout << ans << endl;
}
Problem p03211 (C++)

Buggy submission (status: 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() {
  string s, t = "";
  cin >> s;
  int ans = 999;
  rep(i, s.size() - 2) {
    t += s[i] + s[i + 1] + s[i + 2];
    ans = min(ans, abs(753 - stoi(t)));
    t = "";
  }
  cout << ans << endl;
  return 0;
}


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() {
  string s, t = "";
  cin >> s;
  int ans = 999;
  rep(i, s.size() - 2) {
    t += s[i];
    t += s[i + 1];
    t += s[i + 2];
    ans = min(ans, abs(753 - stoi(t)));
    t = "";
  }
  cout << ans << endl;
  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  vector<int> a;
  ll n = stoi(s);
  for (int i = 0; i < s.length(); ++i) {
    a.push_back(n % 10);
    n /= 10;
  }
  reverse(a.begin(), a.end());
  // for (auto g : a) cout << g << std::endl;
  vector<int> b;
  for (int i = 0; i < s.length() - 2; ++i) {
    b.push_back(a[i] * 100 + a[i + 1] * 10 + a[i + 2]);
  }
  int min = 1 << 29;
  for (int i = 0; i < s.length() - 2; ++i) {
    int x = abs(b[i] - 753);
    if (x < min)
      min = x;
  }
  cout << min << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  vector<int> a;
  ll n = stoll(s);
  for (int i = 0; i < s.length(); ++i) {
    a.push_back(n % 10);
    n /= 10;
  }
  reverse(a.begin(), a.end());
  // for (auto g : a) cout << g << std::endl;
  vector<int> b;
  for (int i = 0; i < s.length() - 2; ++i) {
    b.push_back(a[i] * 100 + a[i + 1] * 10 + a[i + 2]);
  }
  int min = 1 << 29;
  for (int i = 0; i < s.length() - 2; ++i) {
    int x = abs(b[i] - 753);
    if (x < min)
      min = x;
  }
  cout << min << std::endl;
  return 0;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
  string s;
  int MIN = INF;
  for (int i = 0; i < s.size() - 2; i++) {
    int num = abs((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 +
                  (s[i + 2] - '0') - 753);
    MIN = min(MIN, num);
  }
  cout << MIN << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
  string s;
  cin >> s;
  int MIN = INF;
  for (int i = 0; i < s.size() - 2; i++) {
    int num = abs((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 +
                  (s[i + 2] - '0') - 753);
    MIN = min(MIN, num);
  }
  cout << MIN << endl;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <assert.h>
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 1e9;
  for (int i = 0; i < s.size(); i++)
    for (int j = 1; j < s.size() - i + 1; j++)
      ans = min(ans, abs(753 - stoi(s.substr(i, j))));
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <assert.h>
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 1e9;
  for (int i = 0; i < s.size() - 2; i++)
    ans = min(ans, abs(753 - stoi(s.substr(i, 3))));
  cout << ans << endl;

  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;

const string defaultval = "753";

ll dfs(string s, int n) {
  ll x = stoi(s);
  if (x > n)
    return 0;
  ll ret = 0;
  if (count(s.begin(), s.end(), '7') > 0 &&
      count(s.begin(), s.end(), '5') > 0 && count(s.begin(), s.end(), '3') > 0)
    ret = 1;

  for (char c : defaultval) {
    s.push_back(c);
    ret += dfs(s, n);
    s.pop_back();
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  string start = "0";
  cout << dfs(start, n);
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;

const string defaultval = "753";

ll dfs(string s, ll n) {
  ll x = stoll(s);
  if (x > n)
    return 0;
  ll ret = 0;
  if (count(s.begin(), s.end(), '7') > 0 &&
      count(s.begin(), s.end(), '5') > 0 && count(s.begin(), s.end(), '3') > 0)
    ret = 1;

  for (char c : defaultval) {
    s.push_back(c);
    ret += dfs(s, n);
    s.pop_back();
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  string start = "0";
  cout << dfs(start, n);
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll;
typedef vector<int> VI;
typedef pair<ll, ll> pii;
const int MD = 1e9 + 7;
typedef vector<ll> VL;

void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}

int main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;

  int m = sz(s), n = stoi(s), ans = 0;
  int mt[] = {3, 5, 7};
  VI cnd, ct(m, 0);
  auto rec = [&](auto f, int idx) -> void {
    if (idx >= 3) {
      int w = 0;
      VI usd(3);
      rep(i, idx) {
        w = w * 10 + mt[ct[i]];
        usd[ct[i]] = 1;
      }
      if (w >= 1 && w <= n && count(all(usd), 1) == 3) {
        ans++;
      }
      if (idx == m)
        return;
    }
    rep(i, 3) {
      ct[idx] = i;
      f(f, idx + 1);
    }
  };

  rec(rec, 0);
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll;
typedef vector<int> VI;
typedef pair<ll, ll> pii;
const int MD = 1e9 + 7;
typedef vector<ll> VL;

void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}

int main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;

  int m = sz(s), n = stoi(s), ans = 0;
  if (n < 357) {
    puts("0");
    return 0;
  }
  int mt[] = {3, 5, 7};
  VI cnd, ct(m, 0);
  auto rec = [&](auto f, int idx) -> void {
    if (idx >= 3) {
      int w = 0;
      VI usd(3);
      rep(i, idx) {
        w = w * 10 + mt[ct[i]];
        usd[ct[i]] = 1;
      }
      if (w >= 1 && w <= n && count(all(usd), 1) == 3) {
        ans++;
      }
      if (idx == m)
        return;
    }
    rep(i, 3) {
      ct[idx] = i;
      f(f, idx + 1);
    }
  };

  rec(rec, 0);
  cout << ans << "\n";
  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int llui_t;
typedef long long int lli_t;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

/* inputs */
llui_t N;
vector<llui_t> X;

int main() {
  cin >> N;
  llui_t ans = 0;
  uint is7, is5, is3, no753;

  for (llui_t i = 0; i < N; i++) {
    llui_t n = i + 1;
    is7 = 0;
    is5 = 0;
    is3 = 0;
    no753 = 0;

    while (n > 0) {
      uint j = n % 10;
      if (j != 7 && j != 5 && j != 3) {
        no753 = 1;
        break;
      }
      if (j == 7) {
        is7 += 1;
      }
      if (j == 5) {
        is5 += 1;
      }
      if (j == 3) {
        is3 += 1;
      }
      n = n / 10;
    }
    // cout << i << "/" << is7 << "," << is5 << "," << is3 << "," << no753 <<
    // endl;
    if (is7 > 0 && is5 > 0 && is3 > 0 && no753 == 0) {
      ans += 1;
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int llui_t;
typedef long long int lli_t;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

/* inputs */
llui_t N;
vector<llui_t> X;

int main() {
  cin >> N;
  llui_t ans = 0;
  uint is7, is5, is3, no753;

  for (llui_t i = 1; i < N + 1; i += 2) {
    llui_t n = i;
    is7 = 0;
    is5 = 0;
    is3 = 0;
    no753 = 0;

    while (n > 0) {
      uint j = n % 10;
      if (j != 7 && j != 5 && j != 3) {
        no753 = 1;
        break;
      }
      if (j == 7) {
        is7 += 1;
      }
      if (j == 5) {
        is5 += 1;
      }
      if (j == 3) {
        is3 += 1;
      }
      n = n / 10;
    }
    // cout << i << "/" << is7 << "," << is5 << "," << is3 << "," << no753 <<
    // endl;
    if (is7 > 0 && is5 > 0 && is3 > 0 && no753 == 0) {
      ans += 1;
    }
  }

  cout << ans << endl;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <queue>

using namespace std;

int n, ans, now, cnt3, cnt5, cnt7;

queue<string> q;

int main() {
  cin >> n;
  q.push("3");
  q.push("5");
  q.push("7");
  while (!q.empty()) {
    string s = q.front();
    q.pop();
    now = 0;
    cnt3 = 0;
    cnt5 = 0;
    cnt7 = 0;
    for (int i = 1; i <= s.length(); i++) {
      now *= 10;
      now += s[i - 1] - '0';
      if (s[i - 1] == '3')
        cnt3++;
      if (s[i - 1] == '5')
        cnt5++;
      if (s[i - 1] == '7')
        cnt7++;
    }
    if (now <= n) {
      if (cnt3 && cnt5 && cnt7)
        ans++;
      q.push("3" + s);
      q.push("5" + s);
      q.push("7" + s);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <queue>

using namespace std;

long long n, ans, now, cnt3, cnt5, cnt7;

queue<string> q;

int main() {
  cin >> n;
  q.push("3");
  q.push("5");
  q.push("7");
  while (!q.empty()) {
    string s = q.front();
    q.pop();
    now = 0;
    cnt3 = 0;
    cnt5 = 0;
    cnt7 = 0;
    for (int i = 1; i <= s.length(); i++) {
      now *= 10;
      now += s[i - 1] - '0';
      if (s[i - 1] == '3')
        cnt3++;
      if (s[i - 1] == '5')
        cnt5++;
      if (s[i - 1] == '7')
        cnt7++;
    }
    if (now <= n) {
      if (cnt3 && cnt5 && cnt7)
        ans++;
      q.push("3" + s);
      q.push("5" + s);
      q.push("7" + s);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, b) for (int i = 0; i < (b); i++)
#define REPS(i, b) for (int i = 1; i <= (b); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;

ll N, ans;

bool is753(string s) {
  vector<int> c(3, 0);
  REP(i, s.length()) {
    if (s[i] == '7')
      c[0]++;
    else if (s[i] == '5')
      c[1]++;
    else if (s[i] == '3')
      c[2]++;
  }
  if (c[0] > 0 && c[1] > 0 && c[2] > 0)
    return true;
  return false;
}

int dfs(string s) {
  ll res = 0;
  if (stoi(s) > N)
    return 0;
  if (is753(s))
    res++;
  res += dfs(s + "7");
  res += dfs(s + "5");
  res += dfs(s + "3");
  return res;
}

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  cin >> N;
  ans += dfs("7");
  ans += dfs("5");
  ans += dfs("3");
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, b) for (int i = 0; i < (b); i++)
#define REPS(i, b) for (int i = 1; i <= (b); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;

ll N, ans;

bool is753(string s) {
  vector<int> c(3, 0);
  REP(i, s.length()) {
    if (s[i] == '7')
      c[0]++;
    else if (s[i] == '5')
      c[1]++;
    else if (s[i] == '3')
      c[2]++;
  }
  if (c[0] > 0 && c[1] > 0 && c[2] > 0)
    return true;
  return false;
}

int dfs(string s) {
  ll res = 0;
  if (stoll(s) > N)
    return 0;
  if (is753(s))
    res++;
  res += dfs(s + "7");
  res += dfs(s + "5");
  res += dfs(s + "3");
  return res;
}

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  cin >> N;
  ans += dfs("7");
  ans += dfs("5");
  ans += dfs("3");
  cout << ans << endl;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
bool check(int a) {
  bool b3 = false, b5 = false, b7 = false;
  while (a) {
    switch (a % 10) {
    case 3:
      b3 = true;
      break;
    case 5:
      b5 = true;
      break;
    case 7:
      b7 = true;
      break;
    default:
      return false;
    }
    a /= 10;
  }
  return (b3 && b5 && b7);
}
int main() {
  int n;
  int ans = 0;
  cin >> n;
  for (int i = 357; i <= n;) {
    if (check(i)) {
      ans++;
    }
    switch (i) {
    case 77777753:
      i = 333333357;
      break;
    case 337777775:
      i = 353333337;
      break;
    case 357777777:
      i = 373333335;
      break;
    case 377777775:
      i = 533333337;
      break;
    case 537777777:
      i = 553333337;
      break;
    case 557777773:
      i = 573333333;
      break;
    case 577777773:
      i = 733333335;
      break;
    case 737777775:
      i = 753333333;
      break;
    case 757777773:
      i = 773333335;
      break;
    case 777777753:
      i = n;
      break;
    default:
      i += 2;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool check(int a) {
  bool b3 = false, b5 = false, b7 = false;
  while (a) {
    switch (a % 10) {
    case 3:
      b3 = true;
      break;
    case 5:
      b5 = true;
      break;
    case 7:
      b7 = true;
      break;
    default:
      return false;
    }
    a /= 10;
  }
  return (b3 && b5 && b7);
}
int main() {
  int n;
  int ans = 0;
  cin >> n;
  if (n >= 777777753) {
    cout << 26484 << endl;
    return 0;
  }
  for (int i = 357; i <= n;) {
    if (check(i)) {
      ans++;
    }
    switch (i) {
    case 77777753:
      i = 333333357;
      break;
    case 337777775:
      i = 353333337;
      break;
    case 357777777:
      i = 373333335;
      break;
    case 377777775:
      i = 533333337;
      break;
    case 537777777:
      i = 553333337;
      break;
    case 557777773:
      i = 573333333;
      break;
    case 577777773:
      i = 733333335;
      break;
    case 737777775:
      i = 753333333;
      break;
    case 757777773:
      i = 773333335;
      break;
    case 777777753:
      i = n;
      break;
    default:
      i += 2;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03212 (Python)

Buggy submission (status: Runtime Error):
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s + c)
    return ret


print(dfs("0"))


Fixed submission:
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s + c)
    return ret


print(dfs("0"))
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF = 1000000000000000;

ll f357(ll x) {
  string s = to_string(x);
  if (s[s.size() - 1] != '3')
    return x - 2;
  string t = "";
  BREP(i, s.size()) {
    ll a = s[i] - '0';
    if (a != 3) {
      REP(j, i) t += s[j];
      t += ((s[i] - '0') - 2) + '0';
      FOR(k, i + 1, s.size()) t += '7';
      return stoll(t);
    }
  }
  REP(i, s.size() - 1) t += '7';
  return stoll(t);
}

ll start357(ll x) {
  string s = to_string(x);
  string t = "";
  REP(i, s.size()) t += '7';
  int y = stoll(t);
  while (y > x) {
    y = f357(y);
  }
  return y;
}

bool cnt357(ll x) {
  string s = to_string(x);
  bool b3 = 0, b5 = 0, b7 = 0;
  REP(i, s.size()) {
    ll a = s[i] - '0';
    if (a == 3)
      b3 = 1;
    if (a == 5)
      b5 = 1;
    if (a == 7)
      b7 = 1;
  }
  if (b3 * b5 * b7 == 1)
    return true;
  else
    return false;
}
int main() {
  ll n, strat;
  cin >> n;
  ll z = start357(n), cnt = 0;
  while (z >= 77) {
    if (cnt357(z) == true)
      cnt++;
    z = f357(z);
  }
  cout << cnt << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF = 1000000000000000;

ll f357(ll x) {
  string s = to_string(x);
  if (s[s.size() - 1] != '3')
    return x - 2;
  string t = "";
  BREP(i, s.size()) {
    ll a = s[i] - '0';
    if (a != 3) {
      REP(j, i) t += s[j];
      t += ((s[i] - '0') - 2) + '0';
      FOR(k, i + 1, s.size()) t += '7';
      return stoll(t);
    }
  }
  REP(i, s.size() - 1) t += '7';
  return stoll(t);
}

ll start357(ll x) {
  string s = to_string(x);
  string t = "";
  REP(i, s.size()) t += '7';
  int y = stoll(t);
  while (y > x) {
    y = f357(y);
  }
  return y;
}

bool cnt357(ll x) {
  string s = to_string(x);
  bool b3 = 0, b5 = 0, b7 = 0;
  REP(i, s.size()) {
    ll a = s[i] - '0';
    if (a == 3)
      b3 = 1;
    if (a == 5)
      b5 = 1;
    if (a == 7)
      b7 = 1;
  }
  if (b3 * b5 * b7 == 1)
    return true;
  else
    return false;
}
int main() {
  ll n, strat;
  cin >> n;
  if (n < 3) {
    cout << 0 << endl;
    return 0;
  }
  ll z = start357(n), cnt = 0;
  while (z >= 77) {
    if (cnt357(z) == true)
      cnt++;
    z = f357(z);
  }
  cout << cnt << endl;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define Rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long

ll n;
vector<char> c753 = {'3', '5', '7'};

ll dfs(string m) {
  if (stoi(m.c_str()) > n)
    return 0;
  ll res = 1;
  for (char c : c753)
    if (m.find(c) == string::npos)
      res = 0;

  for (char c : c753)
    res += dfs(m + c);
  return res;
}

int main() {
  cin >> n;

  cout << dfs("0") << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define Rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long

ll n;
vector<char> c753 = {'3', '5', '7'};

ll dfs(string m) {
  if (stol(m.c_str()) > n)
    return 0;
  ll res = 1;
  for (char c : c753)
    if (m.find(c) == string::npos)
      res = 0;

  for (char c : c753)
    res += dfs(m + c);
  return res;
}

int main() {
  cin >> n;

  cout << dfs("0") << endl;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  long long N, i, sum = 0;
  cin >> N;
  for (i = 3; i < N + 1;) {
    long long a = 0, b = 0, c = 0, d = 1, n = i;
    for (; n > 0;) {
      if (n % 10 == 3) {
        a = 1;
      } else if (n % 10 == 5) {
        b = 1;
      } else if (n % 10 == 7) {
        c = 1;
      } else {
        d = 0;
        break;
      }
      n = n / 10;
    }
    if (a * b * c * d == 1) {
      sum++;
    }
    if (i % 10 == 7) {
      i += 6;
    } else {
      i += 2;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  long long N, i, sum = 0;
  cin >> N;
  if (N > 500000000) {
    sum = 14384;
    for (i = 500000003; i < N + 1;) {
      long long a = 0, b = 0, c = 0, d = 1, n = i;
      for (; n > 0;) {
        if (n % 10 == 3) {
          a = 1;
        } else if (n % 10 == 5) {
          b = 1;
        } else if (n % 10 == 7) {
          c = 1;
        } else {
          d = 0;
          break;
        }
        n = n / 10;
      }
      if (a * b * c * d == 1) {
        sum++;
      }
      if (i % 10 == 7) {
        i += 6;
      } else {
        i += 2;
      }
    }
    cout << sum << endl;
    return 0;
  }
  for (i = 3; i < N + 1;) {
    long long a = 0, b = 0, c = 0, d = 1, n = i;
    for (; n > 0;) {
      if (n % 10 == 3) {
        a = 1;
      } else if (n % 10 == 5) {
        b = 1;
      } else if (n % 10 == 7) {
        c = 1;
      } else {
        d = 0;
        break;
      }
      n = n / 10;
    }
    if (a * b * c * d == 1) {
      sum++;
    }
    if (i % 10 == 7) {
      i += 6;
    } else {
      i += 2;
    }
  }
  cout << sum << endl;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;

bool is_good(int x) {
  map<int, int> mp;
  while (x > 0) {
    int res = x % 10;
    x /= 10;
    mp[res]++;
  }
  if (mp[3] > 0 && mp[5] > 0 && mp[7] > 0 && mp.size() == 3) {
    return true;
  } else
    return false;
  return 0;
}

int ans;
int n;
void dfs(int x) {
  if (x > n)
    return;
  if (is_good(x))
    ans++;

  if (x < 1e9) {
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
  }
}

int main() {
  cin >> n;
  dfs(0);
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;

bool is_good(int x) {
  map<int, int> mp;
  while (x > 0) {
    int res = x % 10;
    x /= 10;
    mp[res]++;
  }
  if (mp[3] > 0 && mp[5] > 0 && mp[7] > 0 && mp.size() == 3) {
    return true;
  } else
    return false;
  return 0;
}

int ans;
int n;
void dfs(int x) {
  if (x > n)
    return;
  if (is_good(x))
    ans++;

  if (x < 1e8) {
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
  }
}

int main() {
  cin >> n;
  dfs(0);
  cout << ans << endl;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

long long int N;

bool func(string s) {
  bool seven = false, five = false, three = false;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '7') {
      seven = true;
    } else if (s[i] == '5') {
      five = true;
    } else if (s[i] == '3') {
      three = true;
    } else {
      return false;
    }
  }
  if (seven && five && three) {
    return true;
  }
  return false;
}

long long int dfs(string s) {
  long long int ret = 0;
  //	cout<<s<<endl;

  if (s != "" && stoi(s) > N) {
    //		cout<<s + "b"<<endl;
    return 0;
  }
  //	cout<<s + "c"<<endl;
  if (func(s))
    ret = 1;
  ret += dfs(s + "7");
  ret += dfs(s + "5");
  ret += dfs(s + "3");
  //	cout<<s + "a"<<endl;
  return ret;
}

int main() {

  cin >> N;

  cout << dfs("") << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

long long int N;

bool func(string s) {
  bool seven = false, five = false, three = false;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '7') {
      seven = true;
    } else if (s[i] == '5') {
      five = true;
    } else if (s[i] == '3') {
      three = true;
    } else {
      return false;
    }
  }
  if (seven && five && three) {
    return true;
  }
  return false;
}

long long int dfs(string s) {
  long long int ret = 0;
  //	cout<<s<<endl;

  if (s != "" && stoll(s) > N) {
    //		cout<<s + "b"<<endl;
    return 0;
  }
  //	cout<<s + "c"<<endl;
  if (func(s))
    ret = 1;
  ret += dfs(s + "7");
  ret += dfs(s + "5");
  ret += dfs(s + "3");
  //	cout<<s + "a"<<endl;
  return ret;
}

int main() {

  cin >> N;

  cout << dfs("") << endl;
  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define repp(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define repm(i, a, b) for (int i = (int)a; i > (int)b; --i)
using ll = long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

bool flag_3, flag_5, flag_7;
ll n, counts;

void func(string s, ll &counts) {
  if (s == "")
    ;
  else if (stoi(s) > n)
    return;
  flag_3 = false, flag_5 = false, flag_7 = false;
  if (s.size())
    repp(i, 0, s.size()) {
      if (s[i] == '3')
        flag_3 = true;
      else if (s[i] == '5')
        flag_5 = true;
      else if (s[i] == '7')
        flag_7 = true;
    }
  if (flag_3 == true && flag_5 == true && flag_7 == true)
    ++counts;
  func(s + "7", counts);
  func(s + "5", counts);
  func(s + "3", counts);
}

int main() {
  cin >> n;
  string s = "";
  counts = 0;
  func(s, counts);
  cout << counts << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define repp(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define repm(i, a, b) for (int i = (int)a; i > (int)b; --i)
using ll = long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

bool flag_3, flag_5, flag_7;
ll n, counts;

void func(string s, ll &counts) {
  if (s == "")
    ;
  else if (stoll(s) > n)
    return;
  flag_3 = false, flag_5 = false, flag_7 = false;
  if (s.size())
    repp(i, 0, s.size()) {
      if (s[i] == '3')
        flag_3 = true;
      else if (s[i] == '5')
        flag_5 = true;
      else if (s[i] == '7')
        flag_7 = true;
    }
  if (flag_3 == true && flag_5 == true && flag_7 == true)
    ++counts;
  func(s + "7", counts);
  func(s + "5", counts);
  func(s + "3", counts);
}

int main() {
  cin >> n;
  string s = "";
  counts = 0;
  func(s, counts);
  cout << counts << endl;
  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define ll long long

const int N = 1e6 + 5, MOD = 1e9 + 7;

using namespace std;

ll n, ans = 0;
map<ll, bool> vis;
bool occ[10];
bool gg(ll a) {
  memset(occ, 0, sizeof(occ));
  while (a) {
    occ[a % 10] = 1;
    a /= 10;
  }

  return (occ[3] && occ[5] && occ[7]);
}
std::vector<int> v = {3, 5, 7};
void go(ll a) {
  vis[a] = 1;
  if (gg(a))
    ans++;
  for (auto x : v) {

    if (!vis.count(a * 10 + x) && a * 10 + x <= n)
      go(a * 10 + x);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("test.txt", "r", stdin);
#endif

  cin >> n;

  go(0);

  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define ll long long

const int N = 1e6 + 5, MOD = 1e9 + 7;

using namespace std;

ll n, ans = 0;
map<ll, bool> vis;
bool occ[10];
bool gg(ll a) {
  memset(occ, 0, sizeof(occ));
  while (a) {
    occ[a % 10] = 1;
    a /= 10;
  }

  return (occ[3] && occ[5] && occ[7]);
}
std::vector<int> v = {3, 5, 7};
void go(ll a) {
  vis[a] = 1;
  if (gg(a))
    ans++;
  for (auto x : v) {

    if (!vis.count(a * 10 + x) && a * 10 + x <= n)
      go(a * 10 + x);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n;

  go(0);

  cout << ans << "\n";
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int N;

int dfs(string s) {
  if (stoi(s) > N)
    return 0;
  int result = 0;
  if (find(s.begin(), s.end(), '3') != s.end() &&
      find(s.begin(), s.end(), '5') != s.end() &&
      find(s.begin(), s.end(), '7') != s.end())
    result++;
  result += dfs(s + "3");
  result += dfs(s + "5");
  result += dfs(s + "7");
  return result;
}

int main() {
  cin >> N;
  cout << dfs("0") << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int N;

int dfs(string s) {
  if (stol(s) > N)
    return 0;
  int result = 0;
  if (find(s.begin(), s.end(), '3') != s.end() &&
      find(s.begin(), s.end(), '5') != s.end() &&
      find(s.begin(), s.end(), '7') != s.end())
    result++;
  result += dfs(s + "3");
  result += dfs(s + "5");
  result += dfs(s + "7");
  return result;
}

int main() {
  cin >> N;
  cout << dfs("0") << endl;
  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;

int ans = 0;
int N;

void dfs(string S) {
  if (stoi(S) > N)
    return;
  bool ans3{}, ans5{}, ans7{};
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '3')
      ans3 = true;
    if (S[i] == '5')
      ans5 = true;
    if (S[i] == '7')
      ans7 = true;
  }
  if (ans3 && ans5 && ans7)
    ans++;
  string T = S + "3";
  string U = S + "5";
  string W = S + "7";
  dfs(T);
  dfs(U);
  dfs(W);
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  cin >> N;
  dfs("3");
  dfs("5");
  dfs("7");

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;

int ans = 0;
int N;

void dfs(string S) {
  if (stol(S) > N)
    return;
  bool ans3{}, ans5{}, ans7{};
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '3')
      ans3 = true;
    if (S[i] == '5')
      ans5 = true;
    if (S[i] == '7')
      ans7 = true;
  }
  if (ans3 && ans5 && ans7)
    ans++;
  string T = S + "3";
  string U = S + "5";
  string W = S + "7";
  dfs(T);
  dfs(U);
  dfs(W);
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  cin >> N;
  dfs("3");
  dfs("5");
  dfs("7");

  cout << ans << endl;
}