Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mod = 10**9+7
ans = 1
for i in range(1,n+1):
  ans *= i
print(ans%mod)

Fixed submission:
n = int(input())
mod = 10**9+7
ans = 1
for i in range(1,n+1):
  ans = i * ans%mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
x = 1
mod = 10**9+7
for i in range(1,N+1):
  x *= i
print(x%mod)

Fixed submission:
n = int(input())
mod = 10**9+7
ans = 1
for i in range(1,n+1):
  ans = i * ans%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
a,op,b = input().split()
if op == "+":
  print(a+b)
else:
  print(a-b)

Fixed submission:
a,op,b = input().split()
if op == "+":
  print(int(a)+int(b))
else:
  print(int(a)-int(b))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
ans = 0
for i in range(a,b+1):
  if i%x == 0:
    ans += 1
print(ans)

Fixed submission:
def hoge(a,x):
  if a == 0:
    return 0
  else:
    return a//x

a, b, x = map(int, input().split())

ans = hoge(b,x) - hoge(a-1,x)
print(ans)
Buggy python submission (verdict: Runtime Error):
　n = int(input())
  print(n/2(n+1))

Fixed submission:
n = int(input())
print(int(n/2*(n+1)))
Buggy python submission (verdict: Runtime Error):
n = int(input())


def digits_of(n):
    digits = [] 
    while n != 0:
        r = n % 10 
        digits.append(r) 
        n = n // 10  
    return digits


def is_multiple_of_9(n): 
    sum = 0  
    for i in digits_of(n):
        sum += i
    return sum % 9 == 0


if is_multiple_of_9(n):
    print("Yes")
else:
    print("No")


Fixed submission:
n, x, t, = map(int, input().split())

result = n // x
result2 = n % x
if result2 != 0:
    result += 1
result *= t
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())


def digits_of(n):
    digits = [] 
    while n != 0:
        r = n % 10 
        digits.append(r) 
        n = n // 10  
    return digits


def is_multiple_of_9(n): 
    sum = 0  
    for i in digits_of(n):
        sum += i
    return sum % 9 == 0


if is_multiple_of_9(n):
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())


def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)


resu = digitSum(n) % 9
if resu == 0:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())


def digits_of(n):
    digits = [] 
    while n != 0:
        r = n % 10 
        digits.append(r) 
        n = n // 10  
    return digits


def is_multiple_of_9(n): 
    sum = 0  
    for i in digits_of(n):
        sum += i
    return sum % 9 == 0


if is_multiple_of_9(n):
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())


def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)


resu = digitSum(n) % 9
if resu == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
​
cnt = [Counter(), Counter()]
cmn = [0, 0]
for parity in range(2):
    for i in (range(parity, n, 2)):
        cnt[parity][v[i]] += 1
    cmn[parity] = cnt[parity].most_common(1)[0]
​
if cmn[0][0] != cmn[1][0]:
    ret = n - cmn[0][1] - cmn[1][1]
else:
    subcmn_mult = [0, 0]
    for parity in range(2):
        try:
            subcmn_mult[parity] = cnt[parity].most_common(2)[1][1]
        except IndexError:
            subcmn_mult[parity] = 0
    ret = n - cmn[0][1] - max(subcmn_mult[0], subcmn_mult[1])
print(ret)

Fixed submission:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

k = n // 2
half = [Counter(), Counter()]
for i in range(k):
    for par in range(2):
        half[par][v[2*i+par]] += 1

cmn = [0, 0]
for par in range(2):
    cmn[par] = half[par].most_common(2)
    if len(cmn[par]) == 1:
        cmn[par].append(('ghost', 0))
if cmn[0][0][0] != cmn[1][0][0]:
    ret = n - cmn[0][0][1] - cmn[1][0][1]
else:
    ret = n - max(cmn[0][0][1] + cmn[1][1][1], cmn[0][1][1] + cmn[1][0][1])
print(ret)
Buggy python submission (verdict: Runtime Error):
n = int(input())
imin = n // 4
flag = False
for i in range(imin, 3501):
    jmin = i * n // (4 * i - n)
    for j in range(jmin, 3501):
        num = i * j * n
        den = 4 * i * j - i * n - j * n
        if den > 0 and num % den == 0:
            k = num // den
            print("{} {} {}".format(i, j, k))
            flag = True
    if flag:
        break


