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

Buggy submission (status: Time Limit Exceeded):
#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;
}

Fixed submission:
#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;
}
Problem p02596 (C++)

Buggy submission (status: 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;
  }
}


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;

    if (i > 1000000) {
      cout << "-1";
      exit(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 arr(n) array<int, n>
#define INF 1e9
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ll K;
  cin >> K;
  ll x = 0;
  rep(i, 300000000) {
    x = (x * 10 + 7) % K;
    if (x == 0) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

int main() {
  ll K;
  cin >> K;
  ll x = 0;
  rep(i, 30000000) {
    x = (x * 10 + 7) % K;
    if (x == 0) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p02596 (Python)

Buggy submission (status: Time Limit Exceeded):
# coding: utf-8
k = int(input())
kx = k
if k % 2 == 1:
    while True:
        num = list(str(kx))
        if all(kx == "7" for kx in num):
            print(len(str(kx)))
            break
        kx = kx + k
else:
    print("-1")


Fixed submission:
# coding: utf-8
k = int(input())
ans = -1
x = 7

for i in range(k):
    if x % k == 0:
        ans = i + 1
        break
    x = (10 * x + 7) % k
print(ans)
Problem p02596 (Python)

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

if k % 2 == 0:
    print(-1)
else:
    ans = 1
    num = 7 % k
    temp = 7 % k
    while True:
        if num % k == 0:
            print(ans)
            break
        else:
            ans += 1
            temp = temp * 10 % k
            num += temp % k
            num %= k


Fixed submission:
k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    ans = 1
    num = 7 % k
    temp = 7 % k
    while True:
        if num % k == 0:
            print(ans)
            break
        else:
            ans += 1
            temp = temp * 10 % k
            num += temp % k
            num %= k
Problem p02596 (C++)

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

int main() {
  int k;
  cin >> k;
  ll val = 7;
  int count = 0;
  bool temp = true;
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    while (true) {
      if (val % k == 0) {
        count++;
        break;
      } else if (count > k) {
        temp = false;
      } else {
        val = (val % k) * 10 + 7;
        count++;
      }
    }
    if (temp) {
      cout << count << endl;
    } else {
      cout << -1 << endl;
    }
  }
}


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

int main() {
  int k;
  cin >> k;
  ll val = 7;
  int count = 0;
  bool temp = true;
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    while (true) {
      if (val % k == 0) {
        count++;
        break;
      } else if (count > k) {
        temp = false;
        break;
      } else {
        val = (val % k) * 10 + 7;
        count++;
      }
    }
    if (temp) {
      cout << count << endl;
    } else {
      cout << -1 << endl;
    }
  }
}
Problem p02596 (Python)

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

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    ans = 1
    num = 7
    while True:
        if int(num) % k == 0:
            print(ans)
            break
        else:
            ans += 1
            num += 7 * pow(10, ans - 1, k)
            num %= k


Fixed submission:
k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    ans = 1
    num = 7
    while True:
        if num % k == 0:
            print(ans)
            break
        else:
            ans += 1
            num += 7 * pow(10, ans - 1, k)
            num %= k
Problem p02596 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3


def main():
    K = int(input())
    if K % 7 == 0:
        L = 9 * K / 7
    else:
        L = 9 * K
    if L == 2 or L == 5:
        ans = -1
    else:
        i = 1
        tmp = 10
        while True:
            tmp %= L
            if tmp == 1:
                ans = i
                break
            i += 1
            tmp *= 10

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3


def main():
    K = int(input())
    if K % 7 == 0:
        L = 9 * K / 7
    else:
        L = 9 * K
    if L % 2 == 0 or L % 5 == 0:
        ans = -1
    else:
        i = 1
        tmp = 10
        while True:
            tmp %= L
            if tmp == 1:
                ans = i
                break
            i += 1
            tmp *= 10

    print(ans)


if __name__ == "__main__":
    main()
Problem p02596 (Python)

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

ans = 1
a = 7
i = K
while K > 0:
    m = a % K
    if m == 0:
        print(ans)
        break
    else:
        ans += 1
        a = m * 10 + 7
        i -= 1
if m != 0:
    print(-1)


Fixed submission:
K = int(input())

ans = 1
a = 7
i = K
while i > 0:
    m = a % K
    if m == 0:
        print(ans)
        break
    else:
        ans += 1
        a = m * 10 + 7
        i -= 1
if m != 0:
    print(-1)
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}


Fixed submission:
#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;
}
Problem p02596 (C++)

Buggy submission (status: 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;
  }

  return 0;
}


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;
    if (sol == 1000000) {
      cout << -1;
      return 0;
    }
  }

  return 0;
}
Problem p02596 (Python)

