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

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

int main() {
  int k, L;
  cin >> k;
  if (k % 7 == 0)
    k /= 7;
  L = 9 * k;

  if (L == 2 || L == 5) {
    cout << -1 << '\n';
    return 0;
  }

  int tmp = 10, cnt = 1;
  while (1) {
    if (tmp % L == 1) {
      cout << cnt << '\n';
      return 0;
    }
    tmp %= L;
    tmp *= 10;
    cnt++;
  }
}


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

int main() {
  int k, L;
  cin >> k;
  if (k % 7 == 0)
    k /= 7;
  L = 9 * k;

  if (L % 2 == 0 || L % 5 == 0) {
    cout << -1 << '\n';
    return 0;
  }

  int tmp = 10, cnt = 1;
  while (1) {
    if (tmp % L == 1) {
      cout << cnt << '\n';
      return 0;
    }
    tmp %= L;
    tmp *= 10;
    cnt++;
  }
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long k;
  cin >> k;
  long long tmp = 7 % k;
  set<int> s;
  s.insert(7);
  if (tmp == 0) {
    cout << 1 << endl;
    return 0;
  }
  s.insert(tmp);
  for (long long i = 2;; i++) {
    tmp = ((tmp * 10) % k + 7 % k) % k;
    if (tmp == 0) {
      cout << i << endl;
      return 0;
    }

    if (s.find(tmp) != s.end()) {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long k;
  cin >> k;
  long long tmp = 7 % k;
  set<int> s;
  s.insert(7);
  if (tmp == 0) {
    cout << 1 << endl;
    return 0;
  }
  s.insert(tmp);
  for (long long i = 2;; i++) {
    tmp = ((tmp * 10) % k + 7 % k) % k;
    if (tmp == 0) {
      cout << i << endl;
      return 0;
    }

    if (s.find(tmp) != s.end()) {
      cout << -1 << endl;
      return 0;
    }
    s.insert(tmp);
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX >> 2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i, a, n, x) for ((i) = (a); (i) < (n); (i) += (x))
#define fd(i, a, n, x) for ((i) = (a); (i) >= (n); (i) -= (x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a, ll n) {
  ll i, temp;
  f(i, 0, n, 1) {
    cin >> temp;
    a.pb(temp);
  }
}
ll fa[MAX];
ll power(ll p, ll q) {
  ll res = 1;
  p %= mod;
  while (q) {
    if (q & 1)
      res = (res * p) % mod;
    q >>= 1;
    p = (p * p) % mod;
  }
  return res;
}
ll fact(ll n) {
  if (n <= 1)
    return fa[n] = 1;
  if (fa[n])
    return fa[n];
  return fa[n] = (n * fact(n - 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (!r)
    return 1;
  return (((fact(n) * power(fact(n - r), mod - 2)) % mod) *
          power(fact(r), mod - 2)) %
         mod;
}
void solve() {
  ll n = 7, k, count = 1;
  cin >> k;
  while (count <= 100000000) {
    if (!(n % k)) {
      cout << count << endl;
      return;
    }
    n = (((n % k) * 10) % k + 7) % k;
    count++;
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX >> 2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i, a, n, x) for ((i) = (a); (i) < (n); (i) += (x))
#define fd(i, a, n, x) for ((i) = (a); (i) >= (n); (i) -= (x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a, ll n) {
  ll i, temp;
  f(i, 0, n, 1) {
    cin >> temp;
    a.pb(temp);
  }
}
ll fa[MAX];
ll power(ll p, ll q) {
  ll res = 1;
  p %= mod;
  while (q) {
    if (q & 1)
      res = (res * p) % mod;
    q >>= 1;
    p = (p * p) % mod;
  }
  return res;
}
ll fact(ll n) {
  if (n <= 1)
    return fa[n] = 1;
  if (fa[n])
    return fa[n];
  return fa[n] = (n * fact(n - 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (!r)
    return 1;
  return (((fact(n) * power(fact(n - r), mod - 2)) % mod) *
          power(fact(r), mod - 2)) %
         mod;
}
void solve() {
  ll n = 7, k, count = 1;
  cin >> k;
  while (count <= 10000000) {
    if (!(n % k)) {
      cout << count << endl;
      return;
    }
    n = (((n % k) * 10) % k + 7) % k;
    count++;
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p02596 (C++)

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

using namespace std;
using ull = unsigned long long;
using ll = long long;

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

  ll a = 7 % k;
  ll b = 7;
  if (a == 0) {
    cout << 1 << endl;
    return 0;
  }
  if (b % 2 == 0 || b % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int n = 2;; n++) {
    b = (b * 10) % k;
    a = (a + b) % k;
    if (a == 0) {
      cout << n << endl;
      break;
    }
  }
}

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

using namespace std;
using ull = unsigned long long;
using ll = long long;

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

  ll a = 7 % k;
  ll b = 7;
  if (a == 0) {
    cout << 1 << endl;
    return 0;
  }
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int n = 2;; n++) {
    b = (b * 10) % k;
    a = (a + b) % k;
    if (a == 0) {
      cout << n << endl;
      break;
    }
  }
}
Problem p02596 (C++)

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

using namespace std;

int main() {
  ll n, x = 7, ans = 1;
  cin >> n;
  if ((n % 2) == 0) {
    cout << "-1\n";
    return 0;
  }
  while (true) {
    if ((x % n) == 0) {
      cout << ans << '\n';
      return 0;
    }
    x *= 10;
    x += 7;
    x %= n;
    ans++;
  }
}

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

using namespace std;

int main() {
  ll n, x = 7, ans = 1;
  cin >> n;
  if ((n % 2) == 0) {
    cout << "-1\n";
    return 0;
  }
  while (true) {
    if ((x % n) == 0) {
      cout << ans << '\n';
      return 0;
    }
    x *= 10;
    x += 7;
    x %= n;
    ans++;
    if (ans > 1000001) {
      cout << -1 << '\n';
      return 0;
    }
  }
}
Problem p02596 (C++)

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

#define ll long long
#define rep(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////

ll K;

ll i, j, k;

int main() {
  scanf("%lld", &K);
  if (K % 2 == 0) {
    printf("-1\n");
    return 0;
  }
  i = 0;
  do {
    (k = k * 10 + 7) %= K;
    ++i;
  } while (k);
  printf("%lld\n", i);
  return 0;
}

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

#define ll long long
#define rep(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////

ll K;

ll i, j, k;

int main() {
  scanf("%lld", &K);
  if (K % 2 == 0 || K % 5 == 0) {
    printf("-1\n");
    return 0;
  }
  i = 0;
  do {
    (k = k * 10 + 7) %= K;
    ++i;
  } while (k);
  printf("%lld\n", i);
  return 0;
}
Problem p02596 (C++)

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

namespace __temp_inbuilt {
int read(void) {
  int res = 0, sign = 1;
  char ch = std::getchar();
  while (!std::isdigit(ch)) {
    if (ch == '-')
      sign = -1;
    ch = std::getchar();
  }
  while (std::isdigit(ch))
    res = res * 10 + ch - 48, ch = std::getchar();
  return sign * res;
}

template <class Tp> void write(const Tp &x) {
  if (x > 9)
    write(x / 10);
  std::putchar(x % 10 + 48);
}
} // namespace __temp_inbuilt

using __temp_inbuilt::read;

template <class Tp> void writeln(const Tp &x) {
  if (x < 0)
    std::putchar('-');
  __temp_inbuilt::write(x > 0 ? x : -x);
  std::putchar('\n');
}

template <class Tp> void writesp(const Tp &x) {
  if (x < 0)
    std::putchar('-');
  __temp_inbuilt::write(x > 0 ? x : -x);
  std::putchar(' ');
}

template <class Tp> void write(const Tp &x) {
  if (x < 0)
    std::putchar('-');
  __temp_inbuilt::write(x > 0 ? x : -x);
}

typedef long long ll;
typedef unsigned long long ull;
typedef double rl;
typedef long double RL;

const rl PI = 3.1415926535898, E = 2.71828182845904;

namespace contest {
int k;

int main() {
  k = read();
  int mod = 7 % k, ans = 1;
  if (!mod) {
    writeln(ans);
    return 0;
  }
  while (mod) {
    ++ans;
    mod = (mod * 10 + 7) % k;
    if (mod == 7 % k) {
      writeln(-1);
      return 0;
    }
  }
  writeln(ans);
  return 0;
  return 0;
}
} // namespace contest

int main() {
  contest::main();
  return 0;
}

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

namespace __temp_inbuilt {
int read(void) {
  int res = 0, sign = 1;
  char ch = std::getchar();
  while (!std::isdigit(ch)) {
    if (ch == '-')
      sign = -1;
    ch = std::getchar();
  }
  while (std::isdigit(ch))
    res = res * 10 + ch - 48, ch = std::getchar();
  return sign * res;
}

template <class Tp> void write(const Tp &x) {
  if (x > 9)
    write(x / 10);
  std::putchar(x % 10 + 48);
}
} // namespace __temp_inbuilt

using __temp_inbuilt::read;

template <class Tp> void writeln(const Tp &x) {
  if (x < 0)
    std::putchar('-');
  __temp_inbuilt::write(x > 0 ? x : -x);
  std::putchar('\n');
}

template <class Tp> void writesp(const Tp &x) {
  if (x < 0)
    std::putchar('-');
  __temp_inbuilt::write(x > 0 ? x : -x);
  std::putchar(' ');
}

template <class Tp> void write(const Tp &x) {
  if (x < 0)
    std::putchar('-');
  __temp_inbuilt::write(x > 0 ? x : -x);
}

typedef long long ll;
typedef unsigned long long ull;
typedef double rl;
typedef long double RL;

const rl PI = 3.1415926535898, E = 2.71828182845904;

namespace contest {
int k;

int main() {
  k = read();
  int mod = 7 % k, ans = 1;
  if (!mod) {
    writeln(ans);
    return 0;
  }
  while (mod) {
    ++ans;
    mod = (mod * 10 + 7) % k;
    if (mod == 7 % k || ans >= 3e7) {
      writeln(-1);
      return 0;
    }
  }
  writeln(ans);
  return 0;
  return 0;
}
} // namespace contest

int main() {
  contest::main();
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
  ll K, sev = 0, rep = 0;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  while (sev <= K) {
    sev = sev * 10 + 7;
    sev = sev % K;
    rep++;
    if (sev == 0) {
      cout << rep << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
  ll K, sev = 0, rep = 0;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  while (rep <= K) {
    sev = sev * 10 + 7;
    sev = sev % K;
    rep++;
    if (sev == 0) {
      cout << rep << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type)                                          \
  memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353LL;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {
#ifdef ONLINE
  printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
  system("pause");
#endif
}
ll k;
ll ans;
ll now;

void solve() {
  cin >> k;
  if (k % 2 == 0)
    return puts("-1"), void();
  ans = 1, now = 7;
  while (1) {
    if (now % k == 0)
      break;
    ans++;
    now = (now * 10) + 7;
    now %= k;
  }
  printf("%lld\n", ans);
}

int main() {
  TIME__START = clock();
  int Test = 1;
  // scanf("%d", &Test);
  while (Test--)
    solve();
  TIME__END = clock();
  program_end();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type)                                          \
  memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353LL;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {
#ifdef ONLINE
  printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
  system("pause");
#endif
}
ll k;
ll ans;
ll now;

void solve() {
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0)
    return puts("-1"), void();
  ans = 1, now = 7;
  while (1) {
    if (now % k == 0)
      break;
    ans++;
    now = (now * 10) + 7;
    now %= k;
  }
  printf("%lld\n", ans);
}

int main() {
  TIME__START = clock();
  int Test = 1;
  // scanf("%d", &Test);
  while (Test--)
    solve();
  TIME__END = clock();
  program_end();
  return 0;
}
Problem p02596 (C++)

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

using namespace std;

template <typename T> long long modpow(const T n, const T p, const T mod);
template <typename T> long long modinv(const T n, const T mod);
template <typename T> bool chmax(T &a, const T &b);
template <typename T> bool chmin(T &a, const T &b);

long long inf = 1000000007;

int main() {
  long long k;
  cin >> k;
  long long ans = 0;
  long long hoge = 0;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  while (true) {
    ans++;
    hoge *= 10;
    hoge += 7;
    if (hoge % k == 0) {
      cout << ans << endl;
      return 0;
    }
    hoge %= k;
  }

  return 0;
}

template <typename T> long long modpow(const T n, const T p, const T mod) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    long long a = modpow(n, p / 2, mod);
    return a * a % mod;
  }
  if (p % 2 == 1)
    return (modpow(n, p - 1, mod) * n) % mod;
  cerr << "ERROR" << endl;
  return 1;
}

template <typename T> long long modinv(const T n, const T mod) {
  return modpow(n, mod - 2, mod);
}

template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}


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

using namespace std;

template <typename T> long long modpow(const T n, const T p, const T mod);
template <typename T> long long modinv(const T n, const T mod);
template <typename T> bool chmax(T &a, const T &b);
template <typename T> bool chmin(T &a, const T &b);

long long inf = 1000000007;

int main() {
  long long k;
  cin >> k;
  long long ans = 0;
  long long hoge = 0;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  while (true) {
    ans++;
    hoge *= 10;
    hoge += 7;
    if (hoge % k == 0) {
      cout << ans << endl;
      return 0;
    }
    hoge %= k;

    if (ans >= 1000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  return 0;
}

template <typename T> long long modpow(const T n, const T p, const T mod) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    long long a = modpow(n, p / 2, mod);
    return a * a % mod;
  }
  if (p % 2 == 1)
    return (modpow(n, p - 1, mod) * n) % mod;
  cerr << "ERROR" << endl;
  return 1;
}

template <typename T> long long modinv(const T n, const T mod) {
  return modpow(n, mod - 2, mod);
}

template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << "\n";
    return 0;
  }
  int now = 0;
  for (int i = 1; i <= 1e8; i++) {
    now = (10 * now + 7) % K;
    if (now == 0) {
      cout << i << "\n";
      return 0;
    }
  }
  assert(false);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << "\n";
    return 0;
  }
  int now = 0;
  for (int i = 1; i <= 1e8; i++) {
    now = (10 * now + 7) % K;
    if (now == 0) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main() {
  int K;
  cin >> K;

  int ans = 0;
  ll ct = 7;
  ll md = 0;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    md += ct % K;
    ct *= 10;
    ct %= K;
    ans++;
    if (md % K == 0)
      break;
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main() {
  int K;
  cin >> K;

  int ans = 0;
  ll ct = 7;
  ll md = 0;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    md += ct % K;
    ct *= 10;
    ct %= K;
    ans++;
    if (md % K == 0)
      break;
    if (ans >= 1e7) {
      ans = -1;
      break;
    }
  }

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

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

#define ll long long int
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vl>
#define vvi vector<vi>
#define pb push_back
#define P pair<ll, ll>
#define mp make_pair
#define F first
#define S second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Sort(v) sort(v.begin(), v.end())
#define all(v) v.begin(), v.end()

ll mo = 1000000007;
ll MO = 998244353;

ll modpower(ll a, ll b, ll mod) {
  ll ans = 1;
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 1) {
    ans = a;
  }
  ll x = modpower(a, b / 2, mod) % mod;
  ans *= (x * x) % mod;
  ans %= mod;
  return ans;
}

void pri(vl a) {
  for (auto i : a)
    cout << i << " ";
  cout << endl;
}

//-------------------------------------------------------------------------------

void solve() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
    return;
  }
  ll ans = 1, val = 7;
  int x;
  while (val % n != 0) {
    // cout<<val<<endl;
    val %= n;
    val = (val * 10 + 7);
    ans++;
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int nt = 1;
  // cin>>nt;
  while (nt--) {
    solve();
  }
  return 0;
}

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

#define ll long long int
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vl>
#define vvi vector<vi>
#define pb push_back
#define P pair<ll, ll>
#define mp make_pair
#define F first
#define S second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Sort(v) sort(v.begin(), v.end())
#define all(v) v.begin(), v.end()

ll mo = 1000000007;
ll MO = 998244353;

ll modpower(ll a, ll b, ll mod) {
  ll ans = 1;
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 1) {
    ans = a;
  }
  ll x = modpower(a, b / 2, mod) % mod;
  ans *= (x * x) % mod;
  ans %= mod;
  return ans;
}

void pri(vl a) {
  for (auto i : a)
    cout << i << " ";
  cout << endl;
}

//-------------------------------------------------------------------------------

void solve() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
    return;
  }
  ll ans = 1, val = 7;
  int x;
  while (val % n != 0) {
    // cout<<val<<endl;
    val %= n;
    val = (val * 10 + 7);
    ans++;
    if (ans > n) {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int nt = 1;
  // cin>>nt;
  while (nt--) {
    solve();
  }
  return 0;
}
Problem p02596 (C++)

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

long long modAdd(long long a, long long b, long long mod) {
  return ((a % mod) + (b % mod)) % mod;
}

long long modSub(long long a, long long b, long long mod) {
  long long c = ((a % mod) - (b % mod)) % mod;
  return ((c < 0) ? c + mod : c);
}
long long modMul(long long a, long long b, long long mod) {
  return ((a % mod) * (b % mod)) % mod;
}

long long modPow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res = modMul(res, a, mod);
    }
    a = modMul(a, a, mod);
    n >>= 1;
  }
  return res;
}

