Harryxun/stf_run huggingface dataset:
s = input()
k = int(input())

x = int(s[0])
if (x == 1):
   print(s[1])
else:
   print(s[0])


### FIXED CODE ###

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

c1 = False
for i in range(k):
   x = s[i]
   if (x == '1'):
      c1 = True

   else:
      print(x)
      exit()

if (c1):
   print('1')
a,b,c,d=map(int,input().split))
if abs(b-a)<=d and abs(c-b)<=d:
	print(Yes)
else:
	print(No)

### FIXED CODE ###

a,b,c,d=map(int,input().split())
if (abs(b-a)<=d and abs(c-b)<=d) or abs(c-a)<=d:
	print("Yes")
else:
	print("No")
H, N = map(int,input().split())
magic = []
for i in range(N):
    a,b = map(int,input().split())
    magic.append((a, b))
magic.sort(reverse=True)

INF = 1<<60

def solve():
    btab = [INF] * (H+1)
    btab[0] = 0
    for h in range(1, magic[0][0]+1):
        btab[h] = min([b for a, b in magic if a >= h])
    for h in range(2, H+1):
        for s in range(1, magic[0][0]+1):
            c = btab[s] + btab[h-s]
            if c < btab[h]:
                btab[h] = c
    return btab[H]

print(solve())

### FIXED CODE ###

H, N = map(int,input().split())
magic = []
for i in range(N):
    a,b = map(int,input().split())
    magic.append((a, b))
magic.sort(reverse=True)
amax, _ = magic[0]

INF = 1<<60

def solve():
    btab = [INF] * (H+1)
    btab[0] = 0
    oneshot = min(amax, H)
    for h in range(1, oneshot+1):
        btab[h] = min([b for a, b in magic if a >= h])
    for h in range(2, H+1):
        for a, b in magic:
            c = b + btab[max(h-a, 0)]
            if c < btab[h]:
                btab[h] = c
    return btab[H]

print(solve())
def myfunc(h, w, c):
    if 0<=h and h<H+2 and 0<=w and w<W+2 and T[h][w] != '#':
        if T[h][w] == '.' or T[h][w] > c:
            T[h][w] = c
            global warp
            for i in [(0,1), (0,-1), (1,0), (-1,0)]:
                myfunc(h+i[0], w+i[1], c)
                for k in range(-2, 3):
                    for l in range(-2, 3):
                        myfunc(h+k, w+l, T[h][w]+1)

H, W= map(int, input().split())
CH, CW= map(int, input().split())
DH, DW= map(int, input().split())
S = ['#'+input()+'#' for _ in range(H)]
S.insert(0,'#'*(W*2))
S.append('#'*(W*2))
T = [[0] * (W+2) for _ in range(H+2)]
for i in range(H+2):
    for j in range(W+2):
        T[i][j] = S[i][j]
myfunc(CH, CW, 0)
warp = True
# while T[DH][DW] == '.' and warp:
#     warp = False
#     for i in range(H+2):
#         for j in range(W+2):
#             if T[i][j] != '.' and T[i][j] != '#':
#                 for k in range(-2, 3):
#                     for l in range(-2, 3):
#                         myfunc(i+k, j+l, T[i][j]+1)
if T[DH][DW] == '#' or T[DH][DW] == '.':
    print(-1)
else:
    print(T[DH][DW])


### FIXED CODE ###

from collections import deque
H, W= map(int, input().split())
CH, CW= map(int, input().split())
DH, DW= map(int, input().split())
S = [list(map(str, input())) for _ in range(H)]
q = deque([(CH-1, CW-1, 0)])
while q:
    h, w, c = q.popleft()
    if S[h][w] == '.':
        S[h][w] = c
        for i in range(-2, 3):
            for j in range(-2, 3):
                if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j] == '.':
                    if abs(i)+abs(j) == 1:
                        q.appendleft((h+i, w+j, c))
                    elif abs(i)+abs(j) >= 2:
                        q.append((h+i, w+j, c+1))
if S[DH-1][DW-1] == '.':
    print(-1)
else:
    print(S[DH-1][DW-1])
#y,m,d=map(int,input().split())
#a,b=map(int,input().split())
#n=int(input())
#a=int(input())
#b=int(input())
#s=list(input())
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
#b=list(map(int,input().split()))
#b=list(map(int,input().split()))
#a=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#a=[list(input().split())for _ in range(n)]
#a=[int(input())for _ in range(n)]
a=list(map(int,input().split(())))
total=sum(a)
if 22<=total:
    print('bust')
