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

#ifndef DEBUG
#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC optimize("unroll-loops")

#if __cplusplus < 201703L
#pragma GCC target("avx")
#else
#pragma GCC target("avx2")
#endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 999999999999971;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) { return (a - (a % b)) / b; }

Int Ceil(Int a, Int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return Floor(a, b) + 1;
  }
}

Int digits(Int n) { return (Int)to_string(n).size(); }

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

  Int k;
  cin >> k;

  Int na = 7;
  Int ans = 1;

  if (k & 1) {
    for (; ans < 100000000; ans++) {
      if (na % k == 0) {
        break;
      } else {
        na %= k;
        na = na * 10 + 7;
      }
    }

    if (ans == 100000000) {
      ans = -1;
    }

  } else {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#ifndef DEBUG
#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC optimize("unroll-loops")

#if __cplusplus < 201703L
#pragma GCC target("avx")
#else
#pragma GCC target("avx2")
#endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 999999999999971;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) { return (a - (a % b)) / b; }

Int Ceil(Int a, Int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return Floor(a, b) + 1;
  }
}

Int digits(Int n) { return (Int)to_string(n).size(); }

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

  Int k;
  cin >> k;

  Int na = 7;
  Int ans = 1;

  if (k & 1) {
    for (;; ans++) {
      if (na % k == 0) {
        break;
      } else {
        na %= k;
        na = na * 10 + 7;
      }
    }
  } else {
    ans = -1;
  }

  cout << ans << endl;

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

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

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

  ll c = 1;
  ll s = 7;
  ll ss = 7;
  set<pair<ll, ll>> H;
  H.insert(pair<ll, ll>(s, ss));
  while (true) {
    if ((ss % K) == 0) {
      cout << c << endl;
      return (0);
    }
    c++;
    s = (s * 10) % K;
    ss = (ss + s) % K;
    if (H.find(pair<ll, ll>(s, ss)) != H.end()) {
      cout << -1 << endl;
      return (0);
    }
    H.insert(pair<ll, ll>(s, ss));
  }
  return (0);
}


Error: TLE

Fixed submission:

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

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

  ll c = 1;
  ll s = 7;
  ll ss = 7;
  while (true) {
    if (ss % K == 0) {
      cout << c << endl;
      return (0);
    }
    c++;
    s = (s * 10) % K;
    ss = (ss + s) % K;
    //		cout << s << endl;
  }
  return (0);
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <chrono>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

const int DIV = 998244353;

