Harryxun/stf_run huggingface dataset:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N, Q = mi()
Anss = [-1] * N

STXs = [tuple(mi()) for _ in range(N)]
from operator import itemgetter
STXs = sorted(STXs, key=itemgetter(2))

for s, t, x in STXs:
#  print(s,t,x)
  for i in range(s-x,t-x):
    if i>=0 and i<=10**9: #iは今回見ている通行止めにぶつかるDの出発時間なので、0未満は無い
      if Anss[i]==-1: #-1じゃなければもう（より小さい）値が入っているので無視
        Anss[i]==x

for _ in range(Q):
  print(Anss[int(input())])


### FIXED CODE ###

###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N, Q = mi()

Events = []
#イベントを格納する配列
#各要素はタプルで、(s-x or t-x, 1or-1, x)が入っている
#意味は、「時間s-xもしくはt-xに出発する人が」「座標xで」
# 「1:通行止めにぶつかる -1:通行止めにぶつかりそうだったが、助かる」を表す

for _ in range(N):
  s, t, x = mi()
  #1つめの要素がマイナスになることはないので、max(0, hoge)をとる。
  #どちらもマイナスといったコーナーケースでも、「0で通行止めになり0で解除される」となってから時間0に出発する人が処理されるので、影響は出ない
#……と思っていたけど、0になるイベントが複数あると、集合への出し入れがおかしくなる（0を複数入れたあと複数回だそうとするから、無いキーを出そうとしてしまう）
#時間がマイナスでもコード上全く問題無いんだから、外した！
  Events.append((s-x, 1, x))
  Events.append((t-x, -1, x))

#イベント配列は「影響を受ける人（の出発時間）」で降順ソートする
#降順ソートなので、pop()でとっていく
from operator import itemgetter
Events = sorted(Events, key=lambda x:-x[1])
Events = sorted(Events, key=lambda x:-x[0])
#発生タイミング（x[0]）が同じイベントは、集合からのout→inでも並び替える（x[1]について降順）。
#outより先にinが行われると、集合操作がおかしくなる

#イベント配列ができたので、今度は各人について処理していく
#出力する答えはAnss配列に入れていき、最後にfor文で一気に出力する
Anss = []

#制約より、Diは最初から昇順ソートされている
Ds = [int(input()) for _ in range(Q)]

nowkeptout = set() #今通行止めになっている座標を格納するset。常に昇順ソートする
nextevent = Events.pop()  #次に見るイベント
minstop = 10**9+1
for d in Ds:
  #各ループにおいて、「未処理の人のうち、最も出発時間が早い人」がdに入る
  #ということは、時間dまでのEventsを全て処理すれば、その人がぶつかる場所が分かる
  while nextevent[0]<=d: #dを越えたら止まるし、イベントがなくなっても番兵で止まる
    a, b, c = nextevent
    if b==1: #座標xが通行止めになる
      nowkeptout.add(c)
      minstop = min(c, minstop)
    else: #座標xの通行止めが解除される
      nowkeptout.remove(c)
      if c==minstop and nowkeptout: minstop = min(nowkeptout)
      elif not nowkeptout: minstop = 10**9+1
    try: nextevent = Events.pop()
    except:
      nextevent = (10**9+1, 1, 1) #要素がなくなったらもう処理が起きないようにする
      break
  #この時点で、nowkeptoutに値が入っている場合も、入っていない場合もある
  #値が入っていれば、dはその最小値の座標で通行止めにぶつかる
  #値が入っていなければ歩き続けるので、-1にする
  if nowkeptout: Anss.append(minstop)
  else: Anss.append(-1)

for ans in Anss:
  print(ans)
N = int(input())
S = [input() for _ in range(N)]

D = [[0] * 2 for _ in range(N)]

for i in range(N):
  s = S[i]
  ma = 0
  l = 0
  r = 0
  for j in s:
    if j == ")":
      r += 1
    else:
      l += 1
    ma = max(ma, r - l)
  D[i] = [l - r, ma, s]