Fixed submission:
n = int(input())
imin = n // 4
flag = False
for i in range(imin, 3501):
    num = i * n
    den = 4 * i - n
    if den <= 0:
        continue
    jmin = num // den
    for j in range(jmin, 3501):
        num = i * j * n
        den = 4 * i * j - i * n - j * n
        if den > 0 and num % den == 0:
            k = num // den
            print("{} {} {}".format(i, j, k))
            flag = True
            break
    if flag:
        break

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
flag = False
for i in range(3500):
    for j in range(i, 3500):
        num = n * i * j
        den = 4 * i * j - i * n - j * n
        if den > 0 and not num % den:
            k = num // den
            print("{} {} {}".format(i, j, k))
            flag = True
            break
    if flag:
        break


Fixed submission:
n = int(input())
imin = n // 4
flag = False
for i in range(imin, 3501):
    num = i * n
    den = 4 * i - n
    if den <= 0:
        continue
    jmin = num // den
    for j in range(jmin, 3501):
        num = i * j * n
        den = 4 * i * j - i * n - j * n
        if den > 0 and num % den == 0:
            k = num // den
            print("{} {} {}".format(i, j, k))
            flag = True
            break
    if flag:
        break
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e = map(int, input().split())


if a == 0:
        print(1)
    elif b == 0:
        print(2)
    elif c == 0:
        print(3)
    elif d == 0:
        print(4)
    else:
        print(5)

Fixed submission:
a,b,c,d,e = map(int, input().split())


if a == 0:
    print(1)
elif b == 0:
    print(2)
elif c == 0:
    print(3)
elif d == 0:
    print(4)
else:
    print(5)
Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np

h, w, k = map(int, input().split())
f = [list(input()) for i in range(h)]
f = np.array(f)
ans = 0
for i in range(w+1):
    for j in range(h+1):
        for p in itertools.combinations(range(w), i):
            for q in itertools.combinations(range(h), j):
                g = f.copy()
                cnt = 0
                for r in q:
                    g[r] = 'r'
                for r in p:
                    g.T[r] = 'r'
                
                for s in range(w):
                    for t in range(h):
                        if g[t][s] == '#':
                            cnt +=1
                if cnt == k:
                    ans += 1
print(ans)

Fixed submission:
h, w, k = map(int, input().split())
C = [list(input()) for i in range(h)]
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        cnt = 0
        for x in range(h):
            if (i>>x)&1 == 1:
                continue
            for y in range(w):
                if (j>>y)&1 == 1:
                    continue
                if C[x][y] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np
import copy
h, w, k = map(int, input().split())
f = [list(input()) for i in range(h)]
f = np.array(f)
ans = 0
for i in range(w+1):
    for j in range(h+1):
        for p in itertools.combinations(range(w), i):
            for q in itertools.combinations(range(h), j):
                g = f.copy()
                cnt = 0
                for r in q:
                    g[r] = 'r'
                for r in p:
                    g.T[r] = 'r'
                
                for s in range(w):
                    for t in range(h):
                        if g[t][s] == '#':
                            cnt +=1
                if cnt == k:
                    ans += 1
print(ans)

Fixed submission:
h, w, k = map(int, input().split())
C = [list(input()) for i in range(h)]
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        cnt = 0
        for x in range(h):
            if (i>>x)&1 == 1:
                continue
            for y in range(w):
                if (j>>y)&1 == 1:
                    continue
                if C[x][y] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
inf = 1000000000
h, w = map(int, input().split())
root = [[-np.inf]*w for i in range(h)]
root[0][0] = 1
s = [[] for i in range(h)]

cnt = 0
for i in range(h):
    s[i] = input()
    for j in range(w):
        if s[i][j] == '#': cnt+=1
dw = [-1, 0, 1, 0]
dh = [0, 1, 0, -1]
que = deque()
que.append([0, 0])
while que:
    x, y = que.pop()
    for dx, dy in zip(dw, dh):
        nx, ny = x+dx, y+dy
        if 0<=nx<w and 0<=ny<h and root[ny][nx]<=0 and s[ny][nx]=='.':
                que.append([nx, ny])
                root[ny][nx] = root[y][x] + 1
if root[h-1][w-1]<0:
    print(-1)
else:
    print(h*w - cnt - root[h-1][w-1])

Fixed submission:
from collections import deque
inf = 1000000000
h, w = map(int, input().split())
root = [[-1]*w for i in range(h)]
root[0][0] = 1
s = [[] for i in range(h)]