int main(int argc, char *argv[]) {
#ifdef VLAD_LOCAL
  ifstream in("in.txt");
  auto start = std::chrono::steady_clock::now();
#else
  istream &in = cin;
#endif
  int k;
  in >> k;
  int r = 7 % k;
  int result = 1;
  std::vector<char> was(k, 0);
  while (r != 0) {
    was[r] = 1;
    r = ((r * 10) + 7) % k;
    result++;
    if (was[r]) {
      result = -1;
      break;
    }
  }
  printf("%d\\n", result);
#ifdef VLAD_LOCAL
  auto end = std::chrono::steady_clock::now();
  double seconds =
      (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
          .count() /
      1000;
  printf("%.3lf seconds\\n", seconds);
#endif
  return 0;
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <chrono>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

const int DIV = 998244353;

int main(int argc, char *argv[]) {
#ifdef VLAD_LOCAL
  ifstream in("in.txt");
  auto start = std::chrono::steady_clock::now();
#else
  istream &in = cin;
#endif
  int k;
  in >> k;
  int r0 = 7 % k;
  int result = 1;
  int r = r0;
  while (r != 0) {
    r = ((r * 10) + 7) % k;
    result++;
    if (r == r0) {
      result = -1;
      break;
    }
  }
  printf("%d\\n", result);
#ifdef VLAD_LOCAL
  auto end = std::chrono::steady_clock::now();
  double seconds =
      (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
          .count() /
      1000;
  printf("%.3lf seconds\\n", seconds);
#endif
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define lop                                                                    \\
  ios;                                                                         \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define vi vector<ll>
#define vivi vector<vector<ll>>
#define vipa vector<pair<ll, ll>>
#define F first
#define S second
#define M 1000000007
#define kl "\\n"
typedef long long ll;
ll lcm(ll x, ll y) {
  ll k = x * y;
  k /= (__gcd(x, y));
  return k;
}
ll power(ll x, ll y) {
  ll r = 1;
  x = x % M;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      r = (r * x) % M;
    y = y >> 1;
    x = (x * x) % M;
  }
  return r;
}
void solve() {
  ll k;
  cin >> k;
  ll a[10000000], dp[10000000];
  if (k % 7 == 0) {
    k /= 7;
  }

  for (ll i = 0; i < 10000000; i++) {
    a[i] = 1;
  }

  dp[0] = a[0] % k;
  for (ll i = 1; i < 10000000; i++) {
    dp[i] = ((10 * dp[i - 1]) + a[i]) % k;
  }
  ll ans = -2;
  for (ll i = 0; i < 10000000; i++) {
    if (dp[i] == 0) {
      ans = i;
      break;
    }
  }
  cout << ans + 1 << kl;
}
int main() {
  // lop
  solve();
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define lop                                                                    \\
  ios;                                                                         \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define vi vector<ll>
#define vivi vector<vector<ll>>
#define vipa vector<pair<ll, ll>>
#define F first
#define S second
#define M 1000000007
#define kl "\\n"
typedef long long ll;
ll lcm(ll x, ll y) {
  ll k = x * y;
  k /= (__gcd(x, y));
  return k;
}
ll power(ll x, ll y) {
  ll r = 1;
  x = x % M;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      r = (r * x) % M;
    y = y >> 1;
    x = (x * x) % M;
  }
  return r;
}
void solve() {
  ll n;
  ll x = 7;
  ll ans = 1;
  cin >> n;
  vector<ll> v;
  ll i = 0;
  while (1) {
    ll k = x % n;
    if (k == 0) {
      cout << ans;
      return;
    }
    if (v[i] == k and v.size() > 0) {
      cout << -1;
      return;
    }
    v.pb(k);
    ans++;
    x = x * 10 + 7;
  }
}
int main() {
  // lop
  solve();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

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

  int ans = 1;
  ll res = 7;
  ll f = 7 % k;

  int cnt = 0;
  while (res % k != 0) {
    res = (10 * res + 7) % k;
    ans++;
    cnt++;
    if (res == f || cnt >= 10e7) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

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

  int ans = 1;
  ll res = 7;
  ll f = 7 % k;

  while (res % k != 0) {
    res = (10 * res + 7) % k;
    ans++;
    if (res == f) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
int sum[500005];
int vis[500005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j = 0;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1 << endl;
  } else {
    long long p = 7 % n;
    j++;
    while (p != 0) {
      p = (p * 10 + 7) % n;
      j++;
    }
    cout << j << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int sum[500005];
int vis[500005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j = 0;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
  } else {
    long long p = 7 % n;
    j++;
    while (p != 0) {
      p = (p * 10 + 7) % n;
      j++;
    }
    cout << j << endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  int n = k;
  int r = 0;
  int count = 0;
  if (n % 2 == 0 || n % 5 == 0)
    cout << "-1";
  else {
    for (int i = 0; i < (1e7); i++) {
      r = (r * 10 + 7) % k;
      count++;
      if (r == 0) {
        cout << count;
        return 0;
      }
    }
    cout << "-1";
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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


Error: TLE

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define endl "\\n"
#define all(a) a.begin(), a.end()
#define debug(x) cout << x << endl;
#define int long long
#define ordered_set                                                            \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
/* 	1) order_of_key (k) : Number of items strictly smaller than k .
        2) find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace __gnu_pbds;
using namespace std;
using LD = long double;

const int N = 1e6 + 1;
const int mod = 1e9 + 7;
const int INF = 1e18;
int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int col[8] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve() {
  int k;
  cin >> k;
  int num = 7, cnt = 0;
  bool flg = true;
  while (cnt < N) {
    cnt++;
    if (num % k == 0) {
      flg = false;
      break;
    }
    num = num * 10 + 7;
    num %= k;
  }
  if (flg)
    cout << "-1";
  else
    cout << cnt << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int t = 1, i = 1;
  // cin >> t;
  while (t--) {
    // cout << "Case #" << i << ": ";
    solve();
    // i++;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define endl "\\n"
#define all(a) a.begin(), a.end()
#define debug(x) cout << x << endl;
#define int long long
#define ordered_set                                                            \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
/* 	1) order_of_key (k) : Number of items strictly smaller than k .
        2) find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace __gnu_pbds;
using namespace std;
using LD = long double;

const int N = 1e6 + 1;
const int mod = 1e9 + 7;
const int INF = 1e18;
int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int col[8] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve() {
  int k;
  cin >> k;
  int num = 7, cnt = 0;
  bool flg = true;
  while (num < N) {
    cnt++;
    if (num % k == 0) {
      flg = false;
      break;
    }
    num = num * 10 + 7;
    num %= k;
  }
  if (flg)
    cout << "-1";
  else
    cout << cnt << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int t = 1, i = 1;
  // cin >> t;
  while (t--) {
    // cout << "Case #" << i << ": ";
    solve();
    // i++;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i;
  cin >> n;

  long long k = 0;
  for (i = 0; i < n; i++) {
    k = k * 10 + 7;
    k %= n;
    if (k == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int n;
  cin >> n;
  long long int x = 7;
  long long int count = 1;
  if (n % 2 == 0)
    count = -1;

  else {
    while (x % n != 0) {
      x = (x * 10) + 7;
      count++;
    }
  }
  cout << count;

  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 rep1(i, n) for (int i = 1; i <= (int)n; i++)
#define sp(n) cout << fixed << setprecision(n)
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;
}
typedef long long ll;
using namespace std;
int main(void) {
  ll k;
  cin >> k;

  if (k % 7 == 0)
    k /= 7;
  ll pre = 1, tmp = 0;
  map<ll, ll> mp;
  while (true) {
    tmp++;
    pre %= k;
    if (mp[pre] != 0) {
      cout << -1 << endl;
      return 0;
    }
    if (pre == 0) {
      cout << tmp << endl;
      return 0;
    }
    mp[pre]++;
    pre *= 10;
    pre += 1;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i <= (int)n; i++)
#define sp(n) cout << fixed << setprecision(n)
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;
}
typedef long long ll;
using namespace std;
int main(void) {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (k % 7 == 0)
    k /= 7;
  ll pre = 1, tmp = 0;
  while (true) {
    tmp++;
    pre %= k;
    if (pre == 0) {
      cout << tmp << endl;
      return 0;
    }
    pre *= 10;
    pre += 1;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long K;
  cin >> K;
  long now = 7;
  if (K == 7 || K == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  long ans = 1;
  while (now != 0) {
    now += modpow(10, ans, K) * 7;
    now %= K;
    ans++;
    // cout<<now<<endl;
    if (ans > 1000000)
      break;
  }
  if (ans < 1000000)
    cout << ans << endl;
  else
    cout << -1 << endl;
}


Error: TLE

Fixed submission:

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

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long K;
  cin >> K;
  long now = 7;
  if (K == 7 || K == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
  }
  long ans = 1;
  while (now != 0) {
    now += modpow(10, ans, K) * 7;
    now %= K;
    ans++;
    // cout<<now<<endl;
    if (ans > 10000000)
      break;
  }
  if (ans < 10000000)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int k;
  cin >> k;
  int ans = 0, a;
  a = 7 % k;
  for (int i = 1; i <= k; i++) {
    if (a == 0) {
      cout << i << endl;
      return 0;
    }
    a = (a * 10 + 7) % k;
  }
  cout << "-1" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int k;
  cin >> k;
  int a = 7, i = 0;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  while (1) {
    i++;
    if (a % k == 0)
      break;
    else {
      a = 7 + a * 10;
    }
  }
  cout << i << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int k;
  int seven = 7;
  cin >> k;
  if (k % 2 == 0)
    cout << "-1\\n";
  else {
    int ans = 1;
    set<int> s;
    while (seven % k != 0) {
      if (s.count(seven % k)) {
        cout << "-1\\n";
        return 0;
      }
      s.insert(seven % k);
      seven = seven * 10 + 7;
      seven %= k;
      ++ans;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int k;
  int seven = 7;
  cin >> k;
  if (k % 2 == 0)
    cout << "-1\\n";
  else {
    int ans = 1;
    while (seven % k != 0) {
      seven = seven * 10 + 7;
      seven %= k;
      ++ans;
    }
    cout << ans << endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

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

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

  vector<int> remain(K, -1);
  ll tmp = 7, cnt = 1, ans = -1;
  while (true) {
    tmp %= K;
    if (tmp == 0) {
      ans = cnt;
      break;
    } else if (remain[tmp] != -1) {
      break;
    }
    remain[tmp] = 1;
    cnt++;
    tmp = tmp * 10 + 7;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

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

int main() {
  ll K;
  cin >> K;
  ll ans = 0;

  if (K == 2 || K == 5)
    ans = -1;
  else {
    ll tmp = 7, cnt = 1;
    while (true) {
      tmp %= K;
      if (tmp == 0) {
        ans = cnt;
        break;
      }
      cnt++;
      tmp = tmp * 10 + 7;
    }
  }

  cout << ans << endl;

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

Error: TLE

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 (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;
    }
  }
}