Harryxun/stf_run huggingface dataset:
from copy import deepcopy

def getval():
    n,ma,mb = map(int,input().split())
    p = [list(map(int,input().split())) for i in range(n)]
    return n,ma,mb,p 

def main(n,ma,mb,p):
    dp = [[[-1 for i in range(401)] for i in range(401)]]
    dp[0][0][0] = 0
    for i in range(n):
        temp = deepcopy(dp[-1])
        temp[0][0] = 0
        cur = p[i]
        prev = dp[-1]
        for a in range(401):
            for b in range(401):
                if cur[0]>a or cur[1]>b:
                    continue
                if prev[a-cur[0]][b-cur[1]]==-1:
                    continue
                elif prev[a][b]==-1:
                    temp[a][b] = prev[a-cur[0]][b-cur[1]] + cur[2]
                    #print(i,a,b,temp[a][b],prev[a-cur[0]][b-cur[1]])
                else:
                    temp[a][b] = min(prev[a][b], prev[a-cur[0]][b-cur[1]] + cur[2])
        #dp.append(temp)
    ans = -1
    for i in range(1,11):
        if i*ma>10 or i*mb>10:
            break
        if dp[n][i*ma][i*mb]!=-1:
            if ans==-1:
                ans = dp[n][i*ma][i*mb]
            else:
                ans = min(ans,dp[n][i*ma][i*mb])
    print(ans)
    print(dp[n])

if __name__=="__main__":
    n,ma,mb,p = getval()
    main(n,ma,mb,p)

### FIXED CODE ###

from copy import deepcopy

def getval():
    n,ma,mb = map(int,input().split())
    p = [list(map(int,input().split())) for i in range(n)]
    return n,ma,mb,p 

def main(n,ma,mb,p):
    dp = [[[-1 for i in range(401)] for i in range(401)]]
    dp[0][0][0] = 0
    for i in range(n):
        temp = deepcopy(dp[-1])
        temp[0][0] = 0
        cur = p[i]
        prev = dp[-1]
        for a in range(401):
            for b in range(401):
                if cur[0]>a or cur[1]>b:
                    continue
                if prev[a-cur[0]][b-cur[1]]==-1:
                    continue
                elif prev[a][b]==-1:
                    temp[a][b] = prev[a-cur[0]][b-cur[1]] + cur[2]
                    #print(i,a,b,temp[a][b],prev[a-cur[0]][b-cur[1]])
                else:
                    temp[a][b] = min(prev[a][b], prev[a-cur[0]][b-cur[1]] + cur[2])
        dp.append(temp)
    ans = -1
    for i in range(1,401):
        if i*ma>400 or i*mb>400:
            break
        if dp[n][i*ma][i*mb]!=-1:
            if ans==-1:
                ans = dp[n][i*ma][i*mb]
            else:
                ans = min(ans,dp[n][i*ma][i*mb])
    print(ans)
    #print(dp[n])

if __name__=="__main__":
    n,ma,mb,p = getval()
    main(n,ma,mb,p)
from sys import stdin
from functools import lru_cache


# 最小化問題
def chmin(a,b):
    if a > b: return b
    else: return a