cnt = 0
for i in range(h):
    s[i] = input()
    for j in range(w):
        if s[i][j] == '#': cnt+=1
dw = [-1, 0, 1, 0]
dh = [0, 1, 0, -1]
que = deque()
que.append([0, 0])
while len(que)>0:
    x, y = que.popleft()
    for dx, dy in zip(dw, dh):
        nx, ny = x+dx, y+dy
        if 0<=nx<w and 0<=ny<h and root[ny][nx]==-1 and s[ny][nx]=='.':
                que.append([nx, ny])
                root[ny][nx] = root[y][x] + 1
if root[h-1][w-1]<0:
    print(-1)
else:
    print(h*w - cnt - root[h-1][w-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np
from collections import deque

h, w = map(int, input().split())
root = [[-np.inf]*w for i in range(h)]
root[0][0] = 1
s = [[] for i in range(h)]

cnt = 0
for i in range(h):
    s[i] = input()
    for j in range(w):
        if s[i][j] == '#': cnt+=1
dw = [-1, 0, 1, 0]
dh = [0, 1, 0, -1]
que = deque()
que.append([0, 0])
while que:
    x, y = que.pop()
    for dx, dy in zip(dw, dh):
        nx, ny = x+dx, y+dy
        if 0<=nx<w and 0<=ny<h and root[ny][nx]<=0 and s[ny][nx]=='.':
                que.append([nx, ny])
                root[ny][nx] = root[y][x] + 1
if root[h-1][w-1]<0:
    print(-1)
else:
    print(h*w - cnt - root[h-1][w-1])

Fixed submission:
from collections import deque
inf = 1000000000
h, w = map(int, input().split())
root = [[-1]*w for i in range(h)]
root[0][0] = 1
s = [[] for i in range(h)]

cnt = 0
for i in range(h):
    s[i] = input()
    for j in range(w):
        if s[i][j] == '#': cnt+=1
dw = [-1, 0, 1, 0]
dh = [0, 1, 0, -1]
que = deque()
que.append([0, 0])
while len(que)>0:
    x, y = que.popleft()
    for dx, dy in zip(dw, dh):
        nx, ny = x+dx, y+dy
        if 0<=nx<w and 0<=ny<h and root[ny][nx]==-1 and s[ny][nx]=='.':
                que.append([nx, ny])
                root[ny][nx] = root[y][x] + 1
if root[h-1][w-1]<0:
    print(-1)
else:
    print(h*w - cnt - root[h-1][w-1])
Buggy python submission (verdict: Runtime Error):
import sys

n=int(input())
a=list(int(x) for x in input().split())

count=0
z=True
j=0

if  1 not in a:
    print(-1)
    sys.exit(1)

for k in range(j,n):
    if a[k]==count+1:
        j=k
        count=count+1

print(n-count)

Fixed submission:
n=int(input())
a=list(int(x) for x in input().split())

count=0
z=True
j=0

if  1 not in a:
    print(-1)
else:
    for k in range(j,n):
        if a[k]==count+1:
            j=k
            count=count+1

    print(n-count)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=input().split()
ans=1

for i in range(n):
  ans*=int(a[i])
  
if ans>10**18:
  print("-1")
else:
  print(str(ans))

Fixed submission:
n=int(input())
a=input().split()
ans=1

if "0" in a:
  print("0")
  exit()
  
for i in range(n):
  ans*=int(a[i])
  if ans>10**18:
    print("-1")
    exit()
  

print(str(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n=input()
a=list(map(int,input().split()))
ans=1

for i in a:
  ans*=i
  
if ans>10**18:
  print("-1")
else:
  print(str(ans))

Fixed submission:
n=int(input())
a=input().split()
ans=1

if "0" in a:
  print("0")
  exit()
  
for i in range(n):
  ans*=int(a[i])
  if ans>10**18:
    print("-1")
    exit()
  

print(str(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=input().split()
ans=1

for i in a:
  ans*=int(i)
  
if ans>10**18:
  print("-1")
else:
  print(str(ans))

Fixed submission:
n=int(input())
a=input().split()
ans=1

if "0" in a:
  print("0")
  exit()
  
for i in range(n):
  ans*=int(a[i])
  if ans>10**18:
    print("-1")
    exit()
  

print(str(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
tot=0

for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if k-j!=j-i:
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
          tot+=1
          
print(str(tot))

Fixed submission:
n=int(input())
s=input()
r=0
g=0
b=0

for i in range(n):
  if s[i]=="R":
    r+=1
  elif s[i]=="G":
    g+=1
  else:
    b+=1
    
ans=r*g*b

for i in range(n-2):
  for j in range(i+1,i+1+(n-i-1)//2):
    if s[i]==s[j]:
      continue
    elif s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
      ans-=1
      
print(str(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
a = 7 + 10**9 
for i in range(N-1):
  for j in range(i+1,N):
    ans += (A[i] * A[j]) % a
print(ans % a)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
a = 0
ans = 0
mod = 10**9 + 7
for i in range(N-1):
  a += A[N-i-1]
  ans += A[N-i-2] * a
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
S = input()
if S = 'SSS':
  a = 0
if S = 'SSR':
  a = 1
if S = 'SRS':
  a = 1
if S = 'SRR':
  a = 2
if S = 'RSS':
  a = 1
if S = 'RSR':
  a = 1
if S = 'RRS':
  a = 2
if S = 'RRR':
  a = 3
print(a)
  

Fixed submission:
S = input()
if S == 'SSS':
  a = 0
if S == 'SSR':
  a = 1
if S == 'SRS':
  a = 1
if S == 'SRR':
  a = 2
if S == 'RSS':
  a = 1
if S == 'RSR':
  a = 1
if S == 'RRS':
  a = 2
if S == 'RRR':
  a = 3
print(a)
Buggy python submission (verdict: Runtime Error):
def sum(a,N):
  if N == 1:
    return a[0]
  return a[N-1] +  sum(a,N-1)

N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
Sum_1 = 2 * sum(a,N//2) - a[0]
if N%2 == 0:
  print(Sum_1)
if N%2 == 1:
  print(Sum_1 + a[(N+1)//2])

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
if N == 3:
  print(a[0] + a[1])
ans1 = 2*sum(a[0:N//2]) - a[0]
if N%2 == 0:
  print(ans1)
if N%2 == 1 and N != 3:
  print(ans1 + a[N//2])
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/atc001/tasks/unionfind_a
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

def main():
    n,m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a,b = map(lambda x: int(x) -1, input().split())
        uf.union(a,b)
    print(len(uf.groups())-1)

if __name__ == '__main__':
    main()

Fixed submission:
# https://atcoder.jp/contests/atc001/tasks/unionfind_a
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]
    
    def groups(self):
        groups = dict()
        for i in range(self.n):
            p = self.find(i)
            if not groups.get(p):
                groups[p] = set()
            groups[p].add(i)
        return list(groups.values())

def main():
    n,m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a,b = map(lambda x: int(x) -1, input().split())
        uf.union(a,b)
    print(len(uf.groups())-1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
candidates = pow(10, 6)
K = int(input())
num = "7"
if K % 2 == 0:
    print (-1)
else:
    flag = False
    for i in range(candidates):
        if int(num) % K == 0:
            flag = True
            break
        num += "7"
    if flag:
        print (i + 1)
    else:
        print(-1)

Fixed submission:
limit = pow(10, 7)
K = int(input())
num = "7"
if K % 2 == 0 or K % 5 == 0:
    print (-1)
else:
    total = 0
    flag = False
    for i in range(1, limit + 1):
        total = (total * 10 + 7) % K
        if total == 0:
            flag = True
            break
    if flag:
        print (i)
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
import math
alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'j', 'k', 'l', 'm',
       'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
n = int(input())
nums = []
ans = ""
while n >= 1:
    n -= 1
    ans += alp[(n % 26)]
    n = n // 26
print(ans)

Fixed submission:
n = int(input())
nums = []
ans = ""
while n >= 1:
    n -= 1
    ans += chr(ord('a') + n % 26)
    n = n // 26
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(v) for v in input().split()]
ans = 1
num = 1
limit = 1000000000000000000
for i in a:
    if i == 0:
        num = 0
        break
    if i >= limit:
        num = -1
        break
    else:
        num *= i
if num > limit:
    num = -1
ans = num
print(ans)


Fixed submission:
n = int(input())
a = [int(v) for v in input().split()]
limit = 1000000000000000000
if 0 in a:
    print (0)
else:
    ans = 1
    num = 1
    for i in a:
        num *= i
        if num > limit:
            num = -1
            break
    ans = num
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(v) for v in input().split()]
ans = 1
num = 1
for i in a:
    if num <= 10 ** 18:
        num *= i
    else:
        num = -1
if num > 10 ** 18:
    num = -1
ans = num
print(ans)


Fixed submission:
n = int(input())
a = [int(v) for v in input().split()]
limit = 1000000000000000000
if 0 in a:
    print (0)
else:
    ans = 1
    num = 1
    for i in a:
        num *= i
        if num > limit:
            num = -1
            break
    ans = num
    print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
add = a+b
minus = a-b
multi = a*b
print(max(add,minus, multi))

Fixed submission:
d = raw_input().split()
a, b = d[0], d[1]
operators = ["+", "-", "*"]
current = None
soFar = None
for i in range(len(operators)):
    current = eval(a + operators[i] + b)
    soFar = max(current, soFar)
print(soFar)
Buggy python submission (verdict: Runtime Error):
n = list(raw_input())
x, a = int(n[0]), int(n[1])
if x >= a:
    print(10)
else:
    print(0)


Fixed submission:
n = list(raw_input())
x, a = int(n[0]), int(n[2])
if x >= a:
    print(10)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n = raw_input()
input = n.split(" ")
n, x = input[0], input[1]
l = raw_input().split(" ")
current = 0
bounce = 1
for i in range(len(l)):
    current += int(l[i])
    if current <= int(x):
        bounce += 1
    else:
        break
print(bounce)


Fixed submission:
n = raw_input()
input = n.split(" ")
n, x = input[0], input[1]
l = raw_input().split(" ")
current = 0
bounce = 1
for i in range(len(l)):
    current += int(l[i])
    if current <= int(x):
        bounce += 1
    else:
        break
print(bounce)
Buggy python submission (verdict: Runtime Error):
n = int(input())
soFar = []
last = None
flag = True
for i in range(n + 1):
    x = input()
    if i == 0:
        soFar.append(x)
        last = x
    else:
        if x not in soFar and last[len(last) - 1] == x[0]:
            soFar.append(x)
            last = x
        else:
            flag = False
            break
if flag:
    print('Yes')
else:
    print('No')


Fixed submission:
n = int(input())
w = [input() for i in range(n)]
count = 0
for i in range(1, n):
    if w[i - 1][len(w[i - 1]) - 1] != w[i][0]:
        count += 1
if count == 0 and len(list(set(w))) == n:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = input()
t = input()


def iter(string, dic):
    for i in range(len(string)):
        if string[i] in dic.keys():
            dic[string[i]] += 1
        else:
            dic[string[i]] = 1
    return dic


s_pattern = Counter(s)
t_pattern = Counter(t)


def check(string, original):
    count = 0
    length = len(string)
    flag = False
    while 1:
        if string == original:
            flag = True
            break
        if count == length:
            flag = False
            break
        last = string[-1]
        string = last + string[:-1]
    return flag


if s_pattern != t_pattern:
    print('No')
else:
    if check(s, t):
        print('Yes')
    else:
        print('No')


Fixed submission:
from collections import Counter
s = input()
t = input()


s_pattern = Counter(s)
t_pattern = Counter(t)


def check(string, original):
    n = len(string)
    flag = False
    for i in range(n):
        if original == string[i:] + s[:i]:
            flag = True
            break
    return flag


if s_pattern != t_pattern:
    print('No')
else:
    if check(s, t):
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
s = input()
t = input()
s_dic = defaultdict()
t_dic = defaultdict()


def iter(string, dic):
    for i in range(len(string)):
        if string[i] in dic.keys():
            dic[string[i]] += 1
        else:
            dic[string[i]] = 1
    return dic


s_pattern = iter(s, s_dic)
t_pattern = iter(t, t_dic)


def check(string, original):
    count = 0
    length = len(string)
    flag = False
    while 1:
        if string == original:
            flag = True
            break
        if count == length:
            flag = False
            break
        last = string[-1]
        string = last + string[:-1]
    return flag


if s_pattern != t_pattern:
    print('No')
else:
    if check(s, t):
        print('Yes')
    else:
        print('No')


Fixed submission:
from collections import Counter
s = input()
t = input()


s_pattern = Counter(s)
t_pattern = Counter(t)


def check(string, original):
    n = len(string)
    flag = False
    for i in range(n):
        if original == string[i:] + s[:i]:
            flag = True
            break
    return flag


if s_pattern != t_pattern:
    print('No')
else:
    if check(s, t):
        print('Yes')
    else:
        print('No')