Buggy submission (status: Time Limit Exceeded):
from sys import stdin

input = stdin.buffer.readline
k = int(input())
t, c = 7, 1
while t % k:
    t = t * 10 + 7
    c += 1
print(c)


Fixed submission:
from sys import stdin

input = stdin.buffer.readline
k = int(input())
t = 7
for i in range(1, k + 1):
    if not t % k:
        print(i)
        exit()
    t = (t * 10 + 7) % k
print(-1)
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
  int K, X = 7, count = 1;
  cin >> K;
  int N = X % K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  while (N != 0) {
    N = N * 10 + 7;
    N %= K;
    count++;
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
  int K, X = 7, count = 1;
  cin >> K;
  int N = X % K;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  while (N != 0) {
    N = N * 10 + 7;
    N %= K;
    count++;
  }
  cout << count << endl;
}
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 a = 7;
  ll ans = 1;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (a % k == 0) {
      cout << ans << endl;
      return 0;
    }
    a = (a * 10 + 7) % k;
    ans++;
  }
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
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;
}

const int mod = 1000000007;
const int INF = 1001001001;
int main() {
  int K;
  cin >> K;
  int t = 7;
  vector<bool> use(K - 1, false);
  for (int i = 0; i < K; i++) {
    if (use[t % K]) {
      cout << -1 << endl;
      return 0;
    }
    if (t % K == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    use[t % K] = true;
    t %= K;
    t *= 10;
    t += 7;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
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;
}

const int mod = 1000000007;
const int INF = 1001001001;
int main() {
  int K;
  cin >> K;
  int t = 7;
  vector<bool> use(K, false);
  for (int i = 0; i < K; i++) {
    if (use[t % K]) {
      cout << -1 << endl;
      return 0;
    }
    if (t % K == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    use[t % K] = true;
    t %= K;
    t *= 10;
    t += 7;
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

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

  lint cur = 7 % k;
  lint mul = 70;
  int res = 1;

  while (cur != 0) {
    cur += mul;
    cur %= k;
    mul *= 10;
    mul %= k;
    res++;
  }

  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

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

  lint cur = 7 % k;
  lint mul = 70;
  int res = 1;

  while (cur != 0) {
    cur += mul;
    cur %= k;
    mul *= 10;
    mul %= k;
    res++;
    if (res >= k + 2) {
      cout << "-1" << endl;
      exit(0);
    }
  }

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

Buggy submission (status: 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 (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;
}


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 (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;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
  } else {
    ll m = 7 % n;
    ll ten = 10;
    ll cnt = 1;
    while (m != 0) {
      cnt++;
      m += ten * 7 % n;
      m %= n;
      ten *= 10;
      ten %= n;
    }
    cout << cnt << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1 << endl;
  } else {
    ll m = 7 % n;
    ll ten = 10;
    ll cnt = 1;
    while (m != 0) {
      cnt++;
      m += ten * 7 % n;
      m %= n;
      ten *= 10;
      ten %= n;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p02596 (C++)

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

#define pb push_back
#define fi first
#define se second

using namespace std;

long long power(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p; // Update x if it is more than or
             // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

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

  long long remain = 7 % k;

  long long counter = 1;

  while (remain) {
    remain = remain + 7 * power(10, counter, k);
    remain = remain % k;

    counter++;

    if (counter > 10000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << counter << endl;

  return 0;
}


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

#define pb push_back
#define fi first
#define se second

using namespace std;

long long power(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p; // Update x if it is more than or
             // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

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

  long long remain = 7 % k;

  long long counter = 1;

  while (remain) {
    remain = remain + 7 * power(10, counter, k);
    remain = remain % k;

    counter++;

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

  cout << counter << endl;

  return 0;
}
Problem p02596 (C++)

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

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


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

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

Buggy submission (status: 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 = -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;
}

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 = -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;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1000000000000000000, mod = 1000000007, BS, k;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1";
  } else {
    ll sum = 0, curr = 7;
    while (1) {
      if (curr % n == 0) {
        break;
      }
      curr = (curr * 10) % n;
      curr = (curr + 7) % n;
      sum++;
    }
    std::cout << sum + 1 << "\n";
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1000000000000000000, mod = 1000000007, BS, k;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  if (n % 5 == 0) {
    cout << "-1";
    return 0;
  }
  if (n % 2 == 0) {
    cout << "-1";
  } else {
    ll sum = 0, curr = 7;
    while (1) {
      if (curr % n == 0) {
        break;
      }
      curr = (curr * 10) % n;
      curr = (curr + 7) % n;
      sum++;
    }
    std::cout << sum + 1 << "\n";
  }
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl
#define INF (int)1e9
#define EPS (double)1e-9
#define MOD ((int)1e9 + 7)
using namespace std;
typedef long long llong;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
template <class Type> void line(const Type &a) {
  int cnt = 0;
  for (const auto &elem : a) {
    if (cnt++)
      cerr << ' ';
    cerr << elem;
  }
  cerr << endl;
}

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

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

  int ans = 0;
  llong tmp = 0;
  while (1) {
    ans++;
    tmp = 10 * tmp + 7;
    tmp %= k;
    if (tmp == 0)
      break;
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl
#define INF (int)1e9
#define EPS (double)1e-9
#define MOD ((int)1e9 + 7)
using namespace std;
typedef long long llong;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
template <class Type> void line(const Type &a) {
  int cnt = 0;
  for (const auto &elem : a) {
    if (cnt++)
      cerr << ' ';
    cerr << elem;
  }
  cerr << endl;
}

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

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

  int ans = 0;
  llong tmp = 0;
  while (1) {
    ans++;
    tmp = 10 * tmp + 7;
    tmp %= k;
    if (tmp == 0)
      break;
  }

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

Buggy submission (status: 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;
      }
    }
  return 0;
}

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;
      }
      if (cnt > k) {
        puts("-1");
        break;
      }
    }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}


Fixed submission:
#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;
}
Problem p02596 (C++)

Buggy submission (status: 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 (tot % k == 0) {
      ans++;
      ok = false;
      break;
    } else {
      tot *= 10;
      tot += 1;
      tot %= k;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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 (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;
}
Problem p02596 (C++)

Buggy submission (status: 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;
    }
    pow10 *= 10;
    pow10 %= K;
  }
  cout << ans << endl;
}

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


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;
    }
    reminder.insert(n7);
    pow10 *= 10;
    pow10 %= K;
  }
  cout << ans << endl;
}

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

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

using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

void go() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1";
    return;
  }
  int track = 0, ans = -1;
  for (int i = 0;; i++) {
    track = (track * 10 + 7) % k;
    if (track == 0) {
      ans = i + 1;
      break;
    }
  }
  cout << ans;
}
int main() {
  fastio();
  go();

  return 0;
}


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

using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

void go() {
  int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << "-1";
    return;
  }
  int track = 0, ans = -1;
  for (int i = 0;; i++) {
    track = (track * 10 + 7) % k;
    if (track == 0) {
      ans = i + 1;
      break;
    }
  }
  cout << ans;
}
int main() {
  fastio();
  go();

  return 0;
}
Problem p02596 (C++)

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x, y) make_pair((x), (y))
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