class Rec_memo:
    def __init__(self, N):
        self.dp = [float('inf')] * (N+2)

    def rec(self, i):
        if self.dp[i] != float('inf'):
            return self.dp[i]
        elif i == 0:
            return 0
        else:
            self.dp[i] = chmin(self.dp[i],self.rec(i-1)+abs(h_arr[i]-h_arr[i-1]))
            if i>1:
                self.dp[i] = chmin(self.dp[i],self.rec(i-2)+abs(h_arr[i]-h_arr[i-2]))
            return self.dp[i]


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    h_arr = [0] * (N+2)
    h_arr[0:N] = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    # dp[i]:=カエルが足場iへと移動するのに必要な最小コスト
    dp = [float('inf')] * (N+2)  # 最小化問題
    dp[0] = 0                    # 初期条件
    
    # 貰うDP
    #for i in range(0,N):
    #    dp[i] = chmin(dp[i],dp[i-1]+abs(h_arr[i]-h_arr[i-1]))
    #    if i > 1:
    #        dp[i] = chmin(dp[i],dp[i-2]+abs(h_arr[i]-h_arr[i-2]))
    #cnt = dp[N-1]

    # 配るDP
    #for i in range(0,N):
    #    dp[i+1] = chmin(dp[i+1],dp[i]+abs(h_arr[i]-h_arr[i+1]))
    #    dp[i+2] = chmin(dp[i+2],dp[i]+abs(h_arr[i]-h_arr[i+2]))
    #cnt = dp[N-1]

    # メモ化再帰
    memo = Rec_memo(N)
    cnt = memo.rec(N-1)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


### FIXED CODE ###

from sys import stdin


# 最小化問題
def chmin(a,b):
    if a > b: return b
    else: return a


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    h_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dp = [float('inf')] * N  # 最小化問題
    dp[0] = 0                # 初期条件
    
    for i in range(0,N):
        dp[i] = chmin(dp[i],dp[i-1]+abs(h_arr[i]-h_arr[i-1]))
        if i > 1:
            dp[i] = chmin(dp[i],dp[i-2]+abs(h_arr[i]-h_arr[i-2]))
    cnt = dp[N-1]
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)
n = int(input())
A = [int(m) for m in input().split()]
print(max(A)-min(A))

### FIXED CODE ###

s = input()
di = {}
for c in s:
  di[c] = 0
for c in s:
  di[c] +=1
  
is_beautiful = True
for c in s:
  if di[c] %2 ==1:
    is_beautiful = False