cnt = 0
P = []
M = []
for x, y ,s in D:
  if x >= 0:
    if y <= 0:
      cnt += x
    else:
      P.append([x, y])
  else:
    M.append([x, y, s])

P.sort(key = lambda x:x[1])

for x, y in P:
  if y > cnt:
    print("No")
    exit()
  cnt += x

if len(M) == 0:
  if cnt == 0:
    print("Yes")
  else:
    print("No")
  exit()

M.sort(key = lambda x:x[1], reverse = True)

for i in range(len(M) -1, -1, -1):
  x, y, s= M[i]
  if x == -y:
    g = x
    M[i] = [0, 0, ""]
    break
else:
  print("No")
  exit()

for x, y, s in M:
  if cnt < y:
    print("No")
    exit()
  cnt += x

if cnt + g == 0:
  x = 10 / 0
  print("Yes")
else:
  print("No")


### FIXED CODE ###

N = int(input())
S = [input() for _ in range(N)]

D = [[0] * 2 for _ in range(N)]

for i in range(N):
  s = S[i]
  ma = 0
  l = 0
  r = 0
  for j in s:
    if j == ")":
      r += 1
    else:
      l += 1
    ma = max(ma, r - l)
  D[i] = [l - r, ma, s]

cnt = 0
P = []
M = []
for x, y ,s in D:
  if x >= 0:
    if y <= 0:
      cnt += x
    else:
      P.append([x, y])
  else:
    M.append([x, y, s])

P.sort(key = lambda x:x[1])

for x, y in P:
  if y > cnt:
    print("No")
    exit()
  cnt += x

if len(M) == 0:
  if cnt == 0:
    print("Yes")
  else:
    print("No")
  exit()

M.sort(reverse = True)
M.sort(key = lambda x:x[1], reverse = True)

for i in range(len(M)):
  x, y, s = M[i]
  if x == -y:
    g = x
    M[i] = [0, 0, ""]
    break
else:
  print("No")
  exit()

for x, y, s in M:
  if cnt < y:
    print("No")
    exit()
  cnt += x

if cnt + g == 0:
  print("Yes")
else:
  print("No")
H, W = map(int, input().split())
G = [input() for _ in range(H)]
sy, sx, gy, gx = 0, 0, H - 1, W - 1
seen = [[-1] * W for _ in range(H)]

if G[sy][sx] == '#' or G[gy][gx] == '#':
    print(-1)
    exit()

from collections import deque
que = deque()
que.append([sy, sx])
seen[sy][sx] = 0
while que:
    y, x = que.popleft()
    for d in [-1, 0], [1, 0], [0, -1], [0, 1]:
        dy = y + d[0]
        dx = x + d[1]
        if dy < 0 or H <= dy or dx < 0 or W <= dx:
            continue
        if G[dy][dx] == '#':
            continue
        if seen[dy][dx] > -1:
            continue
        que.append([dy, dx])
        seen[dy][dx] = seen[y][x] + 1

count = 0
bunpu = [0] * (H * W + 1)
if seen[gy][gx] == -1:
    print(-1)
else:
    all = H * W
    black = 0
    for i in range(H):
        for j in range(W):
            if G[i][j] == '#':
                black += 1
    #start point = 0,0 
    ans = all - black - seen[gy][gx] - 1
print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
G = [input() for _ in range(H)]
sy, sx, gy, gx = 0, 0, H - 1, W - 1
seen = [[-1] * W for _ in range(H)]

if G[sy][sx] == '#' or G[gy][gx] == '#':
    print(-1)
    exit()

from collections import deque
que = deque()
que.append([sy, sx])
seen[sy][sx] = 0
while que:
    y, x = que.popleft()
    for d in [-1, 0], [1, 0], [0, -1], [0, 1]:
        dy = y + d[0]
        dx = x + d[1]
        if dy < 0 or H <= dy or dx < 0 or W <= dx:
            continue
        if G[dy][dx] == '#':
            continue
        if seen[dy][dx] > -1:
            continue
        que.append([dy, dx])
        seen[dy][dx] = seen[y][x] + 1

