Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
sys.setrecursionlimit(10**6)

n = ni()
def idx(u,v):
    return u*n+v
tree = [[] for i in range(n**2)]
go=[False]*n**2
back=[False]*n**2
memo = [1]*n**2 #memo[i] iからの深さ
start = []
for i in range(n):
    A1 = lma()
    pu,pv = i,A1[0]-1
    if pu>pv:pu,pv=pv,pu
    start.append(idx(pu,pv))
    for j in range(1,n-1):
        u,v = i,A1[j]-1
        if u>v:u,v=v,u
        tree[idx(pu,pv)].append(idx(u,v))
        pu,pv=u,v
        start.append(idx(pu,pv))
#print(tree)
def dfs(s):
    go[s]=True
    for node in tree[s]:
        if not go[node]:
            memo[s] = max(dfs(node)+1,memo[s])
        else:
            if back[node]:
                memo[s] = max(memo[node]+1,memo[s])
            else:
                print(-1)
                exit()
    back[s]=True
    return memo[s]
ans = 0
for s in start:
    if not go[s]:
        ans = max(ans,dfs(s))
print(ans)


Fixed submission:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
sys.setrecursionlimit(10**6)

n = ni()
def idx(u,v):
    return u*n+v
tree = [[] for i in range(n**2)]
go=[False]*n**2
back=[False]*n**2
memo = [1]*n**2 #memo[i] iからの深さ
start = []
for i in range(n):
    A1 = lma()
    pu,pv = i,A1[0]-1
    if pu>pv:pu,pv=pv,pu
    start.append(idx(pu,pv))
    for j in range(1,n-1):
        u,v = i,A1[j]-1
        if u>v:u,v=v,u
        tree[idx(pu,pv)].append(idx(u,v))
        pu,pv=u,v
        start.append(idx(pu,pv))
#print(tree)
def dfs(s):
    go[s]=True
    for node in tree[s]:
        if not go[node]:
            memo[s] = max(dfs(node)+1,memo[s])
        else:
            if back[node]:
                memo[s] = max(memo[node]+1,memo[s])
            else:
                print(-1)
                exit()
    back[s]=True
    return memo[s]
ans = 0
for s in start:
    if not go[s]:
        ans = max(ans,dfs(s))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def dfs_rec(start,prev):
    ans[start] = cnt[start]
    if start!=0:
        ans[start] +=ans[prev]
    for node in tree[start]:
        if node != prev:
            dfs_rec(node,start)
    return
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n,q = map(int,input().split())
tree = [[] for i in range(n)]
cnt = [0] *n
ans = [0] *n

for i in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1]+=x
dfs_rec(0,0)
print(*ans)


Fixed submission:
def main():
    def dfs_rec(start,prev):
        ans[start] = cnt[start]
        if start!=0:
            ans[start] +=ans[prev]
        for node in tree[start]:
            if node != prev:
                dfs_rec(node,start)
        return
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline

    n,q = map(int,input().split())
    tree = [[] for i in range(n)]
    cnt = [0] *n
    ans = [0] *n

    for i in range(n-1):
        a,b = map(int,input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    for i in range(q):
        p,x = map(int,input().split())
        cnt[p-1]+=x
    dfs_rec(0,0)
    print(*ans)
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def dfs_rec(start,prev):
    ans[start] = cnt[start]
    if start!=0:
        ans[start] +=ans[prev]
    for node in tree[start]:
        if node != prev:
            dfs_rec(node,start)
    return
import sys
sys.setrecursionlimit(10**6)


n,q = map(int,input().split())
tree = [[] for i in range(n)]
cnt = [0] *n
ans = [0] *n

for i in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1]+=x
dfs_rec(0,0)
print(*ans)