void solve() {

  int k;
  cin >> k;
  bool rem[k];
  memset(rem, false, sizeof(rem));
  int n = 7;
  int cnt = 0;
  while (1) {
    cnt++;
    if (n % k == 0) {
      cout << cnt << '\n';
      return;
    }
    if (rem[n % k]) {
      cout << -1 << '\n';
      return;
    }
    n = (n * 10 + 7) % k;
  }
}

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

  boost;

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

  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";

    solve();
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x, y) make_pair((x), (y))
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

void solve() {

  int k;
  cin >> k;
  bool rem[k];
  memset(rem, false, sizeof(rem));
  int n = 7;
  int cnt = 0;
  while (1) {
    cnt++;
    if (n % k == 0) {
      cout << cnt << '\n';
      return;
    }
    if (rem[n % k]) {
      cout << -1 << '\n';
      return;
    }
    rem[n % k] = true;
    n = (n * 10 + 7) % k;
  }
}

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

  boost;

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

  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";

    solve();
  }
  return 0;
}
Problem p02596 (C++)

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

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

  ll res = 1;
  ll x = 7;
  while (true) {
    x %= k;
    if (x == 0) {
      cout << res << endl;
      break;
    }
    res++;
    x *= 10;
    x += 7;
  }
}

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

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

  ll res = 1;
  ll x = 7;
  while (true) {
    if (res == 2000000) {
      cout << "-1" << endl;
      break;
    }
    x %= k;
    if (x == 0) {
      cout << res << endl;
      break;
    }
    res++;
    x *= 10;
    x += 7;
  }
}
Problem p02596 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  ll k;
  ll a = 7;
  for (int i = 0; i <= k; i++) {
    if (a % k == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    a = (a * 10 + 7) % k;
  }

  cout << -1 << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  ll k;
  cin >> k;
  ll a = 7;
  for (int i = 0; i <= k; i++) {
    if (a % k == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    a = (a * 10 + 7) % k;
  }

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

Buggy submission (status: 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) {
    cout << -1 << endl;
  } else {
    long long p = 7 % n;
    j++;
    while (p != 0) {
      p = (p * 10 + 7) % n;
      j++;
    }
    cout << j << endl;
  }
}


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 || 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;
  }
}
Problem p02596 (C++)

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

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0)
    return cout << -1, 0;
  string s = "7";
  long long cur_power = 1, cur = 7;
  while (cur % k != 0) {
    cur_power = cur_power * 10 % k;
    cur = cur + 7 * cur_power % k;
    cur %= k;
    s += '7';
  }
  cout << s.size();
}


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

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0)
    return cout << -1, 0;
  string s = "7";
  long long cur_power = 1, cur = 7;
  while (cur % k != 0) {
    cur_power = cur_power * 10 % k;
    cur = cur + 7 * cur_power % k;
    cur %= k;
    s += '7';
    if (s.size() > k)
      return cout << -1, 0;
  }
  cout << s.size();
}
Problem p02596 (C++)

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