count = 0
bunpu = [0] * (H * W + 1)
if seen[gy][gx] == -1:
    print(-1)
    exit()
else:
    all = H * W
    black = 0
    for i in range(H):
        for j in range(W):
            if G[i][j] == '#':
                black += 1
    #start point = 0,0 
    ans = all - black - seen[gy][gx] - 1
print(ans)
N = int(input())
H = list(map(int, input().split()))

cnt = 1

for i in range(1, N):
    if H[i] >= max(H[:i]:
        cnt += 1

print(cnt)


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))

cnt = 1

for i in range(1, N):
    if H[i] >= max(H[:i]):
        cnt += 1

print(cnt)
s = raw_input()
print (s.count("+") - s.count("-"))


### FIXED CODE ###

s = input()
print (s.count("+") - s.count("-"))
S = input()

L = []
cnt = 0
for i in S:
  if i == "A" or i == "C" or i == "G" or i == "T":
    cnt += 1
  else:
    L.append(cnt)
    cnt = 0
    
print(max(L))

### FIXED CODE ###

S = input()

L = []
cnt = 0
for i in S:
  if i == "A" or i == "C" or i == "G" or i == "T":
    cnt += 1
  else:
    L.append(cnt)
    cnt = 0

L.append(cnt)

if len(L) == 0:
	print(0)
else:
	print(max(L))
import numpy as np
N,M,C = map(int,input().split())
B = [int,input().split()]
for i in range(1,N)
    Ai = [int,input().split()]
    ai = np.array(Ai)   
b = np.array(B)
bt = b.reshape([N,1])
cnt = 0
for i in range(1,N)
    if (np.dot(ai,bt) + C >0)
         cnt += 1
print(cnt)




### FIXED CODE ###

import numpy as np
N,M,C = map(int,input().split())
B = [int(k) for k in input().split()]
A = [[int(j) for j in input().split()] for i in range(N)] 
b = np.array(B)
cnt = 0
for i in range(N):
    if (np.dot(np.array(A[i]),b) + C >0):
        cnt += 1
    else:
        cnt = cnt
        
print(cnt)
import sys
s=input()
l=len(s)
if l==1:
  print('No')
  sys.exit()
for i in range(0,l,2):
  if s[i]=='h':
    if s[i+1]!='i':
      print('No')
      sys.exit()
  else:
    print('No')
    sys.exit()
print('Yes')


### FIXED CODE ###

import sys
s=input()
l=len(s)
if l%2==1:
  print('No')
  sys.exit()
for i in range(0,l,2):
  if s[i]=='h':
    if s[i+1]!='i':
      print('No')
      sys.exit()
  else:
    print('No')
    sys.exit()
print('Yes')
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