long long modDiv(long long a, long long b, long long mod) {
  return modMul(a, modPow(b, mod - 2, mod), mod);
}

long long modCombination(long long n, long long r, long long mod) {
  if (r > n / 2)
    return modCombination(n, n - r, mod);
  long long res = 1;
  for (long long i = 1; i <= r; i++) {
    res = modMul(res, n - i + 1, mod);
    res = modDiv(res, i, mod);
  }
  return res;
}

int main() {
  long long k;
  cin >> k;
  vector<long long> m;
  int n = 0;
  m.push_back(7);
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    while (true) {
      if (m[n] % k == 0)
        break;
      m.push_back(modAdd(m[n], modMul(7, modPow(10, n + 1, k), k), k));
      n++;
    }
    cout << n + 1 << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

long long modAdd(long long a, long long b, long long mod) {
  return ((a % mod) + (b % mod)) % mod;
}

long long modSub(long long a, long long b, long long mod) {
  long long c = ((a % mod) - (b % mod)) % mod;
  return ((c < 0) ? c + mod : c);
}
long long modMul(long long a, long long b, long long mod) {
  return ((a % mod) * (b % mod)) % mod;
}

long long modPow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res = modMul(res, a, mod);
    }
    a = modMul(a, a, mod);
    n >>= 1;
  }
  return res;
}

