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

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

int main() {
  int k;
  scanf("%d", &k);
  if (k % 2 == 0) {
    printf("-1");
  } else {
    ll cnt = 0, sum = 0;
    while (true) {
      cnt++;
      sum = sum * 10 + 7;
      if (sum % k == 0) {
        break;
      } else
        sum %= k;
    }
    printf("%lld", cnt);
  }
  return 0;
}


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

int main() {
  int k;
  scanf("%d", &k);
  if (k % 2 == 0 || k % 5 == 0) {
    printf("-1");
  } else {
    ll cnt = 0, sum = 0;
    while (true) {
      cnt++;
      sum = sum * 10 + 7;
      if (sum % k == 0) {
        break;
      } else
        sum %= k;
    }
    printf("%lld", cnt);
  }
  return 0;
}
Problem p02596 (C++)

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

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define all(x) (x).begin(), (x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const int mod = 1e9 + 7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve() {
  ll k;
  cin >> k;
  if (k % 2 == 0)
    cout << -1 << '\n';
  else {
    int cnt = 1;
    ll val = 7;
    while (val % k) {
      val = val * 10 % k;
      val = (val + 7) % k;
      cnt++;
    }
    cout << cnt << '\n';
  }
}

int main() {
  IOS int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}


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

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define all(x) (x).begin(), (x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const int mod = 1e9 + 7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve() {
  ll k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0)
    cout << -1 << '\n';
  else {
    int cnt = 1;
    ll val = 7;
    while (val % k) {
      val = val * 10 % k;
      val = (val + 7) % k;
      cnt++;
    }
    cout << cnt << '\n';
  }
}

int main() {
  IOS int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p02596 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #pragma GCC optimize ("-O3")

using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// const long double PI = 3.14159265358979323846;  /* pi */

int main() {
  // ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int k;
  cin >> k;
  vector<bool> visited(k, false);
  int val = 0;
  int ans = 0;
  for (int i = 0; i < 1e6; i++) {
    ans++;
    val = val * 10 + 7;
    int rem = val % k;
    if (visited[rem])
      break;
    visited[rem] = true;
    if (rem == 0)
      break;
  }
  if (visited[0])
    cout << ans << "\n";
  else
    cout << -1 << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #pragma GCC optimize ("-O3")

using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// const long double PI = 3.14159265358979323846;  /* pi */

int main() {
  // ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int k;
  cin >> k;
  vector<bool> visited(k, false);
  int val = 0;
  int ans = 0;
  for (int i = 0; i < 1e6; i++) {
    ans++;
    val = val * 10 + 7;
    val = val % k;
    int rem = val % k;
    if (visited[rem])
      break;
    visited[rem] = true;
    if (rem == 0)
      break;
  }
  if (visited[0])
    cout << ans << "\n";
  else
    cout << -1 << "\n";
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<ll, pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll now = 7 % k, i = 1;
  while (true) {
    if (now % k == 0) {
      cout << i << endl;
      return 0;
    }
    i++;
    now *= 10;
    now += 7;
    now %= k;
  }
}

Fixed submission:
#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<ll, pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll now = 7 % k, i = 1;
  while (true) {
    if (now % k == 0) {
      cout << i << endl;
      return 0;
    }
    i++;
    now *= 10;
    now += 7;
    now %= k;
  }
}
Problem p02596 (C++)

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

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 1;
  int cur = 7 % k;
  while (cur != 0) {
    cur = 10 * cur + 7;
    cur %= k;
    ++ans;
  }
  cout << ans << endl;
}


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

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 1;
  int cur = 7 % k;
  while (cur != 0) {
    cur = 10 * cur + 7;
    cur %= k;
    ++ans;
    if (ans > 100000000) {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++)

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

int main() {

  unsigned long long N;
  std::cin >> N;

  unsigned long long amari = 0;
  unsigned long long last_amari = 7 % N;
  amari += last_amari;
  int cnt = 1;

  if (N % 2 == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }

  while (amari) {
    last_amari *= 10;
    last_amari %= N;
    amari += last_amari;
    amari %= N;
    cnt++;
  }

  std::cout << cnt << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>

int main() {

  unsigned long long N;
  std::cin >> N;

  unsigned long long amari = 0;
  unsigned long long last_amari = 7 % N;
  amari += last_amari;
  int cnt = 1;

  if (N % 2 == 0 || N % 5 == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }

  while (amari) {
    last_amari *= 10;
    last_amari %= N;
    amari += last_amari;
    amari %= N;
    cnt++;
  }

  std::cout << cnt << std::endl;
  return 0;
}
Problem p02596 (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 reps(i, a, b) for (int i = a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ll k;
  cin >> k;
  vector<ll> vec(k + 1, 0);
  vec.at(1) = 7 % k;
  for (ll i = 2; i <= k + 1; i++) {
    if (vec.at(i - 1) == 0) {
      cout << i - 1 << endl;
      return 0;
    }
    vec.at(i) = (vec.at(i - 1) * 10 + 7) % k;
  }

  cout << -1 << endl;

  return 0;
}

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 reps(i, a, b) for (int i = a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ll k;
  cin >> k;
  vector<ll> vec(k + 2, 0);
  vec.at(1) = 7 % k;
  for (ll i = 2; i <= k + 1; i++) {
    if (vec.at(i - 1) == 0) {
      cout << i - 1 << endl;
      return 0;
    }
    vec.at(i) = (vec.at(i - 1) * 10 + 7) % k;
  }

  cout << -1 << endl;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
// #include"bits/stdc++.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout << "##" << x << "##" << endl
const int INF = (int)2e9 + 9;
const int SIZE = (int)2e5 + 5;
// Brute force answers(BINARY SEARCH) symmetry
// Change perspective
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
  } else {
    int min1 = 0, temp = k;
    while (temp > 0) {
      temp /= 10;
      min1++;
    }
    int ans = 0, pref = 0;
    ll cnt = 7;
    while (1) {
      ans++;
      pref += cnt;
      pref %= k;
      if (pref == 0) {
        break;
      }
      cnt = (cnt * 10) % k;
    }
    cout << ans;
  }
}

Fixed submission:
// #include"bits/stdc++.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout << "##" << x << "##" << endl
const int INF = (int)2e9 + 9;
const int SIZE = (int)2e5 + 5;
// Brute force answers(BINARY SEARCH) symmetry
// Change perspective
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
  } else {
    int min1 = 0, temp = k;
    while (temp > 0) {
      temp /= 10;
      min1++;
    }
    int ans = 0, pref = 0;
    ll cnt = 7;
    while (1) {
      ans++;
      pref += cnt;
      pref %= k;
      if (pref == 0) {
        break;
      }
      cnt = (cnt * 10) % k;
      if (ans >= (int)1e6) {
        ans = -1;
        break;
      }
    }
    cout << ans;
  }
}
Problem p02596 (C++)

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

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

  ll sum = 1;
  int a = 7 % k;
  int tmp = a;
  bool flg = true;
  while (a) {
    a = 10 * a + 7;
    a %= k;
    if (tmp == a) {
      flg = false;
      break;
    }
    sum++;
  }
  if (flg) {
    cout << sum << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

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

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

  ll sum = 1;
  int a = 7 % k;
  int tmp = a;
  bool flg = true;
  while (a) {
    a = 10 * a + 7;
    a %= k;
    if (sum > k) {
      flg = false;
      break;
    }
    sum++;
  }
  if (flg) {
    cout << sum << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}
Problem p02596 (C++)

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

int main() {
  int K;
  cin >> K;
  int L, i = 1;
  int ans = -1;
  if (K % 7 == 0)
    L = 9 * K / 7;
  else
    L = 9 * K;
  if (L % 2 != 0 || L % 5 != 0) {
    int m = 10 % L;
    if (m == 1)
      ans = 1;
    else {
      do {
        m = m * 10 % L;
        i++;
      } while (m != 1);
      ans = i;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int K;
  cin >> K;
  int L, i = 1;
  int ans = -1;
  if (K % 7 == 0)
    L = 9 * K / 7;
  else
    L = 9 * K;
  if (L % 2 != 0 && L % 5 != 0) {
    int m = 10 % L;
    if (m == 1)
      ans = 1;
    else {
      do {
        m = m * 10 % L;
        i++;
      } while (m != 1);
      ans = i;
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

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

  ll n = 1;
  ll S = 7 % K;
  ll d = 7 % K;

  auto start = clock();

  while (S % K != 0) {
    n++;
    d = (d * 10) % K;
    S = (S + d) % K;

    if (((double)clock() - (double)start) / (double)CLOCKS_PER_SEC >= 1.99) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << n << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

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

  ll n = 1;
  ll S = 7 % K;
  ll d = 7 % K;

  auto start = clock();

  while (S % K != 0) {
    n++;
    d = (d * 10) % K;
    S = (S + d) % K;

    if (((double)clock() - (double)start) / (double)CLOCKS_PER_SEC >= 1.9) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << n << endl;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC                                                                     \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  cin.sync_with_stdio(0);
long long num;
long long solve(long long mod) {
  if (mod == 0) {
    return 0;
  }
  return 1 + solve((mod * 10 + 7) % num);
}
int main() {
  cin >> num;
  if (num % 2 == 0) {
    printf("-1\n");
  } else {
    cout << solve(7 % num) + 1 << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC                                                                     \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  cin.sync_with_stdio(0);
long long num;
long long solve(long long mod) {
  if (mod == 0) {
    return 0;
  }
  return 1 + solve((mod * 10 + 7) % num);
}
int main() {
  cin >> num;
  if (num % 2 == 0 || num % 10 == 5) {
    printf("-1\n");
  } else {
    cout << solve(7 % num) + 1 << endl;
  }

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long i = 0, k, n;
int main() {
  cin >> k;
  while (i < 1000000220) {
    i++;
    n = (n * 10 + 7) % k;
    if (n == 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long i = 0, k, n;
int main() {
  cin >> k;
  while (i < 1000000) {
    i++;
    n = (n * 10 + 7) % k;
    if (n == 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
Problem p02596 (C++)

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

#define pb push_back
#define mp make_pair
typedef long long int ll;

void solve() {
  ll k;
  cin >> k;

  ll total = 0;
  for (int i = 1; i <= 1e9; i++) {
    total = (total * 10 + 7) % k;
    if (total == 0) {
      cout << i;
      return;
    }
  }
  cout << -1;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("1input.txt", "r", stdin);
  freopen("1output.txt", "w", stdout);
#endif

  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
    cout << "\n";
  }

  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long int ll;

void solve() {
  ll k;
  cin >> k;

  ll total = 0;
  for (int i = 1; i <= 1e8; i++) {
    total = (total * 10 + 7) % k;
    if (total == 0) {
      cout << i;
      return;
    }
  }
  cout << -1;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("1input.txt", "r", stdin);
  freopen("1output.txt", "w", stdout);
#endif

  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
    cout << "\n";
  }

  return 0;
}
Problem p02596 (C++)

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

int main() {
  int K;
  cin >> K;
  int C = 1;
  int M = 7;
  if (M % K == 0) {
    cout << 1;
  } else if (K % 2 == 0) {
    cout << -1;
  } else {
    M = 77 % K;
    C = 2;
    while (M != 0 && M != (7 % K)) {
      C += 1;
      M = (M * 10 + 7) % K;
    }
    if (M == 0) {
      cout << C;
    } else {
      cout << -1;
    }
  }
}

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

int main() {
  int K;
  cin >> K;
  int C = 1;
  int M = 7;
  if (M % K == 0) {
    cout << 1;
  } else if (K % 2 == 0 || K % 5 == 0) {
    cout << -1;
  } else {
    M = 77 % K;
    C = 2;
    while (M != 0 && M != (7 % K)) {
      C += 1;
      M = (M * 10 + 7) % K;
    }
    if (M == 0) {
      cout << C;
    } else {
      cout << -1;
    }
  }
}
Problem p02596 (C++)

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

int main() {
  int k;
  cin >> k;
  ll ans = 0;
  if (k % 2 == 0)
    cout << -1 << endl;
  else {
    ll num = 7, col = 1;
    while (num % k != 0) {
      ans++;
      num %= k;
      col *= 10;
      col %= k;
      num += 7 * col;
    }
    cout << ans + 1 << endl;
  }
  return 0;
}

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

int main() {
  int k;
  cin >> k;
  ll ans = 0;
  if (k % 2 == 0)
    cout << -1 << endl;
  else if (k % 5 == 0)
    cout << -1 << endl;
  else {
    ll num = 7, col = 1;
    while (num % k != 0) {
      ans++;
      num %= k;
      col *= 10;
      col %= k;
      num += 7 * col;
    }
    cout << ans + 1 << endl;
  }
  return 0;
}
Problem p02596 (C++)

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

using namespace std;
using ll = long long;

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

  ll k;
  cin >> k;

  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  int ans = 1;
  ll r = 7 % k;
  while (r != 0) {
    r = r * 10 + 7;
    r %= k;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

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

  ll k;
  cin >> k;

  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  int ans = 1;
  ll r = 7 % k;
  while (r != 0) {
    r = r * 10 + 7;
    r %= k;
    ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02596 (C++)

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

using namespace std;
typedef long long int ll;

#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1) * 4)
#define pb push_back
#define pi pair<int, int>
#define ff first
#define ss second
#define INF 2000000000
#define delta 0.0000000001
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};
const int Mod = 1000 * 1000 * 1000 + 7;

vll mul_mat(vll a, vll b) {
  vll res(2, vl(2, 0));
  int n = 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        res[i][j] += a[i][k] * b[k][j];
        res[i][j] %= Mod;
      }
    }
  }

  return res;
}

ll powmod(ll a, ll b, ll mod) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
      res %= mod;
    }
    b >>= 1;
    a = a * a;
    a %= mod;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  ll com = 0;
  for (ll i = 0; i <= 5000000; i++) {
    ll f = powmod(2, i, n);
    ll s = powmod(5, i, n);
    ll t = 7;
    com += (f * s * t);
    com %= n;
    if (com == 0) {
      cout << i + 1 << endl;
      return;
    }
  }
  cout << -1 << endl;
}

int main() {
#ifdef _DEBUG
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0); // FAST IO
  int q = 1;
  // cin >> q;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}

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

using namespace std;
typedef long long int ll;

#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1) * 4)
#define pb push_back
#define pi pair<int, int>
#define ff first
#define ss second
#define INF 2000000000
#define delta 0.0000000001
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};
const int Mod = 1000 * 1000 * 1000 + 7;

vll mul_mat(vll a, vll b) {
  vll res(2, vl(2, 0));
  int n = 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        res[i][j] += a[i][k] * b[k][j];
        res[i][j] %= Mod;
      }
    }
  }

  return res;
}

ll powmod(ll a, ll b, ll mod) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
      res %= mod;
    }
    b >>= 1;
    a = a * a;
    a %= mod;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  ll com = 0;
  for (ll i = 0; i <= 2000000; i++) {
    ll f = powmod(2, i, n);
    ll s = powmod(5, i, n);
    ll t = 7;
    com += (f * s * t);
    com %= n;
    if (com == 0) {
      cout << i + 1 << endl;
      return;
    }
  }
  cout << -1 << endl;
}

int main() {
#ifdef _DEBUG
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0); // FAST IO
  int q = 1;
  // cin >> q;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
ll a, b, c, d, e, f, n, T;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a;
  if (a % 2 == 0)
    cout << -1 << endl;
  else {
    b = 7;
    c = 1;
    while (b % a != 0) {
      b %= a;
      b *= 10;
      b += 7;
      c++;
    }
    cout << c << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
ll a, b, c, d, e, f, n, T;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a;
  if (a % 2 == 0 || a % 5 == 0)
    cout << -1 << endl;
  else {
    b = 7;
    c = 1;
    while (b % a != 0) {
      b %= a;
      b *= 10;
      b += 7;
      c++;
    }
    cout << c << endl;
  }
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int, int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int z = 1000000007;
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
int main() {
  int k;
  cin >> k;
  int modk7 = 7 % k;
  int mod_k = 7 % k;
  int ans = 1;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (mod_k == 0)
      break;
    mod_k = (mod_k * 10 + modk7) % k;
    ans++;
  }
  cout << ans << endl;
  ;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int, int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int z = 1000000007;
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
int main() {
  int k;
  cin >> k;
  int modk7 = 7 % k;
  int mod_k = 7 % k;
  int ans = 1;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (ans > 10000000) {
      ans = -1;
      break;
    }
    if (mod_k == 0)
      break;
    mod_k = (mod_k * 10 + modk7) % k;
    ans++;
  }
  cout << ans << endl;
  ;
  return 0;
}
Problem p02596 (C++)

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

using namespace std;

int const NMAX = 1e6;
bool freq[1 + NMAX];

int main() {

  int n, m = 0, ans = 0;
  cin >> n;
  while (freq[m] == false) {
    m = (m * 10 + 7) % n;
    ans++;
    if (m == 0) {
      cout << ans;
      return 0;
    }
  }
  cout << -1;
  return 0;
}


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

using namespace std;

int const NMAX = 1e6;
bool freq[1 + NMAX];

int main() {

  int n, m = 0, ans = 0;
  cin >> n;
  while (freq[m] == false) {
    freq[m] = true;
    m = (m * 10 + 7) % n;
    ans++;
    if (m == 0) {
      cout << ans;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// 　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1000000007;
const ll mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

int cans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

int main() {
  ll ans = 1;
  ll K;
  cin >> K;
  vector<bool> seen(K, false);
  ll mod = 7 % K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (mod == 0) {
      cout << ans << endl;
      return 0;
    } else {
      seen[mod] = true;
      mod = mod * 10 + 7;
      mod %= K;
      ans++;
    }
    // cout << mod << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// 　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1000000007;
const ll mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

int cans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

int main() {
  ll ans = 1;
  ll K;
  cin >> K;
  vector<bool> seen(K, false);
  ll mod = 7 % K;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (mod == 0) {
      cout << ans << endl;
      return 0;
    } else {
      seen[mod] = true;
      mod = mod * 10 + 7;
      mod %= K;
      ans++;
    }
    // cout << mod << endl;
  }

  return 0;
}
Problem p02596 (C++)

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

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

  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  int ans = 1, mod = 7 % k;
  while (true) {
    if (mod == 0) {
      cout << ans << endl;
      return 0;
    }
    mod = (mod * 10 + 7) % k;
    ans++;
  }
}

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

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

  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  int ans = 1, mod = 7 % k;
  while (true) {
    if (mod == 0) {
      cout << ans << endl;
      return 0;
    }
    mod = (mod * 10 + 7) % k;
    ans++;
    if (ans > k) {
      cout << "-1" << endl;
      return 0;
    }
  }
}
Problem p02596 (C++)

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

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (lol i = 0; i < lol(n); i++)
#define REPD(i, n) for (lol i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (lol i = a; i <= lol(b); i++)
#define FORD(i, a, b) for (lol i = a; i >= lol(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) lol(x.size())     // sizeをsize_tからllに直しておく
// 定数
#define PI 3.1415926535897932385 // pi
#define INF 1000000000000        // 10^12:極めて大きい値,∞
#define MOD 1000000007           // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 最大値最小値
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  lol result{0};
  lol k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 1;
  }
  lol l;
  if (k % 7 == 0)
    l = 9 * k / 7;
  else {
    l = 9 * k;
  }
  lol re{1};
  while (true) {
    re = (10 * re) % l;
    result++;
    // cout << re << endl;
    if (re == 1)
      break;
  }

  cout << result << endl;
  return 0;
}

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

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (lol i = 0; i < lol(n); i++)
#define REPD(i, n) for (lol i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (lol i = a; i <= lol(b); i++)
#define FORD(i, a, b) for (lol i = a; i >= lol(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) lol(x.size())     // sizeをsize_tからllに直しておく
// 定数
#define PI 3.1415926535897932385 // pi
#define INF 1000000000000        // 10^12:極めて大きい値,∞
#define MOD 1000000007           // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 最大値最小値
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  lol result{0};
  lol k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    result = -1;
  } else {
    lol l;
    if (k % 7 == 0)
      l = 9 * k / 7;
    else {
      l = 9 * k;
    }
    lol re{1};
    while (true) {
      re = (10 * re) % l;
      result++;
      // cout << re << endl;
      if (re == 1)
        break;
    }
  }

  cout << result << endl;
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
//*s.find_by_order(p)   returns the value of pth largest starting from 0
// s.order_of_key(p)   returns no. of items that are strictly < p
// string bin = bitset<64>(m).to_string();     convert decimal m to binary
int main() {
  fast;
  ll t;
  t = 1;
  while (t--) {
    ll k, a, p;
    cin >> k;
    if (k == 1) {
      cout << "1\n";
      continue;
    }
    if (k % 2 == 0) {
      cout << "-1\n";
      continue;
    }
    a = 7;
    p = 1;
    while (1) {
      a = a % k;
      if (a == 0) {
        cout << p << "\n";
        break;
      }
      p++;
      a = 10 * a + 7;
      // if(p>100000){break;}
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
//*s.find_by_order(p)   returns the value of pth largest starting from 0
// s.order_of_key(p)   returns no. of items that are strictly < p
// string bin = bitset<64>(m).to_string();     convert decimal m to binary
int main() {
  fast;
  ll t;
  t = 1;
  while (t--) {
    ll k, a, p;
    cin >> k;
    if (k == 1) {
      cout << "1\n";
      continue;
    }
    if (k % 2 == 0 || k % 5 == 0) {
      cout << "-1\n";
      continue;
    }
    a = 7;
    p = 1;
    while (1) {
      a = a % k;
      if (a == 0) {
        cout << p << "\n";
        break;
      }
      p++;
      a = 10 * a + 7;
      // if(p>100000){break;}
    }
  }
}
Problem p02596 (Python)

Buggy submission (status: Runtime Error):
k = int(input())
if k % 7 == 0:
    L = 9 * k / 7
else:
    L = 9 * k
out = -1
s = 10
for i in range(L):
    if s % L == 1:
        out = i + 1
        break
    else:
        s = (s % L) * 10
print(out)


Fixed submission:
k = int(input())
if k % 7 == 0:
    L = 9 * k // 7
else:
    L = 9 * k
out = -1
s = 10
for i in range(L):
    if s % L == 1:
        out = i + 1
        break
    else:
        s = (s % L) * 10
print(out)
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
// #define mp              make_pair
#define pii pair<int, int>
#define vec vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define no_of_test(x)                                                          \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)

const int mod = 1e9 + 7;
void very_fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int binary_exponentation(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ret;
}
int32_t main() {
  very_fast();
  // no_of_test(x)
  {
    int n;
    cin >> n;
    if (n % 2 == 0) {
      cout << -1 << endl;
      return 0;
    }
    int m = 0;
    for (int i = 1; 1 <= 1e7; i++) {
      m = (m * 10 + 7) % n;
      if (m == 0) {
        cout << i << endl;
        return 0;
        // break;
      }
    }
    cout << -1 << endl;
    return 0;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
// #define mp              make_pair
#define pii pair<int, int>
#define vec vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define no_of_test(x)                                                          \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)

const int mod = 1e9 + 7;
void very_fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int binary_exponentation(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ret;
}
int32_t main() {
  very_fast();
  // no_of_test(x)
  {
    int n;
    cin >> n;
    if (n % 2 == 0) {
      cout << -1 << endl;
      return 0;
    }
    int m = 0;
    for (int i = 1; i <= 1e7; i++) {
      m = (m * 10 + 7) % n;
      if (m == 0) {
        cout << i << endl;
        return 0;
        // break;
      }
    }
    cout << -1 << endl;
    return 0;
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define en end()
#define pb push_back
#define w(x)                                                                   \
  scanf("%d", &x);                                                             \
  while (x--)
#define ws(x)                                                                  \
  scanf("%d", &x);                                                             \
  getchar();                                                                   \
  while (x--)
#define rep(i, b) for (i = 0; i <= b; i++)
#define ios                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pi 2 * acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int N = 1e6 + 2;
long long mod = 1e9 + 9;
int t, j, cs = 0, n, b, i, a;
string s;

int main() {
  ios scanf("%d", &n);
  int a = 0, cnt = 0;
  while (a < n) {
    a = 10 * a + 7;
    cnt++;
  }

  if (n % 2 == 0) {
    printf("-1\n");
    return 0;
  }
  while (a % n != 0) {
    a = a % n;
    a = a * 10 + 7;
    cnt++;

    // cout<<a<<endl;
  }
  printf("%d\n", cnt);
}


Fixed submission:
#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define en end()
#define pb push_back
#define w(x)                                                                   \
  scanf("%d", &x);                                                             \
  while (x--)
#define ws(x)                                                                  \
  scanf("%d", &x);                                                             \
  getchar();                                                                   \
  while (x--)
#define rep(i, b) for (i = 0; i <= b; i++)
#define ios                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pi 2 * acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int N = 1e6 + 2;
long long mod = 1e9 + 9;
int t, j, cs = 0, n, b, i, a;
string s;

int main() {
  ios scanf("%d", &n);
  int a = 0, cnt = 0;
  while (a < n) {
    a = 10 * a + 7;
    cnt++;
  }

  if (n % 2 == 0 || n % 5 == 0) {
    printf("-1\n");
    return 0;
  }
  while (a % n != 0) {
    a = a % n;
    a = a * 10 + 7;
    cnt++;

    // cout<<a<<endl;
  }
  printf("%d\n", cnt);
}
Problem p02596 (Python)

Buggy submission (status: Time Limit Exceeded):
K = int(input())
if K % 2 == 0:
    print(-1)
else:
    mod, modt, ans = 7 % K, 7 % K, 1
    while mod != 0:
        modt = (modt * (10 % K)) % K
        mod, ans = (mod + modt) % K, ans + 1
    print(ans)


Fixed submission:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    mod, modt, ans = 7 % K, 7 % K, 1
    while mod != 0:
        modt = (modt * (10 % K)) % K
        mod, ans = (mod + modt) % K, ans + 1
    print(ans)
Problem p02596 (Python)

Buggy submission (status: Time Limit Exceeded):
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
now = 0
count = 0
while True:
    now = now * 10 + 7
    count += 1
    if now % K == 0:
        print(count)
        exit()


Fixed submission:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
now = 0
count = 0
while True:
    now = (now * 10 + 7) % K
    count += 1
    if now % K == 0:
        print(count)
        exit()
Problem p02596 (C++)

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

using namespace std;

void fastio() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;

int main() {
  fastio();

  LL k;
  cin >> k;

  LL low = k % 10;

  if (low == 2 || low == 4 || low == 5 || low == 6 || low == 8) {
    cout << -1 << "\n";
    return 0;
  }

  LL mod = 7 % k, c = 1;
  while (mod != 0) {
    mod = ((mod * 10) + 7) % k;
    c++;
  }
  cout << c << "\n";
}

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

using namespace std;

void fastio() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;

int main() {
  fastio();

  LL k;
  cin >> k;

  LL low = k % 10;

  if (low == 2 || low == 4 || low == 5 || low == 6 || low == 8 || low == 0) {
    cout << -1 << "\n";
    return 0;
  }

  LL mod = 7 % k, c = 1;
  while (mod != 0) {
    mod = ((mod * 10) + 7) % k;
    c++;
  }
  cout << c << "\n";
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define LLU long long unsigned
#define rarr(arr, n)                                                           \
  for (int aab = 0; aab < n; aab++) {                                          \
    cin >> arr[aab];                                                           \
  }
#define parr(arr, n)                                                           \
  for (int aab = 0; aab < n; aab++) {                                          \
    cout << arr[aab] << " ";                                                   \
  }
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen                                                                \
  freopen("in.txt", "r", stdin);                                               \
  freopen("out.txt", "w", stdout);                                             \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);

int main() {
  long long int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1;
  } else {
    long long int ans = 1, number = 7;
    while (1) {
      if (number % n == 0) {
        cout << ans;
        return 0;
      }
      ans++;
      number = (number * 10 + 7) % n;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define LLU long long unsigned
#define rarr(arr, n)                                                           \
  for (int aab = 0; aab < n; aab++) {                                          \
    cin >> arr[aab];                                                           \
  }
#define parr(arr, n)                                                           \
  for (int aab = 0; aab < n; aab++) {                                          \
    cout << arr[aab] << " ";                                                   \
  }
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen                                                                \
  freopen("in.txt", "r", stdin);                                               \
  freopen("out.txt", "w", stdout);                                             \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);

int main() {
  long long int n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1;
  } else {
    long long int ans = 1, number = 7;
    while (1) {
      if (number % n == 0) {
        cout << ans;
        return 0;
      }
      ans++;
      number = (number * 10 + 7) % n;
    }
  }
}