print('Yes' if is_beautiful else 'No')
s = input()
t = input()
ls = len(s)
lt = len(t)
S = s*(lt//ls+2)
N = len(S)
mod = 2**61-1
base = 4#ランダムに撮るのが好ましい
power = [1]*N#power[i] = base^iの配列
for i in range(1, N):
    power[i] = power[i-1]*base%mod
rolling_hash = [0]*(N+1)
k = lt
for i, s in enumerate(S[:k]):
    rolling_hash[i+1] = (rolling_hash[i]*base+ord(s))%mod
for i in range(k, N):
    rolling_hash[i+1] = ((rolling_hash[i]-ord(S[i-k])*power[k-1])*base+ord(S[i]))%mod
thash = 0
for i, ti in enumerate(t):
    thash+=ord(ti)*power[k-i-1]
    thash%=mod
is_same = [False]*ls
for i, h in enumerate(rolling_hash[k:ls+k]):
    if h == thash:
        is_same[i] = True
length = [-1]*N
is_visited = [False]*N
def rec(i):
    if length[i]>=0:
        return length[i]
    if is_visited[i]:
        return -1
    is_visited[i] = True
    if not is_same[i]:
        length[i] = 0
        return 0
    ni = (i+lt)%ls
    length[i] = rec(ni)+1
    if length[i] == 0:
        return -1
    return length[i]
for i in range(ls):
    if is_visited[i]:
        continue
    res = rec(i)
    if res == -1:
        ans = -1
        break
    ans = max(ans, res)
print(ans)

### FIXED CODE ###


def search_rolling_hash(S, T):
    base = 1234
    mod = 10**9+7
    n, m = len(S), len(T)
    rolling_hash = [0]*(n-m+1)  
    rolling_hash[0] = ord(S[0])
    b_m = pow(base, m, mod)
    T_hash = ord(T[0])
    start_index = []
    for i in range(1, m):
        rolling_hash[0]*=base
        rolling_hash[0]+=ord(S[i])
        rolling_hash[0]%=mod
        T_hash = (T_hash*base+ord(T[i]))%mod
    if rolling_hash[0] == T_hash: start_index.append(0)
    for i in range(1, ls):
        rolling_hash[i] = (rolling_hash[i-1]*base-ord(S[i-1])*b_m+ord(S[i+m-1]))%mod
        if rolling_hash[i] == T_hash: start_index.append(i)
    return start_index
import sys
s = input()
t = input()
ls, lt = len(s), len(t)
S = s*(lt//ls+2)
index = search_rolling_hash(S, t)
flag = [False]*ls
for i in index:
    flag[i] = True
stack = []
inf = float('inf')
cnt = [inf]*ls
for i in range(ls):
    if flag[i] == False:
        stack.append(i)
        cnt[i] = 0
while stack:
    x = stack.pop()
    y = (x-lt)%ls
    if cnt[y] == inf:
        cnt[y] = cnt[x]+1
        stack.append(y)
ans = max(cnt)
if ans == inf:
    print(-1)
else:
    print(ans)
N,K = map(int,input().rstrip().split())
A = list(map(int,input().rstrip().split()))
sum =0
while len(A)>=2:
    sum+=1
    A.insert(K,min(A[:K]))
    del A[0:K]
print(sum)

### FIXED CODE ###

N = list(input())
sum=0
for i in N:
    if i == '+':
        sum+=1
    elif i == '-':
        sum-=1
print(sum)
a=input().split()
N=int(a[0])
K=int(a[1])
count=0
n=1
while True:
    count=count+0.5**math.ceil(math.log2(K)-math.log2(n))/n
    n=n+1
    if n==N:
        break
print(count)

### FIXED CODE ###

import math
n,k=map(int,input().split())
a=0
k=math.log2(k)
for i in range(n):
    a+=2**-max(math.ceil(k-math.log2(i+1)),0)/n
print(a)
from collections import deque
from functools import lru_cache

nCr = {}


@lru_cache(maxsize=None)
def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

### FIXED CODE ###

from collections import deque
import numpy as np
from functools import lru_cache

nCr = {}


@lru_cache(maxsize=None)
def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)
import math
N, K = map(int, input().split())

cnt_list = []
for i in range(K):
  C1 = math.factorial(N-K+1)/(math.factorial(i+1)*math.factorial(N-K+1-i-1))
  C2 = math.factorial(K-1)/(math.factorial(i+1-1)*math.factorial(K-1-i))
  cnt = int(C1*C2)
  cnt_list.append(cnt%(10**9+7))

for i in range(len(cnt_list)):
    print(cnt_list[i])

### FIXED CODE ###

import math

def combi(n ,k):
    return math.factorial(n)//(math.factorial(k)*math.factorial(n-k))

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

cnt_list = []
for i in range(1,K+1):
    if N-K+1 >= i:
        cnt = int(combi(N-K+1,i)*combi(K-1,i-1))
    else:
        cnt =0
    cnt_list.append(cnt%(10**9+7))

for i in range(len(cnt_list)):
    print(cnt_list[i])
import sys
n=int(input())
lst=[]
for i in range(n):
  T,X,Y=map(int,input().split())
  lst.append([T,X,Y])
lst.sort(lambda x:x[0])
for j in range(n-1):
  if abs(lst[j][1]-lst[j+1][1])==1 or abs(lst[j][2]-lst[j+1][2])==1:
    pass
  else:
    print('No')
    sys.exit()
print('Yes')

### FIXED CODE ###

import sys
n=int(input())
lst=[]
for i in range(n):
  T,X,Y=map(int,input().split())
  lst.append([T,X,Y])
if (abs(lst[0][1])+abs(lst[0][2]))%2==lst[0][0]%2:
  if abs(lst[0][1])+abs(lst[0][2])<=lst[0][0]:
    pass
  else:
    print('No')
    sys.exit()
else:
  print('No')
  sys.exit()

for j in range(n-1):
  if (abs(lst[j][1]-lst[j+1][1])+abs(lst[j][2]-lst[j+1][2]))%2==(lst[j+1][0]-lst[j][0])%2:
    if abs(lst[j][1]-lst[j+1][1])+abs(lst[j][2]-lst[j+1][2])<=(lst[j+1][0]-lst[j][0]):
      pass
    else:
      print('No')
      sys.exit()
  else:
    print('No')
    sys.exit()
print('Yes')
import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0
if p == 2:
  s = list(s)
  for i,si in enumerate(s):
    if int(si)%2 == 0:
      ans += i+1
  print(int(ans))
  exit()

elif p == 5:
  s = list(s)
  for i,si in enumerate(s):
    if int(si)%5 == 0:
      ans += i+1
  print(int(ans))
  exit()

chk = [0]*p
chk[0] = 1

for i in range(1,n):
  m = s[:-i]
  k = int(int(m)%p)
  chk[k] += 1
r = int(int(s)%p)
chk[r] += 1
for i in chk:
  ans += i*(i-1)/2
print(int(ans))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0

import math
def nCr(n, r):
  if n < r:
    return 0
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
    exit()

else:
  chk = [0]*p
  chk[0] = 1
  m = 0
  for i in range(n)[::-1]:
    m = (int(s[i])*pow(10,n-1-i,p)+m)%p
    chk[m] += 1
  for i in chk:
    ans += nCr(i,2)
  print(ans)
n = int(input())
a = map(int,input().split())
for i in range(n-1)
    r += 1 / a[i]
print(1/r)

### FIXED CODE ###

d = input()
a = input().split()
r = 0
for i in a:
    r += 1 / int(i)
print(1 / r)
import sys
for line in sys.stdin():
    p = list(map(float, line.split(',')))
    v = [p[i] - p[(i + 2) % 8] for i in range(8)]
    ip = [v[j] * v[(j + 3) % 8] - v[j + 1] * v[(j + 2) % 8] > 0 for j in range(0,8,2)]
    if sum(ip) == 0 or sum(ip) == 4:
        print('YES')
    else:
        print('NO')

### FIXED CODE ###

import sys
for line in sys.stdin:
    try:
        p = list(map(float, line.split(',')))
    except:
        break
    v = [p[i] - p[(i + 2) % 8] for i in range(8)]
    ip = [v[j] * v[(j + 3) % 8] - v[j + 1] * v[(j + 2) % 8] > 0 for j in range(0,8,2)]
    if sum(ip) == 0 or sum(ip) == 4:
        print('YES')
    else:
        print('NO')
first = input()
seconds = list(map(int,input().split()))

print(" ".join(seconds.reverse()))

### FIXED CODE ###

first = input()
seconds = list(map(int,input().split()))
seconds.reverse()
t2=list(map(str, seconds))
print(" ".join(t2))
# coding: utf-8
# Your code here!
N = int(input())
res = ""

for i in list(input()):
    ascii = ord(i)
    n = ascii - 65
    n = (n + N) % 26
    res += chr(n + 65)
print(res == input())

### FIXED CODE ###

N = int(input())
res = ""

for i in list(input()):
    ascii = ord(i)
    n = ascii - 65
    n = (n + N) % 26
    res += chr(n + 65)
print(res)
n,i = map(int,input().spilt())
print(n-i+1)


### FIXED CODE ###

n,i = map(int,input().split())
print(n-i+1)
from sys import stdin
import numpy as np

if __name__ == '__main__':

    N = int(stdin.readline())
    # A だけどNUMPYにあわせてｂ
    b = [int(x) for x in stdin.readline().rstrip().split()]

    # [NumPyで全要素を同じ値で初期化した配列ndarrayを生成 \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-zeros-ones-full/)
    A = np.zeros((N, N), np.int8)
    for i in range(N):
        if i == N - 1:
            A[i][0] = 1
            A[i][i] = 1
        else:
            A[i][i] = 1
            A[i][i+1] = 1

    B = np.array(b)

    # [\[Pythonで数値解析\]\(第5回\)連立一次方程式の数値解法 \- Qiita](https://qiita.com/Y_F_Acoustics/items/b386ff8da11e2c912712)
    ans = np.linalg.solve(A, B)

    int_ans = [str(int(x) * 2) for x in ans]
    print(' '.join(int_ans))


### FIXED CODE ###

from sys import stdin

if __name__ == '__main__':

    N = int(stdin.readline())
    A = [int(x) for x in stdin.readline().rstrip().split()]

    tmp = list()
    for i in range(N):
        if i % 2 == 0:
            continue

        tmp.append(A[i])

    X = list()
    X.append(sum(A) - sum(tmp) * 2)

    for i in range(N):
        if i == 0:
            continue

        X.append(2 * A[i-1] - X[i-1])

    print(' '.join([str(x) for x in X]))
n, m = map(int, input().split())

m_a = []
m_b = []
for i in range(m):
  m_a_tmp, m_b_tmp = map(int, input().split())
  m_a.append(m_a_tmp)
  m_b.append(m_b_tmp)

n_n = [0 for i in range(n)]

for a,b in zip(m_a, m_b):
  n_n[a] += 1
  n_n[b] += 1

for n in n_n:
  print(n)

### FIXED CODE ###

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

m_a = []
m_b = []
for i in range(m):
  m_a_tmp, m_b_tmp = map(int, input().split())
  m_a.append(m_a_tmp)
  m_b.append(m_b_tmp)

n_n = [0 for i in range(n)]

for a,b in zip(m_a, m_b):
  n_n[a-1] += 1
  n_n[b-1] += 1

for n in n_n:
  print(n)
h, w, k = map(int, input().split())
C = [list(map(str, input())) for _ in range(h)]

n = h + w
tmp = [0] * (n)
for idx, ch in enumerate(C):
    tmp[idx] = ch.count("#")
    for i, c in enumerate(ch):
        if c == "#": tmp[i + 2] += 1

if k > w:
    cnt = 1
    for i in range(n):
        if tmp[i] == k: cnt += 1

else:
    cnt = 0
    for i in range(n):
        if tmp[i] == k: cnt += 1
        for j in range(n - i):
            if i == j: continue
            if (tmp[i] + tmp[j]) == k: cnt += 1
print(cnt)

### FIXED CODE ###

#bit全探索
#解説AC

H, W, K = map(int, input().split())
C = [list(map(str, input())) for _ in range(H)]

ans = 0
#1<<n : 2^n
for i in range(1<<H):
    for j in range(1<<W):
      cnt = 0
      for h in range(H):
        for w in range(W):
          #1>>n : 下からn桁目(0 index)
          if (i>>h & 1): continue
          if (j>>w & 1): continue
          cnt += C[h][w] == '#'

      if cnt == K: ans += 1
print(ans)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/* TLEだった orz 
int main() {
  ll N; cin >> N;
  ll val = 357, cnt = 0;
  while (N >= val) {
    string s = to_string(val);
    bool three=false,five=false,seven=false,ok=true;
    for(int i=0; i < s.size(); i++) {
      if(s[i]=='3')three=true;
      else if(s[i]=='5')five=true;
      else if(s[i]=='7')seven=true;
      else ok = false;
    }
    if(three&&five&&seven&&ok){
      cnt++;
      //cout<<"s = "<<s<<endl;
      //printf("cnt=%d\n",cnt);
    }
    val++;
  }
  cout << cnt << endl;
} 
*/
int N, ans;
void dfs(ll x,bool flag3,bool flag5,bool flag7) {
    if(x > N) {
        return ;
    }
    if(flag3 && flag5 && flag7) {
        ans++;
    }
    dfs(x*10+3, true, flag5, flag7);
    dfs(x*10+5, flag3, true, flag7);
    dfs(x*10+7, flag3, flag5, true);
}
int main() {
    cin >> N;
    dfs(0,0,0,0);
    cout << ans << endl;
}

### FIXED CODE ###

N = int(input())

def dfs(s):
    if int (s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))