long long modDiv(long long a, long long b, long long mod) {
  return modMul(a, modPow(b, mod - 2, mod), mod);
}

long long modCombination(long long n, long long r, long long mod) {
  if (r > n / 2)
    return modCombination(n, n - r, mod);
  long long res = 1;
  for (long long i = 1; i <= r; i++) {
    res = modMul(res, n - i + 1, mod);
    res = modDiv(res, i, mod);
  }
  return res;
}

int main() {
  long long k;
  cin >> k;
  vector<long long> m;
  int n = 0;
  m.push_back(7);
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    while (true) {
      if (m[n] % k == 0)
        break;
      m.push_back(modAdd(m[n], modMul(7, modPow(10, n + 1, k), k), k));
      n++;
      if (n >= 1000000)
        n = -2;
    }
    cout << n + 1 << endl;
  }
  return 0;
}
Problem p02596 (C++)

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

#define sws                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define fo(i, n) for (int i = 0; i < n; i++)

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;

ll eleva(ll x, int y, int mod) {
  ll res = 1;

  while (y) {
    if (y & 1) {
      res = (res * x) % mod;
    }

    y >>= 1;
    x = (x * x) % mod;
  }

  return res;
}

int main() {
  sws;

  ll k;
  cin >> k;

  if (!(k & 1)) {
    cout << "-1\n";
    return 0;
  }

  int resto = 7 % k;
  int cont = 1;
  while (resto != 0) {
    resto = (resto + ((7 * eleva(10, cont, k)) % k)) % k;
    // cout << resto << endl;
    cont++;
  }

  cout << cont << endl;

  return 0;
}

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