Fixed submission:
def main():
    def dfs_rec(start,prev):
        ans[start] = cnt[start]
        if start!=0:
            ans[start] +=ans[prev]
        for node in tree[start]:
            if node != prev:
                dfs_rec(node,start)
        return
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline

    n,q = map(int,input().split())
    tree = [[] for i in range(n)]
    cnt = [0] *n
    ans = [0] *n

    for i in range(n-1):
        a,b = map(int,input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    for i in range(q):
        p,x = map(int,input().split())
        cnt[p-1]+=x
    dfs_rec(0,0)
    print(*ans)
if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
ls_s = list(s)
ls_t = list(t)
set_s = set(ls_s)
set_t = set(list(t))
if not set_t <= set_s:
    print(-1)
    exit()
tag_t = [-1]*len(t)
cnt_t = 0 #index of t
cnt = 0 #count i
tag = 0 #index of s
n = len(s)-1
nt = len(t)-1
for i in range(nt+1):
    while True:
        if ls_t[i] == ls_s[tag]:
            tag_t[i] = tag +1
            tag += 1
            if tag > n:
                tag = 0
            break
        tag += 1
        if tag > n:
            tag = 0
now = tag_t[0]
cnt+= now
for i in range(1,nt+1):
    pre = now
    now = tag_t[i]
    if now > pre:
        cnt +=  now - pre
    else:
        cnt += n+1 - pre + now
print(cnt)


Fixed submission:
def sn(a):
    return ord(a) - ord("a")

def isok(idx,prev):##適宜変更
    return prev>=idx+n*loops


def bisect(ls,val): ##valの関数isok(x,val)がTrueとなる一番右のindex を返す 全部Falseなら-1
    ok = -1
    ng = len(ls)
    x = (ok+ng)//2
    while ng-ok>1:
        num = ls[x]
        if isok(num,val):
            ok = x
        else:
            ng = x
        x = (ok+ng)//2
    return ok ##一番右のTrueのindex  Trueの個数はok+1こ

S = input()
T = input()
lt = list(T)
ls = list(S)
set_s = set(list(S))
set_t = set(lt)
if not set_t <= set_s:
    print(-1)
    exit()
cnts = [[] for i in range(26)]
cnts_idx = [0]*26
for i,w in enumerate(ls):
    cnts[sn(w)].append(i)

loops = 0
n = len(S)
prev = -1
for t in lt:
    idx = bisect(cnts[sn(t)],prev)+1
    if idx==len(cnts[sn(t)]):
        loops+=1
        idx = 0
    prev = cnts[sn(t)][idx] + loops*n

print(prev+1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
ls = list(s)

set_s = set(ls)
set_t = set(list(t))
if not set_t <= set_s:
    print(-1)
    exit()
now = t[0]
cnt_t = 0 #index of t
cnt = 0 #count i
tag = 0 #index of s
n = len(s)-1
while cnt_t <= len(t)-1:
    if t[cnt_t] == s[tag]:
        cnt_t += 1
    tag += 1
    cnt += 1
    if tag > n:
        tag = 0
print(cnt)


Fixed submission:
def sn(a):
    return ord(a) - ord("a")

def isok(idx,prev):##適宜変更
    return prev>=idx+n*loops


def bisect(ls,val): ##valの関数isok(x,val)がTrueとなる一番右のindex を返す 全部Falseなら-1
    ok = -1
    ng = len(ls)
    x = (ok+ng)//2
    while ng-ok>1:
        num = ls[x]
        if isok(num,val):
            ok = x
        else:
            ng = x
        x = (ok+ng)//2
    return ok ##一番右のTrueのindex  Trueの個数はok+1こ

S = input()
T = input()
lt = list(T)
ls = list(S)
set_s = set(list(S))
set_t = set(lt)
if not set_t <= set_s:
    print(-1)
    exit()
cnts = [[] for i in range(26)]
cnts_idx = [0]*26
for i,w in enumerate(ls):
    cnts[sn(w)].append(i)

loops = 0
n = len(S)
prev = -1
for t in lt:
    idx = bisect(cnts[sn(t)],prev)+1
    if idx==len(cnts[sn(t)]):
        loops+=1
        idx = 0
    prev = cnts[sn(t)][idx] + loops*n

print(prev+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
di = {}
for i in range(n):
    sl = "".join(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = 1
    for i in range(1,n+1):
        a *= i
    return int(a / 2) #1c2 =0
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)


Fixed submission:
n = int(input())
di = {}
for i in range(n):
    sl = "".join(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = n * (n-1) /2
    return int(a) #1c2 =0
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)

Buggy python submission (verdict: Runtime Error):
di ={}
n = int(input())
di = {}
for i in range(n):
    sl = tuple(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = 1
    for i in range(1,n+1):
        a *= i
    return int(a / 2) #1c2 =0
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)


Fixed submission:
n = int(input())
di = {}
for i in range(n):
    sl = "".join(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = n * (n-1) /2
    return int(a) #1c2 =0
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)

Buggy python submission (verdict: Runtime Error):
di ={}
n = int(input())
di = {}
for i in range(n):
    sl = tuple(sorted(list(input()))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = 1
    for i in range(1,n):
        a *= i
    return int(a / 2)
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)


Fixed submission:
n = int(input())
di = {}
for i in range(n):
    sl = "".join(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = n * (n-1) /2
    return int(a) #1c2 =0
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)
Buggy python submission (verdict: Runtime Error):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
a,b = ma()
k2 = abs(b-a)
if k%2==1:
    print(k2//2+min(b,a))
else:
    print("IMPOSSIBLE")


Fixed submission:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
a,b = ma()
k2 = abs(b-a)
if k2%2==0:
    print(k2//2+min(b,a))
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 13
mp = 10**9+7
n = len(S)
dp = [[0]*13 for i in range(n+1)]
dp[-1][0] = 1
d = 1
for i in range(n):
    s = S[-i-1]
    if s=="?":
        for k in range(10):
            for j in range(13):
                l = (k*d + j)%mod
                if dp[i-1][j] !=0:
                    dp[i][l] +=dp[i-1][j]
                    dp[i][l] %=mp
    else:
        for j in range(13):
            l = (int(s)*d + j)%mod
            if dp[i-1][j] !=0:
                dp[i][l] = dp[i-1][j]
    d = d*10 %mod
print(dp[n-1][5])


Fixed submission:
S = input()
mod = 13
mp = 10**9+7
n = len(S)
dp = [[0]*13 for i in range(n+1)]
dp[-1][0] = 1
d = 1
for i in range(n):
    s = S[-i-1]
    if s=="?":
        for k in range(10):
            for j in range(13):
                l = (k*d + j)%mod
                if dp[i-1][j] !=0:
                    dp[i][l] +=dp[i-1][j]
                    dp[i][l] %=mp
    else:
        for j in range(13):
            l = (int(s)*d + j)%mod
            if dp[i-1][j] !=0:
                dp[i][l] = dp[i-1][j]
    d = d*10 %mod
print(dp[n-1][5])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w = map(int,input().split())
mz = []
q = deque()
for i in range(h):
    mz.append(list(input()))
    ls = [[i,j,0] for j, a in enumerate(mz[-1]) if a == '#'] #i黒のところのindexをqueに追加
    q.extend(ls)


delta = [[-1,0],[0,-1],[1,0],[0,1]]
while q:
    y,x,c = q.popleft()
    for dy,dx in delta:
        if (0<= y+dy <h) and (0<=x+dx <w):
            if mz[y+dy][x+dx] == ".":
                mz[y+dy][x+dx]="#" #黒に置き換え
                q.append([y+dy,x+dx,c+1])

            else: #すでに黒なら訪問しなくてよい
                pass

print(c)#cは最後にpopされたcost


Fixed submission:
from collections import deque
h,w = map(int,input().split())
mz = []
q = deque()
for i in range(h):
    mz.append(list(input()))
    ls = [[i,j,0] for j, a in enumerate(mz[-1]) if a == '#'] #i黒のところのindexをqueに追加
    q.extend(ls)


delta = [[-1,0],[0,-1],[1,0],[0,1]]
while q:
    y,x,c = q.popleft()
    for dy,dx in delta:
        if (0<= y+dy <h) and (0<=x+dx <w):
            if mz[y+dy][x+dx] == ".":
                mz[y+dy][x+dx]="#" #黒に置き換え
                q.append([y+dy,x+dx,c+1])

            else: #すでに黒なら訪問しなくてよい
                pass

print(c)#cは最後にpopされたcost
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
pal =1
minabs = 10**9
for i in range(n):
    if a[i] <0:
        pal *=-1
        a[i] = -1*a[i]
    minabs = min(minabs,a[i])
if pal ==1:
    print(sum(a))
else:
    print(sum(a)-2*minabs)


Fixed submission:
a,b,t = map(int,input().split())
s = t//a
print(b*s)
Buggy python submission (verdict: Runtime Error):
s = list(input())
lis = ["A","T","G","C"]
ans = []
for i in range(len(s)):
    cnt = 0
    for j in range(len(s)-i):
        if s[i+j] in lis:
            cnt +=1
        else:
            ans.append(cnt)
            break
print(max(ans))


Fixed submission:
s = list(input())
lis = ["A","T","G","C"]
ans = []
for i in range(len(s)):
    cnt = 0
    for j in range(len(s)-i):
        if s[i+j] in lis:
            cnt +=1
        else:
            ans.append(cnt)
            break
    else:ans.append(cnt)
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = list(input())
def ac(s,l,r):
    cnt = 0
    for i in range(r-l):
        if s[l-1+i] == "A" and s[l+i] == "C":
            cnt+= 1
    return cnt

for j in range(q):
    l,r = map(int,input().split())
    print(ac(s,l,r))


Fixed submission:
n,q = map(int,input().split())
s = input()
cnt = [0]*(n+1)
p = s[0]
for i in range(1,n+1):
    if p == "A" and s[i-1] == "C":
            cnt[i] = cnt[i-1] +1
    else:
        cnt[i] = cnt[i-1]
    p = s[i-1]

for i in range(q):
    l,r = map(int,input().split())
    print(cnt[r] - cnt[l])
Buggy python submission (verdict: Runtime Error):
ma = lambda : map(int,input().split())
class unionfind():
    def __init__(self,n):
        self.par = list(range(n))
        self.size = [1]*n
        self.rank = [0]*n

    def root(self,x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def same(self,x,y):
        return self.root(x) == self.root(y)

    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x!=y:
            if self.rank[x] < self.rank[y]:
                 x,y = y,x
            if self.rank[x] < self.rank[y]:
                self.rank[x]+=1
            self.par[y] = x
            self.size[x] +=self.size[y]
    def get_size(self,x):
        x = self.root(x)
        return self.size[x]

n,m = ma()
ans = [0]*m
ab = []
for i in range(m):
    a,b = ma()
    ab.append((a-1,b-1))

uf = unionfind(n)
ans[m-1] = n*(n-1)//2
for i in range(m-1,0,-1):
    a,b = ab[i]
    if uf.same(a,b):
        ans[i-1] = ans[i]
    else:
        ans[i-1] = ans[i] - uf.get_size(a)*uf.get_size(b)
        uf.unite(a,b)
for a in ans:print(a)


Fixed submission:
ma = lambda : map(int,input().split())
import sys
sys.setrecursionlimit(10**6)
class unionfind():
    def __init__(self,n):
        self.par = list(range(n))
        self.size = [1]*n
        self.rank = [0]*n

    def root(self,x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def same(self,x,y):
        return self.root(x) == self.root(y)

    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x!=y:
            if self.rank[x] < self.rank[y]:
                 x,y = y,x
            if self.rank[x] < self.rank[y]:
                self.rank[x]+=1
            self.par[y] = x
            self.size[x] +=self.size[y]
    def get_size(self,x):
        x = self.root(x)
        return self.size[x]

n,m = ma()
ans = [0]*m
ab = []
for i in range(m):
    a,b = ma()
    ab.append((a-1,b-1))

uf = unionfind(n)
ans[m-1] = n*(n-1)//2
for i in range(m-1,0,-1):
    a,b = ab[i]
    if uf.same(a,b):
        ans[i-1] = ans[i]
    else:
        ans[i-1] = ans[i] - uf.get_size(a)*uf.get_size(b)
        uf.unite(a,b)
for a in ans:print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))

dp = [[0]*(W+1) for i in range(N+1)]
# dp[i][j] はi-1番目までのものから重さj以下になるように選んだ最大値

for i in range(1,N+1):
    w,v = ls[i-1]
    for j in range(1,W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j] ,dp[i-1][j-w]+v)
            #ここでj-wを指定してしまっていいのか-> dp[i-1][j-w]>dp[i-1][j-w-1]であるので良い　j-wはそれ以下の最大値になっている
        else:
            dp[i][j] = dp[i-1][j]
print(dp[-1][-1])


Fixed submission:
N,W = map(int,input().split())
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))

dp = [[0]*(W+1) for i in range(N+1)]
# dp[i][j] はi-1番目までのものから重さj以下になるように選んだ最大値

for i in range(1,N+1):
    w,v = ls[i-1]
    for j in range(1,W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j] ,dp[i-1][j-w]+v)
            #ここでj-wを指定してしまっていいのか-> dp[i-1][j-w]>dp[i-1][j-w-1]であるので良い　j-wはそれ以下の最大値になっている
        else:
            dp[i][j] = dp[i-1][j]
print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n,k = ma()
A = lma()
bu = []
for i in range(n):
    tmp=0
    for j in range(i,n):
        tmp+=A[j]
        bu.append(tmp)
mb = bin(max(bu))
ans = 0
for i in range(len(mb)-3,-1,-1):
    tmp=[]
    for b in bu:
        if (b>>i &1):
            tmp.append(b)
    if len(tmp2)>=k:
        ans+=2**i
        bu=tmp
    else:
        pass
print(ans)


Fixed submission:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n,k = ma()
A = lma()
bu = []
for i in range(n):
    tmp=0
    for j in range(i,n):
        tmp+=A[j]
        bu.append(tmp)
mb = bin(max(bu))
ls = [0]*(len(mb)-2)
for b in bu:
    for i in range(len(bin(b))-2):
        if (b>>i &1):
            ls[i]+=1
ans = 0
tmp=bu
for i in range(len(mb)-3,-1,-1):
    if ls[i]<k:
        continue
    tmp2=[]
    for b in tmp:
        if (b>>i &1):
            tmp2.append(b)
    if len(tmp2)>=k:
        ans+=2**i
        tmp=tmp2
    else:
        pass
print(ans)
Buggy python submission (verdict: Runtime Error):
def tempDif(h,T,A):
  temp = T - 0.006*h
  dif = A -temp
  if dif < 0:
    dif = -dif
  return dif
 
N = int(input())
T,A = map(int,input().split())
lis = [int(n) for n in input().split()]
 
lisnew = [tempDif(H,T,A) for H in lis]
print(listnew.index(max(listnew)))

Fixed submission:
def tempDif(h,T,A):
  temp = T - 0.006*h
  dif = A -temp
  if dif < 0:
    dif = -dif
  return dif
 
N = int(input())
T,A = map(int,input().split())
lis = [int(n) for n in input().split()]
 
lisnew = [tempDif(H,T,A) for H in lis]
print(lisnew.index(min(lisnew))+1)
Buggy python submission (verdict: Runtime Error):
import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())