if len(set(v)) == 1:
    print(n // 2)
else:
    v1 = [v[i] for i in range(0, n, 2)]
    v2 = [v[i + 1] for i in range(0, n, 2)]

    kw1 = Counter(v1)
    kw2 = Counter(v2)

    x1 = kw1.most_common()[0][0]
    x2 = kw2.most_common()[0][0]

    if x1 != x2:
        ans = 0
        for i in v1:
            if i != x1:
                ans += 1
        for i in v2:
            if i != x2:
                ans += 1
    else:
        y1 = kw1.most_common()[1][0]
        y2 = kw2.most_common()[1][0]

        ans1 = 0
        ans2 = 0

        for i in v1:
            if i != y1:
                ans1 += 1
        for i in v2:
            if i != x2:
                ans1 += 1

        for i in v1:
            if i != x1:
                ans2 += 1
        for i in v2:
            if i != y2:
                ans2 += 1

        ans = min(ans1, ans2)

print(ans)


### FIXED CODE ###

from collections import Counter

n = int(input())
v = list(map(int, input().split()))

if len(set(v)) == 1:
    print(n // 2)
else:
    v1 = [v[i] for i in range(0, n, 2)]
    v2 = [v[i + 1] for i in range(0, n, 2)]

    kw1 = Counter(v1)
    kw2 = Counter(v2)

    x1 = kw1.most_common()[0][0]
    x2 = kw2.most_common()[0][0]

    if x1 != x2:
        ans = 0
        for i in v1:
            if i != x1:
                ans += 1
        for i in v2:
            if i != x2:
                ans += 1
    else:
        y1 = kw1.most_common()[1][0]
        y2 = kw2.most_common()[1][0]

        ans1 = 0
        ans2 = 0

        for i in v1:
            if i != y1:
                ans1 += 1
        for i in v2:
            if i != x2:
                ans1 += 1

        for i in v1:
            if i != x1:
                ans2 += 1
        for i in v2:
            if i != y2:
                ans2 += 1

        ans = min(ans1, ans2)

    print(ans)
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
1count=0
ncount=0
for i in range(x):
    if a.count(i)==1:
        1count+=1
for i in range(x,n+1):
    if a.count(i)==1:
        ncount+=1
print(min(1count,ncount))


### FIXED CODE ###

n,m,x=map(int,input().split())
a=list(map(int,input().split()))
counta=0
countb=0
for i in range(x):
    if a.count(i)==1:
        counta+=1
for i in range(x,n+1):
    if a.count(i)==1:
        countb+=1
print(min(counta,countb))
from collections import Counter

key = "keyence"

S = input()

idx = 0
for i in S:
    if i == key[idx]:
        idx += 1

if idx == len(key):
    print("YES")
else:
    print("NO")

### FIXED CODE ###

keyence = "keyence"

S = input()

flag = False
for sta in range(len(S)):
    for end in range(sta,len(S)):
        if S[:sta] + S[end:] == keyence:
            flag = True

if flag:
    print("YES")
else:
    print("NO")
# 木の深さ優先探索

def add_edge(u, v, distance ):
	G[u].append([v, distance])
	G[v].append([u, distance])

def dfs(vertex, distance_from_start):
	global colors

	colors[vertex] = distance_from_start % 2

	for info in G[vertex]:
		v = info[0]
		if colors[v] >= 0: 
			#探索済み
			pass
		else:
			dfs(v, distance_from_start + info[1])


n = int(input())
edges = [list(map(int, input().split())) for _ in range(n-1)]

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1, edge[2])

colors = [-1] * n
colors[0] = 0

dfs(0, 0)

for i in range(n):
	print(colors[i])


### FIXED CODE ###

# 木の深さ優先探索
import sys

sys.setrecursionlimit(100000+10)


def add_edge(u, v, distance ):
	G[u].append([v, distance])
	G[v].append([u, distance])

def dfs(vertex, distance_from_start):
	global colors

	colors[vertex] = distance_from_start % 2

	for info in G[vertex]:
		v = info[0]
		if colors[v] >= 0: 
			#探索済み
			pass
		else:
			dfs(v, distance_from_start + info[1])

n = int(input())
edges = [list(map(int, input().split())) for _ in range(n-1)]

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1, edge[2])

colors = [-1] * n
colors[0] = 0

dfs(0, 0)

for i in range(n):
	print(colors[i])
import math
N, M= list(map(int, input().split()))
'''
# 組み合わせ計算
print(math.factorial(N)//math.factorial(N-2)//2)
print(math.factorial(M)//math.factorial(max(M-2, 1))//2)
'''
num = math.factorial(N)//math.factorial(N-2)//2 + math.factorial(M)//math.factorial(max(M-2, 1))//2
print(num)

### FIXED CODE ###