(n, k) = [int(s) for s in input().split()]

data = arr = [[0 for i in range(k + 1)] for j in range(n + 1)]

for i in range(0, k):
    d = int(input())
    a = [int(s) for s in input().split()]

    for m in a:
        data[m - 1][d - 1] = 1

dd = []

for d in data:
    dd.append(sum(d))

ans = 0

for ddd in dd:
    if ddd == 0:
        ans += 1

print(ans)



### FIXED CODE ###

(n, k) = [int(s) for s in input().split()]

data = [[0 for i in range(k)] for j in range(n)]

for i in range(0, k):
    d = int(input())
    a = [int(s) for s in input().split()]

    for m in a:
        data[m - 1][i] = 1

dd = []

for d in data:
    dd.append(sum(d))

ans = 0

for ddd in dd:
    if ddd == 0:
        ans += 1

print(ans)
N = int(input())
li = list(map(int,input().split()))
out_count = 0


for j in range(N - 1 , 0 , -1):
  if li[j] >= li[j - 1] + 2:
    out_count += 1
  elif li[j] == li[j - 1] + 1:
    li[j - 1] -= 1

if li[0] > li[1] + 1:
  out_count += 1
    
if out_count == 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = int(input())
li = list(map(int,input().split()))
out_count = 0

for j in range(N - 1 , 0 , -1):
  if li[j] <= li[j - 1] - 2:
    out_count += 1
  elif li[j] == li[j - 1] - 1:
    li[j - 1] -= 1
