alexjercan/bugnet huggingface dataset:
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

/*---------------------------------------------*/
/*
    ABC174 C
 */
/*---------------------------------------------*/

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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t>> Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x)                                                            \\
  Sort(x);                                                                     \\
  reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back(make_pair((a), (b)))

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;
}
template <typename V, typename T> bool find_num(V v, T num) {
  if (find(ALL(v), num) == v.end()) {
    return false;
  }
  return true;
}

int main() {
  int64_t n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
  } else {
    int64_t num = 7;
    repb(i, 1, 10000000) {
      if (num % n == 0) {
        cout << i << endl;
        return 0;
      }
      num = num * 10 + 7;
      num %= n;
    }
    cout << -1 << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

/*---------------------------------------------*/
/*
    ABC174 C
 */
/*---------------------------------------------*/

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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t>> Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x)                                                            \\
  Sort(x);                                                                     \\
  reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back(make_pair((a), (b)))

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;
}
template <typename V, typename T> bool find_num(V v, T num) {
  if (find(ALL(v), num) == v.end()) {
    return false;
  }
  return true;
}

const int64_t INF = 0x3fffffffffffffff;

int main() {
  int64_t n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
  } else {
    int64_t num = 7;
    repb(i, 1, INF) {
      if (num % n == 0) {
        cout << i << endl;
        return 0;
      }
      num = num * 10 + 7;
      num %= n;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

int main() {
  long long k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans(7 % k);
  int cur(7 % k);
  int res(1);
  while (ans) {
    cur = cur * 10 % k;
    ans = (ans + cur) % k;
    res++;
  }
  cout << res << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip> //setprecision()
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

double Mcos(double k) { return cos(k * atan(1.0) * 4 / 180); }

void monmo() {}

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1";
    exit(0);
  }
  int s = 7;
  int hoji = 7;
  for (int i = 1;; i++) {
    if (s % k == 0) {
      cout << i;
      exit(0);
    }
    s %= k;
    hoji = (hoji * 10) % k;
    s += hoji;

    if (i > 1000000) {
      cout << "-1";
      exit(0);
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip> //setprecision()
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

double Mcos(double k) { return cos(k * atan(1.0) * 4 / 180); }

void monmo() {}

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1";
    exit(0);
  }
  int s = 7;
  int hoji = 7;
  for (int i = 1;; i++) {
    if (s % k == 0) {
      cout << i;
      exit(0);
    }
    s %= k;
    hoji = (hoji * 10) % k;
    s += hoji;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <vector>

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

using namespace std;
using ll = long long;

int main(void) {
  ll k;
  cin >> k;
  ll f = 0;
  rep(1, 2000001) {
    f = (f * 10 + 7) % k;
    if (!f)
      return cout << i << endl, 0;
  }
  return cout << -1 << endl, 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <vector>

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

using namespace std;
using ll = long long;

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

  ll res = 0;
  if (k % 2 == 0) {
    res = -1;
  } else {
    ll n = 0;
    while (res < 200000001) {
      ++res;
      n = (n * 10 + 7) % k;
      if (n == 0)
        break;
    }
  }
  cout << res << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int K;
  cin >> K;
  int remainder = 0;
  int digit = 0;
  while (digit < 1000000) {
    digit++;
    int i = (10 * remainder + 7) % K;
    if (i == remainder)
      break;
    remainder = i;
    if (remainder == 0)
      break;
  }
  if (remainder == 0)
    cout << digit << endl;
  else
    cout << -1 << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int K;
  cin >> K;
  int remainder = 0;
  int digit = 0;
  while (true) {
    digit++;
    int i = (10 * remainder + 7) % K;
    if (i == remainder)
      break;
    remainder = i;
    if (remainder == 0)
      break;
  }
  if (remainder == 0)
    cout << digit << endl;
  else
    cout << -1 << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int n, sol, usu;
int main() {
  ios::sync_with_stdio(false);

  cin >> n;

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

  sol = 1;
  usu = 7;
  while (true) {
    if (usu % n == 0) {
      cout << sol;
      return 0;
    }

    usu = usu % n;
    usu = usu * 10 + 7;

    ++sol;
    if (sol == 1000000) {
      cout << -1;
      return 0;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int n, sol, usu;
int main() {
  ios::sync_with_stdio(false);

  cin >> n;

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

  sol = 1;
  usu = 7;
  while (true) {
    if (usu % n == 0) {
      cout << sol;
      return 0;
    }

    usu = usu % n;
    usu = usu * 10 + 7;

    ++sol;
  }

  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

void solve() {
  ll k;
  cin >> k;
  int ans = -1;
  ll cur = 0;
  for (int i = 0; i < 1e6 + 1000; i++) {
    cur = (10 * cur) + 7;
    cur %= k;
    if (cur % k == 0) {
      ans = i + 1;
      break;
    }
  }
  cout << ans;
}

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

  // int t; cin >> t;
  // while (t--)
  solve();
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

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

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

  // int t; cin >> t;
  // while (t--)
  solve();
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define ms(a, v) memset(a, v, sizeof(a))
#define sfor(i, n) for (int i = 1; i <= n; ++i)
#define tfor(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;

#ifdef GONGKUNPENG
#define MAXN 20
#else
#define MAXN 100005
#endif

int main() {
  int k, a, p, t = 0, r = 1;
  scanf("%d", &k);
  if ((k & 1) && (k % 5)) {
    if (7 % k) {
      if (k % 7 == 0)
        k /= 7;
      t = 1;
      p = 10 % k;
      while (t %= k) {
        t = t * p + 1;
        ++r;
      }
      printf("%d\\n", r);
    } else
      printf("1\\n");
  } else
    printf("-1\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define ms(a, v) memset(a, v, sizeof(a))
#define sfor(i, n) for (int i = 1; i <= n; ++i)
#define tfor(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;

#ifdef GONGKUNPENG
#define MAXN 20
#else
#define MAXN 100005
#endif

int main() {
  int k, a, p, t = 0, r = 1;
  scanf("%d", &k);
  if (k & 1) {
    if (a = 7 % k) {
      t = a;
      p = 10 % k;
      while (t %= k) {
        t = t * p + a;
        ++r;
      }
      printf("%d\\n", r);
    } else
      printf("1\\n");
  } else
    printf("-1\\n");
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll K;
  cin >> K;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 1;
  ll x = 7;
  x %= K;
  while (x) {
    ans++;
    x = x * 10 + 7;
    x %= K;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 1;
  ll x = 7;
  x %= K;
  while (x) {
    ans++;
    x = x * 10 + 7;
    x %= K;
  }
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int k;

int main(void) {
  cin >> k;
  if (k == 2 || k == 5) {
    cout << -1 << endl;
    return 0;
  }
  int r = 7;
  int i = 1;
  int maxc = 1e7;
  while (maxc--) {
    if (r % k == 0) {
      cout << i << endl;
      return 0;
    }
    r = 10 * r + 7;
    r %= k;
    i++;
  }
  cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int k;

int main(void) {
  cin >> k;
  if (k == 2 || k == 5) {
    cout << -1 << endl;
    return 0;
  }
  int r = 7;
  int i = 1;
  while (1) {
    if (r % k == 0) {
      cout << i << endl;
      return 0;
    }
    r = 10 * r + 7;
    r %= k;
    i++;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int k;
  cin >> k;
  int count = 1;
  int b = (10 % (9 * k / 7));
  if (k % 7 == 0) {
    while (true) {
      if ((9 * k / 7) % 2 == 0 or (9 * k / 7) % 5 == 0) {
        cout << "-1" << endl;
        break;
      }
      if (b % (9 * k / 7) == 1) {
        cout << count << endl;
        break;
      }
      b = b % (9 * k / 7);
      count = count + 1;
      b = 10 * b;
    }
  } else {
    int b = (10 % (9 * k));
    while (true) {
      if ((9 * k) % 2 == 0 or (9 * k) % 5 == 0) {
        cout << "-1" << endl;
        break;
      }
      if (b % (9 * k) == 1) {
        cout << count << endl;
        break;
      }
      b = b % (9 * k);
      count = count + 1;
      b = 10 * b;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  int count = 1;
  int b = (10 % (9 * k / 7));
  if (k % 7 == 0) {
    while (true) {
      if (b % (9 * k / 7) == 1) {
        cout << count << endl;
        break;
      }
      b = b % (9 * k / 7);
      count = count + 1;
      b = 10 * b;
    }
  } else {
    int b = (10 % (9 * k));
    while (true) {
      if (b % (9 * k) == 1) {
        cout << count << endl;
        break;
      }
      b = b % (9 * k);
      count = count + 1;
      b = 10 * b;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: 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++;
    if (ans > k) {
      cout << "-1" << endl;
      return 0;
    }
  }
}

Error: TLE

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++;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (n); i++)
#define PI 3.1415926535897932384626433832795028841971693993
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> dat(1e7);
  dat[1] = 7 % n;
  for (int i = 2; i <= n; i++) {
    dat[i] = (dat[i - 1] * 10 + 7) % n;
  }
  rep(i, n) {
    if (dat[i] == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  int n, m, x, ans = -1;
  cin >> n >> m >> x;
  vector<vector<int>> c(n, vector<int>(m));
  rep(i, n) rep(j, m + 1) cin >> c[i][j];
  rep(i, 1 << n) {
    vector<int> allc(m + 1);
    rep(j, n) {
      if (i >> j & 1) {
        rep(k, m + 1) { allc[k] += c[j][k]; }
      }
    }
    int datam = 0;
    rep(u, m) // allc'kakuninn
    {
      if (allc[u + 1] >= x)
        datam++;
    }
    if (datam == m && ans == -1)
      ans = allc[0];
    else if (datam == m)
      ans = min(ans, allc[0]);
  }
  cout << ans;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！
using P = pair<int, int>;
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

int main() {
  int k;
  cin >> k;
  int x = 7 % k;
  set<int> s;
  int i = 1;
  while (s.count(x) == 0) { // s.count(x)はsに含まれるxの個数
    if (x == 0) {
      cout << i << endl;
      return 0; // return 0はここでプログラムを終えるという意味
    }
    s.insert(x); // setだから0か1
    x = (x * 10 + 7) % k;
    i++;
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

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

  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
  } else {
    ll seven = 0;
    bool flag = true;
    ll i = 0;
    while (flag) {
      seven += 7 * pow(10, i);

      if (seven % K == 0) {
        cout << i + 1 << endl;
        ;
        flag = false;
        break;
      }
      i++;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
bool checkValue(long long v) {
  while (v > 0) {
    if ((v % 7 != 0) || (v % 10 == 0))
      return false;
    v /= 10;
  }
  return true;
}
int main() {
  long long x;
  cin >> x;
  unsigned long long value = 7;
  set<long long> result;
  long long cnt = 0;
  while (value > 0) {
    cnt++;
    // cout << value%x << endl;
    value = value % x;
    if (value == 0) {
      cout << cnt << endl;
      return 0;
    }
    // if(result.size()%10000!=0){
    // for(long long i = 0; i < result.size(); i++){
    // if(result[i]==value){
    // cout << -1 << endl;
    // return 0;
    //}
    //}
    //}
    if (result.count(value) != 0) {
      cout << -1 << endl;
      return 0;
    }
    result.insert(value);
    value = value * 10 + 7;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool checkValue(long long v) {
  while (v > 0) {
    if ((v % 7 != 0) || (v % 10 == 0))
      return false;
    v /= 10;
  }
  return true;
}
int main() {
  long long x;
  cin >> x;
  unsigned long long value = 7;
  vector<long long> result;
  long long cnt = 0;
  while (value > 0) {
    cnt++;
    // cout << value%x << endl;
    value = value % x;
    if (value == 0) {
      cout << cnt << endl;
      return 0;
    }
    // if(result.size()%10000!=0){
    // for(long long i = 0; i < result.size(); i++){
    // if(result[i]==value){
    // cout << -1 << endl;
    // return 0;
    //}
    //}
    //}
    if (count(result.begin(), result.end(), value) != 0) {
      cout << -1 << endl;
      return 0;
    }
    result.push_back(value);
    value = value * 10 + 7;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int t;
ll l;
ll phi(ll x) {
  ll res = x;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      res = res / i * (i - 1);
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    res = res / x * (x - 1);
  return res;
}
ll ksm(ll a, ll b, ll c) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % c;
    a = (a * a) % c;
    b >>= 1;
  }
  return res;
}
int main() {
  int kase = 0;
  ll l;
  cin >> l;
  ll mod = l / __gcd(7ll, l) * 9ll;
  ll p = phi(mod);
  ll res = 1e18;
  for (ll x = 1; x * x <= p; x++) {
    if (p % x != 0)
      continue;
    if (ksm(10, x, mod) == 1)
      res = min(res, x);
    if (ksm(10, p / x, mod) == 1)
      res = min(res, p / x);
  }
  if (res == 1e18)
    cout << "-1" << endl;
  else
    cout << res << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const ll mod = 1e8;
char a[200010];
int main() {
  ll n;
  cin >> n;
  cin >> a;
  ll i, r = 0, w = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == 'R')
      r++;
    else
      w++;
  }
  if (w == 0)
    cout << "0";
  else {
    ll s = 0;
    for (i = 0; i < r; i++)
      if (a[i] != 'R')
        s++;
    cout << s;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1";
    return 0;
  }
  long long s;
  s = 7;
  for (long long i = 1; i <= 100000000; i++) {
    if (s % n == 0) {
      cout << i;
      return 0;
    }
    s = s % n;
    s *= 10;
    s += 7;
  }
  cout << "-1";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1";
    return 0;
  }
  long long s = 7;
  for (long long i = 1; i <= 10000000000; i++) {
    if (s % n == 0) {
      cout << i;
      return 0;
    }
    s = s % n;
    s *= 10;
    s += 7;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  long answer = 1;

  if (K % 2 == 0) {
    answer = -1;
  }

  if (answer == -1) {
  } else {
    int amari = 7 % K;
    for (long i = 2; amari != 0 && i < 1000000; i++) {
      amari = (amari * 10 + 7) % K;
      answer = i;
      if (i == 999999) {
        answer = -1;
      }
    }
  }
  cout << answer << endl;
}


Error: TLE

Fixed submission:

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

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

  long answer = 1;

  if (K % 2 == 0) {
    answer = -1;
  }

  if (answer == -1) {
  } else {
    int amari = 7 % K;
    for (long i = 2; amari != 0; i++) {
      amari = (amari * 10 + 7) % K;
      answer = i;
    }
  }
  cout << answer << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

// minimum operations to reach y from x
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
int smod(string &s, int n) {
  ll res = 0;
  for (int i = 0; i < s.length(); i++)
    res = (res * 10 + (int)s[i] - '0') % n;

  return (int)res;
}

void solve() {
  int x;
  cin >> x;
  if (x % 2 == 0 || x % 5 == 0) {
    cout << -1 << endl;
    return;
  }
  string s = "7";
  ll cnt = 1;
  ll ans = 0;
  while (1) {
    ans = (ans * 10 + (int)s[s.size() - 1] - '0') % x;
    if (ans % x == 0) {
      cout << cnt << endl;
      break;
    }
    s += '7';
    cnt++;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--)
    solve();
}

Error: TLE

Fixed submission:

// minimum operations to reach y from x
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
int smod(string &s, ll n) {
  int res = 0;
  for (int i = 0; i < s.length(); i++)
    res = (res * 10 + (int)s[i] - '0') % n;

  return res;
}

void solve() {
  ll x;
  cin >> x;
  if (x % 2 == 0 || x % 5 == 0 || x % 10 == 0) {
    cout << -1 << endl;
    return;
  }
  string s = "7";
  int cnt = 1;
  while (1) {
    if (smod(s, x) == 0) {
      cout << cnt << endl;
      break;
    } else
      s += '7';
    cnt++;
  }
}

int main() {
  int t;
  t = 1;
  while (t--)
    solve();
}