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

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

int k;

int main() {
  cin >> k;
  if (!(k & 1) || !(k % 5)) {
    cout << -1 << endl;
    return 0;
  }
  if (!(k % 7))
    k /= 7;
  int a = 1, b = 1, n = 1;
  while (a % k) {
    ++n;
    b = b * 10 % k;
    a = (a + b) % k;
  }
  cout << n << endl;
}


Error: TLE

Fixed submission:

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

int k;

int main() {
  cin >> k;
  if (!(k & 1)) {
    cout << -1 << endl;
    return 0;
  }
  if (!(k % 7))
    k /= 7;
  int a = 1, b = 1, n = 1;
  while (a % k) {
    ++n;
    b = b * 10 % k;
    a = (a + b) % k;
  }
  cout << n << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//(a+b-1)/b
ll k;
ll f(ll a, ll b) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    ll t = f(a, b / 2);
    return t * t % k;
  }
  return a * f(a, b - 1) % k;
}

signed main() {
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (k % 7 == 0)
    k /= 7;
  ll j = 0;
  ll cnt = 0;
  ll ans = -2;
  rep(i, 0, 1000000) {
    j += f(10, cnt);
    if (j == k) {
      ans = cnt;
      break;
    }
    cnt++;
    j %= k;
    // cout<<j<<endl;
  }
  //	if(k==ans)ans--;
  cout << ++ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//(a+b-1)/b
ll k;
ll f(ll a, ll b) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    ll t = f(a, b / 2);
    return t * t % k;
  }
  return a * f(a, b - 1) % k;
}

signed main() {
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (k % 7 == 0)
    k /= 7;
  ll j = 0;
  ll cnt = 0;
  ll ans = -1;
  rep(i, 0, 10000000) {
    j += f(10, cnt);
    if (j == k) {
      ans = cnt;
      break;
    }
    cnt++;
    j %= k;
    // cout<<j<<endl;
  }
  //	if(k==ans)ans--;
  cout << ++ans << endl;

  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a, b, c)                                                           \\
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c       \\
       << " = " << (c) << endl;