if out_count == 0:
  print('Yes')
else:
  print('No')
# B Frog 2

n, k = map(int, input().split())
h_list = [int(x) for x in input().split()]

dp = [float('Inf')] * n
dp[0] = 0

for i in range(n):
    for j in range(1,k+1,1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h_list[i+j]-h_list[i]))

        
print(dp[n-1])

### FIXED CODE ###

# B Frog 2

n, k = map(int, input().split())
h_list = [int(x) for x in input().split()]

dp = [float('Inf')] * n
dp[0] = 0

for i in range(n):
    for j in range(1,k+1,1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h_list[i-j]-h_list[i]))

        
print(dp[n-1])
N,K=map(int,input().split())
Tree=[[] for i in range(N)]
MOD=10**9+7
import sys
sys.setrecursionlimit(2*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)
def P(n,m):
  _=n
  for i in range(m-1):
    n-=1
    _*=(n%MOD)
  return _%MOD
def dfs(p,i):
  global Tree,ans
  n=len(Tree[i])-1
  if n==0:
    return
  if i==0:
    ans*=P(K-1,n)
  else:
    ans*=P(K-2,n)
    ans%=MOD
  for j in Tree[i]:
    if j==p:
      continue
    dfs(i,j)
Tree[0].append(-1)
ans=K
dfs(-1,0)
print(ans%MOD)