int main() {
  ll k;
  ll count = 0;
  ll amount = 0;
  ll ans = -1;
  cin >> k;
  if (k % 2 == 0) {
    cout << ans << endl;
  } else {
    for (;;) {
      amount *= 10;
      amount += 7;
      count++;
      if (amount % k == 0) {
        ans = count;
        break;
      } else {
        amount = amount % k;
      }
    }
    cout << ans << endl;
  }
}

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

int main() {
  ll k;
  ll count = 0;
  ll amount = 0;
  ll ans = -1;
  cin >> k;
  if (k % 2 == 0) {
    cout << ans << endl;
  } else {
    rep(i, 1e7) {
      amount *= 10;
      amount += 7;
      count++;
      if (amount % k == 0) {
        ans = count;
        break;
      } else {
        amount = amount % k;
      }
    }
    cout << ans << endl;
  }
}
Problem p02596 (C++)

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

int main() {
  int k;
  cin >> k;
  if ((k % 2) == 0 || (k % 5) == 0)
    cout << -1 << endl;
  else if (k == 1)
    cout << 1 << endl;
  else {
    if ((k % 7) == 0)
      k /= 7;
    vector<int> x(0);
    x.push_back(1 % k);
    while (1) {
      int X = (10 * x.at(x.size() - 1)) % k;
      if (X == 1)
        break;
      x.push_back(X);
    }
    int c = 0, m = 0;
    bool b = 0;
    while (1) {
      for (int X : x) {
        c++;
        m += X;
        m = m % k;
        if (m == 0) {
          b = 1;
          break;
        }
      }
      if (b)
        break;
    }
    cout << c << endl;
  }
}

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

