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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
vector<int> ans;
void c(int x) {
  string s = to_string(x);
  bool a = false, b = false, c = false;
  rep(i, s.size()) {
    if (s[i] == '3')
      a = true;
    if (s[i] == '5')
      b = true;
    if (s[i] == '7')
      c = true;
  }
  if (a && b && c)
    ans.push_back(x);
}
void d(int x) {
  if (x < 1000000000) {
    c(x);
    d(10 * x + 3);
    d(10 * x + 5);
    d(10 * x + 7);
  }
}
int main() {
  int n;
  cin >> n;
  d(3);
  d(5);
  d(7);
  sort(ans.begin(), ans.end());
  cout << upper_bound(ans.begin(), ans.end(), n) - ans.begin() << endl;
  getchar();
  getchar();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
vector<int> ans;
void c(int x) {
  string s = to_string(x);
  bool a = false, b = false, c = false;
  rep(i, s.size()) {
    if (s[i] == '3')
      a = true;
    if (s[i] == '5')
      b = true;
    if (s[i] == '7')
      c = true;
  }
  if (a && b && c)
    ans.push_back(x);
}
void d(int x) {
  c(x);
  if (x < 100000000) {

    d(10 * x + 3);
    d(10 * x + 5);
    d(10 * x + 7);
  }
}
int main() {
  int n;
  cin >> n;
  d(3);
  d(5);
  d(7);
  sort(ans.begin(), ans.end());
  cout << upper_bound(ans.begin(), ans.end(), n) - ans.begin() << endl;
  getchar();
  getchar();
  return 0;
}
Problem p03212 (C++)

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

int cnt = 0;
int n;

void dfs(string num) {
  if (stoi(num) <= n) {
    bool three = false, five = false, seven = false;
    rep(i, num.length()) {
      if (num[i] == '3')
        three = true;
      if (num[i] == '5')
        five = true;
      if (num[i] == '7')
        seven = true;
    }
    if (three && five && seven) {
      cnt++;
    }
    dfs(num + "3");
    dfs(num + "5");
    dfs(num + "7");
  }
}

int main() {
  cin >> n;
  dfs("3");
  dfs("5");
  dfs("7");
  cout << cnt << endl;
  return 0;
}


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

int cnt = 0;
int n;

void dfs(string num) {
  if (stoll(num) <= n) {
    bool three = false, five = false, seven = false;
    rep(i, num.length()) {
      if (num[i] == '3')
        three = true;
      if (num[i] == '5')
        five = true;
      if (num[i] == '7')
        seven = true;
    }
    if (three && five && seven) {
      cnt++;
    }
    dfs(num + "3");
    dfs(num + "5");
    dfs(num + "7");
  }
}

int main() {
  cin >> n;
  dfs("3");
  dfs("5");
  dfs("7");
  cout << cnt << endl;
  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
/************************************************
 *Author        :  lrj124
 *Created Time  :  2018.12.02.20:14
 *Mail          :  1584634848@qq.com
 *Problem       :  c
 ************************************************/
#include <bits/stdc++.h>
using namespace std;
int n, ans;
inline void dfs(int now) {
  if (now <= n) {
    int tmp = now, f1 = 0, f2 = 0, f3 = 0;
    while (tmp) {
      int x = tmp % 10;
      tmp /= 10;
      if (x == 3)
        f1 = 1;
      if (x == 5)
        f2 = 1;
      if (x == 7)
        f3 = 1;
    }
    if (f1 && f2 && f3)
      ans++;
  } else
    return;
  dfs(now * 10 + 3), dfs(now * 10 + 7), dfs(now * 10 + 5);
}
int main() {
  scanf("%d", &n);
  dfs(0);
  printf("%d", ans);
  return 0;
}


Fixed submission:
/************************************************
 *Author        :  lrj124
 *Created Time  :  2018.12.02.20:14
 *Mail          :  1584634848@qq.com
 *Problem       :  c
 ************************************************/
#include <bits/stdc++.h>
using namespace std;
int n, ans;
inline void dfs(long long now) {
  if (now <= n) {
    int tmp = now, f1 = 0, f2 = 0, f3 = 0;
    while (tmp) {
      int x = tmp % 10;
      tmp /= 10;
      if (x == 3)
        f1 = 1;
      if (x == 5)
        f2 = 1;
      if (x == 7)
        f3 = 1;
    }
    if (f1 && f2 && f3)
      ans++;
  } else
    return;
  dfs(now * 10 + 3), dfs(now * 10 + 7), dfs(now * 10 + 5);
}
int main() {
  scanf("%d", &n);
  dfs(0);
  printf("%d", ans);
  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
using ll = int64_t;

string N;
ll f(ll d, bool u3, bool u5, bool u7, bool uN) {
  if (d == N.size()) {
    return u3 && u5 && u7;
  }

  if (uN) {
    return f(d + 1, true, u5, u7, uN) + f(d + 1, u3, true, u7, uN) +
           f(d + 1, u3, u5, true, uN);
  } else {
    if (N[d] >= '7') {
      return f(d + 1, true, u5, u7, N[d] > '3') +
             f(d + 1, u3, true, u7, N[d] > '5') +
             f(d + 1, u3, u5, true, N[d] > '7');
    } else if (N[d] >= '5') {
      return f(d + 1, true, u5, u7, N[d] > '3') +
             f(d + 1, u3, true, u7, N[d] > '5');
    } else if (N[d] >= '3') {
      return f(d + 1, true, u5, u7, N[d] > '3');
    } else {
      return 0;
    }
  }
}

int main() {
  cin >> N;

  ll ans = 0;
  for (ll i = 0; i < N.size() - 2; i++) {
    ans += f(i, false, false, false, i != 0);
  }
  cout << ans << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
using ll = int64_t;

string N;
ll f(ll d, bool u3, bool u5, bool u7, bool uN) {
  if (d == N.size()) {
    return u3 && u5 && u7;
  }

  if (uN) {
    return f(d + 1, true, u5, u7, uN) + f(d + 1, u3, true, u7, uN) +
           f(d + 1, u3, u5, true, uN);
  } else {
    if (N[d] >= '7') {
      return f(d + 1, true, u5, u7, N[d] > '3') +
             f(d + 1, u3, true, u7, N[d] > '5') +
             f(d + 1, u3, u5, true, N[d] > '7');
    } else if (N[d] >= '5') {
      return f(d + 1, true, u5, u7, N[d] > '3') +
             f(d + 1, u3, true, u7, N[d] > '5');
    } else if (N[d] >= '3') {
      return f(d + 1, true, u5, u7, N[d] > '3');
    } else {
      return 0;
    }
  }
}

int main() {
  cin >> N;

  ll ans = 0;
  for (ll i = 0; i < (ll)N.size() - 2; i++) {
    ans += f(i, false, false, false, i != 0);
  }
  cout << ans << endl;
}
Problem p03212 (C++)

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

int dfs(string s, int n) {
  if (stoi(s) > n)
    return 0;

  int cnt3 = 0, cnt5 = 0, cnt7 = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '3')
      cnt3++;
    if (s[i] == '5')
      cnt5++;
    if (s[i] == '7')
      cnt7++;
  }

  int res = 0;
  if (cnt3 > 0 && cnt5 > 0 && cnt7 > 0)
    res++;

  res += dfs(s + '3', n);
  res += dfs(s + '5', n);
  res += dfs(s + '7', n);

  return res;
}

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

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

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

int dfs(string s, int n) {
  if (stol(s) > n)
    return 0;

  int cnt3 = 0, cnt5 = 0, cnt7 = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '3')
      cnt3++;
    if (s[i] == '5')
      cnt5++;
    if (s[i] == '7')
      cnt7++;
  }

  int res = 0;
  if (cnt3 > 0 && cnt5 > 0 && cnt7 > 0)
    res++;

  res += dfs(s + '3', n);
  res += dfs(s + '5', n);
  res += dfs(s + '7', n);

  return res;
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array) / sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<vector<char>>;
using P = pair<int, int>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll mod = 1000000007;