### FIXED CODE ###

N,K=map(int,input().split())
Tree=[[] for i in range(N)]
MOD=10**9+7
import sys
sys.setrecursionlimit(10**9)
for i in range(N-1):
  a,b=map(int,input().split())
  Tree[a-1].append(b-1)
  Tree[b-1].append(a-1)
def P(n,m):
  _=n
  for i in range(m-1):
    n-=1
    _*=n
    _%=MOD
  return _%MOD
def dfs(p,i):
  global Tree,ans
  n=len(Tree[i])-1
  if n==0:
    return
  if i==0:
    ans*=P(K-1,n)
  else:
    ans*=P(K-2,n)
    ans%=MOD
  for j in Tree[i]:
    if j==p:
      continue
    dfs(i,j)
Tree[0].append(-1)
ans=K
dfs(-1,0)
print(ans%MOD)
r,g,b=map(int, input().split())
rgb=str(r)+str(g)+str(b)
print("YES" if rgb%4==0 else "NO")


### FIXED CODE ###

r,g,b=map(int, input().split())
rgb=str(r)+str(g)+str(b)
print("YES" if int(rgb)%4==0 else "NO")
k = list(map(int,input()))
N , M =k[0],k[1]
if N == 2 or M == 2:
  print(0)
elif N == 1 or M == 1:
  print(abs(max(N,M)-2))