int main() {
  int k;
  cin >> k;
  if ((k % 2) == 0 || (k % 5) == 0)
    cout << -1 << endl;
  else if (k == 1 || k == 7)
    cout << 1 << endl;
  else {
    if ((k % 7) == 0)
      k /= 7;
    vector<int> x(0);
    x.push_back(1 % k);
    while (1) {
      int X = (10 * x.at(x.size() - 1)) % k;
      if (X == 1)
        break;
      x.push_back(X);
    }
    int c = 0, m = 0;
    bool b = 0;
    while (1) {
      for (int X : x) {
        c++;
        m += X;
        m = m % k;
        if (m == 0) {
          b = 1;
          break;
        }
      }
      if (b)
        break;
    }
    cout << c << endl;
  }
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n)                                                              \
  ;                                                                            \
  for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> state;
long double pi = acos(-1);
const int INF = 1001001001;

// 最小公倍数を求める
int euqlid(int a, int b) {
  int temp;
  temp = a % b;
  if (temp == 0)
    return b;
  return euqlid(b, temp);
}
ll conbination(ll a, ll b) {
  ll u = 1;
  ll d = 1;
  while (b != 0) {
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s) { return (int(s - '0')); }
char changeS(char alpha) {
  if (0x41 <= alpha and alpha <= 0x5A)
    return (alpha + 0x20);
  else if (0x61 <= alpha and alpha <= 0x7A)
    return (alpha - 0x20);
  return alpha;
}
int fact(int n) {
  if (n == 1)
    return 1;
  return n * fact(n - 1);
}
int ceil(int a, int b) {
  // a/bの切り上げを考える
  return (a + b - 1) / b;
}

int main() {
  int k;
  cin >> k;
  int ans = -1;

  if (k % 2 == 0) {
    cout << ans << endl;
    return 0;
  }
  int seven = 7;
  int cnt = 1;
  seven %= k;
  while (1) {
    if (seven == 0)
      break;
    else {
      seven = (7 + seven * 10) % k;
      cnt++;
    }
  }
  cout << cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n)                                                              \
  ;                                                                            \
  for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> state;
long double pi = acos(-1);
const int INF = 1001001001;

// 最小公倍数を求める
int euqlid(int a, int b) {
  int temp;
  temp = a % b;
  if (temp == 0)
    return b;
  return euqlid(b, temp);
}
ll conbination(ll a, ll b) {
  ll u = 1;
  ll d = 1;
  while (b != 0) {
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s) { return (int(s - '0')); }
char changeS(char alpha) {
  if (0x41 <= alpha and alpha <= 0x5A)
    return (alpha + 0x20);
  else if (0x61 <= alpha and alpha <= 0x7A)
    return (alpha - 0x20);
  return alpha;
}
int fact(int n) {
  if (n == 1)
    return 1;
  return n * fact(n - 1);
}
int ceil(int a, int b) {
  // a/bの切り上げを考える
  return (a + b - 1) / b;
}

int main() {
  int k;
  cin >> k;
  int ans = -1;

  if (k % 2 == 0) {
    cout << ans << endl;
    return 0;
  }
  int seven = 7;
  int cnt = 1;
  seven %= k;
  while (1) {
    if (seven == 0)
      break;
    else {
      seven = (7 + seven * 10) % k;
      cnt++;
    }
    if (cnt > k) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << cnt << endl;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  int count = 1;
  cin >> n;
  k = 7;
  long long int sum = 7;
  if (n % 2 == 0 || n == 5) {
    cout << "-1\n";
    return 0;
  }
  while (sum % n != 0) {
    sum = sum + ((k % n) * (10 % n)) % n;
    k = ((k % n) * (10 % n));
    count++;
  }
  cout << count << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  int count = 1;
  cin >> n;
  k = 7;
  long long int sum = 7;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << "-1\n";
    return 0;
  }
  while (sum % n != 0) {
    sum = sum + ((k % n) * (10 % n)) % n;
    k = ((k % n) * (10 % n));
    count++;
  }
  cout << count << "\n";
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
// author-Shivam gupta

#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert(B <= A && A <= C)

#define MP make_pair
#define FOR(i, a) for (int i = 0; i < a; i++)

#define FOR1(i, j, a) for (int i = j; i < a; i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout << x << '\n'
#define out1(x) cout << x << " "
#define END cout << '\n'
#define int long long
void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

signed main() {

  int n;
  cin >> n;
  if (n % 2 == 0) {
    out(-1);
    return 0;
  }
  int x = 0;
  int p = n;
  int cnt = 0;
  while (p > 0) {
    x *= 10;
    x += 7;
    p = p / 10;
    cnt++;
  }
  if (x < n) {
    x *= 10;
    x += 7;
    cnt++;
  }
  int a = x % n;
  if (a == 0) {
    out(cnt);
    return 0;
  }
  p = a;
  while (p < n) {
    p *= 10;
    p += 7;
    cnt++;
  }
  while (1) {
    a = p % n;
    if (a == 0) {
      out(cnt);
      return 0;
    }

    p = a;
    while (p < n) {
      p *= 10;
      p += 7;
      cnt++;
    }
  }
  out(-1);
}


Fixed submission:
// author-Shivam gupta

#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert(B <= A && A <= C)

#define MP make_pair
#define FOR(i, a) for (int i = 0; i < a; i++)

#define FOR1(i, j, a) for (int i = j; i < a; i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout << x << '\n'
#define out1(x) cout << x << " "
#define END cout << '\n'
#define int long long
void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

signed main() {

  int n;
  cin >> n;
  if (n % 2 == 0) {
    out(-1);
    return 0;
  }
  int x = 0;
  int p = n;
  int cnt = 0;
  while (p > 0) {
    x *= 10;
    x += 7;
    p = p / 10;
    cnt++;
  }
  if (x < n) {
    x *= 10;
    x += 7;
    cnt++;
  }
  int a = x % n;
  if (a == 0) {
    out(cnt);
    return 0;
  }
  p = a;
  while (p < n) {
    p *= 10;
    p += 7;
    cnt++;
  }
  int w = 1000000;
  while (w--) {
    a = p % n;
    if (a == 0) {
      out(cnt);
      return 0;
    }

    p = a;
    while (p < n) {
      p *= 10;
      p += 7;
      cnt++;
    }
  }
  out(-1);
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template <typename T> T gcd(T a, T b) { return (a % b) ? gcd(b, a % b) : b; }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }

int main(void) {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    int i = 1;
    ll rem = 0;
    ll num = 7;
    while (1) {
      num = num % k;
      rem += num;
      if (rem % k == 0) {
        cout << i << endl;
        break;
      }
      num *= 10;
      i++;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template <typename T> T gcd(T a, T b) { return (a % b) ? gcd(b, a % b) : b; }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }

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

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

using ll = long long;
using namespace std;

int main() {
  long a = 0;
  long K;
  cin >> K;
  if (K % 7 == 0)
    K /= 7;
  if (K % 2 == 0) {
    cout << -1;
    exit(0);
  }
  long n = 1;
  long r = 1 % K;
  while (r != 0) {
    r = (10 * r + 1) % K;
    n += 1;
  }
  cout << n;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using ll = long long;
using namespace std;

int main() {
  long a = 0;
  long K;
  cin >> K;
  if (K % 7 == 0)
    K /= 7;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1;
    exit(0);
  }
  long n = 1;
  long r = 1 % K;
  while (r != 0) {
    r = (10 * r + 1) % K;
    n += 1;
  }
  cout << n;
  return 0;
}