Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N, W = map(int, input().split())
 
dp = [[0]*(W+1) for _ in range(N+1)]
 
for i in range(1, N+1):
  w, v = map(int, input().split())
  for j in range(1, W+1):
    dp[i][j] = dp[i-1][j]
    if j >= w:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)

print(dp[N][W])

### FIXED CODE ###

N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

table = {i: [0]*(W+1) for i in range(N+1)}
def dp(N, W):
  for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(1, W+1):
      if w <= j:
        table[i][j] = max(table[i-1][j-w]+v, table[i-1][j])
      else:
        table[i][j] = table[i-1][j]
  return table[N][W]

print(dp(N, W))
### BUGGY CODE ###


import itertools
result = 10 ** 15
N = int(input())

h = [int(x) for x in input().split()]

numbers = []
for i in range(N):
    numbers.append(1)
    numbers.append(2)
combination = list(dict.fromkeys([seq for i in range(len(numbers), 0, -1) for seq in itertools.combinations(numbers, i) if sum(seq) == N - 1]))
for i in range(len(combination)):
    idouti = 0
    for j in range(len(combination[i]) + 1):
        if j == 0:
            #idouti += abs(h[0] - h[combination[i][j]])
            continue
        a = sum(combination[i][0:j])

        b = sum(combination[i][0:j - 1])

        idouti += abs(h[a] - h[b])
    if result > idouti:
        result = idouti

print(result)


### FIXED CODE ###

N = int(input())
h = [int(x) for x in input().split()]
dp = []
dp1 = 0
dp2 = 0
for i in range(N):
    if i == 0:
        dp.append(0)
        continue

    if i == 1:
        dp.append(abs(h[0] - h[1]))
        continue

    dp1 = dp[i - 1] + abs(h[i] - h[i - 1])
    dp2 = dp[i - 2] + abs(h[i] - h[i - 2])

    if dp1 < dp2:
        dp.append(dp1)
    else:
        dp.append(dp2)
print(dp[-1])
### BUGGY CODE ###

N=int(input())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ans=[]
for i in range(4**len(str(N))):
    num=Base_10_to_n(i,4).zfill(len(str(N))+1).replace('0','').replace('1','7').replace('2','5')
    # print(num)
    if set(list(num))==set(['3','5','7']) and int(num)<=N:
        ans.append(num)
print(len(set(ans)))




### FIXED CODE ###

N=int(input())
N_num=len(str(N))
ans=0

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

for i in range(3,N_num+1):#i桁についての3進数演算
    for j in range(3**i):
        num=Base_10_to_n(j,3).zfill(i).replace('0','3').replace('1','5').replace('2','7')
        if set(list(num))==set(['3','5','7']) and int(num)<=N:
            ans+=1
print(ans)
### BUGGY CODE ###

a = int(input())
ar = list(map(int,input().split(" ")))
for i in range(a):
    count= 0
    x = 0
    for j in range(a):
        if i != j:
            count += abs(x - ar[j])
            x = ar[j]
    count += abs(x - 0)
    print(count)

### FIXED CODE ###

a = int(input())
ar = list(map(int,input().split(" ")))
ar.insert(0,0)
ar.append(0)
count = 0
for i in range(1,a+2):
    count += abs(ar[i]-ar[i-1])
for i in range(1,a+1):
    b = abs(ar[i-1]-ar[i+1])
    c = abs(ar[i-1]-ar[i])
    d = abs(ar[i]-ar[i+1])
    print(count + b - c - d)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
 
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
n,q = list(map(int,input().split()))
ball = list(map(int,input().split()))
 
h = Bit(n+1)

L_most = {}
L = {}
jump = {}
on = {}

for i,b in enumerate(ball):
  if b not in L_most:
    L_most[b]=i
    h.add(i+1,1)
    on[i+1]=1
  if b in L:
    jump[L[b]]=i+1
  L[b] = i+1

Q = []
 
for _ in range(q):
  l,r = list(map(int,input().split()))
  Q.append((l,r))
  
LOO = list(Q)
Q.sort(key=lambda x:x[0])

c = 1
ans = {}

for l,r in Q:
  for i in range(c,l):
    if i in on:
      on.pop(i)
      h.add(i,-1)
      if i in jump:
        dest = jump[i]
        h.add(dest,1)
        on[dest]=1

  tmp = h.sum(r)- h.sum(l-1)
  ans[(l,r)] = tmp
  c = l