else:
  print((N-2) * (M-2))

### FIXED CODE ###

a = input()
b = input()
c = input()
print(a[0]+b[1]+c[2])
def search(value, ten, five, one, num):
    global ans
    if ans or value < 0:
        return
    
    if value == 0 and (ten+five+one) == num:
        ans = (ten, five, one)
    search(value-10, ten+1,five,one, num)
    search(value-5, ten, five+1, one, num)
    search(value-1, ten, five,one+1,  num)

num, value = map(int, input().split())
value //= 1000
num_ten = 0
num_five = 0
num_one = 0
ans = None
if (num-1)*100 < value < num*100:
    print("-1 -1 -1")
else:
    search(value, num_ten, num_five, num_one, num)
    print(ans[0], ans[1], ans[2])

### FIXED CODE ###

inputs = input().split("/")
if inputs[0] is not '2018':
    inputs[0] = "2018"
print("/".join(inputs))
n = int(input())
a = n.find("7")
if a>-1:
    print("Yes")
else :
    print("No")

### FIXED CODE ###

n = int(input())
a = str(n).find("7")
if a>-1:
    print("Yes")
else :
    print("No")
n, k=map(int, input().split())
x=list(map(int, input().split()))

R=[0]
L=[0]
for i in range(n):
    if x[i]>=0:
        R.append(x[i])
    else:
        L.append(-x[i])

R=sorted(R)
L=sorted(L)


lenR=len(R)
lenL=len(L)

if lenR>k:
    ans=R[k]
    for i in range(k):
        ans=min(ans,R[k-i]+2*L[i], 2*R[k-i]+L[i])
        #print('i,ans,R[k-i]+2*L[i], 2*R[k-i]+L[i]=',i,ans,R[k-i]+2*L[i], 2*R[k-i]+L[i])
else:
    ans=R[lenR-1]+L[k-lenR-1]
    for i in range(lenR):
        if k-i<lenL:
            ans=min(ans,R[i]+2*L[k-i], 2*R[i]+L[k-i])

print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
k-=1
ans=1<<99
for i in range(n-k):
    ans=min(ans,abs(a[i])+a[k+i]-a[i],abs(a[k+i])+a[k+i]-a[i])
print(ans)
n = int(input())
h = list(map(int, input().split()))

n = len(h)
dp =[[-2] * 2 for i in range(n)]


def f(index, is_sub):
    if(dp[index][is_sub] != -2):
        return dp[index][is_sub]

    v = h[index] - is_sub
    if(index == 0):
        dp[index][is_sub] = v
        return dp[index][is_sub]

    pre_v = f(index-1, 0)
    if(pre_v != -1 and pre_v <= v):
        dp[index][is_sub] = v
    pre_v = f(index-1, 1)
    if(pre_v != -1 and pre_v <= v):
        dp[index][is_sub] = v
 
    if(dp[index][is_sub]!=v):
        dp[index][is_sub] = -1
    
    #print(dp)
    return dp[index][is_sub]


#print(dp)
if(f(n-1,1)!=-1 or f(n-1,0)!=-1):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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


h[0] = h[0] -1
for i in range(1,n):
    if(h[i-1] < h[i]):
        h[i] = h[i]-1

flag = True
for i in range(1,n):
    if(h[i-1]>h[i]):
        flag = False

if(flag):
    print("Yes")
else:
    print("No")
S = input()
count =  0
for i in S:
  if i == '1':
    count++
print(count)

### FIXED CODE ###

S = input()
count =  0
for i in S:
  if i == '1':
    count+=1
print(count)