import math
N, M= list(map(int, input().split()))
'''
# 組み合わせ計算
print(math.factorial(N)//math.factorial(N-2)//2)
print(math.factorial(M)//math.factorial(max(M-2, 1))//2)
'''
num = math.factorial(N)//math.factorial(max(N-2, 1))//2 + math.factorial(M)//math.factorial(max(M-2, 1))//2
print(num)
a,b,k=map(int,input().split())
l=list(range(a,b+1))
ans=sorted(set(l[:k])|set(l[-k:]))
for i in ans:
    print(i)

### FIXED CODE ###

a,b,k = map(int,input().split())
r = range(a,b+1)
for i in sorted (set(r[:k])|set(r[-k:])):
    print(i)
import collections
from math import factorial
N = int(input())
A = list(map(int,input().split()))
ans = 0
aa = collections.Counter(A)
for i in range(N):
    for k,v in aa.items():
        if k == A[i]:
            if v >= 3:
                num = factorial(v-1) / factorial(2) / factorial(v - 3)
                ans += num
        else:
            if v >= 2:
                num = factorial(v) / factorial(2) / factorial(v - 2)
                ans += num
    print(int(ans))
    ans = 0

### FIXED CODE ###

from itertools import groupby
import copy

def equalfind(A):
    A.sort()
    s=1
    count=0
    if len(A)==1:
        return count
    else:
        for i in range(0,len(A)-1):
            if A[i]==A[i+1]:
                s+=1
            else:
                count+=s*(s-1)//2
                s=1
        return count+s*(s-1)//2


N=int(input())
A=list(map(int,input().split()))

B=copy.copy(A)
s=equalfind(B)
data=groupby(B)
ans=[0 for i in range(0,N+1)]
for key,group in data:
    g=len(list(group))
    ans[key]=g

for i in range(0,N):
    minus=ans[A[i]]-1
    print(s-minus)
n = int(input())

s = list(map(int,input().split(" ")))
 
count = 0
for x in range(n):
  print(s[x])
  if s[x]%2 == 0 and (s[x]%5 != 0 and s[x]%3 != 0):
    count += 1
    
if count == 0:
  print("APPROVED")
else:
  print("DENIED")

### FIXED CODE ###

a,b,c = map(int,input().split(" "))
if (a == b and a == c) or (a != b and b != c and c!= a):
  print("No")
else:
  print("Yes")
N,X = map(int, input().split())
L = list(map(int, input().split()))

distance = 0
for i in range(N+1):
  distance += L[i]
  if distance > X:
    print(i+1)
    break
    

### FIXED CODE ###

N,X = map(int, input().split())
L = list(map(int, input().split()))

distance = 0
for i in range(N):
  distance += L[i]
  if distance > X:
    print(i+1)
    break
else: 
  print(N+1)
n, m = [int(i) for i in input().split(" ")]

par = [i for i in range(0, n + 1)]
d2p = [0 for i in range(0, n + 1)]

def root(x):
    global par
    global d2p
    if par[x] == x:
        return (x, 0)
    else:
        r = root(par[x])
        par[x] = r[0]
        d2p[x] += r[1]
        #print(par, d2p)
        return (r[0], d2p[x])


def unite(x, y, d):
    global par
    global d2p
    #print(x, y, d)
    rx, dx = root(x)
    ry, dy = root(y)
    if rx != ry:
        par[x] = y
        d2p[x] = d
        #print(par, d2p,"noz")
        return True
    else:
        if abs(dx - dy) != d:
            #print(rx, ry, dx, dy)
            return False
        else:
            return True

l = [0] * n
r = [0] * n
d = [0] * n

for i in range(0, m):
    l[i], r[i], d[i] = [int(i) for i in input().split(" ")]

f = True
for i in range(0, m):
    if not unite(l[i], r[i], d[i]):
        f = False
        break

if f and max(d2p) <= 10**9:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import queue

n, m = [int(i) for i in input().split(" ")]

g = [[] for i in range(0, n + 1)]
v = [0] * (n + 1)
v_asn = [False] * (n + 1)
f = True