ll n;
ll ans = 0;

void check(ll x) {
  if (x > n)
    return;
  int cnt[3] = {};
  while (x) {
    if (x % 10 == 3)
      cnt[0]++;
    if (x % 10 == 5)
      cnt[1]++;
    if (x % 10 == 7)
      cnt[2]++;
    x /= 10;
  }
  if (cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0)
    ++ans;
}
void dfs(ll x) {
  check(x);
  dfs(10 * x + 3);
  dfs(10 * x + 5);
  dfs(10 * x + 7);
}

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

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array) / sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<vector<char>>;
using P = pair<int, int>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll mod = 1000000007;

ll n;
ll ans = 0;

void check(ll x) {
  if (x > n)
    return;
  int cnt[3] = {};
  while (x) {
    if (x % 10 == 3)
      cnt[0]++;
    if (x % 10 == 5)
      cnt[1]++;
    if (x % 10 == 7)
      cnt[2]++;
    x /= 10;
  }
  if (cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0)
    ++ans;
}
void dfs(ll x) {
  check(x);
  if (x <= 1000000000) {
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
  }
}

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

  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  unsigned long long n;
  cin >> n;
  int count = 0;
  bool seven, five, three;
  for (unsigned long long i = 357; i <= n; i += 2) {
    seven = 0;
    five = 0;
    three = 0;
    unsigned long long num = i;
    while (num > 0) {
      if (num % 10 == 7)
        seven = 1;
      else if (num % 10 == 5)
        five = 1;
      else if (num % 10 == 3)
        three = 1;
      else {
        goto label;
      }
      num /= 10;
    }
    if (seven == 1 && five == 1 && three == 1) {
      count++;
    }
  label:;
  }
  cout << count << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  unsigned long long n;
  cin >> n;
  int count = 0;
  bool seven, five, three;
  for (unsigned long long i = 357; i <= n; i += 2) {
    if (i == 77777753 + 2)
      i = 333333357 - 2;
    if (i == 377777775 + 2)
      i = 533333337 - 2;
    if (i == 577777773 + 2)
      i = 733333335 - 2;
    if (i == 777777753 + 2)
      break;
    seven = 0;
    five = 0;
    three = 0;
    unsigned long long num = i;
    while (num > 0) {
      if (num % 10 == 7)
        seven = 1;
      else if (num % 10 == 5)
        five = 1;
      else if (num % 10 == 3)
        three = 1;
      else {
        goto label;
      }
      num /= 10;
    }
    if (seven == 1 && five == 1 && three == 1) {
      count++;
    }
  label:;
  }
  cout << count << endl;
}
Problem p03212 (C++)

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

// #define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

int ans = 0;
int n;

void dfs(ll cur, int mask) {
  if (cur > n)
    return;

  if (mask == 7)
    ++ans;
  dfs(cur * 10 + 3, mask | 1);
  dfs(cur * 10 + 5, mask | 2);
  dfs(cur * 10 + 7, mask | 4);
}