for q in LOO:
  print(ans[q])

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
n,q = list(map(int,input().split()))
ball = list(map(int,input().split()))
 
h = Bit(n+1)

L = {}
jump = {}
on = set()

for i,b in enumerate(ball):
  if b not in L:
    h.add(i+1,1)
    on.add(i+1)
  if b in L:
    jump[L[b]]=i+1
  L[b] = i+1

Q = []
 
for _ in range(q):
  l,r = list(map(int,input().split()))
  Q.append((l,r))
  
LOO = list(Q)
Q.sort(key=lambda x:x[0])

c = 1
ans = {}

for l,r in Q:
  for i in range(c,l):
    if i in on:
      on.remove(i)
      h.add(i,-1)
      if i in jump:
        dest = jump[i]
        h.add(dest,1)
        on.add(dest)

  tmp = h.sum(r)- h.sum(l-1)
  ans[(l,r)] = tmp
  c = l

p = []
for q in LOO:
  p.append(ans[q])
  
print(*p, sep="\n")
### BUGGY CODE ###

import collections

lst = []
n = int(input())
for i in range(n):
  s = input()
  c = collections.Counter(s)
  lst.append(c)

cnt = 0
for i, elem1 in enumerate(lst):
  for elem2 in lst[i+1:]:
    if elem1 == elem2:
      cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())

dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if not s in dic:
    dic[s] = 1
  else:
    dic[s] += 1

res = 0
for v in dic.values():
  if v >= 2:
    res += v*(v-1)