n,m = ma()
gcd = 1
for d in range(m//n-2*n,m//n+1):
    q,r = divmod(m,d)
    if r == 0 and q>=n:gcd = d
print(gcd)


Fixed submission:
import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())
def divisor(n):
    d = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            d.append(i)
            if i != n//i:
                d.append(n//i)
    #d.sort()
    return d
n,m = ma()
gcd = 1
D = divisor(m)
for d in D:
    q,r = divmod(m,d)
    if q>=n and r==0:gcd = max(gcd,d)
print(gcd)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())

n,m = ma()
gcd = 1
for d in range(1,m//n+1):
    q,r = divmod(m,d)
    if r == 0 and q>=n:gcd = d
print(gcd)


Fixed submission:
import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())
def divisor(n):
    d = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            d.append(i)
            if i != n//i:
                d.append(n//i)
    #d.sort()
    return d
n,m = ma()
gcd = 1
D = divisor(m)
for d in D:
    q,r = divmod(m,d)
    if q>=n and r==0:gcd = max(gcd,d)
print(gcd)
Buggy python submission (verdict: Runtime Error):
i=input;i()
i(sum([len(bin(a&-a))-3 for a in map(int,i().split())]))


Fixed submission:
input()
print(sum(map(lambda a:len(bin(int(a)&-int(a)))-3,input().split())))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
pp = list(input())
cnt = 0
lis = []
for i in range(n):
    for j in range(i):
        if pp[j] == "W":
            cnt += 1
    for k in range(i+1,n):
        if pp[k] =="E":
            cnt += 1
    lis.append(cnt) 
    cnt = 0
print(min(lis))


Fixed submission:
n = int(input())
pp = list(input())
cnt = 0
lis = [0]*n
w = [0]*n
e = [0]*n
if pp[0] =="W":
    w[0] =1
else:
    e[0] =1
for i in range(1,n):
    if pp[i] == "W":
        w[i] = w[i-1]+1
        e[i] = e[i-1]

    else:
        e[i] = e[i-1]+1
        w[i] = w[i-1]
for i in range(1,n):
    lis[i] = w[i-1]+e[n-1]-e[i]
lis[0] = e[n-1]-e[0]

print(min(lis))

Buggy python submission (verdict: Runtime Error):
n = int(input())
pp = list(input())
cnt = 0
lis = []
for i in range(n):
    for j in range(i):
        if pp[j] == "E":
            cnt += 1
    for k in range(i+1,n):
        if pp[k] =="W":
            cnt += 1
    lis.apped(cnt) 
    cnt = 0
print(min(lis))


Fixed submission:
n = int(input())
pp = list(input())
cnt = 0
lis = [0]*n
w = [0]*n
e = [0]*n
if pp[0] =="W":
    w[0] =1
else:
    e[0] =1
for i in range(1,n):
    if pp[i] == "W":
        w[i] = w[i-1]+1
        e[i] = e[i-1]

    else:
        e[i] = e[i-1]+1
        w[i] = w[i-1]
for i in range(1,n):
    lis[i] = w[i-1]+e[n-1]-e[i]
lis[0] = e[n-1]-e[0]

print(min(lis))
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
edge = [(0,1),(0,-1),(1,0),(-1,0)]
ans = []
for i in range(h):
    for j in range(w):
        if s[i][j] =="#":
            for x,y in edge:
                if 0<= i+x <w and 0<= j+y < h and s[i+x][j+y] =="#":break #三番目のforから抜け出す
            else:
                print("No")
                break #二番目
    else:continue
    break
else:print("Yes")


Fixed submission:
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
edge = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(h):
    for j in range(w):
        if s[i][j] =="#":
            for x,y in edge:
                if 0<= i+y <h and 0<= j+x < w and s[i+y][j+x] =="#":break #三番目のforから抜け出す
            else:
                print("No")
                break #二番目
    else:continue
    break
else:print("Yes")