for i in range(0, m):
    l, r, d = [int(i) for i in input().split(" ")]
    g[l].append([r, d])
    g[r].append([l, -d])

for i in range(1, n + 1):
    if not v_asn[i]:
        q = queue.Queue()
        v_asn[i] = True
        q.put(i)
        while not q.empty():
            qi = q.get()
            for a in g[qi]:
                if not v_asn[a[0]]:
                    v_asn[a[0]] = True
                    v[a[0]] = v[qi] + a[1]
                    q.put(a[0])
                else:
                    if v[a[0]] != v[qi] + a[1]:
                        f = False
                        break
        if not f:
            break

if f:
    print("Yes")
else:
    print("No")
from string import ascii_lowercase
from functools import reduce
from operator import mul
n = int(input())
S = input()
mod = 10**9 + 7
print(reduce(lambda x, y: x*y % mod, S.count(c)+1 for c in ascii_lowercase))

### FIXED CODE ###

from string import ascii_lowercase
n = int(input())
S = input()
mod = 10**9 + 7
s = 1
for c in ascii_lowercase:
  s *= S.count(c)+1
  s %= mod
print(s-1)
import math

N, X = map(int,input().split())
city = list(map(int,input().split()))
X_diff = [0]*N
for i in range(N):
    X_diff[i] = abs(X-city[i])
    
ans = X_diff[0]
for i in range(1,N):
    ans = math.gcd(ans,X_diff[i])

print(ans)

### FIXED CODE ###

def gcd(a,b):   #　ユーグリッドの互除法
    if b == 0:
        return a
    return gcd(b, a % b)

N, X = map(int,input().split())
city = list(map(int,input().split()))
X_diff = [0]*N
for i in range(N):
    X_diff[i] = abs(X-city[i])
    
ans = X_diff[0]
for i in range(1,N):
    ans = gcd(ans,X_diff[i])

print(ans)
lst = map(int, input().split())
x_lst = []
y_lst = []
max_lst = []
for i in range(2):
  x_lst.append(lst[i])
  y_lst.append(lst[(i+1)*-1])
for j in range(len(x_lst)):
  for k in range(len(y_lst)):
    max_lst.append(x_lst[j] * y_lst[k])
print(max(max_lst))


### FIXED CODE ###

lst = list(map(int, input().split()))
x_lst = []
y_lst = []
max_lst = []
for i in range(2):
  x_lst.append(lst[i])
  y_lst.append(lst[(i+1)*-1])
for j in range(len(x_lst)):
  for k in range(len(y_lst)):
    max_lst.append(x_lst[j] * y_lst[k])