typedef long long int ll;
typedef string str;
ll power(ll x, ll y, ll p) {
  ll res = 1;

  x = x % p;
  while (y) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

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

void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t, n, m, k, i, a, b, j;
  cin >> k;

  if (k % 2 == 0)
    cout << "-1\\n";
  else if (k == 1)
    cout << "1\\n";
  else {
    ll po[k + 7];
    po[0] = 1;
    for (i = 1; i <= k + 3; i++) {
      po[i] = (po[i - 1] * 10) % k;
    }
    a = 7, i = 0;
    b = a % k;
    while (i <= k && b != 0) {
      i++;
      a = ((7 * po[i]) % k + b) % k;
      b = a % k;
    }
    if (b != 0)
      i = -2;
    cout << i + 1 << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a, b, c)                                                           \\
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c       \\
       << " = " << (c) << endl;

typedef long long int ll;
typedef string str;
ll power(ll x, ll y, ll p) {
  ll res = 1;

  x = x % p;
  while (y) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

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

void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t, n, m, k, i, a, b, j;
  cin >> k;

  if (k % 2 == 0)
    cout << "-1\\n";
  else if (k == 1)
    cout << "1\\n";
  else {
    ll po[k + 7];
    po[0] = 1;
    for (i = 1; i <= k + 3; i++) {
      po[i] = (po[i - 1] * 10) % k;
    }
    a = 7 % k, i = 0;
    while (a % k != 0) {
      b = a % k;
      i++;
      a = (7 * po[i] + b) % k;
    }
    cout << i + 1 << "\\n";
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, a, b) for (int i = a; i <= b; i++)
inline ll r() {
  ll x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  if (c == '-')
    f = -1, c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
#define d r()
ll k, phi;
ll qp(ll a, ll b, ll p) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a % p;
    a = a * a % p;
    b /= 2;
  }
  return ans;
}
ll wws, ak;
int main() {
  k = d, ak = k;
  if (k % 7 == 0)
    k /= 7;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1;
    return 0;
  }
  if (k == 1) {
    cout << 1;
    return 0;
  }
  while (ak)
    ak /= 10, wws++;
  ll kk = phi = k;
  for (int i = 2; i * i <= k; i++)
    if (k % i == 0) {
      while (k % i == 0)
        k /= i;
      phi = phi * (i - 1) / i;
    }
  if (k != 1)
    phi = phi * (k - 1) / k;
  ll cnt = 0, now = 0;
  while (1) {
    cnt++;
    if (cnt < phi)
      now += qp(10, cnt % phi, kk);
    else
      now += qp(10, cnt % phi + phi, kk);
    if (now % kk == 0 && cnt >= wws)
      break;
  }
  printf("%lld", cnt);
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, a, b) for (int i = a; i <= b; i++)
inline ll r() {
  ll x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  if (c == '-')
    f = -1, c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
#define d r()
ll k, phi;
ll qp(ll a, ll b, ll p) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a % p;
    a = a * a % p;
    b /= 2;
  }
  return ans;
}
ll wws, ak;
int main() {
  k = d, ak = k;
  if (k % 7 == 0)
    k /= 7;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1;
    return 0;
  }
  while (ak)
    ak /= 10, wws++;
  ll kk = phi = k;
  for (int i = 2; i * i <= k; i++)
    if (k % i == 0) {
      while (k % i == 0)
        k /= i;
      phi = phi * (i - 1) / i;
    }
  if (k)
    phi = phi * (k - 1) / k;
  ll cnt = 0, now = 0;
  while (1) {
    cnt++;
    if (cnt < phi)
      now += qp(10, cnt % phi, kk);
    else
      now += qp(10, cnt % phi + phi, kk);
    if (now % kk == 0 && cnt >= wws)
      break;
  }
  printf("%lld", cnt);
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (k % 7 == 0) {
    k = k / 7;
  }
  while (k % 10 == 0) {
    k = k / 10;
  }
  ll ans = 0;
  bool ok = true;
  ll tot = 1;
  while (ok) {
    if (ans >= 999983) {
      cout << -1 << endl;
      return 0;
    }
    if (tot % k == 0) {
      ans++;
      ok = false;
      break;
    } else {
      tot *= 10;
      tot += 1;
      tot %= k;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (k % 7 == 0) {
    k = k / 7;
  }
  while (k % 10 == 0) {
    k = k / 10;
  }
  ll ans = 0;
  bool ok = true;
  ll tot = 1;
  while (ok) {
    if (tot % k == 0) {
      ans++;
      ok = false;
      break;
    } else {
      tot *= 10;
      tot += 1;
      tot %= k;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int dp[1000005];

int main(void) {
  int k, i;

  scanf("%d", &k);

  for (i = 1; i <= k; i++) {
    dp[i] = (dp[i - 1] * 10 + 7) % k;

    if (dp[i] == 0) {
      printf("%d", i);
      return 0;
    }
  }

  puts("-1");
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int dp[1000005];

int main(void) {
  int k, i;

  scanf("%d", &k);

  for (i = 1;; i++) {
    dp[i] = (dp[i - 1] * 10 + 7) % k;

    if (dp[i] == 0) {
      printf("%d", i);
      return 0;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

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

  if (K % 2 == 0 || K % 5 == 0)
    cout << "-1" << endl;
  else {
    ll i = 0;
    ll K_sub = K;
    while (true) {
      if (K_sub / 10 > 0) {
        K_sub /= 10;
        i++;
      } else
        break;
    }
    ll d = 7;
    for (int j = 0; j < i; j++)
      d = d * 10 + 7;
    if (K > d) {
      i += 2;
      d = d * 10 + 7;
    } else
      i++;
    d = d % K;
    if (d == 0) {
      cout << i << endl;
      return 0;
    }
    while (true) {
      i++;
      if ((d * 10 + 7) % K == 0) {
        cout << i << endl;
        return 0;
      } else {
        d = (d * 10 + 7) % K;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

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

  if (K % 2 == 0)
    cout << "-1" << endl;
  // if(K%5 == 0) cout << "-1" << endl;

  else {
    ll i = 0;
    ll K_sub = K;
    while (true) {
      if (K_sub / 10 > 0) {
        K_sub /= 10;
        i++;
      } else
        break;
    }
    ll d = 7;
    for (int j = 0; j < i; j++)
      d = d * 10 + 7;
    if (K > d) {
      i += 2;
      d = d * 10 + 7;
    } else
      i++;
    d = d % K;
    if (d == 0) {
      cout << i << endl;
      return 0;
    }
    while (true) {
      i++;
      if ((d * 10 + 7) % K == 0) {
        cout << i << endl;
        return 0;
      } else {
        d = (d * 10 + 7) % K;
      }
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define INF 0x3f3f3f
#define ll long long
#define pb push_back
#define mp make_pair
#define pair pair<int, int>
#define C(a) cout << a << endl;
#define CY cout << "YES" << endl;
#define CN cout << "NO" << endl;
#define Cy cout << "Yes" << endl;
#define Cn cout << "No" << endl;
#define ull unsigned long long
#define me(a) memset(a, 0, sizeof(a));
#define my(a, b) memcpy(a, b, sizeof(b));
#define cio ios::sync_with_stdio(false)
ll mod = 1e9 + 7;
ll gcd(ll a, ll b) { return (a % b == 0) ? b : gcd(b, a % b); }
int main() {

  ll n;
  cin >> n;

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define INF 0x3f3f3f
#define ll long long
#define pb push_back
#define mp make_pair
#define pair pair<int, int>
#define C(a) cout << a << endl;
#define CY cout << "YES" << endl;
#define CN cout << "NO" << endl;
#define Cy cout << "Yes" << endl;
#define Cn cout << "No" << endl;
#define ull unsigned long long
#define me(a) memset(a, 0, sizeof(a));
#define my(a, b) memcpy(a, b, sizeof(b));
#define cio ios::sync_with_stdio(false)
ll mod = 1e9 + 7;
ll gcd(ll a, ll b) { return (a % b == 0) ? b : gcd(b, a % b); }
int main() {

  ll n;
  cin >> n;
  if (n == 2) {
    cout << -1 << endl;
    return 0;
  }
  ll cnt = 0;
  ll s = 7;
  int i;
  int x = 0;
  for (i = 1;; i++) {
    x = x * 10 + 7;
    x = x % n;
    if (x == 0) {
      break;
    }
  }
  cout << i << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define HAS_TEST_CASE 0 // Do you forget to complete this?

namespace registerGen {
typedef long long ll;

const int N = 1e6;

int n, m, a[N + 10];
char str[N + 10];
bool vis[N + 10];

inline void main() {
  int k;
  scanf("%d", &k);
  if (!(k % 2))
    return puts("-1"), void();
  int ans = 0, now = 0;
  while (1) {
    now = (now * 10 + 7) % k;
    if (vis[now])
      return puts("-1"), void();
    vis[now] = 1;
    ans++;
    if (now == 0)
      break;
  }
  printf("%d\\n", ans);
}
} // namespace registerGen

int main() {
#ifndef ONLINE_JUDGE
///	freopen("tmp.out","w",stdout);
#endif
  int T = 1;
#if HAS_TEST_CASE
  scanf("%d", &T);
#endif
  while (T--)
    registerGen::main();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define HAS_TEST_CASE 0 // Do you forget to complete this?

namespace registerGen {
typedef long long ll;

const int N = 5e5;

int n, m, a[N + 10];
char str[N + 10];

inline void main() {
  int k;
  scanf("%d", &k);
  if (!(k % 2))
    return puts("-1"), void();
  int ans = 0, now = 0;
  while (1) {
    now = (now * 10 + 7) % k;
    ans++;
    if (now == 0)
      break;
  }
  printf("%d\\n", ans);
}
} // namespace registerGen

int main() {
#ifndef ONLINE_JUDGE
///	freopen("tmp.out","w",stdout);
#endif
  int T = 1;
#if HAS_TEST_CASE
  scanf("%d", &T);
#endif
  while (T--)
    registerGen::main();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;

void Main() {
  int K;
  cin >> K;

  if (7 % K == 0) {
    cout << 1 << endl;
    return;
  }

  int ans = -1;
  set<int> reminder;
  reminder.insert(7 % K);
  int n7 = 7;
  int pow10 = 10;
  int counter = 1;
  while (true) {
    ++counter;
    n7 += pow10 * 7;
    n7 %= K;
    if (n7 == 0) {
      ans = counter;
      break;
    }
    if (reminder.count(n7) > 0) {
      ans = -1;
      break;
    }
    reminder.insert(n7);
    pow10 *= 10;
    pow10 %= K;
  }
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

void Main() {
  int K;
  cin >> K;

  if (7 % K == 0) {
    cout << 1 << endl;
    return;
  }

  int ans = -1;
  set<int> reminder;
  reminder.insert(7 % K);
  int n7 = 7;
  int pow10 = 10;
  int counter = 1;
  while (true) {
    ++counter;
    n7 += pow10 * 7;
    n7 %= K;
    if (n7 == 0) {
      ans = counter;
      break;
    }
    if (reminder.count(n7) > 0) {
      ans = -1;
      break;
    }
    pow10 *= 10;
    pow10 %= K;
  }
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int findSmallestNumber(vector<int> &arr, int n) {

  // Initialize both vectors with their initial values
  vector<int> dp(n, numeric_limits<int>::max() - 5);
  vector<pair<int, int>> result(n, make_pair(-1, 0));

  // Sort the vector of digits
  sort(arr.begin(), arr.end());

  // Initialize the queue
  queue<int> q;
  for (auto i : arr) {
    if (i != 0) {

      // If modulus value is not present
      // in the queue
      if (dp[i % n] > 1e9) {

        // Compute digits modulus given number and
        // update the queue and vectors
        q.push(i % n);
        dp[i % n] = 1;
        result[i % n] = {-1, i};
      }
    }
  }

  // While queue is not empty
  while (!q.empty()) {

    // Remove the first element of the queue
    int u = q.front();
    q.pop();
    for (auto i : arr) {

      // Compute new modulus values by using old queue
      // values and each digit of the set
      int v = (u * 10 + i) % n;

      // If value is not present in the queue
      if (dp[u] + 1 < dp[v]) {
        dp[v] = dp[u] + 1;
        q.push(v);
        result[v] = {u, i};
      }
    }
  }

  // If required condition can't be satisfied
  if (dp[0] > 1e9)
    return -1;
  else {

    // Initialize new vector
    vector<int> ans;
    int u = 0;
    while (u != -1) {

      // Constructing the solution by backtracking
      ans.push_back(result[u].second);
      u = result[u].first;
    }

    return ans.size();
  }
}
int main() {
  vector<int> arr = {7};
  int n;
  cin >> n;
  cout << findSmallestNumber(arr, n) << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1\\n";
    return 0;
  }
  queue<int> q;
  vector<bool> visited(n);
  vector<int> parent(n);
  vector<bool> digit(n);
  int rem = 7 % n;
  visited[rem] = 1;
  parent[rem] = -1;
  digit[rem] = 1;
  q.push(rem);
  int t = 0;
  int fg = 0;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    t += 1;
    if (t > 1000000) {
      fg = 1;
      break;
    }
    // cout<<t<<" ";
    if (curr == 0)
      break;
    int mod1 = (curr * 10 + 7) % n;
    if (visited[mod1] == 0) {
      visited[mod1] = 1;
      parent[mod1] = curr;
      digit[mod1] = 1;
      q.push(mod1);
    }
  }
  if (fg == 1) {
    cout << "-1\\n";
    return 0;
  }
  string ans = "";
  int i = 0;
  while (i != -1) {
    ans += digit[i] + '6';
    i = parent[i];
  }
  reverse(ans.begin(), ans.end());
  cout << ans.length() << "\\n";
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

const int mxn = 1e6;

bool flag[mxn + 11];

int main() {
  int k;
  scanf("%d", &k);
  int cur = 0;
  for (int i = 1; i; i++) {
    cur *= 10;
    cur += 7;
    if (cur % k == 0) {
      printf("%d\\n", i);
      return 0;
    }
    cur %= k;
    if (flag[cur]) {
      puts("-1");
      return 0;
    }
    flag[cur] = true;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int k;
  scanf("%d", &k);
  int cur = 0;
  for (int i = 1; i; i++) {
    cur *= 10;
    cur += 7;
    if (cur % k == 0) {
      printf("%d\\n", i);
      return 0;
    }
    cur %= k;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define EL '\\n'
#define print(i) std::cout << (i) << '\\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO {
  FIO() {
    std::cin.tie(0);
    std::cout.tie(0);
    std::ios_base::sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15);
  }
} fIO;
/*-*/

int main() {
  lnt k;
  std::cin >> k;
  lnt x = 7;
  rep(i, 1000005) {
    if (x % k == 0) {
      print(i + 1);
      return 0;
    }
    x *= 10;
    x += 7;
    x %= k;
  }
  print(-1);
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define EL '\\n'
#define print(i) std::cout << (i) << '\\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO {
  FIO() {
    std::cin.tie(0);
    std::cout.tie(0);
    std::ios_base::sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15);
  }
} fIO;
/*-*/

int main() {
  lnt k;
  std::cin >> k;
  if (k % 2 == 0) {
    print(-1);
    return 0;
  }
  lnt x = 7;
  int i = 1;
  while (x % k) {
    i++;
    x *= 10;
    x += 7;
    x %= k;
  }
  print(i);
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int k;
  cin >> k;
  set<int> s;
  bool flag = true;
  int c = 1;
  int a = 7;
  a %= k;
  s.insert(a);
  while (flag) {
    if (a == 0) {
      cout << c << endl;
      break;
    } else {
      a = a * 10 + 7;
      a %= k;
      c++;
      if (s.find(a) != s.end()) {
        cout << -1 << endl;
        break;
      } else {
        s.insert(a);
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int k;
  cin >> k;
  vector<int> v;
  bool flag = true;
  int c = 1;
  int a = 7;
  a %= k;
  v.push_back(a);
  while (flag) {
    if (a == 0) {
      cout << c << endl;
      break;
    } else {
      a = a * 10 + 7;
      a %= k;
      c++;
      if (find(v.begin(), v.end(), a) != v.end()) {
        cout << -1 << endl;
        break;
      } else {
        v.push_back(a);
      }
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
inline int read(void) {
  int num = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-')
      f = -1;
  while (isdigit(ch))
    num = num * 10 + ch - '0', ch = getchar();
  return num * f;
}
int main() {
  int k = read(), n = 0, cnt = 0;
  if (!(k % 2))
    puts("-1");
  else
    while (true) {
      n = n * 10 + 7;
      cnt++;
      n %= k;
      if (!n) {
        printf("%d\\n", cnt);
        break;
      }
      if (cnt > k) {
        puts("-1");
        break;
      }
    }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
inline int read(void) {
  int num = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-')
      f = -1;
  while (isdigit(ch))
    num = num * 10 + ch - '0', ch = getchar();
  return num * f;
}
int main() {
  int k = read(), n = 0, cnt = 0;
  if (!(k % 2))
    puts("-1");
  else
    while (true) {
      n = n * 10 + 7;
      cnt++;
      n %= k;
      if (!n) {
        printf("%d\\n", cnt);
        break;
      }
    }
  return 0;
}