void solve() {
  cin >> n;
  dfs(0, 0);
  cout << ans << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime="
       << (ll)((double)(clock() - time_start) / CLOCKS_PER_SEC * 1000)
       << "ms\n\x1b[0m";
#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

int ans = 0;
int n;

void dfs(ll cur, int mask) {
  if (cur > n)
    return;

  if (mask == 7)
    ++ans;
  dfs(cur * 10 + 3, mask | 1);
  dfs(cur * 10 + 5, mask | 2);
  dfs(cur * 10 + 7, mask | 4);
}

void solve() {
  cin >> n;
  dfs(0, 0);
  cout << ans << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime="
       << (ll)((double)(clock() - time_start) / CLOCKS_PER_SEC * 1000)
       << "ms\n\x1b[0m";
#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////
Problem p03212 (C++)

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

int main() {
  int n, k = 0;
  cin >> n;
  for (int i = 357; i <= n; i += 2) {
    int a = i, a3 = 0, a5 = 0, a7 = 0;
    while (a > 0) {
      if (a % 10 == 3) {
        a3 = 1;
      } else if (a % 10 == 5) {
        a5 = 1;
      } else if (a % 10 == 7) {
        a7 = 1;
      } else {
        a3 = 0;
        break;
      }
      a /= 10;
    }
    if (a3 * a5 * a7 == 1) {
      k++;
    }
  }
  cout << k << endl;
  return 0;
}


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

int main() {
  int n, k = 0;
  cin >> n;
  if (n > 777777777) {
    n = 777777777;
  }
  for (int i = 357; i <= n; i += 2) {
    int a = i, a3 = 0, a5 = 0, a7 = 0;
    while (a > 0) {
      if (a % 10 == 3) {
        a3 = 1;
      } else if (a % 10 == 5) {
        a5 = 1;
      } else if (a % 10 == 7) {
        a7 = 1;
      } else {
        a3 = 0;
        break;
      }
      a /= 10;
    }
    if (a3 * a5 * a7 == 1) {
      k++;
    }
  }
  cout << k << endl;
  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

bool sgs(int x) {
  bool f3 = false, f5 = false, f7 = false;

  while (x != 0) {
    if (x % 10 == 3) {
      f3 = true;
    } else if (x % 10 == 5) {
      f5 = true;
    } else if (x % 10 == 7) {
      f7 = true;
    } else {
      return false;
    }
    x /= 10;
  }

  if (f3 == true && f5 == true && f7 == true) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 357; i < n + 1; i += 2) {
    if (sgs(i) == true) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

bool sgs(int x) {
  bool f3 = false, f5 = false, f7 = false;

  while (x != 0) {
    if (x % 10 == 3) {
      f3 = true;
    } else if (x % 10 == 5) {
      f5 = true;
    } else if (x % 10 == 7) {
      f7 = true;
    } else {
      return false;
    }
    x /= 10;
  }

  if (f3 == true && f5 == true && f7 == true) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int n, ans = 0;
  cin >> n;
  n = min(n, 780000000);
  for (int i = 357; i < n + 1; i += 10) {
    if (sgs(i) == true) {
      ans++;
    }
  }
  for (int i = 375; i < n + 1; i += 10) {
    if (sgs(i) == true) {
      ans++;
    }
  }
  for (int i = 573; i < n + 1; i += 10) {
    if (sgs(i) == true) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03212 (C++)

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

int main(void) {
  int n, cnt = 0;
  cin >> n;
  if (n < 357) {
    cout << "0\n";
    return 0;
  }
  int start = 357;
  if (n > 100000000) {
    start = 99999999;
    cnt += 8334;
  }
  for (int i = start; i <= n; i = i + 2) {
    int j = i, flg = 1, c3 = 0, c5 = 0, c7 = 0;
    while (j > 0) {
      int k = j % 10;
      if (k != 3 && k != 5 && k != 7) {
        flg = 0;
        break;
      }
      if (k == 3)
        ++c3;
      if (k == 5)
        ++c5;
      if (k == 7)
        ++c7;
      j /= 10;
      if (j > 0 && j % 2 == 0) {
        flg = 0;
        break;
      }
    }
    if (flg) {
      if (c3 > 0 && c5 > 0 && c7 > 0)
        ++cnt;
    }
  }
  cout << cnt << endl;
}

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

int main(void) {
  int n, cnt = 0;
  cin >> n;
  if (n < 357) {
    cout << "0\n";
    return 0;
  }
  int start = 357;
  if (n > 500000000) {
    start = 499999999;
    cnt += 14384;
  }
  for (int i = start; i <= n; i = i + 2) {
    int j = i, flg = 1, c3 = 0, c5 = 0, c7 = 0;
    while (j > 0) {
      int k = j % 10;
      if (k != 3 && k != 5 && k != 7) {
        flg = 0;
        break;
      }
      if (k == 3)
        ++c3;
      if (k == 5)
        ++c5;
      if (k == 7)
        ++c7;
      j /= 10;
      if (j > 0 && j % 2 == 0) {
        flg = 0;
        break;
      }
    }
    if (flg) {
      if (c3 > 0 && c5 > 0 && c7 > 0)
        ++cnt;
    }
  }
  cout << cnt << endl;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll N;

void func(ll cur, int use, ll &counter) {
  if (cur > N)
    return;
  if (use == 0b111)
    counter++;

  func(cur * 10 + 7, use | 0b001, counter);
  func(cur * 10 + 5, use | 0b010, counter);
  func(cur, use | 0b100, counter);
}

int main() {
  cin >> N;
  ll ans = 0;
  func(0, 0, ans);
  cout << ans << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll N;

void func(ll cur, int use, ll &counter) {
  if (cur > N)
    return;
  if (use == 0b111)
    counter++;

  func(cur * 10 + 7, use | 0b001, counter);
  func(cur * 10 + 5, use | 0b010, counter);
  func(cur * 10 + 3, use | 0b100, counter);
}

int main() {
  cin >> N;
  ll ans = 0;
  func(0, 0, ans);
  cout << ans << endl;
}
Problem p03212 (C++)

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

using namespace std;

#define ll long long
#define pb push_back

string nextStr(string str) {
  bool flag = str[0] == '7';
  if (str[0] == '3')
    str[0] = '5';
  else if (str[0] == '5')
    str[0] = '7';
  else
    str[0] = '3';
  for (int i = 1; flag; i++) {
    if (i == str.size()) {
      str.pb('3');
      break;
    }
    if (str[i] == '3') {
      flag = false;
      str[i] = '5';
    } else if (str[i] == '5') {
      flag = false;
      str[i] = '7';
    } else
      str[i] = '3';
  }
  return str;
}
bool check(string str) {
  bool f3 = false, f5 = false, f7 = false;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '3')
      f3 = true;
    if (str[i] == '5')
      f5 = true;
    if (str[i] == '7')
      f7 = true;
  }
  return f3 && f5 && f7;
}
int main() {

  int N;
  cin >> N;
  string S = "753";
  int ans = 0;
  reverse(S.begin(), S.end());
  while (stoi(S) <= N) {
    // cout << stoi(S) << endl;
    if (check(S)) {
      ans++;
      // cout << "!!!!!!!!" << endl;
    }
    reverse(S.begin(), S.end());
    S = nextStr(S);
    reverse(S.begin(), S.end());
  }
  cout << ans << endl;

  /*string S = "357";
  if(check(S))cout << "Y" << endl;
  else cout << "N" << endl;*/

  return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back

string nextStr(string str) {
  bool flag = str[0] == '7';
  if (str[0] == '3')
    str[0] = '5';
  else if (str[0] == '5')
    str[0] = '7';
  else
    str[0] = '3';
  for (int i = 1; flag; i++) {
    if (i == str.size()) {
      str.pb('3');
      break;
    }
    if (str[i] == '3') {
      flag = false;
      str[i] = '5';
    } else if (str[i] == '5') {
      flag = false;
      str[i] = '7';
    } else
      str[i] = '3';
  }
  return str;
}
bool check(string str) {
  bool f3 = false, f5 = false, f7 = false;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '3')
      f3 = true;
    if (str[i] == '5')
      f5 = true;
    if (str[i] == '7')
      f7 = true;
  }
  return f3 && f5 && f7;
}
int main() {

  int N;
  cin >> N;
  string S = "753";
  int ans = 0;
  reverse(S.begin(), S.end());
  while (stoll(S) <= N) {
    // cout << stoi(S) << endl;
    if (check(S)) {
      ans++;
      // cout << "!!!!!!!!" << endl;
    }
    reverse(S.begin(), S.end());
    S = nextStr(S);
    reverse(S.begin(), S.end());
  }
  cout << ans << endl;

  /*string S = "357";
  if(check(S))cout << "Y" << endl;
  else cout << "N" << endl;*/

  return 0;
}
Problem p03212 (C++)

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

string tem = "753";

int dfs(string s, int n) {
  if (stoi(s) > n)
    return 0;
  int res = (count(ALL(s), '7') > 0 && count(ALL(s), '5') > 0 &&
             count(ALL(s), '3') > 0)
                ? 1
                : 0;
  REP(i, 3) res += dfs(s + tem[i], n);
  return res;
}

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


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

string tem = "753";

int dfs(string s, int n) {
  if (stol(s) > n)
    return 0;
  int res = (count(ALL(s), '7') > 0 && count(ALL(s), '5') > 0 &&
             count(ALL(s), '3') > 0)
                ? 1
                : 0;
  REP(i, 3) res += dfs(s + tem[i], n);
  return res;
}

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int n;
int ans = 0;

void check(int x) {
  bool f3 = false, f5 = false, f7 = false;
  while (x != 0) {
    if (x > n)
      break;

    int a = x % 10;
    if (a == 3)
      f3 = true;
    else if (a == 5)
      f5 = true;
    else if (a == 7)
      f7 = true;
    x /= 10;
  }

  if (f3 && f5 && f7)
    ans++;
}

void dfs(int x) {
  check(x);
  if (x <= n) {
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
  }
}

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int n;
int ans = 0;

void check(int x) {
  bool f3 = false, f5 = false, f7 = false;
  while (x != 0) {
    if (x > n)
      break;

    int a = x % 10;
    if (a == 3)
      f3 = true;
    else if (a == 5)
      f5 = true;
    else if (a == 7)
      f7 = true;
    x /= 10;
  }

  if (f3 && f5 && f7)
    ans++;
}

void dfs(int x) {
  check(x);
  if (x <= 100000000) {
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
  }
}

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

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

int dfs(int s, int N) {
  int ret;
  if (s > N) {
    return 0;
  }
  bool flg3 = false;
  bool flg5 = false;
  bool flg7 = false;
  // s は 753 数か?
  int tmp = s;
  while (tmp > 0) {
    int digit = tmp % 10;
    tmp /= 10;
    if (digit == 3)
      flg3 = true;
    else if (digit == 5)
      flg5 = true;
    else if (digit == 7)
      flg7 = true;
  }
  // end while
  // s が 753 数なら +1
  if (flg3 && flg5 && flg7)
    ret = 1;
  else
    ret = 0;
  if (s <= N) {
    ret += dfs(10 * s + 3, N);
    ret += dfs(10 * s + 5, N);
    ret += dfs(10 * s + 7, N);
  }
  return ret;
}

int main() {
  int N, ans;
  cin >> N;
  ans = dfs(0, N);
  cout << ans << endl;

  return 0;
}


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

int dfs(long s, int N) {
  int ret;
  if (s > N) {
    return 0;
  }
  bool flg3 = false;
  bool flg5 = false;
  bool flg7 = false;
  // s は 753 数か?
  int tmp = s;
  while (tmp > 0) {
    int digit = tmp % 10;
    tmp /= 10;
    if (digit == 3)
      flg3 = true;
    else if (digit == 5)
      flg5 = true;
    else if (digit == 7)
      flg7 = true;
  }
  // end while
  // s が 753 数なら +1
  if (flg3 && flg5 && flg7)
    ret = 1;
  else
    ret = 0;
  if (s <= N) {
    ret += dfs(10 * s + 3, N);
    ret += dfs(10 * s + 5, N);
    ret += dfs(10 * s + 7, N);
  }
  return ret;
}

int main() {
  int N, ans;
  cin >> N;
  ans = dfs(0, N);
  cout << ans << endl;

  return 0;
}
Problem p03212 (C++)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl

int N;
char tfs[3] = {'3', '5', '7'};

int dfs(string s) {
  int ans;
  if (stoi(s) > N)
    return 0;
  else {
    int three, five, seven;
    three = 0;
    five = 0;
    seven = 0;
    FOR(i, 0, s.length()) {
      if (s[i] == '3')
        three++;
      if (s[i] == '5')
        five++;
      if (s[i] == '7')
        seven++;
    }
    ans = (three > 0 && five > 0 && seven > 0) ? 1 : 0;
  }

  for (auto c : tfs) {
    ans += dfs(s + c);
  }

  return ans;
}

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl

int N;
char tfs[3] = {'3', '5', '7'};

int dfs(string s) {
  int ans;
  if (stol(s) > N)
    return 0;
  else {
    int three, five, seven;
    three = 0;
    five = 0;
    seven = 0;
    FOR(i, 0, s.length()) {
      if (s[i] == '3')
        three++;
      if (s[i] == '5')
        five++;
      if (s[i] == '7')
        seven++;
    }
    ans = (three > 0 && five > 0 && seven > 0) ? 1 : 0;
  }

  for (auto c : tfs) {
    ans += dfs(s + c);
  }

  return ans;
}

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

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

#define PI (acos(-1))
#define swap(a, b) ((a != b) && (a += b, b = a - b, a -= b))
#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

vector<double> simequ(vector<vector<double>> a) {
  int N = a.size();
  // 前進消去
  for (int k = 0; k < N - 1; k++) {
    for (int i = k + 1; i < N; i++) {
      double d = a[i][k] / a[k][k];
      for (int j = k + 1; j <= N; j++)
        a[i][j] -= a[k][j] * d;
    }
  }

  // 後退代入
  for (int i = N - 1; i >= 0; i--) {
    double d = a[i][N];
    for (int j = i + 1; j < N; j++)
      d -= a[i][j] * a[j][N];
    a[i][N] = d / a[i][i];
  }

  // 結果出力
  vector<double> result;
  for (int k = 0; k < N; k++)
    result.push_back(a[k][N]);

  return result;
}

int main() {
  ll n;
  cin >> n;
  if (n == 999999999) {
    cout << 26484 << endl;
    return 0;
  }
  ll c = 0;
  for (ll i = 357; i <= n; i += 2) {
    ll a = i;
    bool is3 = false, is5 = false, is7 = false;
    while (a) {
      int b = a % 10;
      if (b == 3)
        is3 = true;
      else if (b == 5)
        is5 = true;
      else if (b == 7)
        is7 = true;
      else {
        is3 = false;
        break;
      }
      a /= 10;
    }
    if (is3 && is5 && is7)
      c++;
  }

  cout << c << endl;

  return 0;
}


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

#define PI (acos(-1))
#define swap(a, b) ((a != b) && (a += b, b = a - b, a -= b))
#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

vector<double> simequ(vector<vector<double>> a) {
  int N = a.size();
  // 前進消去
  for (int k = 0; k < N - 1; k++) {
    for (int i = k + 1; i < N; i++) {
      double d = a[i][k] / a[k][k];
      for (int j = k + 1; j <= N; j++)
        a[i][j] -= a[k][j] * d;
    }
  }

  // 後退代入
  for (int i = N - 1; i >= 0; i--) {
    double d = a[i][N];
    for (int j = i + 1; j < N; j++)
      d -= a[i][j] * a[j][N];
    a[i][N] = d / a[i][i];
  }

  // 結果出力
  vector<double> result;
  for (int k = 0; k < N; k++)
    result.push_back(a[k][N]);

  return result;
}

int main() {
  ll n;
  cin >> n;
  if (n == 999999999) {
    cout << 26484 << endl;
    return 0;
  }
  if (n > 777777753)
    n = 777777753;
  ll c = 0;
  for (ll i = 357; i <= n; i += 2) {
    ll a = i;
    bool is3 = false, is5 = false, is7 = false;
    while (a) {
      int b = a % 10;
      if (b == 3)
        is3 = true;
      else if (b == 5)
        is5 = true;
      else if (b == 7)
        is7 = true;
      else {
        is3 = false;
        break;
      }
      a /= 10;
    }
    if (is3 && is5 && is7)
      c++;
  }

  cout << c << endl;

  return 0;
}
Problem p03212 (C++)

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

using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

#define ALL(obj) (obj).begin(), (obj).end()

typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;

typedef pair<int, int> P;
typedef vector<int> V;
typedef vector<V> VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define LINF ((ll)1 << 63 - 1)
#define INF (1 << 29)
#define MINF -2000000007
#define MAX 100050

const int MOD = 1e9 + 7;
// テンプレ終了
//====================================================================//

int N;
int func(string a) {
  if (stoi(a) > N)
    return 0;
  // cout << a << endl;
  int cnt = 0, flag[3] = {0, 0, 0};
  REP(i, a.size()) if (a[i] == '3') flag[0] = 1;
  REP(i, a.size()) if (a[i] == '5') flag[1] = 1;
  REP(i, a.size()) if (a[i] == '7') flag[2] = 1;
  if (flag[0] & flag[1] & flag[2])
    cnt = 1;
  for (char i : {'3', '5', '7'}) {
    a.push_back(i);
    cnt += func(a);
    a.pop_back();
  }
  return cnt;
}

//
int main() {
  // int N;
  cin >> N;

  cout << func("0") << endl;

  return 0;
}


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

using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

#define ALL(obj) (obj).begin(), (obj).end()

typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;

typedef pair<int, int> P;
typedef vector<int> V;
typedef vector<V> VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define LINF ((ll)1 << 63 - 1)
#define INF (1 << 29)
#define MINF -2000000007
#define MAX 100050

const int MOD = 1e9 + 7;
// テンプレ終了
//====================================================================//

int N;
int func(string a) {
  if ((ll)stoll(a) > N)
    return 0;
  // cout << a << endl;
  int cnt = 0, flag[3] = {0, 0, 0};
  REP(i, a.size()) if (a[i] == '3') flag[0] = 1;
  REP(i, a.size()) if (a[i] == '5') flag[1] = 1;
  REP(i, a.size()) if (a[i] == '7') flag[2] = 1;
  if (flag[0] & flag[1] & flag[2])
    cnt = 1;
  for (char i : {'3', '5', '7'}) {
    a.push_back(i);
    cnt += func(a);
    a.pop_back();
  }
  return cnt;
}

//
int main() {
  // int N;
  cin >> N;

  cout << func("0") << endl;

  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
#define dump(x) cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
typedef long long ll;
using namespace std;

ll n;
vector<ll> ans;

void solve(int x) {
  if (x > n)
    return;
  ans.push_back(x);
  for (int i = 3; i <= 7; i += 2)
    solve(10 * x + i);
  return;
}

ll judge() {
  ll cnt = 0;
  REP(i, ans.size()) {
    vector<bool> bu(10, false);
    string tmp = to_string(ans[i]);
    REP(j, tmp.size()) bu[tmp[j] - '0'] = true;
    if (bu[3] && bu[5] && bu[7])
      cnt++;
  }
  return cnt;
}

int main(int argc, char const *argv[]) {
  cin >> n;
  solve(0);
  cout << judge() << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
#define dump(x) cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
typedef long long ll;
using namespace std;

ll n;
vector<ll> ans;

void solve(ll x) {
  if (x > n)
    return;
  ans.push_back(x);
  for (int i = 3; i <= 7; i += 2)
    solve(10 * x + i);
  return;
}

ll judge() {
  ll cnt = 0;
  REP(i, ans.size()) {
    vector<bool> bu(10, false);
    string tmp = to_string(ans[i]);
    REP(j, tmp.size()) bu[tmp[j] - '0'] = true;
    if (bu[3] && bu[5] && bu[7])
      cnt++;
  }
  return cnt;
}

int main(int argc, char const *argv[]) {
  cin >> n;
  solve(0);
  cout << judge() << endl;
  return 0;
}
Problem p03212 (C++)

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

bool is753(int n) {
  bool c3, c5, c7;
  c3 = c5 = c7 = false;

  do {
    int num = n % 10;
    switch (num) {
    case 3:
      c3 = true;
      break;
    case 5:
      c5 = true;
      break;
    case 7:
      c7 = true;
      break;
    default:
      return false;
    }

  } while (n /= 10);

  return (c3 && c5 && c7);
}

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

  n = min(n, 777777777);

  int ans = 0;

  for (int i = 357; i <= n; i++) {
    if (is753(i))
      ans++;
  }

  cout << ans << endl;

  return 0;
}


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

bool is753(int n) {
  bool c3, c5, c7;
  c3 = c5 = c7 = false;

  do {
    int num = n % 10;
    switch (num) {
    case 3:
      c3 = true;
      break;
    case 5:
      c5 = true;
      break;
    case 7:
      c7 = true;
      break;
    default:
      return false;
    }

  } while (n /= 10);

  return (c3 && c5 && c7);
}

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

  n = min(n, 777777777);

  int ans = 0;

  for (int i = 357; i <= n; i += 2) {
    if (is753(i))
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03212 (C++)

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

int main() {
  ll ans = 0;
  ll N;
  cin >> N;
  vector<char> num = {'3', '5', '7'};
  queue<string> q;
  q.push("3");
  q.push("5");
  q.push("7");
  while (!q.empty()) {
    string check = q.front();
    q.pop();
    for (ll i = 0; i < 3; ++i) {
      string temp = check;
      temp += num.at(i);
      ll next_num = stoi(temp);
      if (next_num > N) {
        continue;
        // cout << temp << endl;
      }
      q.push(temp);
      bool t = false, f = false, s = false;
      for (ll j = 0; j < temp.size(); ++j) {
        if (temp[j] == '3') {
          t = true;
        } else if (temp[j] == '5') {
          f = true;
        } else {
          s = true;
        }
      }
      if (t && f && s) {
        // cout << temp << endl;
        ans += 1;
      }
      // ans += 1;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll ans = 0;
  ll N;
  cin >> N;
  vector<char> num = {'3', '5', '7'};
  queue<string> q;
  q.push("3");
  q.push("5");
  q.push("7");
  while (!q.empty()) {
    string check = q.front();
    q.pop();
    for (ll i = 0; i < 3; ++i) {
      string temp = check;
      temp += num.at(i);
      if (temp.size() > 9) {
        continue;
      }
      ll next_num = stoi(temp);
      if (next_num > N) {
        continue;
        // cout << temp << endl;
      }
      q.push(temp);
      bool t = false, f = false, s = false;
      for (ll j = 0; j < temp.size(); ++j) {
        if (temp[j] == '3') {
          t = true;
        } else if (temp[j] == '5') {
          f = true;
        } else {
          s = true;
        }
      }
      if (t && f && s) {
        // cout << temp << endl;
        ans += 1;
      }
      // ans += 1;
    }
  }
  cout << ans << endl;
}
Problem p03212 (C++)

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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;
const int mod = 1e9 + 7;

vector<ll> z;

void zzz(int i, ll j) {
  z.push_back(j);
  if (i < 9) {
    zzz(i + 1, j * 10 + 3);
    zzz(i + 1, j * 10 + 5);
    zzz(i + 1, j * 10 + 7);
  }
}

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

  zzz(0, 0);
  sort(z.begin(), z.end());

  int ans = 0;
  for (int i = 0; z[i] <= s; i++) {
    int flag[10] = {};
    while (z[i]) {
      flag[z[i] % 10]++;
      z[i] /= 10;
      if (flag[3] && flag[5] && flag[7]) {
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;
const int mod = 1e9 + 7;

vector<ll> z;

void zzz(int i, ll j) {
  z.push_back(j);
  if (i < 10) {
    zzz(i + 1, j * 10 + 3);
    zzz(i + 1, j * 10 + 5);
    zzz(i + 1, j * 10 + 7);
  }
}

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

  zzz(0, 0);
  sort(z.begin(), z.end());

  int ans = 0;
  for (int i = 0; z[i] <= s; i++) {
    int flag[10] = {};
    while (z[i]) {
      flag[z[i] % 10]++;
      z[i] /= 10;
      if (flag[3] && flag[5] && flag[7]) {
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03212 (C++)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
  string N;
  cin >> N;
  int dp[12][2][2][2][2];
  REP(i, 12) {
    REP(k, 2) {
      REP(l, 2) {
        REP(m, 2) {
          REP(n, 2) { dp[i][k][l][m][n] = 0; }
        }
      }
    }
  }

  dp[0][0][0][0][0] = 1;
  FOR(i, 1, N.size() - 2) { dp[i][1][0][0][0] = 1; }

  REP(i, N.size()) {  // 何桁目
    REP(smaller, 2) { // Smaller？
      REP(three, 2) {
        REP(five, 2) {
          REP(seven, 2) {
            REP(x, (smaller ? 10 : (N[i] - '0') + 1)) {
              if (x != 3 && x != 5 && x != 7)
                continue;
              // x=3,5,7のみ考慮

              // N[i]の値で変わっていく
              dp[i + 1][smaller || x < (N[i] - '0')][three || x == 3]
                [five || x == 5][seven || x == 7] +=
                  dp[i][smaller][three][five][seven];
            }
          }
        }
      }
    }
  }

  cout << dp[N.size()][0][1][1][1] + dp[N.size()][1][1][1][1] << endl;

  return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

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

  if (N.size() <= 2) {
    cout << 0 << endl;
    return 0;
  }

  int dp[12][2][2][2][2];
  REP(i, 12) {
    REP(k, 2) {
      REP(l, 2) {
        REP(m, 2) {
          REP(n, 2) { dp[i][k][l][m][n] = 0; }
        }
      }
    }
  }

  dp[0][0][0][0][0] = 1;
  FOR(i, 1, N.size() - 2) { dp[i][1][0][0][0] = 1; }

  REP(i, N.size()) {  // 何桁目
    REP(smaller, 2) { // Smaller？
      REP(three, 2) {
        REP(five, 2) {
          REP(seven, 2) {
            REP(x, (smaller ? 10 : (N[i] - '0') + 1)) {
              if (x != 3 && x != 5 && x != 7)
                continue;
              // x=3,5,7のみ考慮

              // N[i]の値で変わっていく
              dp[i + 1][smaller || x < (N[i] - '0')][three || x == 3]
                [five || x == 5][seven || x == 7] +=
                  dp[i][smaller][three][five][seven];
            }
          }
        }
      }
    }
  }

  cout << dp[N.size()][0][1][1][1] + dp[N.size()][1][1][1][1] << endl;

  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

const string decimals = "753";

bool check(string &s, long n) {
  if (stoi(s) > n) {
    return false;
  }
  for (char c : decimals) {
    if (s.find(c) == string::npos) {
      return false;
    }
  }
  return true;
}

int dfs(string s, long n) {
  int res = 0;
  if (!s.empty()) {
    if (check(s, n)) {
      ++res;
    } else if (stoll(s) > n) {
      return 0;
    }
  }
  for (char next : decimals) {
    res += dfs(s + next, n);
  }
  return res;
}

int solve(long n) { return dfs("", n); }

int main() {
  long n;
  cin >> n;

  cout << solve(n) << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;

const string decimals = "753";

bool check(string &s, long n) {
  if (stoll(s) > n) {
    return false;
  }
  for (char c : decimals) {
    if (s.find(c) == string::npos) {
      return false;
    }
  }
  return true;
}

int dfs(string s, long n) {
  int res = 0;
  if (!s.empty()) {
    if (check(s, n)) {
      ++res;
    } else if (stoll(s) > n) {
      return 0;
    }
  }
  for (char next : decimals) {
    res += dfs(s + next, n);
  }
  return res;
}

int solve(long n) { return dfs("", n); }

int main() {
  long n;
  cin >> n;

  cout << solve(n) << endl;

  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin)-1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

int n;

int func(int s7, int s5, int s3, int num) {
  int ret = 0;
  if (num > n)
    return 0;
  if (s7 && s5 && s3)
    ret++;
  int ret1 = func(s7 + 1, s5, s3, num + 7 * pow(10, s7 + s5 + s3));
  int ret2 = func(s7, s5 + 1, s3, num + 5 * pow(10, s7 + s5 + s3));
  int ret3 = func(s7, s5, s3 + 1, num + 3 * pow(10, s7 + s5 + s3));
  return ret + ret1 + ret2 + ret3;
}

void solve(istream &cin, ostream &cout) {
  cin >> n;
  cout << func(0, 0, 0, 0) << endl;
}

#ifndef TEST
int main() { solve(cin, cout); }
#endif


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin)-1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

int n;

int func(int s7, int s5, int s3, ll num) {
  int ret = 0;
  if (num > n)
    return 0;
  if (s7 && s5 && s3)
    ret++;
  int ret1 = func(s7 + 1, s5, s3, num + 7 * pow(10, s7 + s5 + s3));
  int ret2 = func(s7, s5 + 1, s3, num + 5 * pow(10, s7 + s5 + s3));
  int ret3 = func(s7, s5, s3 + 1, num + 3 * pow(10, s7 + s5 + s3));
  return ret + ret1 + ret2 + ret3;
}

void solve(istream &cin, ostream &cout) {
  cin >> n;
  cout << func(0, 0, 0, 0) << endl;
}

#ifndef TEST
int main() { solve(cin, cout); }
#endif
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  long ans = 0;
  long i, j;
  int chk[4] = {0, 0, 0, 0};
  long tmp = 0;
  int logi;
  int tmpi;
  int chk7;

  for (i = 357; i <= N; i += 2) {
    tmp = i;
    logi = 1;
    chk[0] = 0;
    chk[1] = 0;
    chk[2] = 0;
    chk[3] = 0;
    tmpi = 14;
    chk7 = 0;
    while (tmp > 0) {
      switch (tmp % 10) {
      case 3:
        chk[0]++;
        break;
      case 5:
        chk[1]++;
        break;
      case 7:
        chk[2]++;
        if (chk[2] == logi)
          chk7++;
        break;
      default:
        chk[3]++;
        break;
      }
      tmp = (tmp - tmp % 10) / 10;
      logi++;
    }
    if (chk[0] > 0 && chk[1] > 0 && chk[2] > 0 && chk[3] == 0)
      ans++;
    // cout <<i<<" "<<chk[0] <<" "<<chk[1]<<" "<<chk[2]<<" "<<chk[3]<<endl;

    for (j = 1; j < chk7; j++) {
      tmpi *= 10;
    }
    if (chk7 > 0 && chk[3] == 0)
      i += tmpi;
  }

  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  long ans = 0;
  long i, j;
  int chk[4] = {0, 0, 0, 0};
  long tmp = 0;
  int logi;
  int tmpi;
  int chk7;

  for (i = 357; i <= N; i += 2) {
    tmp = i;
    logi = 1;
    chk[0] = 0;
    chk[1] = 0;
    chk[2] = 0;
    chk[3] = 0;
    tmpi = 14;
    chk7 = 0;
    while (tmp > 0 && chk[3] == 0) {
      switch (tmp % 10) {
      case 3:
        chk[0]++;
        break;
      case 5:
        chk[1]++;
        break;
      case 7:
        chk[2]++;
        if (chk[2] == logi)
          chk7++;
        break;
      default:
        chk[3]++;
        break;
      }
      tmp = (tmp - tmp % 10) / 10;
      logi++;
    }
    if (chk[0] > 0 && chk[1] > 0 && chk[2] > 0 && chk[3] == 0)
      ans++;
    // cout <<i<<" "<<chk[0] <<" "<<chk[1]<<" "<<chk[2]<<" "<<chk[3]<<endl;

    for (j = 1; j < chk7; j++) {
      tmpi *= 10;
    }
    if (chk7 > 0 && chk[3] == 0)
      i += tmpi;
  }

  cout << ans;
}