#define sws                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define fo(i, n) for (int i = 0; i < n; i++)

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;

ll eleva(ll x, int y, int mod) {
  ll res = 1;

  while (y) {
    if (y & 1) {
      res = (res * x) % mod;
    }

    y >>= 1;
    x = (x * x) % mod;
  }

  return res;
}

int main() {
  sws;

  ll k;
  cin >> k;

  if (!(k & 1) or (k % 5 == 0)) {
    cout << "-1\n";
    return 0;
  }

  int resto = 7 % k;
  int cont = 1;
  while (resto != 0) {
    resto = (resto + ((7 * eleva(10, cont, k)) % k)) % k;
    // cout << resto << endl;
    cont++;
  }

  cout << cont << endl;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {

  long long int K, amari = 0, ba;

  std::cin >> K;

  if (K % 2 == 0) {
    cout << -1;
  } else {
    long long int i = 0;
    while (1) {
      i++;
      ba = amari;
      amari = (amari * 10 + 7) % K;
      if (amari == 0) {
        cout << i << endl;
        break;
      }
      if (amari == ba) {
        cout << -1 << endl;
        break;
      }
    }
  }

  return 0;
}

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

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

int main() {

  long long int K, amari = 0, ba;

  std::cin >> K;

  if (K % 2 == 0) {
    cout << -1;
  } else {
    long long int i = 0;
    while (1) {
      i++;
      ba = amari;
      amari = (amari * 10 + 7) % K;
      if (amari == 0) {
        cout << i << endl;
        break;
      }
      if (amari == ba) {
        cout << -1 << endl;
        break;
      }
      if (i > K + 10) {
        cout << -1 << endl;
        break;
      }
    }
  }

  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 MOD 1e9 + 7;
using namespace std;
using ll = long long;

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

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

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

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

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


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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath>
#include <cstdlib> // abs(int)
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define roundup(n, d) (((n) + ((d)-1)) / (d))
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define FAST_IO                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(), v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;

int main(void) {
  FAST_IO
  ll k;
  cin >> k;

  ll count = 1;
  ll n = 7;
  if (k % 2 == 0 && k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  while (n % k > 0) {
    n = (n * 10 + 7) % k;
    count++;
  }
  cout << count << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath>
#include <cstdlib> // abs(int)
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define roundup(n, d) (((n) + ((d)-1)) / (d))
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define FAST_IO                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(), v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;

int main(void) {
  FAST_IO
  ll k;
  cin >> k;

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

  while (n % k > 0) {
    n = (n * 10 + 7) % k;
    count++;
  }
  cout << count << endl;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORa(i, a, b) for (int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a, n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define UP(s) transform(s.begin(), s.end(), s.begin(), ::toupper)

//-------------------------------------------------------//

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

  if (k == 2 || k == 5)
    cout << "-1" << endl;
  else {
    int a = 1, b = 7 % k;
    while (b != 0) {
      b = (b * 10 + 7) % k;
      a++;
    }

    cout << a << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORa(i, a, b) for (int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a, n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define UP(s) transform(s.begin(), s.end(), s.begin(), ::toupper)

//-------------------------------------------------------//

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

  if (k % 2 == 0 || k % 5 == 0)
    cout << "-1" << endl;
  else {
    int a = 1, b = 7 % k;
    while (b != 0) {
      b = (b * 10 + 7) % k;
      a++;
    }

    cout << a << endl;
  }

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
// const int N = ;
int k;
int main() {
  cin >> k;
  if (k % 2 == 0)
    puts("-1");
  else {
    int x = 7, ans = 1;
    x %= k;
    while (x != 0) {
      x = (x * 10 + 7) % k;
      ans++;
    }
    cout << ans;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// const int N = ;
int k;
int main() {
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0)
    puts("-1");
  else {
    int x = 7, ans = 1;
    x %= k;
    while (x != 0) {
      x = (x * 10 + 7) % k;
      ans++;
    }
    cout << ans;
  }
  return 0;
}
Problem p02596 (C++)

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

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

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

  unsigned int i = 0;
  unsigned int ai = 0;
  while (true) {
    i++;
    ai = ai * 10 + 7;
    if (ai % K == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


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

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

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

  unsigned int i = 0;
  unsigned int ai = 0;
  while (true) {
    i++;
    ai = (ai * 10 + 7) % K;
    if (ai == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
Problem p02596 (C++)

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

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

  ll tmpk = k, rank = 0;

  while (tmpk) {
    tmpk /= 10;
    rank++;
  }

  ll ans = 1;
  if (k % 2 == 0 && k / 2 > 0) {
    ans = -1;
  } else {
    ll sevens = 7;
    for (int i = 1; i < rank; i++) {
      sevens *= 10;
      sevens += 7;
      ans++;
    }
    ll amari = sevens % k;
    while (amari) {
      amari %= k;
      if (amari == 0)
        break;
      ans++;
      amari *= 10;
      amari += 7;
      if (ans >= 1000000000) {
        ans = -1;
        break;
      }
    }
  }

  cout << ans << endl;
}

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

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

  ll tmpk = k, rank = 0;

  while (tmpk) {
    tmpk /= 10;
    rank++;
  }

  ll ans = 1;
  if (k % 2 == 0 && k / 2 > 0) {
    ans = -1;
  } else {
    ll sevens = 7;
    for (int i = 1; i < rank; i++) {
      sevens *= 10;
      sevens += 7;
      ans++;
    }
    ll amari = sevens % k;
    while (amari) {
      amari %= k;
      if (amari == 0)
        break;
      ans++;
      amari *= 10;
      amari += 7;
      if (ans >= 100000000) {
        ans = -1;
        break;
      }
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  ll ans = 1, num = 7;
  while (num % k != 0) {
    num = (10 * num + 7) % k;
    ans++;
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = (a); i < (b); i++)
#define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n)-1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (a)-1; i >= (b); i--)
#define rrep4(i, a, b, c) for (ll i = (a)-1; i >= (b); i -= (c))
#define rrep(...)                                                              \
  overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
const ll INF = 1e18, MOD = 1e9 + 7;
const int iINF = 1e9;

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

  int seven = 7, k, ans = 1;
  cin >> k;
  if (k % 2 == 0) {
    ans = -1;
  } else {
    while (true) {
      if (seven % k == 0)
        break;
      seven = seven % k;
      seven = seven * 10 + 7;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = (a); i < (b); i++)
#define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n)-1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (a)-1; i >= (b); i--)
#define rrep4(i, a, b, c) for (ll i = (a)-1; i >= (b); i -= (c))
#define rrep(...)                                                              \
  overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
const ll INF = 1e18, MOD = 1e9 + 7;
const int iINF = 1e9;

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

  int seven = 7, k, ans = 1;
  cin >> k;
  if (k % 2 == 0) {
    ans = -1;
  } else {
    while (true) {
      if (seven % k == 0)
        break;
      if (ans > 1e7) {
        ans = -1;
        break;
      }
      seven = seven % k;
      seven = seven * 10 + 7;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02596 (C++)

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

#define ll long long
#define pb push_back
#define endl '\n'
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define hell 1000000007
#define INF (1ll << 60)
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define time                                                                   \
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N = 100005;
void solve() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1" << endl;
    return;
  }
  ll ans = 1;
  ll temp = 7;
  while (temp % n != 0) {
    temp = (temp * 10 + 7) % n;
    ans++;
  }
  cout << ans << endl;
}
signed main() {
  ios int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--) {
    solve();
  }
  // time
  return 0;
}

Fixed submission:
// Patwari26
// #include template<t> as mine
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define endl '\n'
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define hell 1000000007
#define INF (1ll << 60)
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define time                                                                   \
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N = 100005;
void solve() {
  ll n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << "-1" << endl;
    return;
  }
  ll ans = 1;
  ll temp = 7;
  while (temp % n != 0) {
    temp = (temp * 10 + 7) % n;
    ans++;
  }
  cout << ans << endl;
}
signed main() {
  ios int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--) {
    solve();
  }
  // time
  return 0;
}
Problem p02596 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  long long k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << '\n';
  }
  if (k % 7 == 0) {
    k /= 7;
  }
  k *= 9;
  if (k == 9) {
    cout << 1 << '\n';
    return 0;
  }
  long long cnt = 1;
  long long hehe = 10;
  while (hehe != 1) {
    hehe *= 10;
    hehe %= k;
    cnt++;
  }
  cout << cnt << '\n';
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  long long k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << '\n';
    return 0;
  }
  if (k % 7 == 0) {
    k /= 7;
  }
  k *= 9;
  if (k == 9) {
    cout << 1 << '\n';
    return 0;
  }
  long long cnt = 1;
  long long hehe = 10;
  while (hehe != 1) {
    hehe *= 10;
    hehe %= k;
    cnt++;
  }
  cout << cnt << '\n';
  return 0;
}