Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    dic = {}
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            dic
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1
            if right == 1:
                print(-1)
                return

if __name__ == "__main__":
    run()

Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    right_set = set()
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            right_set.add(right)
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1
            if right in right_set:
                print(-1)
                return

if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    dic = {}
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            dic
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1
            if right == 1:
                print(-1)
                return

if __name__ == "__main__":
    run()

Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    right_set = set()
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            right_set.add(right)
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1
            if right in right_set:
                print(-1)
                return

if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1

if __name__ == "__main__":
    run()

Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    right_set = set()
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            right_set.add(right)
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1
            if right in right_set:
                print(-1)
                return

if __name__ == "__main__":
    run()