else:
    print('win')

### FIXED CODE ###

#y,m,d=map(int,input().split())
#a,b=map(int,input().split())
#n=int(input())
#a=int(input())
#b=int(input())
#s=list(input())
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
#b=list(map(int,input().split()))
#b=list(map(int,input().split()))
#a=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#a=[list(input().split())for _ in range(n)]
#a=[int(input())for _ in range(n)]
a=list(map(int,input().split()))
total=sum(a)
if 22<=total:
    print('bust')
else:
    print('win')
N = int(input())
act = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(1,N+1):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + act[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + act[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + act[i][2]
  
print(max(dp[N]))

### FIXED CODE ###

N = int(input())
act = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + act[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + act[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + act[i][2]
  
print(max(dp[N]))
S = input()
length = len(S)
temp = []
for i in range(1,length):
    if S[i] != S[i-1]:
        temp.append(max(i , length - i))
print(min(temp))

### FIXED CODE ###

S = input()
length = len(S)
temp = []
for i in range(1,length):
    if S[i] != S[i-1]:
        temp.append(max(i , length - i))
if len(temp) == 0:
    print(length)
else:
    print(min(temp))
a, b = map(int, input().split())
for c in range(1, 4):
    if (a*b*c) % 2 != 0:
        print('Yes')
        exit()
print('No')

### FIXED CODE ###

nums = input()

if '2' in nums:
    print("No")
else:
    print("Yes")
#17025159 | nowg's solution for [AtCoder-4250] [Problem A]
N,K = map(int,input().split())
S = input()

A = [0]
B = [0]
for s in S:
  if s == '1':
    A[-1] += 1
  elif A[-1] != 0:
    A.append(0)
  if s == '0':
    B[-1] += 1
  elif B[-1] != 0:
    B.append(0)

ans = 0

c,d,e,f = 0,0,0,0

for i in range(min(len(A),len(B))):
  a = 0
  if i == 0:
    if S[0] == '1':
      c,d = sum(A[i:min(i + K + 1,len(A))]),sum(B[i:min(i + K,len(B))])
      a = c + d
    else:
      c,d = sum(A[i:min(i + K,len(A))]) , sum(B[i:min(i + K,len(B))])
      a = c + d
  else:
    if S[0] == '1':
      if i + K <= len(A):
        c += A[min(i + K,len(A) - 1)] - A[i - 1]
        d += B[min(i + K - 1,len(A) - 1)] - B[i - 1]
        a = c + d
    else:
      a = sum(A[i - 1:min(i + K,len(A))]) + sum(B[i:min(i + K,len(B))])
      if i + K <= len(A):
        c += A[min(i + K,len(A) - 1)] - (0 if i == 1 else A[i - 2])
        d += B[min(i + K - 1,len(A) - 1)] - B[i - 1]
        a = c + d
      
  ans = max(ans,a)
print(ans)

### FIXED CODE ###

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

A = [0]
B = [0]
for s in S:
  if s == '1':
    A[-1] += 1
  elif A[-1] != 0:
    A.append(0)
  if s == '0':
    B[-1] += 1
  elif B[-1] != 0:
    B.append(0)

ans = 0
c,d,e,f = 0,0,0,0

for i in range(min(len(A),len(B))):
  a = 0
  if i == 0:
    if S[0] == '1':
      c,d = sum(A[i:min(i + K + 1,len(A))]),sum(B[i:min(i + K,len(B))])
      a = c + d
    else:
      c,d = sum(A[i:min(i + K,len(A))]) , sum(B[i:min(i + K,len(B))])
      a = c + d
  else:
    if S[0] == '1':
      if i + K < len(A):
        c += A[min(i + K,len(A) - 1)] - A[i - 1]
        d += B[min(i + K - 1,len(B) - 1)] - B[i - 1]
        a = c + d
    else:
      if i + K <= len(A):
        c += A[min(i + K - 1,len(A) - 1)] - (0 if i == 1 else A[i - 2])
        d += B[min(i + K - 1,len(B) - 1)] - B[i - 1]
        a = c + d
  ans = max(ans,a)
print(ans)
n = int(input())
a = list(map(int,input().split()))
sum = 0
ans = 0
# for i in range(n):
#     a[i] = a[i] % (10**9 +7)
#
# s = 0

for i in range(n):
    sum += a[i]

for i in range(n-1):
    sum -= a[i]
    ans += a[i] * sum

print(ans % (10**9 + 7))


### FIXED CODE ###

d,t,s = map(int,input().split())
if d/s <= t:
    print("Yes")

else:
    print("No")
n = int(input())
a = input().split(" ")
lista = [int(n) for n in a]
if 0 in lista:
  print(0)
  exit()
kotae=1
while kotae<=10**18:
  for i in range(n+1):
    kotae=kotae*lista[i]
  print(kotae)
  break
print(-1)  
       

### FIXED CODE ###

n = int(input())
a = input().split(" ")
kotae=1
listaa = [int(n) for n in a]
lista = sorted(listaa)
if lista[0]==0:
  print(0)
  exit()
for i in range(n):
  kotae*=lista[i]
  if kotae>10**18:
    kotae=-1
    break
if kotae>10**18:
  kotae=-1
print(kotae)
K = input()
S = int(input())

if len(S) <= K:
  print(S)
else:
  print(S[:K] + '...')



### FIXED CODE ###

K = int(input())
S = input()
 
if len(S) <= K:
  print(S)
else:
  print(S[:K] + '...')
n = int(input())
A = [int(s) for s in input().split()]
cen = n //2
ANS = [0]*(cen)
A_p = A[cen:n]
ANS = ANS + A_p

for i in range(cen):
    part_sum = sum(ANS[cen-i-1::cen-i])
    dot = part_sum % 2
    if dot == A[cen-i-1]:
        pass
    else:
        ANS[cen-i-1] = 1

sum_ans = sum(ANS)
print(sum_ans)
if sum_ans == 0:
    pass
else:
    B=[]
    for i in range(n):
        if ANS[i] != 0:
            B.append(i+1)
        else:
            pass
    B = " ".join(B)
    print(B)


### FIXED CODE ###

n = int(input())
A = [int(s) for s in input().split()]
cen = n //2
ANS = [0]*(cen)
A_p = A[cen:n]
ANS = ANS + A_p

for i in range(cen):
    part_sum = sum(ANS[cen-i-1::cen-i])
    dot = part_sum % 2
    if dot == A[cen-i-1]:
        pass
    else:
        ANS[cen-i-1] = 1

sum_ans = sum(ANS)
print(sum_ans)
if sum_ans == 0:
    pass
else:
    B = []
    for i in range(n):
        if ANS[i] != 0:
            B.append(i+1)
        else:
            pass
    BB = [str(a) for a in B]
    BB =" ".join(BB)
    print(BB)
n, k = list(map(int, input().split()))

ans = 0
if k = 0:
    ans = n * n
else:
    for b in range(k + 1, n + 1):
        ans += n // b * (b - k)
        ans += max(0, (n - (n // b * b)) - k + 1)

print(ans)


### FIXED CODE ###

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

ans = 0
if k == 0:
    ans = n * n
else:
    for b in range(k + 1, n + 1):
        ans += n // b * (b - k)
        ans += max(0, (n - (n // b * b)) - k + 1)

print(ans)
S = input()
N = len(S)
ans=[0]*N
#分割統治法
def RL(k):
    i=0
    count_R=0
    while S[k+i]=="R":
        count_R +=1
        i += 1
    j=0
    count_L=0
    while S[k+i+j]=="L":
        count_L += 1
        if k+i+j==N-1:
            break
        j+= 1
        
    
    ans[k+i-1] += (count_R+1)//2+count_L//2
    ans[k+i] += (count_R)//2+(count_L+1)//2

    if k+i+j!=N-1:
        RL(k+i+j)

RL(0)
[print(x) for x in ans]

### FIXED CODE ###

S = input()
N = len(S)
ans=[0]*N


count=0
for i in range(N):
    if S[i]=="R":
        count+=1
    else:
        ans[i-1] += (count+1)//2
        ans[i] += count//2
        count=0

count=0
for i in range(1,N+1):
    if S[N-i]=="L":
        count+=1
    else:
        ans[N-i] += count//2
        ans[N-i+1] += (count+1)//2
        count=0

[print(x) for x in ans]
class UnionFind:
    def __init__(self, size):
        """
        リストの添字を集合の値として利用し
        リストの要素を根, 節の管理に用いる
        要素が負の添字は素集合の根であり、集合の要素数
        要素が0以上の添字は節であり
        要素は節の親の添字を指す
        """
        self.table = [-1] * size
        
    def find(self, x):
        """
        xを持つ素集合の根を返す
        """
        if self.table[x] < 0:
            # 根の場合
            return x
        else:
            # 節の場合: 経路圧縮(path compression)
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        """
        x, yを持つ素集合を併合(Union)する
        """
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:  # x,yが異なる素集合に含まれている場合のみ併合
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

if __name__=="__main__":
    N, M = map(int, input().split())
    Q = [list(map(int, input().split())) for _ in range(M)]
    u = UnionFind(N)
    unconv = N*(N-1)//2
    ans = []
    for q in reversed(Q):
        ans.append(unconv)
        a = u.find(q[0]-1)
        b = u.find(q[1]-1)
        if a==b:
            continue
        unconv -= abs(u.table[a]*u.table[b])
        if unconv<0:
            unconv = 0
        u.union(q[0]-1, q[1]-1)
    for a in reversed(ans):
        print(a)

### FIXED CODE ###

class UnionFind:
    def __init__(self, size):
        import sys
        sys.setrecursionlimit(10**5)
        """
        リストの添字を集合の値として利用し
        リストの要素を根, 節の管理に用いる
        要素が負の添字は素集合の根であり、集合の要素数
        要素が0以上の添字は節であり
        要素は節の親の添字を指す
        """
        self.table = [-1] * size
        self.size = [1] * size
        
    def find(self, x):
        """
        xを持つ素集合の根を返す
        """
        if self.table[x] < 0:
            # 根の場合
            return x
        else:
            # 節の場合: 経路圧縮(path compression)
            self.table[x] = self.find(self.table[x])
            return self.table[x]
 
    def union(self, x, y):
        """
        x, yを持つ素集合を併合(Union)する
        """
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:  # x,yが異なる素集合に含まれている場合のみ併合
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
 
if __name__=="__main__":
    N, M = map(int, input().split())
    Q = [list(map(int, input().split())) for _ in range(M)]
    u = UnionFind(N)
    unconv = N*(N-1)//2
    ans = []
    for q in reversed(Q):
        ans.append(unconv)
        a = u.find(q[0]-1)
        b = u.find(q[1]-1)
        if a!=b:
            unconv -= u.table[a]*u.table[b]
        u.union(q[0]-1, q[1]-1)
    for a in reversed(ans):
        print(a)
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if not 0 <= n <= 100 and 0 <= m <= 100 and 2 <= n + m:
    print('Unsupported...')  
if n >= 2:
    n_comb = combinations_count(n, 2)
else:
    n_comb = 0
if m >= 2:
    m_comb = combinations_count(m, 2)
else:
    m_comb = 0
    
print(n_comb + m_comb)

### FIXED CODE ###

import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

if not 0 <= n <= 100 and 0 <= m <= 100 and 2 <= n + m:
    print('Unsupported...')  
if n >= 2:
    n_comb = combinations_count(n, 2)
else:
    n_comb = 0
if m >= 2:
    m_comb = combinations_count(m, 2)
else:
    m_comb = 0
    
print(n_comb + m_comb)
import math
n,k=map(int,input().split(" "))
a=list(map(int,input().split(" ")))

g=a[0]
m=a[0]
for i in range(n):
    g=math.gcd(g,a[i])
    m=max(a[i],m)

if k % g==0 and k<=m:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

def gcd(a,b):
    if a==0: return b
    else: return gcd(b%a,a)

def main():
    n,k=map(int,input().split(" "))
    a=list(map(int,input().split(" ")))
    g=a[0]
    m=a[0]
    for e in a:
        g=gcd(g,e)
        if m<e: m=e
    if k % g==0 and k<=m:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

main()
import math
N=int(input())
n=1
while True:
    if N <= 26**n:
        break
    n+=1
c=N
for n_ in range(1,n):
    c-=26**n_

a=[chr(i) for i in range(97, 97+26)]
# [chr(i) for i in range(ord('a'), ord('z')+1)]

answers=[]
while N>=26:
    b=N%26
    answers.append(a[b-1])
    N=N//26

answers.append(a[b-1])
answers.reverse()
b=''
for a in answers:
    b+=a
print(b)


### FIXED CODE ###

import math
N=int(input())

a=[chr(i) for i in range(97, 97+26)]
# [chr(i) for i in range(ord('a'), ord('z')+1)]
if N>26:
    answers = []
    while N > 0:
        N-=1
        b = N % 26
        answers.append(a[b ])
        N = N // 26

    answers.reverse()
    b = ''
    for a in answers:
        b += a
    print(b)
else:
    print(a[N-1])
N, Q = map(int, input().split())

tree = [[0] * 1 for i in range(N)]


tree_list = [0] * N
end = [0] * N

for index in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    tree[a].append(b)
    tree[b].append(a)

for index in range(Q):
    a, b = map(int, input().split())
    a -= 1
    tree_list[a] += b


def iter(node):
    end[node] = -1
    child = tree[node]
    for c in child:
        if end[c] == 0:
            tree_list[c] += tree_list[node]
            iter(c)


iter(0)

print(*tree_list)


### FIXED CODE ###

import sys

sys.setrecursionlimit(10000000)
input = sys.stdin.readline

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

tree = [[0] * 1 for i in range(N)]


tree_list = [0] * N
end = [0] * N

for index in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    tree[a].append(b)
    tree[b].append(a)

for index in range(Q):
    a, b = map(int, input().split())
    a -= 1
    tree_list[a] += b


def iter(node):
    end[node] = -1
    child = tree[node]
    for c in child:
        if end[c] == 0:
            tree_list[c] += tree_list[node]
            iter(c)


iter(0)

print(*tree_list)
n = math.sqrt(int(input()))
print(math.floor(n)**2)

### FIXED CODE ###

import math
n = math.sqrt(int(input()))
print(math.floor(n)**2)
#! -*- coding: utf-8 -*-
import sys

tree = dict()
cost = dict()

N = int(input())
sys.setrecursionlimit(N*10)
for i in range(N - 1):
    a, b, c = map(int, input().split())
    if a in tree:
        tree[a].append(b)
    else:
        tree[a] = []
        tree[a].append(b)
    if b in tree:
        tree[b].append(a)
    else:
        tree[b] = []
        tree[b].append(a)
    cost[(a, b)] = c
    cost[(b, a)] = c
starts = []
ends = []
Q, K = map(int, input().split())
for i in range(Q):
    x, y = map(int, input().split())
    starts.append(x)
    ends.append(y)

depth = [100010 for i in range(N)]

def dps(position, total_cost):
    if depth[position - 1] > total_cost:
        depth[position - 1] = total_cost
    for next_position in tree[position]:
        if depth[next_position - 1] == 100010:
            dps(next_position, depth[position - 1] + cost[(position, next_position)])

depth[K-1] = 0
dps(K, 0)

for start, end in zip(starts, ends):
    print(depth[start - 1] + depth[end - 1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

tree = dict()
cost = dict()

N = int(input())
for i in range(N - 1):
    a, b, c = map(int, input().split())
    if a in tree:
        tree[a].append(b)
    else:
        tree[a] = []
        tree[a].append(b)
    if b in tree:
        tree[b].append(a)
    else:
        tree[b] = []
        tree[b].append(a)
    cost[(a, b)] = c
    cost[(b, a)] = c
starts = []
ends = []
Q, K = map(int, input().split())
for i in range(Q):
    x, y = map(int, input().split())
    starts.append(x)
    ends.append(y)

depth = [1000000000000000 for i in range(N)]

def dps(position, total_cost):
    if depth[position - 1] > total_cost:
        depth[position - 1] = total_cost
    for next_position in tree[position]:
        if depth[next_position - 1] == 1000000000000000:
            dps(next_position, depth[position - 1] + cost[(position, next_position)])

depth[K-1] = 0
dps(K, 0)

for start, end in zip(starts, ends):
    print(depth[start - 1] + depth[end - 1])
#ABC123

a = [int(input()) for _ in range(5)]
b = [a[i] // 10 for i in range(5)]
c = sorted([a[i] % 10 for i in range(5) if a[i] % 10 != 0])
s = 10 * sum(b) + c[0] + (len(c)-1) * 10


print(s)

### FIXED CODE ###

#ABC123

a = [int(input()) for _ in range(5)]
b = [a[i] // 10 for i in range(5)]
c = [10] + sorted([a[i] % 10 for i in range(5) if a[i] % 10 != 0])

s = 10 * sum(b) + (len(c)-2) * 10 + min(c)

print(s)
import math
import sys

X = int(input())

for i in range(-100, 1000):
  for j in range(-100, 1000):
    if	math.pow(i, 5) - math.pow(j, 5)	== X:
      print("%d %d" % (i, j))
      sys.exit()


### FIXED CODE ###

S = input()
 
if S == 'ABC':
  print('ARC')
else:
  print('ABC')
N, M, Q = map(int, input().split())
a = [0 for _ in range(Q)]
b = [0 for _ in range(Q)]
c = [0 for _ in range(Q)]
d = [0 for _ in range(Q)]
for k in range(Q):
  a[k], b[k], c[k], d[k] = map(int, input().split())
A = [1 for _ in range(N)]

def point(A):
  p = 0
  for ai, bi, ci, di in zip(a, b, c, d):
    if A[bi-1] - A[ai-1] == ci:
      p += di
  return p

def next(A):
  k = 1
  while k < N+1:
    if A[-k] < M:
      A[-k] += 1
      return A
      break
    else:
      for j in range(1, k+1):
        A[-j] = A[-k-1] + 1
      k += 1
      
ans = max(ans, point([M for _ in range(N)]))
while A[0] < M:
  ans = max(ans, point(A))
  A = next(A)
print(ans)

### FIXED CODE ###

N, M, Q = map(int, input().split())
a = [0 for _ in range(Q)]
b = [0 for _ in range(Q)]
c = [0 for _ in range(Q)]
d = [0 for _ in range(Q)]
for k in range(Q):
  a[k], b[k], c[k], d[k] = map(int, input().split())
A = [1 for _ in range(N)]

def point(A):
  p = 0
  for ai, bi, ci, di in zip(a, b, c, d):
    if A[bi-1] - A[ai-1] == ci:
      p += di
  return p

def next(A):
  k = 1
  while k < N+1:
    if A[-k] < M:
      A[-k] += 1
      return A
      break
    else:
      for j in range(1, k+1):
        A[-j] = A[-k-1] + 1
      k += 1

ans = point([M for _ in range(N)])
while A[0] < M:
  ans = max(ans, point(A))
  A = next(A)
print(ans)
A,B,C,D=map(int,input().split())
while A>0:
  C-=B
  if C<=0:
    print("Yes")
    exit()
  A-=D
print("No")

### FIXED CODE ###

s,w=map(int,input().split())
if s>w:
    print("safe")
else:
    print("unsafe")
a, b = input().split("\n")
array = list(map(int,b.split()))
del array[0]
print(min(array), max(array), sum(array))


### FIXED CODE ###

input()
array = list(map(int, input().split()))
print(min(array), max(array), sum(array))
import math
while True:
	x = map(int,raw_input().split(' '))
	a =int( math.log10(x[0] + x[1]) + 1)
	if str(x[0]) != 'hellowork':
		print a
		continue
	else:
		break

### FIXED CODE ###

while True:
	try:
		a,b = map(int,raw_input().split(' '))
		print len(str(a+b))
	except: break
N, W = map(int, input().split())

import numpy as np
weight = np.empty((110), int)
value = np.empty((110), int)
dp = np.zeros((110, 10010), int)
#print(weight.shape, value.shape, dp.shape)

for i in range(N):
  weight[i], value[i] = map(int, input().split())

dp[0, :W+1] = 0

for i in range(N):
  for w in range(W+1):
    if w >= weight[i]:
      dp[i+1, w] = max(dp[i, w-weight[i]] + value[i], dp[i, w])
    else:
      dp[i+1, w] = dp[i, w]

ans = dp[N, W]
print(ans)

### FIXED CODE ###

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

weight = [None] * N
value = [None] * N
dp = [[None] * (W+1) for _ in range(N+1)]

for i in range(N):
  weight[i], value[i] = map(int, input().split())

for j in range(W+1):
  dp[0][j] = 0

for i in range(N):
  for w in range(W+1):
    if w >= weight[i]:
      dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w])
    else:
      dp[i+1][w] = dp[i][w]

ans = dp[N][W]
print(ans)
day = input()
week = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
ans = 6;

for i in int(len(week)):
    if day != week[i]:
        ans -= 1
print(ans)


### FIXED CODE ###

day = input()
week = ['SUN','MON','TUE','WED','THU','FRI','SAT']
ans = 7;

for i in range(len(week)):
    if day != week[i]:
        ans -= 1
    else:
        break
print(ans)