print(max(max_lst))
n = int(input())
print(N*(N-1)//2)

### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
N=int(input())
S=list(map(int, input().split()))
A=[]
for i in range(1,N-1):
  A.append(abs(S[:i]-S[i:]))
print(min(A))

### FIXED CODE ###

N=int(input())
S=list(map(int, input().split()))
A=[]
for i in range(1,N):
  A.append(abs(sum(S[:i])-sum(S[i:])))
print(min(A) if not A==[] else abs(S[0]-S[1]))
inputs= list(input().split())
A=int(inputs[0])
B=int(inputs[1]+0.5)*100
Ans=A*B/100
print(Ans)

### FIXED CODE ###

inputs= list(input().split())
A=int(inputs[0])
B=float(inputs[1])
B=int(B*100+0.5)
Ans=A*B//100
print(Ans)
import copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = []
for i in range(H):
   wi = [0]*W
   object.append(wi)
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object[h-1][w-1]
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max - 1
p = len(cand_h)*len(cand_w)
if M >= p:
   for i in range(len(cand_h)):
      for j in range(len(cand_w)):
         if object[cand_h[i]][cand_w[j]] == 0:
            ans = h_max + w_max            
else:
   ans += 1
print(ans)

### FIXED CODE ###

import copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = []
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object.append([h-1, w-1])
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max
c = 0
p = len(cand_h)*len(cand_w)
cand_h = set(cand_h)
cand_w = set(cand_w)
if M >= p:
   for i in range(len(object)):
      if object[i][0] in cand_h and object[i][1] in cand_w:
         c += 1
print(ans - (c == p))
s = input()
k = int(input())

counter = 0
for i in range(len(s)):
  if s[i] == "1":
    counter += 1
  else:
    ans = i
    break
  
if k <= i:
  ans = 1
else:
  ans = s[ans]
  
print(ans)

### FIXED CODE ###

s = input()
k = int(input())

counter = 0
for i in range(len(s)):
  if s[i] == "1":
    counter += 1
    ans = 1
  else:
    ans = i
    break
  
if k <= counter:
  ans = 1
else:
  ans = s[ans]
  
print(ans)
N = int(input())

a = list(map(int,input().split()))

"""
for i in range(N):

    cnt = 1
    summ = 0
    flag = True

    while (i + 1) * cnt <= N:

        summ += a[(i + 1) * cnt -1]
        cnt += 1

    if summ % 2 != a[i]:
        flag = False
        print (i+1,"はみたさない")
        break

    else:
        pass
        print (summ,a[i],"でおｋ")

if flag :
    

    #print (lis)

    print (sum(a))

    ans = ""

    for i in range(len(a)):
        if a[i] == 1:
            ans += str(i+1) + " "

    print (ans[:-1])

else:
    print (-1)

"""

lis = [-1] * N



for i in range(N):

    i = N-i
    cnt = 2
    summ = 0
    flag = True

    while i * cnt <= N:

        summ += lis[i * cnt -1]
        cnt += 1

    #print (a[i-1],summ)

    if a[i-1] == 0 and summ % 2 == 0:
        lis[i-1] = 0
        #print ("a")

    elif a[i-1] == 0 and summ % 2 == 1:
        llis[i-1] = 1

    elif a[i-1] == 1 and summ % 2 == 0:
        lis[i-1] = 1

    elif a[i-1] == 1 and summ % 2 == 1:
        lis[i-1] = 0

    if not flag:
        break

if flag:

    #print (lis)

    print (sum(lis))

    ans = ""

    for i in range(len(lis)):
        if lis[i] == 1:
            ans += str(i+1) + " "

    print (ans)

else:
    print (-1)


    


### FIXED CODE ###


N = int(input())

a = list(map(int,input().split()))

"""
for i in range(N):

    cnt = 1
    summ = 0
    flag = True

    while (i + 1) * cnt <= N:

        summ += a[(i + 1) * cnt -1]
        cnt += 1

    if summ % 2 != a[i]:
        flag = False
        print (i+1,"はみたさない")
        break

    else:
        pass
        print (summ,a[i],"でおｋ")

if flag :
    

    #print (lis)

    print (sum(a))

    ans = ""

    for i in range(len(a)):
        if a[i] == 1:
            ans += str(i+1) + " "

    print (ans[:-1])

else:
    print (-1)

"""

lis = [-1] * N



for i in range(N):

    i = N-i
    cnt = 2
    summ = 0
    flag = True

    while i * cnt <= N:

        summ += lis[i * cnt -1]
        cnt += 1

    #print (a[i-1],summ)

    if a[i-1] == 0 and summ % 2 == 0:
        lis[i-1] = 0
        #print ("a")

    elif a[i-1] == 0 and summ % 2 == 1:
        lis[i-1] = 1

    elif a[i-1] == 1 and summ % 2 == 0:
        lis[i-1] = 1

    elif a[i-1] == 1 and summ % 2 == 1:
        lis[i-1] = 0

    if not flag:
        break

if flag:

    #print (lis)

    print (sum(lis))

    ans = ""

    for i in range(len(lis)):
        if lis[i] == 1:
            ans += str(i+1) + " "

    print (ans)

else:
    print (-1)