print(res//2)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

MOD = 1000000007  # type: int

def solve(N: int, M: int, S: "List[int]", T: "List[int]"):
    dp = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD
            if S[i] == T[j]:
                dp[i+1][j+1] += dp[i][j] + 1
            dp[i+1][j+1] %= MOD
    return (dp[-1][-1] + 1) % MOD


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    T = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    result = solve(N, M, S, T)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

MOD = 1000000007  # type: int

def solve(N: int, M: int, S: "List[int]", T: "List[int]"):
    dp = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD
            if S[i] == T[j]:
                dp[i+1][j+1] += dp[i][j] + 1
            dp[i+1][j+1] %= MOD
    return (dp[-1][-1] + 1) % MOD


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    T = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    result = solve(N, M, S, T)
    print(result)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

for i in range(n):
    tarr = list(arr)
    tarr.remove(tarr[i])
    tarr.sort()
    print(tarr[(len(tarr) + 1) // 2 - 1])

### FIXED CODE ###

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

tarr = list(arr)

tarr.sort()

num1 = tarr[len(tarr) // 2 - 1]
num2 = tarr[len(tarr) // 2]

for i in range(n):
    if arr[i] < num2:
        print(num2)
    else:
        print(num1)
### BUGGY CODE ###

import numpy as np

n, m = map(int, input().split())
a = np.zeros(m)
for i in range(m):
    a[i] = int(input())

dp = np.zeros(n + 1)

for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(int(dp[n]))

"""
100 5
1
23
45
67
89
"""


### FIXED CODE ###

n, m = map(int, input().split())
A = set()
for i in range(m):
    a = int(input())
    A.add(a)
dp = [0] * (n + 1)
for i in range(n + 1):
    if i in A:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

"""
100 5
1
23
45
67
89
"""
### BUGGY CODE ###

def com(n,r):
    if n-r<r:
        r=n-r
    re=1
    for i in range(n,n-r,-1):
        re*=i
    for i in range(1,r+1):
        re//=i
    return re

def f(n,m,k):
    md = 10 ** 9 + 7
    ans = 0
    for d in range(1, m):
        ans = (ans + d * (m - d) * n * n) % md
    for d in range(1, n):
        ans = (ans + d * (n - d) * m * m) % md
    ans = (ans * com(n * m - 2, k - 2)) % md
    print(ans)

n,m,k=map(int,input().split())
f(n, m, k)


### FIXED CODE ###

def com(n,r):
    re=fct[n]*pow(fct[r],md-2,md)*pow(fct[n-r],md-2,md)
    re%=md
    return re

n,m,k=map(int,input().split())
md=10**9+7
ans=0
fct=[1]*(n*m-1)
f=1
for i in range(1,n*m-1):
    f=f*i%md
    fct[i]=f
for d in range(1,m):
    ans=(ans+d*(m-d)*n*n)%md
for d in range(1,n):
    ans=(ans+d*(n-d)*m*m)%md
ans=(ans*com(n*m-2,k-2))%md
print(ans)
### BUGGY CODE ###

from itertools import*
n,k=map(int,input().split())
z=[list(map(int,input().split()))for _ in range(n)]
x=[]
y=[]
for i,j in z:
    x.append(i)
    y.append(j)
x.sort()
y.sort()
a=10**20
for s,t in combinations(x,2):
    for u,v in combinations(y,2):
        c=sum(s<=i<=t and u<=j<=v for i,j in z)
        if c>=k:
            a=min(a,(t-s)*(v-u))
print(a)

### FIXED CODE ###

n,k=map(int,input().split())
z=[list(map(int,input().split()))for _ in range(n)]
z.sort()
a=10**20
for i in range(n):
    for j in range(i+1,n):
        x=z[j][0]-z[i][0]
        l=sorted(t[1]for t in z[i:j+1])
        for u,v in zip(l,l[k-1:]):
            a=min(a,x*(v-u))
print(a)
### BUGGY CODE ###

from itertools import combinations

N = int(input())
S = input()

R = [i for i, s in enumerate(S) if s == 'R']
G = [i for i, s in enumerate(S) if s == 'G']
B = [i for i, s in enumerate(S) if s == 'B']

#aa = list()
ans = len(R) * len(G) * len(B)
for (i, j) in combinations(range(N - 1), 2):
    k = j*2 - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        ans -= 1
#        aa.append((i, j, k))

print(ans)
#print(aa)


### FIXED CODE ###

N = int(input())
S = input()

RGB = [list()] * 3
color = ['R', 'G', 'B']
RGB[0] = [i for i, s in enumerate(S) if s == color[0]]
RGB[1] = [i for i, s in enumerate(S) if s == color[1]]
RGB[2] = [i for i, s in enumerate(S) if s == color[2]]

order = sorted([0, 1, 2], key=lambda i: len(RGB[i]))
color = [color[i] for i in order]
RGB = [RGB[i] for i in order]

# b = list()
ans = len(RGB[0]) * len(RGB[1]) * len(RGB[2])
for c1 in RGB[0]:
    for c2 in RGB[1]:
        p = c1 * 2 - c2
        if 0 <= p and p < N and S[p] == color[2]:
            # b.append((c1, c2, p))
            ans -= 1

        p = c2 * 2 - c1
        if 0 <= p and p < N and S[p] == color[2]:
            # b.append((c1, c2, p))
            ans -= 1

        if (c1 + c2) % 2 == 0 and S[(c1 + c2) // 2] == color[2]:
            # b.append(c1, c2, c1 + c2 / 2)
            ans -= 1

print(ans)

# b = [sorted(t) for t in b]
# print(sorted(b))
### BUGGY CODE ###

N,K = map(int,input().split())
P = list(map(int,input().split()))

Q = [(P[i]+1)/2 for i in range(N)]

max = 0
for i in range(N-K+1):
    if max < sum(Q[i:K+i]):
        max = sum(Q[i:K+i])

print(max)


### FIXED CODE ###

N,K = map(int,input().split())
P = list(map(int,input().split()))

Q = [(P[i]+1)/2 for i in range(N)]

max,tmp = sum(Q[0:K]),sum(Q[0:K])
for i in range(N-K):
    tmp = tmp + Q[K+i] - Q[i]
    if max < tmp:
        max = tmp

print(max)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
n = int(input())
graph = {i:[] for i in range(n+1)}
for j in range(n-1):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

memo_ls = [[None for j in range(2)] for i in range(n+1)]
# i番目の人がj色の時の通り数 0 : 白
cur = 0
def dfs(cur, col, last):
    if memo_ls[cur][col] is not None:
        return memo_ls[cur][col]
    next_col_num = 1 if col == 1 else 2
    _sum = 1
    cnt = 0
    for _next in graph[cur]:
        res = 0
        for next_col in range(next_col_num):
            if _next == last:
                continue
            cnt += 1
            res += dfs(_next, next_col, cur)
        _sum *= max(1, res)
    if cnt == 0:
        memo_ls[cur][col] = 1
        return 1
    res = _sum % (10 ** 9 + 7)
    memo_ls[cur][col] = res
    return res
res = dfs(0,0,-1) + dfs(0,1,-1)
print(res % (10**9+7))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
n = int(input())
graph = {i:[] for i in range(n+1)}
for j in range(n-1):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

memo_ls = [[None for j in range(2)] for i in range(n+1)]
# i番目の人がj色の時の通り数 0 : 白
cur = 0
def dfs(cur, col, last):
    if memo_ls[cur][col] is not None:
        return memo_ls[cur][col]
    next_col_num = 1 if col == 1 else 2
    _sum = 1
    cnt = 0
    for _next in graph[cur]:
        if _next == last:
            continue
        cnt += 1
        res = 0
        for next_col in range(next_col_num):
            res += dfs(_next, next_col, cur)
        _sum *= max(1, res)
    if cnt == 0:
        memo_ls[cur][col] = 1
        return 1
    res = _sum % (10 ** 9 + 7)
    memo_ls[cur][col] = res
    return res
res = dfs(0,0,-1) + dfs(0,1,-1)
print(res % (10**9+7))
### BUGGY CODE ###



R, G, B, N = map(int, input().split())
rgb = []
for i in range(N + 1):
    for j in range(N - i + 1):
        key = i * R + j * G
        key = N - key
        if key % B == 0 and key / B >= 0:
            rgb.append([i, j, key // B])

#print(rgb)
print(len(rgb))

### FIXED CODE ###



R, G, B, N = map(int, input().split())
rgb = []
for i in range(N + 1):
    for j in range(N - (i * R) + 1):
        key = i * R + j * G
        key = N - key
        if key % B == 0 and key / B >= 0:
            rgb.append([i, j, key // B])

#print(rgb)
print(len(rgb))
### BUGGY CODE ###

import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import defaultdict
from collections import Counter
import bisect
from decimal import *
def main():
    N, D, A = MI()
    Enemy = defaultdict()
    Enemy_ran = []
    for i in range(N):
        x, h = MI()
        Enemy[x] = h
        Enemy_ran.append(x)
    Enemy_ran.sort()
    cnt = 0
    dam = [0] * N
    for i in range(N):
        x = Enemy_ran[i]
        HP = Enemy[x] - dam[i]
        if HP <= 0:
            continue
        else:
            ata = math.ceil(Decimal(Enemy[x] - dam[i]) / Decimal(A))
            cnt += ata
            ran = x + 2 * D
            y = bisect.bisect_right(Enemy_ran, ran)
            for j in range(i + 1, y):
                dam[j] += ata * A


    print(cnt)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import defaultdict
from collections import deque
import bisect
from decimal import *
def main():
    N, D, A = MI()
    Enemy = defaultdict()
    Enemy_ran = []
    for i in range(N):
        x, h = MI()
        Enemy[x] = h
        Enemy_ran.append(x)
    Enemy_ran.sort()
    cnt = 0
    dam_list = deque()
    dam_all = 0
    for i in range(N):
        x = Enemy_ran[i]
        while len(dam_list) != 0 and i >= dam_list[0][0]:
            dam_all -= dam_list.popleft()[1]
        HP = Enemy[x] - dam_all
        if HP <= 0:
            continue
        else:
            ata = math.ceil(Decimal(HP) / Decimal(A))
            cnt += ata
            ran = x + 2 * D
            y = bisect.bisect_right(Enemy_ran, ran)
            dam = ata * A
            dam_list.append((y, dam))
            dam_all += dam


    print(cnt)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

N,K = map(int,input().split())
p = list(map(int,input().split()))
box = []
ans = 0

for i in range(N-(K-1)):
    tmp = []
    for _ in range(i,K+i):
        tmp.append(p[_])
    box.append(sum(tmp))
max_p = box.index(max(box))

for j in range(0,K):
    dice = []
    for k in range(1,p[max_p + j]+1):
        dice.append(k)
    ex = 0
    P = 1/len(dice)
    for l in dice:
        Px = P*l
        ex += Px
    ans += ex
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
p = list(map(int,input().split()))
R = [0]*(N+1)
ans = 0
for i in range(1,N+1):
    X = p[i-1]
    R[i] = R[i-1] + (X*(X+1))/2/X
    if i+1 >= K:
        ans = max(ans,R[i]-R[i-K])

print(ans)
### BUGGY CODE ###

n = int(input())
from functools import reduce
from fractions import gcd
import numpy as np
arr = np.array(list(set(map(int, input().split()))))

from collections import deque
q = deque([arr])
ans = arr.min()
mi = reduce(gcd, arr)
while len(q) > 0:
    ar = q.popleft()
    ans = min(ar.min(), ans)
    if ans <= mi:
        break
    if ans <= reduce(gcd, ar):
        continue
    for mon in ar:
        tmp = (ar - 1) % mon + 1
        if np.any(ar != tmp):
            q.append(np.sort(np.unique(tmp)))

print(ans)


### FIXED CODE ###

n = int(input())
from functools import reduce
from fractions import gcd
ans = reduce(gcd, (map(int, input().split())))

print(ans)
### BUGGY CODE ###

import copy
N = int(input())
A_ = [int(input()) for _ in range(N)]

for i in range(N):
    A = copy.copy(A_)
    A.pop(i)
    print(max(A))

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
A_ = sorted(A)
max1 = A_[-1]
max2 = A_[-2]

for i in range(N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)
### BUGGY CODE ###

def main():
    from itertools import permutations, tee

    INF = 1 << 30

    N, M, R = map(int, input().split())
    *r, = (int(x) - 1 for x in input().split())

    d = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        d[a][b] = d[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(
                    d[i][j],
                    d[i][k] + d[k][j]
                )

    ans = INF
    for perm in permutations(r):
        perm_iter = iter(perm)
        frm_iter, to_iter = tee(perm_iter, 2)
        next(to_iter)
        t = 0
        for frm, to in zip(frm_iter, to_iter):
            t += d[frm][to]
        ans = min(ans, t)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from itertools import permutations

inf = float('inf')
n, m, r = map(int, input().split())  # 町数、道数、訪問地数
t = tuple(int(x) - 1 for x in input().split())  # 訪問地
g = [[inf] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j])

ans = inf
for p in permutations(t):
    ans = min(ans, sum(g[a][b] for a, b in zip(p, p[1:])))
print(ans)
### BUGGY CODE ###

s = input()
q = int(input())

query = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        s = s[::-1]
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        else:
            s += r[2]

print(s)

### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)
### BUGGY CODE ###

from itertools import product
k, s = map(int, input().split())
numbers = list(product([i for i in range(k+1)], repeat=2))
ans = 0
for x, y in numbers:
    if x + y > s:
        continue
    if x + y == s:
        ans += 1
    elif x + y < s:
        for z in range(k+1):
            if x + y + z == s:
                ans += 1
                break
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())
ans = 0
if s <= k:
    ans = (s+2)*(s+1) / 2
elif k < s <= 2*k:
    for i in range(k+1):
        j = s-k+i
        if j <= k:
            ans += j+1
        else:
            ans += j+1-2*(j-k)
elif 2*k < s < 3*k:
    ans = 3
else:
    ans =  1
print(int(ans))
### BUGGY CODE ###

a={}
_,q=map(int,input().split())
for i in range(q):
    b,c=map(int,input().split())
    if b in a:a[b]+=c
    else:a[b]=c
    d=max(a.items(),key=lambda x:x[1])
    if list(a.values()).count(d[1])>1:
        e={}
        for i in a:
            if a[i]==d[1]:e[i]=d[1]
        print(*min(e.items(),key=lambda x:x[0]))
    else:print(*d)

### FIXED CODE ###

n,q=list(map(int, input().split()))
c=[0 for _ in range(n + 1)]
b=[0,0]
for _ in range(q):
    a,v=map(int, input().split())
    c[a]+=v
    if b[0]==a and v>0:b[1]+=v
    elif b[0]==a:mx=max(c[0:]);b[0],b[1]=min([i for i, value in enumerate(c) if value == mx]),mx
    elif b[1]<c[a]:b[0],b[1]=a,c[a]
    elif b[1]==c[a] and b[0] > a:b[0],b[1]=a,c[a]
    print(*b)
### BUGGY CODE ###

N = int(input())
count = 0
for i in range(1, N + 1):
    c = 0
    while i*i <= N:
        if i*i == N:
            c += 1
        elif N % i == 0:
            c += 2
    if c == 8:
        count += 1
print(count)

### FIXED CODE ###

N = int(input())
count = 0
for i in range(1, N + 1, 2):
    c = 0
    j = 1
    while j*j <= i:
        if j*j == i:
            c += 1
        elif i % j == 0:
            c += 2
        j += 1
    if c == 8:
        count += 1
print(count)
### BUGGY CODE ###

pos = 1
curr = 7
k = int(input())
while curr % k != 0:
  pos += 1
  k *= 10
  k += 7
print(pos)

### FIXED CODE ###

k=int(input())
x=7
for i in range(1,k+1):
  if x%k==0:
    print(i)
    break
  x=(x*10+7)%k
else:
  print(-1)