#     Clever Fat Rat
import time
from datetime import datetime

import itertools

max_oats = 10**6 + 1

def is_goal(state):
    (a, ws) = state
    if(len(ws) == 1 and ws[0][0] <= a[0]):
        return True

def child(state):
    (a, ws) = state
    scales = ws[0]
    if(len(ws) == 1):
        return [];

    b = [[0]*(len(scales)-1)]
    for (jdx, scale) in enumerate(scales):
        if a[jdx] >= scale:
            if(jdx == 0):
                b = map(lambda x: [x[0]+a[jdx]] + x[1:], b)
#                b[0] += a[jdx]
            elif (jdx == len(scales)-1):
                b = map(lambda x:  x[:-1]+[x[-1]+a[-1]], b)
#                b[-1] += a[-1]
            else:
                b = map(lambda x:  [x[:jdx]+[x[jdx]+a[jdx]]+x[jdx+1:], x[:jdx-1]+[x[jdx-1]+a[jdx]]+x[jdx:]], b)
                b = reduce (lambda a,b: a+b, b)
#                b[jdx-1] += a[jdx]/2.
#                b[jdx] += a[jdx]/2.
#    print b
    return map(lambda x: (x, ws[1:]), b)

def is_possible_reach_goal(state):
#    print state
    (a, ws) = state
    return (sum(a) >= ws[-1][0])

def is_broken(i, a, ws):
    return 1 if (a[i] >= ws[0][i]) else 0

def fall(idx, a, ws):
    return a[idx]  * is_broken(idx, a, ws)

def check_break(a, ws):
    break_list = [[0,0]]
    for idx in range(0, len(a)-1):
        break_list += [[0,0]]
        if(fall(idx, a, ws) + fall(idx+1, a, ws) >= ws[1][idx]):
            break_list[idx][1] = is_broken(idx, a, ws)
            break_list[idx+1][0] = is_broken(idx+1, a, ws)
#    print break_list
    return break_list

def next_step(a, break_list):
    next_step = [[]]
    for idx, b in enumerate(break_list):
        if b == [0,0]:
            next_step = map((lambda x: x+[0]), next_step)
        elif b == [0,1]:
            next_step = map((lambda x: x+[a[idx]]), next_step)
        elif b == [1,0]:
            next_step = map((lambda x: x[:-1] + [x[-1]+a[idx]] +[0]), next_step)
        else:   # [1,1]
            next_step = map((lambda x: [x[:-1] + [x[-1]+a[idx]] +[0], x+[a[idx]]]), next_step)
            next_step = reduce (lambda a,b: a+b, next_step)
    return map(lambda x: x[:-1],next_step)

def weight(p):
    return p[0]

def right(p):
    return p[1][1]

def left(p):
    return p[1][0]

def plus(l, r):
    return (weight(l)+weight(r), (left(l), right(r)))

# 01 can cover 02?
def cover(o1, o2):
    return left(o1) >= left(o2) and right(o1) <= right(o2) and weight(o1) >= weight(o2)

def add_only_unique(oats, oat):
    for idx, o_n in enumerate(oats):
        if oat == o_n or cover(o_n, oat):
            return oats
        if cover(oat, o_n):
            oats[idx] = oat
            return oats
    oats.append(oat)
    return oats

def unique(oats):
    new_oats = []
    for o in oats:
#        if o not in new_oats:
        should_add = True
        for idx, o_n in enumerate(new_oats):
            if o == o_n or cover(o_n, o):
                should_add = False
                break
            if cover(o, o_n):
                should_add = False
                new_oats[idx] = o
        if(should_add):
            new_oats.append(o)
    return new_oats

def max_drop(oats):
    max_drop = 0
    for oat in oats:
        max_drop = weight(oat) if  weight(oat) > max_drop else max_drop
    return max_drop

def print_now(message):
    print message,
    print datetime.now().strftime(u'%H:%M:%S:%f')

def possible_oats(a, ws):
#    print_now("> possible_oats")
    oats_list = []
    for idx in range(0, len(a)-1):  # same as len(ws)
#        print_now("> possible_oats loop")
        oats = []
        left_oat = a[idx]
        right_only_oat = [e for e in a[idx+1] if not e in left_oat ]
        left_only_oat = [e for e in a[idx] if not e in a[idx+1] ]
#        print len(right_only_oat)
#        print len(left_only_oat)

#        max_r = max_drop(a[idx+1])
        if ((len(a[idx+1]) == 0) or
            (idx != len(a)-2 and max_drop(a[idx+1])+max_drop(a[idx+2]) >= ws[0][idx+1])):
            for l in left_oat:
                if weight(l) >= ws[0][idx]:
                    oats.append(l)

        if ((len(a[idx]) == 0) or
            (idx != 0 and len(oats_list[-1]) != 0)):
            for r in right_only_oat:
                if weight(r) >= ws[0][idx]:
                    oats = add_only_unique(oats, r)
#        print_now("> possible_oats - pre for")
#        print len(a),
#        print len(oats),
#        print len(left_only_oat),
#        print len(right_only_oat)

        for c in itertools.product(left_only_oat,right_only_oat):
            (l,r) = c
            if weight(r)+weight(l) >= ws[0][idx] and right(l) < left(r):
                oats = add_only_unique(oats, plus(l,r))
#        print_now("> possible_oats - unique")
        if len(oats) > 30:
            oats.sort(key=weight, reverse=True)
            oats = oats[:30]
#            print oats
        oats_list.append(oats)
#    print_now("> possible_oats - return")
    return oats_list

def is_break_all(limit, oats_list):
    for idx, oat in enumerate(oats_list):
        for o in oat:
            if weight(o) >= limit[idx]:
                return True
    return False

def fatrat(state):
#    print state

    (a, ws) = state
#    if len(a) == 11:
#        return "Fat Rat"

    ws = map(lambda x: [max_oats]+x+[max_oats], ws)

    goal_oats = []
    pre_goal_oat = [0, 0]
    for idx in range(len(ws)-1,-1,-1):
        goal_oat = []
        for jdx in range(1,len(ws[idx])-1):
            goal_oat.append(max(ws[idx][jdx],min(pre_goal_oat[jdx-1], pre_goal_oat[jdx])))
        goal_oats.append(goal_oat)
        pre_goal_oat = [max_oats] + goal_oat + [max_oats]
    goal_oats.reverse()
    ws = map(lambda x: x[1:-1], ws)
#    print goal_oats

    oats_list = []
    for idx in range(0, len(a)):
        if a[idx] >= ws[0][idx]:
            oats_list.append([(a[idx], (idx,idx))])
        else:
            oats_list.append([])

    repeat = 0
    while(True):
        ws = ws[1:]
        if not len(ws):
            if len(oats_list[0]):
                return "Cerealguy"
            else:
                return "Fat Rat"

#        print goal_oats[0]
#        print oats_list
        if is_break_all(goal_oats[0], oats_list):
            return "Cerealguy"

        oats_list = possible_oats(oats_list, ws)
        goal_oats = goal_oats[1:]

#        repeat +=1
#        if repeat > 20:
#            print oats_list
#            return "Finish"

def fatrat3(state):
    print state
    (a, ws) = state

    a_list = [a]
    while(True):
        print len(ws)
        print len(a_list)
        print
#        print a_list[0:20]
#        if len(a_list) > 100:
#            break
        if len(ws) == 1:
            for e_a_list in a_list:
                if e_a_list[0] >= ws[0][0]:
                    return "Cerealguy"
            return "Fat Rat"

        a_list = map((lambda a: next_step(a, check_break(a, ws))), a_list)
        a_list = reduce (lambda a,b: a+b, a_list)

        new_list = []
        for e_a_list in a_list:
            if e_a_list not in new_list:
                if sum(e_a_list) >= ws[-1][0]:
                    new_list.append(e_a_list)

        a_list = new_list
        ws = ws[1:]

        if not len(a_list):
            return "Fat Rat"

def create_goals(ws):
    ws = map(lambda x: [max_oats]+x+[max_oats], ws)

    goal_oats = []
    pre_goal_oat = [0, 0]
    for idx in range(len(ws)-1,-1,-1):
        goal_oat = []
        for jdx in range(1,len(ws[idx])-1):
            goal_oat.append(max(ws[idx][jdx],min(pre_goal_oat[jdx-1], pre_goal_oat[jdx])))
        goal_oats.append(goal_oat)
        pre_goal_oat = [max_oats] + goal_oat + [max_oats]
    goal_oats.reverse()
#    ws = map(lambda x: x[1:-1], ws)
    return goal_oats
#    print goal_oats

def compare_goal(goals, oats):
    for idx in range(0,len(goals)):
        if(goals[idx] <= oats[idx]):
            return True
    return False

def fatrat2(state):
    stack = [state]
    visited = []
    start = datetime.now()

    goals = create_goals(state[1])
    while(stack):

        state = stack.pop(0)
        visited += [state[0]]

#        if(is_goal(state)):
        if(compare_goal(goals[len(goals)-len(state[0])], state[0])):
            return "Cerealguy"

        children = child(state)
        for c in children:
            if(c[0] not in visited and c not in stack):
                if is_possible_reach_goal(c):
                    stack += [c]

    return "Fat Rat"

Debug = False
if(not Debug):
    n = int(raw_input())
    a_s = raw_input().split()
    a = []
    for a_s_e in a_s:
        a += [int(a_s_e)]

    ws = []
    for i in range(0, int(n)):
        r = raw_input().split()
#        rs = [max_oats]
        rs = []
        for e_rs in r:
            rs += [int(e_rs)]
#        rs += max_oats
        ws += [rs]
#    print fatrat(n, a, ws)
    print fatrat(((a, ws)))
else:
    worst_w = [[50]]
    for idx in range(1,50):
        worst_w.append([1]*(idx+1))
    worst_w.reverse()
#    print fatrat(([1]*50, worst_w))   #F

    print fatrat(([1,1,1,1,1,1,1],[[1,9,1,9,1,9,9],[1,9,1,9,1,9],[1,1,9,1,9],[1,9,9,1],[1,9,1],[1,1],[3]])) #C
    print fatrat(([1, 1, 2, 2, 1, 1], [[1, 1, 2, 2, 1, 1],[2, 4, 2, 4, 2],[2,2,2,2],[4,10,4],[4,4],[8]]))   #F
    print fatrat(([1, 1, 1], [[1, 1, 1],[1, 1],[4]]))   #F
    print fatrat(([2, 2, 2], [[2, 2, 2],[3, 2],[4]]))   #C
    print fatrat(([1], [[1]]))   #C
    print fatrat(([2, 2], [[1, 2],[4]]))   #C
    print fatrat(([2, 2], [[1, 2],[5]]))   #F
    print fatrat(([798097, 886901, 292688, 792934], [[987579, 447910, 689959, 311317],[41624, 797440, 706737],[921438, 988902],[506461]]))   #C
    a =( [232602, 103849, 827367, 389557, 651438, 216320, 824798, 525699, 23338, 518302, 719391, 553814, 331160, 617684, 289434, 312706, 618709, 259095, 21269, 998945, 461731]
    + [896427, 149781, 499724, 6493, 239022, 333269, 513014, 671173, 502655, 287667, 863972, 857850, 644809, 824618, 402957, 617413, 295280, 915642, 78666, 498130, 693142])
    #0
    w =[0]*42
    w[0]=( [442788, 122361, 376827, 1098, 885713, 765876, 370112, 54990, 458771, 438057, 765395, 895171, 272899, 408086, 963600, 961459, 805320, 99236, 780298, 932795, 511481]
     +[195036, 855105, 514771, 711514, 234442, 539631, 644411, 463491, 112557, 217985, 629316, 185503, 888215, 728675, 175993, 704847, 245992, 469172, 819496, 608942, 786465])
#    W1=( [604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685])
    #+ [614993, 744625, 774390, 147357, 217239, 448556, 977399, 440373, 650208, 929115, 60946, 434417, 20...
#    w1 = ([806141, 604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685]
#[765593, 147600, 186480, 720359, 234733, 364648, 8995, 884055, 565526, 558538, 319000, 388...
    w[1] = ([765593, 147600, 186480, 720359, 234733, 364648, 8995, 884055, 565526, 558538, 319000, 388544, 274611, 872762, 244955, 981313, 877169, 440983, 367837, 367936]
    + [806141, 604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685])

    w[2]=( [103072, 936498, 847907, 650645, 566772, 244240, 76487, 607887, 833591, 261100, 535448, 472137, 921365, 782021, 699092, 571729, 884498, 898861, 570530, 8136, 278423, 614993, 744625, 774390, 147357, 217239, 448556, 977399, 440373, 650208]
    + [929115, 60946, 434417, 203564, 373657, 245610, 284531, 327005, 518126, 979469])

    w[3]= ([415376, 150228, 72136, 403305, 640672, 652152, 214427, 737311, 208036, 769173, 693842, 421040, 183828, 647456, 73520, 674069, 253765, 239577, 992072, 247531, 5556, 775497, 835157, 659594, 777970, 399659, 357111, 242550, 765227, 396071]
    + [337931, 684782, 912212, 59641, 407013, 892962, 529009, 168624, 729261])

    w[4]=([579778, 603392, 7187, 711763, 980786, 891205, 187614, 347504, 871321, 16499, 165802, 430266, 767897, 943796, 838570, 489956, 126553, 519253, 411089, 156752, 209661, 853585, 233490, 370034, 817847, 507577, 999103, 22978, 790519, 52028]
    +[728211, 18397, 740606, 627417, 513419, 851193, 795920, 975646])

    w[5]=([364270, 878531, 313352, 760219, 57774, 979287, 495749, 821992, 400807, 118875, 624706, 11664, 398468, 399161, 480516, 516761, 361857, 676791, 254124, 676721, 383882, 346228, 368172, 543223, 372419, 89729, 450007, 183906, 578337, 782425]
    +[239888, 133714, 848309, 211198, 276004, 422001, 342793])

    w[6]=(
    [669810, 70004, 223430, 545763, 495696, 659851, 458070, 320934, 70213, 2510, 670903, 398360, 955053, 229649, 10354, 681727, 93774, 345990, 810132, 724068, 178347, 919760, 900818, 664569, 731142, 68854, 562838, 348118, 412534, 711858]
    +[217450, 390687, 476960, 552361, 384448, 269506])

    w[7]= ([686869, 943862, 411867, 608029, 563528, 355743, 650398, 806908, 984874, 442601, 965871, 224704, 395748, 333576, 560520, 44827, 222000, 210286, 63258, 240375, 156949, 653188, 279453, 955766, 955005, 475318, 105273, 315988, 259444, 554025]
    +[169162, 673513, 337343, 217480, 802836])

    w[8]=([524812, 846231, 854588, 192451, 593937, 58689, 804666, 287964, 117042, 310411, 495542, 750086, 835403, 781732, 699317, 778671, 275391, 903769, 90240, 110812, 176953, 320104, 584756, 341201, 623117, 929603, 391734, 803929, 440316, 17762]
    +[349381, 33395, 717334, 254917])

    w[9]=([852392, 358681, 885946, 1989, 714822, 291374, 275129, 793814, 698964, 135683, 654809, 411164, 475752, 828614, 173173, 465830, 881709, 429319, 942530, 613387, 394352, 150504, 429484, 432671, 47638, 720929, 915486, 178642, 362160, 697774]
    +[582177, 990694, 63463])

    w[10]=([775829, 967068, 76364, 48338, 231255, 628921, 800537, 721127, 331827, 449577, 987306, 400525, 752721, 529533, 823633, 106767, 436626, 205685, 547258, 868397, 522545, 178774, 793439, 158477, 194198, 537780, 714979, 545295, 240759, 136464]
    +[342543, 669949])

    w[11]=([395243, 682010, 637544, 537377, 568397, 939159, 617065, 455601, 589065, 520285, 39074, 59942, 70214, 98748, 330093, 61675, 314160, 4343, 820744, 569072, 156641, 964848, 619284, 939421, 248299, 973729, 72425, 651620, 337476, 228294]
    +[446228])
    w[12] = [733423, 120527, 880793, 28654, 481273, 936515, 808693, 646362, 891193, 526586, 645212, 971930, 320632, 217240, 232724, 519503, 911492, 119638, 207340, 834315, 393853, 595370, 182300, 154260, 490060, 679573, 469578, 931192, 795252, 794504]
    w[13] = [992937, 935048, 234752, 790452, 581692, 261170, 364764, 938989, 760569, 392383, 343936, 652090, 226824, 806565, 456839, 687163, 528042, 195594, 873694, 66359, 594999, 965206, 59095, 345665, 918463, 273203, 35037, 899079, 842258]
    w[14]=[529636, 112898, 877687, 806044, 60735, 189749, 160846, 725032, 512840, 609679, 511, 993861, 575660, 560076, 254140, 79046, 330071, 166742, 370339, 396898, 344306, 315773, 868616, 819708, 981564, 686084, 252763, 573950]
    w[15]=[928772, 710357, 920822, 465694, 16512, 799572, 971974, 162499, 157133, 294992, 241747, 325056, 798852, 528918, 760749, 755326, 867061, 621152, 114485, 917241, 244803, 775595, 547781, 427681, 292956, 933798, 764221]
    w[16]=[406560, 631571, 780422, 992747, 904507, 669339, 120822, 171670, 667218, 377506, 620268, 569831, 150401, 606727, 427415, 149877, 467369, 558074, 701300, 941164, 905161, 621807, 105600, 109208, 227333, 278783]
    w[17]=[844232, 600660, 956873, 275867, 943068, 825161, 895623, 436781, 797538, 72677, 546140, 158861, 475846, 930202, 119313, 70300, 894159, 977232, 72700, 731713, 575949, 152873, 737159, 830782, 65071]
    w[18]=[237486, 549512, 427886, 634225, 662555, 1168, 679325, 898994, 922755, 757632, 664644, 637155, 527137, 507924, 980575, 388955, 210941, 125059, 22317, 78152, 38200, 739583, 554051, 627713]
    w[19]=[479028, 892887, 24398, 430711, 392354, 172860, 835107, 14025, 685353, 867105, 40260, 188534, 475120, 432763, 315378, 632428, 97800, 678056, 637610, 606208, 221689, 756844, 982589]
    w[20]=[496311, 545320, 850902, 922063, 260033, 790113, 586049, 527404, 349253, 221895, 828342, 465666, 633175, 282389, 519791, 331199, 728647, 567952, 2615, 162184, 714835, 235531]
    w[21]=[186477, 32274, 159996, 18134, 428838, 997537, 290934, 736388, 681330, 933659, 158840, 221272, 113015, 443400, 254260, 225996, 711610, 257129, 157857, 458557, 87869]
    w[22]=[601009, 200243, 37750, 427458, 155172, 379052, 313175, 219565, 161355, 632012, 541089, 436743, 196945, 780260, 562593, 479, 977598, 261257, 459383, 188043]
    w[23]=[397, 325219, 455107, 109068, 14827, 610661, 275371, 915727, 386383, 761111, 574986, 371344, 639217, 380366, 910264, 143066, 89832, 111998, 900082]
    w[24]=[54569, 953315, 43302, 252838, 348912, 495555, 823785, 117598, 949, 228308, 699837, 421190, 302746, 843111, 189564, 330203, 411320, 382797]
    w[25]=[285720, 115251, 233252, 448050, 374380, 478883, 644371, 21203, 879789, 5904, 534234, 486941, 73215, 738517, 214733, 114020, 753636]
    w[26]=[674062, 749897, 823484, 423759, 75711, 302798, 112824, 642967, 508005, 530628, 866877, 950023, 649878, 761438, 473985, 474066]
    w[27]=[764631, 542492, 923110, 543523, 771130, 380714, 749869, 488147, 391730, 58854, 709912, 984884, 156149, 574527, 865313]
    w[28]=[285322, 581452, 403449, 558544, 440730, 791866, 963533, 797693, 557146, 188615, 805740, 869602, 58823, 974248]
    w[29]=[541348, 328412, 178390, 827724, 8540, 807870, 861826, 343941, 825017, 837266, 74180, 685457, 162275]
    w[30]=[746285, 307489, 744197, 268642, 453102, 888605, 112405, 860770, 926547, 858125, 451650, 520853]
    w[31]=[750071, 509514, 692960, 418551, 57836, 476673, 681027, 636141, 1841, 259624, 120838]
    w[32]=[260295, 857040, 643083, 533047, 108837, 61847, 849988, 290, 137973, 706032]
    w[33]=[54921, 310584, 531482, 398431, 714080, 21340, 948456, 37528, 652013]
    w[34]=[913611, 142924, 415931, 772076, 351461, 16265, 459565, 738745]
    w[35]=[890204, 456669, 440916, 421772, 768120, 173826, 433774]
    w[36]=[358083, 892804, 903312, 679503, 168920, 921433]
    w[37]=[317439, 489653, 710322, 371652, 567242]
    w[38]=[75849, 947287, 694039, 831792]
    w[39]=[759605, 295166, 463625]
    w[40]=[539029, 755676]
    w[41]=[954370]

#    print fatrat((a, w))   #C


n,d,s=map(int,raw_input().split())
c0=[]
c1=[]
v=0
for i in range(n):
	c,f,l=map(int,raw_input().split())
	v+=c
	if l>=d:
		c0+=[f]
		if c:
			c1+=[f]
c0.sort()
y=z=0
if c1!=[]:
	u=min(c1)
	c0.remove(u)
	v+=1
	for i in c0:
		if u<=s:
			z,y=max([z,y],[min(v,n),-u])
		else:
			break
		u+=i
		v+=1
	if u<=s:
		z,y=max([z,y],[min(v,n),-u])
v=u=0
for i in c0:
	if u+i>s:
		break
	u+=i
	v+=1
z,y=max([z,y],[v,-u])
print z,-y


a=int(input())
if a==1:
    print("-1")
else:
    if a%2==0:
        print(a,2)
    else:
        print(a-1,2)


n, k, m, d = map(int, input().split())
ans = int(0)
for i in range(1, d+1):
    num = n // (k*(i-1)+1)
    if num > m:
        num = m
    ans = max(ans, num * i)
print(ans)


N, M, K = map(int, raw_input().split())
piles = []
draw = { 'G': 0, 'R': 0 }
for row in xrange(N):
    line = raw_input().strip()

    if ('R' in line) and ('G' in line):
        piles.append(abs(line.index('R') - line.index('G')) - 1)

    elif '-' in line:
        for letter in ['R', 'G']:
            if letter in line:
                draw[letter] = 1

def SecondWins():
    for bit in xrange(7):
        sum = 0
        for index in xrange(len(piles)):
            sum += (piles[index] >> bit) & 1

        if 0 != sum % (K + 1):
            return False

    return True

# G == First
# R == Second

if not piles:
    if draw['G'] == 0:
        print "Second"
    elif draw['R'] == 0:
        print "First"
    else:
        print "Draw"
    exit(0)

if SecondWins():
    draw['R'] = 2
else:
    draw['G'] = 2

if 1 in draw.values():
    print "Draw"
else:
    print "First" if draw['G'] == 2 else "Second"


import typing

def rit(*args) -> typing.Iterator:
    """Read input and yield split cast values.
    """
    func, funcs = int, (int, float, str)
    sep = " "
    for a in args:
        if a in funcs:
            func = a
        elif isinstance(a, str):
            sep = a
    return map(func, input().strip().split(sep))

def pit(itr: typing.Iterable, sep:str=" ") -> None:
    print(sep.join(map(str, itr)))

def rank(n):
    eps = 0.5 if n in (0, 1, 2, 4) or n % 4 == 2 else 0
    if n == 3:
        return 1
    return (n // 4 - 1) + (n - 1) // 2 + eps

def main():
    n = int(input())

    B = 1
    T = int(1e10)
    k = T // 2

    while True:
        if rank(k) == n:
            print(k)
            break
        elif n > rank(k):
            B = k
            if T - k == 1:
                k = T
            else:
                k += (T - k) // 2
        else:
            T = k
            if k - B == 1:
                k = B
            else:
                k -= (k - B) // 2

main()


T = 1
for test_no in range(T):
	x0, y0, ax, ay, bx, by = map(int, input().split())
	xs, ys, t = map(int, input().split())

	LIMIT = 2 ** 62 - 1
	x, y = [x0], [y0]
	while ((LIMIT - bx) / ax >= x[-1] and (LIMIT - by) / ay >= y[-1]):
		x.append(ax * x[-1] + bx)
		y.append(ay * y[-1] + by)

	n = len(x)
	ans = 0
	for i in range(n):
		for j in range(i, n):
			length = x[j] - x[i] + y[j] - y[i]
			dist2Left = abs(xs - x[i]) + abs(ys - y[i])
			dist2Right = abs(xs - x[j]) + abs(ys - y[j])
			if (length <= t - dist2Left or length <= t - dist2Right): ans = max(ans, j-i+1)

	print(ans)


s = raw_input()
left,right = s.split('=')
c = len(right)
first,second = left.split('+')
a = len(first)
b = len(second)
dif = a+b-c
if dif == 0:
	print s
elif abs(dif)==2:
	if dif>0:
		if a>1:
			right+='|'
			first = first[0:a-1]
		else:
			right+='|'
			second = second[0:b-1]
	else:
		first+='|'
		right=right[0:c-1]
	print first+'+'+second+'='+right
else:
	print 'Impossible'


n,k = map(int, raw_input().split())
from itertools import permutations
import sys
numbers = [raw_input() for x in xrange(n)]
min_val = sys.maxint
for perm in permutations(range(k)):
	permed_numbers = []
	for num in numbers:
		s = ""
		for x in perm:
			s += num[x]
		permed_numbers.append(int(s))
	temp = max(permed_numbers) - min(permed_numbers)
	if temp < min_val:
		min_val = temp

print(min_val)


def gcd(a,b): return a if (b==0) else gcd(b,a%b)
n,m,x,y,a,b=map(int,raw_input().split())
d=gcd(a,b)
k=min(n*d/a,m*d/b)
p,q=a/d*k,b/d*k
c,d=min(n-p,max(x-(p+1)/2,0)),min(m-q,max(y-(q+1)/2,0))
print c,d,c+p,d+q


from math import sqrt
n, m = map(int, input().split())
s = 0
f =  int(sqrt(m))
if f < n:
    for i in range(f):
        if ((i + 1) ** 2) == m:
            s += 1
        elif m % (i + 1) == 0 and (m // (i + 1)) <= n:
            s += 2
else:
    for i in range(n):
        if  m % (i + 1) == 0 and (m // (i + 1)) <= n:
            s += 1
print(s)


n,M=map(int,input().split())
t=[int(z)for z in input().split()]
for i in range(n):
    r=0
    a=sorted(t[:i])
    b=t[i]
    while sum(a)+b>M:
        a.pop(-1)
        r+=1
    print(r,end=' ')


n,a,b,c,d = map(int, raw_input().split())
dif = max([abs(b-c), abs(a-d), abs(c+d-a-b), abs(b+d-a-c)])
print (0 if dif >= n else n*(n-dif))


from fractions import gcd
n = int(input())
crush = list(map(int,input().split()))
was = [0] * n
ans = 1
for i in range(n):
    if was[i]:
        continue
    num = i
    j = 0
    while not was[num]:
        was[num] = 1
        num = crush[num] - 1
        j += 1
    if i != num:
        ans = -1
        break
    else:
        if j % 2 == 0:
            j //= 2
        ans = ans * j // gcd(ans,j)
print(ans)


m,b = map(lambda x:int(x),raw_input().strip().split())
sign1 = -m*b/abs(m*b)
maxs = 0
for y in range(b+1):
	if m*b>=m*b-m*y>=0:
		x = m*b-m*y
		s = (x+y)*(x+1)*(y+1)/2
		maxs = max(s,maxs)
	else:
		continue
print maxs


import math

a,b,x,y = map(int,input().split(" "))
gcdd = math.gcd(x,y)
x/=gcdd
y/=gcdd

aux = int(a/x)
aux2 = int(b/y)
menor = min(aux,aux2)

print(int(x*menor),"",int(y*menor))


def write(arg):
	print (str(arg))
	exit()
a,r,w=map(int,raw_input().split())
b=w%a
if -a<r<a and w%a>0:
	k=w/a
	k=k+min(1,b)
	if k==1:
		if -a/2.0<r<a/2.0:
			write(1)
		else:
			write(-1)
	else:
		if (k%2==0):
			if (-a/2.0<r<a/2.0):
				write( (k/2-1)*2+k/2+1)
			else:
				write(-1)
		elif k%2==1:
			b=k/2
			if -a<r<0:
				write( (b*2+(k-b)-1))
			elif 0<r<a:
				write( (b*2+(k-b)))
			else:
				write(-1)
else:
	write(-1)


'''
#generate all beautiful numbers < maxn
k = 0
n = 1
maxv = 100000
while n<=maxv:
	n -= 2**k
	n += 2**(2*k+1)
	n += 2**(2*k+2)
	k+=1
	print(n)
'''
bn = [130816,32640,8128,2016,496,120,28,6,1]
bn.reverse()
ans = 1
n = int(input())
for num in bn:
	if n%num==0:
		ans=num
print(ans)


def judge():
    for i in range(4):
        if a[i][3] == 0:
            continue
        left = (i + 3) % 4
        right = (i + 1) % 4
        mid = (i + 2) % 4
        if a[i][0] or a[i][1] or a[i][2] or a[left][2] or a[mid][1] or a[right][0]:
            return True
    return False

while True:
    try:
        a = []
        for i in range(4):
            a.append(list(map(int, input().split(' '))))
        print("YES" if judge() else "NO")
    except:
        break


mod = 10**9 + 7
ways = [[0 for j in range(502)] for i in range(502)]

ways[0][0] = 1
for i in range(1, 501):
    ways[i][0] = 1
    for j in range(1, 501):
        ways[i][j] = (ways[i - 1][j - 1] + ways[i - 1][j]) % mod

n, k = map(int, raw_input().split())
if n == 1:
    print 1
    exit(0)

def get(r, c):
    total = (r * n) + (c * n)
    common = r * c
    return pow(k - 1, total - common, mod) * pow(k, (n - r) * (n - c), mod)

res = 0

for r in range(n + 1):
    for c in range(n + 1):
        x = 1
        if (r + c) % 2 == 1:
            x *= -1

        res += x * get(r, c) * (ways[n][r] * ways[n][c]) % mod
        res %= mod

print res


import math
from collections import defaultdict, Counter, deque

INF = float('inf')

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

def isPrime(n):
	if (n <= 1):
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while (i ** 2) <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def can(m, s):
	if 0 <= s <= m * 9:
		return True
	return False

def main():
	m, n = vars()

	num = int('9' * m)

	ans = (num // n) * n
	if n <= num and len(str(ans)) == m:
		print(ans)
	else:
		print(-1)

if __name__ == "__main__":
	# t = int(input())
	t = 1
	for _ in range(t):
		main()


def  foo():
    str1 = raw_input().lower()
    str2 = raw_input().lower()

    if str1 == str2:
        print 0
    elif str1 > str2:
        print 1
    else:
        print -1

foo()


a,b,s = [abs(int(x)) for x in input().strip().split()]
d = s-(a+b)
if d>=0 and d%2==0:
    print("Yes")
else:
    print("No")


def solve(l,r):
    if(l>r): return 0
    if(l == r): return 1
    if(dp[l][r] != -1): return dp[l][r]
    ans = solve(l+1,r)+1
    for i in range(l+1,r+1):
        if(s[i]==s[l]): ans = min(ans , solve(l+1,i-1)+solve(i,r))
    dp[l][r] = ans
    return ans

def F():
    n = int(input())
    global s;
    s = input()

    global dp;
    dp = [[-1]*n for _ in range(n)]
    ans = solve(0,n-1)

    print(ans)
F()


if __name__ == "__main__":
    nmk = input().split(' ')
    for i in range(len(nmk)):
        nmk[i] = int(nmk[i])

    m = nmk[1]
    k = nmk[2]
    prices = input().split(' ')

    for i in range(len(prices)):
        prices[i] = int(prices[i])

    avail_houses = list()
    for i in range(len(prices)):
        if prices[i] != 0 and k >= prices[i]:
            avail_houses.append(i+1)
    min_dist = len(prices)
    for h in avail_houses:
        if h - m < min_dist:
            min_dist = abs(h - m)
    print(min_dist*10)


# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

def sep(): return map(int, inp().split())

def strsep(): return map(str, inp().split())

def fsep(): return map(float, inp().split())

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def pow(x, y, p):
    res = 1  # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0):
        return 0
    while (y > 0):
        if ((y & 1) == 1):  # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1  # y = y/2
        x = (x * x) % p
    return res

from functools import reduce

def factors(n):
    return set(reduce(list.__add__,
                      ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

# discrete binary search
# minimise:
# def search():
#     l = 0
#     r = 10 ** 15
#
#     for i in range(200):
#         if isvalid(l):
#             return l
#         if l == r:
#             return l
#         m = (l + r) // 2
#         if isvalid(m) and not isvalid(m - 1):
#             return m
#         if isvalid(m):
#             r = m + 1
#         else:
#             l = m
#     return m

# maximise:
# def search():
#     l = 0
#     r = 10 ** 15
#
#     for i in range(200):
#         # print(l,r)
#         if isvalid(r):
#             return r
#         if l == r:
#             return l
#         m = (l + r) // 2
#         if isvalid(m) and not isvalid(m + 1):
#             return m
#         if isvalid(m):
#             l = m
#         else:
#             r = m - 1
#     return m

##to find factorial and ncr
# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
#     fac.append((fac[-1] * i) % mod)
#     inv.append(mod - (inv[mod % i] * (mod // i) % mod))
#     finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
#     if n < r:
#         return 0
#     else:
#         return fac[n] * (finv[r] * finv[n - r] % mod) % mod

##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
#     dp[pos]=0
#     l=max(1,k+pos-n-1)
#     for j in range(min(pos,k),l-1,-1):
#         dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])

def prefix_sum(ar):  # [1,2,3,4]->[1,3,6,10]
    return list(accumulate(ar))

def suffix_sum(ar):  # [1,2,3,4]->[10,9,7,4]
    return list(accumulate(ar[::-1]))[::-1]

def N():
    return int(inp())

# =========================================================================================
from collections import defaultdict

def numberOfSetBits(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def solve():
    n=N()
    ar=lis()
    for i in range(len(ar)):
        m=ar[i]
        v = m // 2
        u = v // 2
        w = (v - u)
        print((u * w + u + w + 1) % mod)

solve()
#testcase(int(inp()))


n,a,b,c=map(int,raw_input().split())
w=0
for i in range(0,min(n,c*2)+1,2):
  j=n-i
  w+=max(0,min(a/2,j)+min(b,j)-j+1)
print w


s = input().strip()

start = (0, 0)
Map = [ (0, 0) ]
graph = {}
num = {}
num[start] = 0
x = 0
y = 0

for t in s:
    if t == 'U':
        y += 1
    elif t == 'D':
        y -= 1
    elif t=='L':
        x -= 1
    else:
        x += 1
    Map.append( (x, y) )

goal = Map[-1]
#print(Map)

for m in Map:
    graph[m] = set()
    for n in Map:
        if m != n and ( ( abs( m[0] - n[0] ) == 1 and m[1] == n[1] ) \
                        or  ( abs( m[1] - n[1] ) == 1 and m[0] == n[0] ) ):
            graph[m].add(n)

#print(graph)

visited, queue = set(), [start]
while queue:
    vertex = queue.pop(0)
    if vertex == goal:
        break
    if vertex not in visited:
        visited.add(vertex)
        for item in graph[vertex] - visited:
            num[item] = num[vertex] + 1
            queue.append(item)

if len(s) > num[goal]:
    print('BUG')
else:
    print('OK')


s = input()
d, k = 0, 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        k += 1
    else:
        k = 1
    if d < k:
        d = k
print("YES" if d > 6 else "NO")


q = int(input())
stroke = input()

d1 = {}

for i in range(q-1):

    u = i + 2
    key = stroke[i:u:]
    if not key in d1:
        d1[key] = 0
    d1[key] += 1
max_value = max(d1.values())
print([key for key, value in d1.items() if value == max_value][0])
#print(list(d1.items())[0][0])


n,k=[int(f)for f in input().split()]
a=(0 if n==k or k==0 else 1)
b=(k*2 if n//3>=k else n-k)
print(a,(b if k!=0 else 0))


import math
s = raw_input()
st = int(s)
l = [(-2,0),(-1,-2), (1,-2),(2,0),(1,2),(-1,2)]

if (st <= 6):
	if (st == 0):
		print "0 0"
		exit()

	if (st == 1):
		print "1 2"
		exit()
	if (st == 2):
		print "-1 2"
		exit()
	if (st == 3):
		print "-2 0"
		exit()
	if (st == 4):
		print "-1 -2"
		exit()
	if (st == 5):
		print "1 -2"
		exit()
	if (st == 6):
		print "2 0"
		exit()

a = 6
yy = 1
d = 6
n = int((-3 + math.sqrt(9+12*st))/6)
yy = n
ru = (n*(3*n+3))
#print ru
while (ru > st):
	n -= 1
	yy -= 1
	ru = n*(3*n+3)

diff = st - ru
#print diff , ru

x = 2*(yy)
y = 0

if (diff == 0):
	print x , y
	exit()
elif (diff == 1):
	x += 1
	y += 2
	print x, y
	exit()
elif (diff <= yy+1):
	x += 1
	y += 2
	diff -= 1
	x -= 1*diff
	y += 2*diff
	print x , y
	exit()

elif (diff > yy+1):
	x += 1
	y += 2
	x -= yy
	y += 2*yy
	diff -= yy+1
	li = 0

	while (diff > yy+1 ) :
		if (li < len(l)):
			x += l[li][0]*(yy+1)
			y += l[li][1]*(yy+1)
			diff -= (yy+1)
			li += 1
		else:
			break

	x += l[li][0]*diff
	y += l[li][1]*diff
	print x,y
	exit()


n,m= map(int,raw_input().split())
for i in range(n):
    l = map(int,raw_input().split())
for i in range(m):
    l = map(int,raw_input().split())

if n==m:
    print "Yes"
else:
    print "No"


"""

"""

x0, y0 = map(int, raw_input().split())
n = input()

def cdist(x, y):
    return x * x + y * y

d0 = [0] * n
d1 = [[0] * n for i in xrange(n)]
d2 = []

for i in xrange(n):
    x, y = map(int, raw_input().split())
    d0[i] = cdist(x - x0, y - y0)

    for j in xrange(i):
        d1[i][j] = cdist(x - d2[j][0], y - d2[j][1])
        d1[j][i] = d1[i][j]

    d2.append((x,y))

p = [2 ** i for i in xrange(n)]
a = [None] * (1 << n)
a[0] = 0
p2 = [0] * (1 << n)

for i in xrange(1 << n):
    if a[i] is not None:
        for j in xrange(n):
            if i & p[j] == 0:

                t = i + p[j]

                if not a[t] or a[t] > a[i] + d0[j] * 2:
                    a[t] = a[i] + d0[j] * 2
                    p2[t] = i

                for k in xrange(j + 1, n):
                    if t & p[k] == 0:
                        t2 = t + p[k]
                        c = a[i] + d0[j] + d1[j][k] + d0[k]
                        if not a[t2] or a[t2] > c:
                            a[t2] = c
                            p2[t2] = i
                break

z = (1 << n) - 1
print a[z]

r = [0]
while z > 0:
    t = z - p2[z]
    while t:
        x = -t & t
        t -= x
        i = 0

        while x > 0:
            i += 1
            x /= 2
        r.append(i)

    z = p2[z]
    r.append(0)

print ' '. join(map(str,r))


x = map(int, raw_input().split())
x = sorted(x)
print x[2] - x[0]


count = map(int,raw_input()).pop()
row = raw_input()
row += raw_input()
row += raw_input()
row += raw_input()

beats = list(row)
flag = True
if (beats.count('.') != 16):
    m_beat = map(int,max(beats)).pop()
    for x in range(len(beats)):
        try:
            beats[x] = int(beats[x])
        except ValueError:
            beats[x] = beats[x]
    for x in range(m_beat+1):
        if (beats.count(x) > count*2):
            flag = False
            break
if flag:
    print "YES"
else:
    print "NO"


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

def prod(a, mod=10**9+7):
    ans = 1
    for each in a:
        ans = (ans * each) % mod
    return ans

def lcm(a, b): return a * b // gcd(a, b)

def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

for _ in range(int(input()) if not True else 1):
    #n = int(input())
    #n, k = map(int, input().split())
    n,m,x1,y1,x2,y2 = map(int, input().split())
    #c, d = map(int, input().split())
    #a = list(map(int, input().split()))
    #b = list(map(int, input().split()))
    #s = input()
    x, y = abs(x2-x1), abs(y2-y1)
    x, y = min(x,y), max(x,y)
    if [x,y] in [[0,0], [0,1], [0,2], [0,3], [0,4],
                 [1,1], [1,2], [1,3], [1,4],
                 [2,2], [2,3], [2,4],
                 [3,3]]:
        print("First")
    else:
        print("Second")


# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 15/07/2020

from sys import stdin,stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

n = ii1()
s = "abcdefghijklmnopqrstuvwxyz"
res = ""
for i in s:
    cost = 0
    while n - cost >= 0:
        n -= cost
        cost += 1
        res += i
    if not n:
        break
print(res)


#!/usr/bin/python
from math import *

def cost(hr, hb, nr, nb) :
  return hr * nr + hb * nb

if __name__ == '__main__':
  c, hr, hb, wr, wb = map(int, raw_input().split())
  sq = int(ceil(sqrt(c)))
  if wb < sq and (wr >= sq or wb * hr < wr * hb) :
    wr, wb = wb, wr
    hr, hb = hb, hr

  ans = 0
  for i in xrange(sq + 1) :
    nb = i
    nr = max(0, c - nb * wb) // wr
    if (nb * wb <= c) :
      ans = max(ans, cost(hr, hb, nr, nb))

  print ans


def CF579A():
    return str(bin(int(input()))).count('1')

if __name__ == '__main__':
    print(CF579A())


import sys
input = sys.stdin.buffer.readline

def prog():
    n = int(input())
    a = list(map(int,input().split()))

    freq = [0]*101
    for i in range(n):
        freq[a[i]] += 1
    mx = max(freq)
    amt = freq.count(mx)

    if amt >= 2:
        print(n)
    else:
        must_appear = freq.index(mx)
        ans = 0
        for j in range(1,101):
            if j == must_appear:
                continue

            first_idx = [10**6]*(n+1)
            first_idx[0] = -1
            curr = 0
            for i in range(n):
                if a[i] == must_appear:
                    curr += 1
                elif a[i] == j:
                    curr -= 1
                ans = max(ans, i - first_idx[curr])
                first_idx[curr] = min(first_idx[curr],i)

        print(ans)

prog()


from math import sqrt

n = int(input())
if 1 <= n <= 2*pow(10,9):
    if n%2 == 1:
        print("0")
    else:
        half = n/2
        if half % 2 == 0:
            print(int((half/2)-1))
        else:
            print(int((half-1)/2))


n,k=map(int,input().split())
if n%2==0:
    if k<=n/2:
        print(2*k-1)
    else:
        k=k-int(n/2)
        print(2*k)
else:
    if (k<=int(n/2)+1):
        print(2*k-1)
    else:
        k=k-int(n/2)-1
        print(2*k)


import decimal
decimal.getcontext().prec = 500

a,b,c = input().split()

div = decimal.Decimal(a) / decimal.Decimal(b)
div = str(div)
dec = div.find('.')
after_dec = div[dec + 1 :]
if(len(after_dec) != 500):
    after_dec = after_dec + '0'
z= after_dec.find(c)

if(z == -1 or z == 499):
    print(-1)
else:
    print(z + 1)


def increase_difference(to_start, diff):
    res = 1
    for i in to_start:
        if i + diff < 10:
            break
        if i + diff > 9:
            diff = diff - (9 - i)
            res += 1
    return res

def decrease_difference(to_start, diff):
    res = 1
    for i in to_start:
        if i - diff > -1:
            break
        if i - diff < 0:
            diff = diff - i
            res += 1
    return res

ticket = list(raw_input())

ticket = [int(x) for x in ticket]

ticket1 = sorted([ticket[0], ticket[1], ticket[2]])
ticket2 = sorted([ticket[3], ticket[4], ticket[5]])

sum_first_three = ticket[0] + ticket[1] + ticket[2]
sum_last_three = ticket[3] + ticket[4] + ticket[5]

if sum_first_three == sum_last_three:
    print 0
    exit(0)

total_diff = max(sum_first_three, sum_last_three) - min(sum_first_three, sum_last_three)

#########################
to_start = ticket1
if sum_first_three > sum_last_three:
    to_start = ticket2

res1 = increase_difference(to_start, total_diff)

#########################
ticket1.reverse()
ticket2.reverse()

to_start = ticket1
if sum_last_three > sum_first_three:
    to_start = ticket2

res2 = decrease_difference(to_start, total_diff)

#########################
to_start = ticket1
if sum_last_three > sum_first_three:
    to_start = ticket2

lower_diff = total_diff / 2
higher_diff = total_diff - lower_diff

res3 = 0
if sum_first_three > sum_last_three:
    ticket2 = sorted(ticket2)
    res3 = min(decrease_difference(ticket1, lower_diff) +
               increase_difference(ticket2, higher_diff),
               decrease_difference(ticket1, higher_diff) +
               increase_difference(ticket2, lower_diff))
else:
    ticket1 = sorted(ticket1)
    res3 = min(increase_difference(ticket1, lower_diff) +
               decrease_difference(ticket2, higher_diff),
               increase_difference(ticket1, higher_diff) +
               decrease_difference(ticket2, lower_diff))

print min(res1, res2, res3)


R = lambda: map(int,input().split())
N = list(R())
T = list(R())
mixn = min(N[::2])
maxn = max(N[::2])
miyn = min(N[1::2])
mayn = max(N[1::2])
mix = min(T[::2])
maxx = max(T[::2])
miy = min(T[1::2])
may = max(T[1::2])

mid = (miy+may)//2
for y in range(miy,may+1):
    t = abs(y-mid)
    for x in range(mix+t,maxx-t+1):
        if mixn <= x <= maxn and miyn <= y <= mayn:
            print("YES")
            quit()
print("NO")


str=input()
m=0
n=len(str)
for i in range(n):
    for j in range(i,n+1) :
        if str[i:j] in str[i+1:n] and len(str[i:j])>m:
            m=len(str[i:j])
print(m)


#!/usr/bin/env python3

import itertools

class Solitaire:
  def __init__(self):
    # Read inputs
    (self.n,self.m) = map(int,input().split())
    self.table = [input().split() for i in range(self.n)]

    # Determine the unused cards and the positions of the jokers
    ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"]
    suits = ["C", "D", "H", "S"]
    deck = set(("%s%s" % card) for card in itertools.product(ranks,suits))
    self.J1_position = None
    self.J2_position = None

    for (r,c) in itertools.product(range(self.n), range(self.m)):
      card = self.table[r][c]
      deck.discard(card)
      if (card == "J1"):
        self.J1_position = (r,c)
      elif (card == "J2"):
        self.J2_position = (r,c)

    self.unused_cards = list(deck)
    self.unused_cards.sort() # Sort to make things deterministic (easier for testing)

  def is_solved_square(self, r, c):
    cards = [self.table[r+ro][c+co] for (ro, co) in itertools.product(range(3), range(3))]
    suits = set(card[1] for card in cards)
    ranks = set(card[0] for card in cards)
    solved = (len(suits) == 1) or (len(ranks) == 9)
    return solved

  def is_solved(self):
    all_positions = itertools.product(range(self.n-2), range(self.m-2))
    all_solved_squares = [(r,c) for (r,c) in all_positions if self.is_solved_square(r,c)]
    for ((r1, c1), (r2,c2)) in itertools.combinations(all_solved_squares, 2):
      if (abs(r1-r2) >= 3) or (abs(c1-c2) >= 3):
        return ((r1,c1),(r2,c2))
    return None

  def replace_card(self, position, card):
    (r,c) = position
    self.table[r][c] = card

  def print_solution(self, joker_line, solution):
    if (solution == None):
      print("No solution.")
    else:
      ((r1,c1),(r2,c2)) = solution
      print("Solution exists.")
      print(joker_line)
      print("Put the first square to (%d, %d)." % (r1+1,c1+1))
      print("Put the second square to (%d, %d)." % (r2+1,c2+1))
    exit()

  def solve(self):
    if (self.J1_position != None) and (self.J2_position != None):
      for (replacement1, replacement2) in itertools.permutations(self.unused_cards,2):
        self.replace_card(self.J1_position, replacement1)
        self.replace_card(self.J2_position, replacement2)
        solution = self.is_solved()
        if (solution):
          self.print_solution("Replace J1 with %s and J2 with %s." % (replacement1, replacement2), solution)
    elif (self.J1_position != None):
      for replacement in self.unused_cards:
        self.replace_card(self.J1_position, replacement)
        solution = self.is_solved()
        if (solution):
          self.print_solution("Replace J1 with %s." % replacement, solution)
    elif (self.J2_position != None):
      for replacement in self.unused_cards:
        self.replace_card(self.J2_position, replacement)
        solution = self.is_solved()
        if (solution):
          self.print_solution("Replace J2 with %s." % replacement, solution)
    else:
      solution = self.is_solved()
      self.print_solution("There are no jokers.", solution)
    self.print_solution("", None)

Solitaire().solve()


#!/bin/python

def split_array():
	a = int(raw_input().strip())
	ar = map(int, raw_input().strip().split())

	tb = [[0 for _ in range(a)] for _ in range(a)]

	for i in range(a):
		for j in range(i, a):
			if i == j:
				tb[i][j] = ar[i]
			else:
				tb[i][j] = sum(ar[i:j+1])

	k = 0
	head = 0
	tail = 0
	res = []
	possible = True

	while tail < a:

		if tail == a -1:
			if tb[head][tail] == 0:
				possible = False
				break
			else:
				res.append([head+1, tail+1])

				tail += 1
		else:
			if tb[head][a-1] != 0:
				res.append([head+1, a])

				break
			elif tb[head][tail] == 0:
				tail += 1
			else:
				res.append([head+1, tail+1])
				head = tail+1
				tail = tail +1

	if not possible:
		print "NO"
	else:
		print 'YES'
		print len(res)
		for each in res:
			print ' '.join(map(str, each))

if __name__ == '__main__':
	split_array()


n,d=map(int,input().split());s=input()
if '0'*d in s:print('-1')
else:
    i,c=0,0
    while i<n-1:
        if s[i]=='1':i+=d;c+=1
        else:i-=1
    print(c)


"""
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000

"""
import sys
input = sys.stdin.buffer.readline
import math
def solution():
    l,r,x,y=map(int,input().split())
    if y%x!=0:
        print(0)
        return
    p=y//x
    cnt=0
    for i in range(1,int(p**0.5)+1):
        if p%i==0:
            a=i
            b=p//i
            if a*x>=l and b*x>=l and a*x<=r and b*x<=r:
                if math.gcd(a,b)==1:
                    if a==b:
                        cnt+=1
                    else:
                        cnt+=2

    print(cnt)

solution()


import sys
range = xrange
input = raw_input

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
coupl = [[] for _ in range(n)]
for _ in range(n - 1):
    u = inp[ii] - 1; ii += 1
    v = inp[ii] - 1; ii += 1
    coupl[u].append(v)
    coupl[v].append(u)

P = [-1] * n
root = 0
bfs = [root]
P[root] = root
for node in bfs:
    for nei in coupl[node]:
        del coupl[nei][coupl[nei].index(node)]
        bfs.append(nei)
        P[nei] = node

ans = list(range(n));cost = 0
for node in reversed(bfs):
    if ans[node] != node:continue
    cost += 2
    if node != root:p = P[node]
    else:p = coupl[node][0]
    ans[node],ans[p] = ans[p],ans[node]
print cost;print ' '.join(str(x + 1) for x in ans)


MOD = 10 ** 9 + 7
n, m = input().split(' ')
n = int(n)
m = int(m)
ans = pow(2 * (n + 1), m, MOD)
ans = (ans * (n + 1 - m)) % MOD
ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD
print(ans)


import bisect
from collections import defaultdict
from collections import deque
import math
import re

def ni():
    return int(raw_input())

def nis():
    return map(int, raw_input().split())

def si():
    return raw_input()

def sis():
    return raw_input().split()

vals = [[0], [1], [2], [3], [2, 2, 3], [5], [3, 5], [7], [2, 2, 2, 7], [2, 3, 3, 7]]

n = ni()
a = filter(lambda x: x > 1, map(int, list(si())))

ans = []
for x in a:
    ans.extend(vals[x])

ans.sort(reverse=True)

print ''.join(map(str, ans))


P = 10**9 + 7

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

print(n + 1 if k == 1 else (k * pow(2 * k - 1, n, P) - pow(k, n, P)) * pow(k - 1, P - 2, P) % P)


n = int(raw_input())

min1,max1 = map(int,raw_input().split())
min2,max2 = map(int,raw_input().split())
min3,max3 = map(int,raw_input().split())

answer1 = min1
answer2 = min2
answer3 = min3

answer = answer1 + answer2 + answer3 #at least...
if (answer < n):
	answer1 = min(max1,n-answer + min1)
answer = answer1 + answer2 + answer3 #updating...

if (answer < n):
	answer2 = min(max2,n-answer + min2)
answer = answer1 + answer2 + answer3 #updating...

if (answer < n):
	answer3 = min(max3,n-answer + min3)

print answer1,answer2,answer3


ans=1000000000000
mul = []

def dfs(now, num, opt):
	if num == 0:
		global ans
		ans = min(ans, opt)
		return
	if now == -1:
		return
	i=-10
	while i * mul[now] <= num:
		i+=1
	dfs(now-1, num-(i-1)*mul[now], opt+abs(i-1)*(now+1))
	dfs(now-1, num-i*mul[now], opt+abs(i)*(now+1))

def main():
	mul.append(int(1))
	num = int(input())
	for i in range(1,18,1):
		mul.append(mul[i-1]*10)
	for i in range(1,18,1):
		mul[i] += mul[i-1]
	i = 1
	while mul[i] <= num:
		i+=1
	n=i
	dfs(n, num, 0)
	print(ans)

main()


n=int(input())
l=list(input())
z=[]
for i in range(n):
    x,y=map(str,input().split("->"))
    z.append(x)
    z.append(y)
z1=list(set(z))
z2=[]
for i in range(len(z1)):
    z2.append(z.count(z1[i]))
for i in range(len(z2)):
    if z2[i]%2==1:
        print("contest")
        break
else:
    print("home")


n, m, k = map(int, raw_input().split())

if n % 2:
    if k == 1:
        if m == 1:
            print('Marsel')
        else:
            print('Timur')
    else:
        d = 2
        ok = False
        while d * d <= m:
            if m % d == 0:
                if m / d >= k:
                    ok = True
                break
            d += 1

        if ok:
            print('Timur')
        else:
            print('Marsel')
else:
    print('Marsel')


'''input
abracadabra
10
'''
s = raw_input().strip()
k = input()
s += '?'*k
ans = 0
for n in range(1,len(s)//2+1):
	for i in range(len(s)-2*n+1):
		flag = True
		for j in range(n):
			if s[i+j] == '?' or s[i+j+n] == '?' or s[i+j] == s[i+j+n]:
				continue
			flag = False
			break
		if flag :
			ans = max(ans,2*n)
print ans


w0, h0 = map(int, raw_input().split())
u1, d1 = map(int, raw_input().split())
u2, d2 = map(int, raw_input().split())
w = w0
for i in range(h0, 0, -1):
    w += i
    if i == d1:
        w = max(w - u1, 0)
    if i == d2:
        w = max(w - u2, 0)
print(w)


I=lambda:map(int, raw_input().split())
n=input()
def dfs(x):
    if x>n: return 0
    return dfs(x*10)+dfs(x*10+1)+1
print dfs(1)


n=int(input())
s=input()
s=s.strip()
a=0
b=0

l=len(s)
for i in range(l):
    if (s[i]=='U'):
      a+=1

    if (s[i]=='D'):
       a+=-1

    if (s[i]=='L'):
       b-=1

    if (s[i]=='R'):
        b+=1

print(l-abs(b)-abs(a))


from math import pi, sin
n , R , r=map(int,input().split())
print(['NO','YES'][ R >= r+r/sin(pi/n) or (n==1 and R>=r)])


str=input()
nc=str.count('n')
ic=str.count('i')
tc=str.count('t')
ec=str.count("e")
print(max(0,min((nc-1)//2,ec//3,ic,tc)))


import sys

def read_two_ints(itr):
    return map(int, next(itr).split(' '))

def fits(a_board, b_board, a_pictures, b_pictures):
    return ((a_board >= a_pictures and b_board >= b_pictures) or
            (a_board >= b_pictures and b_board >= a_pictures))

def combos(a1, b1, a2, b2):
    yield (a1+a2, max(b1, b2))
    yield (b1+b2, max(a1, a2))
    yield (a1+b2, max(b1, a2))
    yield (b1+a2, max(a1, b2))

a1, b1 = read_two_ints(sys.stdin)
a2, b2 = read_two_ints(sys.stdin)
a3, b3 = read_two_ints(sys.stdin)

# for a_pic, b_pic in combos(a2, b2, a3, b3):
#     print 'Trying to fit {}, {}'.format(a_pic, b_pic)
#     if fits(a1, b1, a_pic, b_pic):
#         print "It worked!"
#         break
# else:
#     print "I'm stuck"

if any(fits(a1, b1, a_pic, b_pic) for a_pic, b_pic in combos(a2, b2, a3, b3)):
    print "YES"
else:
    print "NO"


k = int(input()) & 1

p = []
s = range(1, 6)

for q in map(int, input().split()[::-1]):

    if k:
        p += [(x, -y) for x, y in p]
        p = [(x - q, y) for x, y in p]
        p += [(-x, 0) for x in s[:q]]
    else:
        p += [(y, -x) for x, y in p]
        p = [(x - q, y + q) for x, y in p]
        p += [(-x, x) for x in s[:q]]

    p = list(set(p))
    k = 1 - k

print(len(p))


num = input()
num += "1"
answer = "YES"
if num[0] == "1":
    i = 1
    n_s = len(num)
    while i < n_s:
        s = num[i]
        if s == "4":
            if num[i+1] == "1":
                i += 2
            elif num[i+1:i+3] == "41":
                i += 3
            else:
                answer = "NO"
                break
        elif s == "1":
            i += 1
        else:
            answer = "NO"
            break
else:
    answer = "NO"
print(answer)


n,m=map(int,input().split())
i=0
if(n>m):
    i=m
else:
    i=n
if(i%2==0):
    print("Malvika")
else:
    print("Akshat")


import sys
range = xrange
input = raw_input
import __pypy__
mulmod = __pypy__.intop.int_mulmod

MOD = 10**9+7
n, k = [int(x) for x in input().split()]
k += 2

def f(n):
    s = 0
    for i in range(n):
        s += pow(i,k-2,MOD)
        s %= MOD
    return s

precalc = [0]
for i in range(k - 1):
    precalc.append((precalc[-1] + pow(i,k-2,MOD)) % MOD)

big = 10**6 + 10
modinv = [1]*big
for i in range(2,big):
    modinv[i] = mulmod(-(MOD//i), modinv[MOD%i], MOD)

invfac = [1]
for i in range(1,big):
    invfac.append(invfac[-1]*modinv[i]%MOD)
invneg_fac = [invfac[i] * (1 - 2 * (i & 1)) for i in range(len(invfac))]

def g(x):
    if x < k:
        return precalc[x]
    base = 1
    for j in range(-x, k - x):
        base = mulmod(base, j, MOD)
    s = 0
    for i in range(k):
        pr = precalc[i]
        pr = mulmod(pr, pow(i - x, MOD - 2, MOD), MOD)
        pr = mulmod(pr, mulmod(invneg_fac[i], invfac[k - i - 1], MOD), MOD)
        s = (s + pr) % MOD
    return mulmod(s, base, MOD)

print (g(n + 1) - (k == 2)) % MOD


a = raw_input()

x = " " * 3
cnt = -1
for i in xrange(1,len(a)):
  for j in xrange(i+1,len(a)):
    x = a[:i], a[i:j], a[j:]
    if not any([b for b in x if (b.startswith('0') and b != '0') or int(b) > 1000000]):
      cnt = max(cnt, sum(map(int, x)))

print cnt


def kset(n, k):
	if ((n >> (k - 1)) and 1):
		return 1
	else:
	    return 0
def compute(S, X):
    A = (S - X)//2
    a = 0
    b = 0

    # Traverse through all bits
    for i in range(64):
        Xi = (X & (1 << i))
        Ai = (A & (1 << i))
        if (Xi == 0 and Ai == 0):
            # Let us leave bits as 0.
            pass

        elif (Xi == 0 and Ai > 0):
            a = ((1 << i) | a)
            b = ((1 << i) | b)

        elif (Xi > 0 and Ai == 0):
            a = ((1 << i) | a)
            # We leave i-th bit of b as 0.

        else: # (Xi == 1 and Ai == 1)
            return [-1,-1]

    return [a,b]
ss=input().split()
x=int(ss[0])
s=int(ss[1])
if x==s==0:
    print(0)
elif s==x and x!=0 and s!=0:
    print(1)
    print(s)
elif s<x or (s-x)%2 !=0:
    print(-1)
else:
    z=compute(s,x)
    if z[0]==-1:
        print(3)
        print((s-x)//2,(s-x)//2,x)
    else:
        print(2)
        print(z[0],z[1])


n, k = map(int, raw_input().split())
res = 0
while n and k:
	res += max((n - 1) * 2 - 1, 0)
	n -= 2
	k -= 1
print res


n,k = map(int, raw_input().split())
a = list(raw_input())
g = a.index('G')
t = a.index('T')
if g<t:
	while True:
		g+=k
		if g>n-1:
			print "NO"
			break
		if a[g] == '#' or g>t:
			print "NO"
			break
		elif g == t:
			print "YES"
			break
else:
	while True:
		g-=k
		if g<0:
			print "NO"
			break
		if a[g] == '#' or g<t:
			print "NO"
			break
		elif g == t:
			print "YES"
			break


a, b, c = map(int,raw_input().split())
ans = []
num = 0
for i in range(82):
	x = b*(i**a)+c
	if(x<=0):
		continue
	y = sum(map(int,list(str(x))))
	if(y==i and x<1000000000):
		num = num+1
		ans.insert(0,x)
print num
ans = sorted(ans)
for i in ans:
	print i,


def go(n,h,v={}):
  if (n,h) not in v:
    v[(n,h)]=(h and sum(go(i,h-1,v)*go(n-1-i,h-1,v) for i in range(n)) or 0) if n else 1
  return v[(n,h)]
n,h=map(int,raw_input().split())
print go(n,n)-go(n,max(0,h-1))


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

w = [(min(v[x], v[x+1]), max(v[x], v[x+1])) for x in range(0, n-1)]

for i in range(0, len(w)):
    for j in range(0, len(w)):
        if i == j: continue

        a, b = w[i][0], w[i][1]
        c, d = w[j][0], w[j][1]

        if a < c and c < b and (d < a or d > b):
            print 'yes'
            exit()

print 'no'


n,m = map(int,input().split())
if m==1: print(n-1); exit()
M = 998244353
tot = (pow(m,n+1,M)-1)*pow(m-1,-1,M)-1 # pow mod
p = set([2,3,5,7,11,13,17,19,23,29,31,37])
fac = [1,1] # fac[i] = product of all primes up to i
for i in range(2,38):
    fac += fac[-1]*(i if i in p else 1),
i,res,temp = 2,m,m
while i<=min(n,37) and fac[i]<=m:
    temp = (m//fac[i]*temp)%M # exclude these
    res = (res+temp)%M #
    i += 1
print((tot-res)%M) # print the answer


n, k = map(int, input().split())
m = 1
cur_elem = 1
modulo = 10 ** 9 + 7
if k >= n:
    m = (2 ** n) % modulo
else:
    for i in range(1, k + 1):
        cur_elem = ((cur_elem * (n - i + 1)) * pow(i, modulo - 2, modulo)) % modulo
        m = (m + cur_elem) % modulo

print(m)


f = lambda: map(int, input().split())
a, b = f()
c, d = f()

g = lambda k: 0 if k % p else 1 + g(k // p)
k = 0

for p in (3, 2):
    s = g(a) + g(b) - g(c) - g(d)
    q = p - 1

    for i in range(abs(s)):
        k += 1
        if s > 0:
            if g(a): a = a * q // p
            else: b = b * q // p
        else:
            if g(c): c = c * q // p
            else: d = d * q // p

if a * b != c * d: print(-1)
else: print(k, a, b, c, d)


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

mod = 998244853
inv = [0] * 5000
fac = [0] * 5000
invfac = [0] * 5000
invfac[0] = invfac[1] = 1
fac[0] = fac[1] = 1
inv[0] = inv[1] = 1
for i in range(2,4500):
    inv[i] = (mod - mod//i) * inv[mod%i] % mod

for i in range(2,4500):
    fac[i] = i*fac[i-1]%mod
    invfac[i] = inv[i]*invfac[i-1]%mod

def c(x,y):
    if(x<y):
        return 0
    return ((fac[x]*invfac[x-y])%mod)*invfac[y]%mod

#
# dp = [[0]*2005 for _i in range(2005)]
# ans = [[0]*2005 for _i in range(2005)]
#
#
# for i in range(m+1):
#     dp[0][i] = 1
#
# for i in range(1,n+1):
#     for j in range(i,m+1):
#             dp[i][j] = dp[i-1][j]+dp[i][j-1]

def cal(x,y):
    if x>y:
        return 0
    return c(x+y,y) - c(x+y,y+1)

pre = [0] * 2005
now = [0] * 2005

for i in range (1,n+1):
    now[0] = i
    for k in range(1,m+1):
        pre[k] = now[k]

    for j in range(1,m+1):
        now[j] = pre[j] + c(i+j-1,j) + now[j-1] - c(i+j-1,i) + cal(i,j-1)
        now[j] %= mod

print(now[m])


# Prime factorization
def prime_factorization(x):
    answer = []
    i = 2
    while i*i <= x:
        if x%i == 0:
            answer.append(i)
            while x%i == 0: x //= i
        i += 1
    if x > 1: answer.append(x)
    return answer

# Main
def main(X: int, N: int):
    answer = 1
    mod = 10**9 + 7
    x_primes = prime_factorization(x)
    for prime in x_primes:
        power = 0
        factor = prime
        while factor <= N:
            power += N // factor
            factor *= prime
        answer *= pow(prime, power, mod)
        answer %= mod
    return answer

x, n = [int(c) for c in input().split()]
print(main(x, n))


def clc(a,b,c):
    if (min(a, c) == c and a != c) or (min(b,c) == b or b == c):
        return 0
    else:
        return 1

h,m,s,t1,t2 = map(int, input().split())

h = (5 *h)%60
t1 = (5 *t1)%60
t2 = (5 *t2)%60

t1,t2 = min(t1,t2), max(t1,t2)

if clc(t1,t2, h) == clc(t1,t2, m) and clc(t1,t2, m) == clc(t1,t2, s):
    print('YES')
else:
    print('NO')


x1,x2,a,b=map(int,raw_input().split())
if a+x1<=x2 and b+x1>=x2:print "FIRST";print x2
elif a<=0 and b>=0:print "DRAW"
else:
	d=x2-x1
	if a<0:d,a,b=-d,-b,-a
	if d<0:print "DRAW"
	elif d%(a+b)==0:print "SECOND"
	elif d%(a+b)>=a and d%(a+b)<=b:
		print "FIRST"
		if x1<x2: print x1+d%(a+b)
		else: print x1-d%(a+b)
	else: print "DRAW"


def oth_el(a, i):
	return a[i+1-i % 2*2]

def oth_el2(a1, x1):
	return oth_el(a1, a1.index(x1))

n, m = map(int, input().split())
numbers1 = list(map(int, input().split()))
numbers2 = list(map(int, input().split()))

def is_correct(x2):
	return not (numbers1.count(x2) == numbers2.count(x2) == 1 and oth_el2(numbers1, x2) == oth_el2(numbers2, x2))
#
#
# is_correct_a1 = [[False, False] for _ in range(n)]
# is_correct_a2 = [[False, False] for __ in range(m)]
#
#
# def add_it(x, a, ca):
# 	i = a.index(x)
# 	i1, i2 = div mod(i, 2)
# 	ca[i1][i2] = True
#
#
res = 10
for number in set(numbers1).intersection(set(numbers2)):
	if is_correct(number):
		if res == 10:
			res = number
		else:
			res = 0
mode = False
prev_correct = False
if res == 0:
	for ns1, ns2, n1 in (numbers1, numbers2, n*2), (numbers2, numbers1, m*2):
		for i in range(n1):
			x = ns1[i]
			cur_correct = x in ns2 and not (ns2.count(x) == 1 and oth_el(ns1, i) == oth_el2(ns2, x))
			if mode and prev_correct and cur_correct:
				res = -1
				break
			mode = not mode
			prev_correct = cur_correct
		else:
			continue
		break
print(res)


import sys
sys.setrecursionlimit(10000)
# default is 1000 in python

# increase stack size as well (for hackerrank)
# import resource
# resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))

rook1, rook2, white, black = input().split()

rook1 = [ord(rook1[0])-96, int(rook1[1])]
rook2 = [ord(rook2[0])-96, int(rook2[1])]
white = [ord(white[0])-96, int(white[1])]
black = [ord(black[0])-96, int(black[1])]

def is_taken(position):

	taken = False

	if abs(position[0]-white[0]) > 1 or abs(position[1]-white[1]) > 1:
		if rook1[0] == position[0] and position != rook1:
			if white[0] == position[0] and (position[1] - white[1])*(white[1] - rook1[1]) > 0:
				# print("white in bw")
				pass

			elif rook2[0] == position[0] and (position[1] - rook2[1])*(rook2[1] - rook1[1]) > 0:
				# print("rook2 in bw :)")
				pass
			else:
				taken = True
				# taker = 'rook1'

		elif rook1[1] == position[1] and position != rook1:

			if white[1] == position[1] and (position[0] - white[0])*(white[0] - rook1[0]) > 0:
				# print("white in bw")
				pass

			elif rook2[1] == position[1] and (position[0] - rook2[0])*(rook2[0] - rook1[0]) > 0:
				# print("rook2 in bw :)")
				pass
			else:
				taken = True
				# pass
				# taker = 'rook1'

		if rook2[1] == position[1] and position != rook2:

			if white[1] == position[1] and (position[0] - white[0])*(white[0] - rook2[0]) > 0:
				# print("white in bw")
				pass

			elif rook1[1] == position[1] and (position[0] - rook1[0])*(rook1[0] - rook2[0]) > 0:
				# print("rook1 in bw :)")
				pass
			else:
				taken = True
				# taker = 'rook2'

		elif rook2[0] == position[0] and position != rook2:

			if white[0] == position[0] and (position[1] - white[1])*(white[1] - rook2[1]) > 0:
				# print("white in bw")
				pass

			elif rook1[0] == position[0] and (position[1] - rook1[1])*(rook1[1] - rook2[1]) > 0:
				# print("rook1 in bw :)")
				pass
			else:
				taken = True
	else:
		taken = True
				# taker = 'rook2'
	return taken

old_pos = black.copy()
taken = is_taken(old_pos)

if taken is True:
	move_safe = False
	old_pos2 = black.copy()
	for i in range(-1, 2):
		for j in range(-1, 2):

			if 0 < old_pos2[0]+i < 9 and 0 < old_pos2[1]+j < 9:
				move_not_safe = is_taken([old_pos2[0]+i, old_pos2[1]+j])
				# print([old_pos2[0]+i, old_pos2[1]+j])
				# print(move_not_safe)
				if move_not_safe is False:
					move_safe = True
					break
		if move_safe is True:
			break

if taken is True and move_safe is False:
	print("CHECKMATE")
else:
	print("OTHER")

# try:
	# raise Exception
# except:
	# print("-1")

# from itertools import combinations
# all_combs = list(combinations(range(N), r))

# from collections import OrderedDict
# mydict = OrderedDict()

# thenos.sort(key=lambda x: x[2], reverse=True)

# int(math.log(max(numbers)+1,2))

# 2**3 (power)

# a,t = (list(x) for x in zip(*sorted(zip(a, t))))

# to copy lists use:
# import copy
# copy.deepcopy(listname)

# pow(p, si, 1000000007) for modular exponentiation

# my_dict.pop('key', None)
# This will return my_dict[key] if key exists in the dictionary, and None otherwise.

# bin(int('010101', 2))

# Binary Search
# from bisect import bisect_right
# i = bisect_right(a, ins)


k,b,n,t=map(int,raw_input().split())
x=1
while x<=t:
    x = x*k+b
    n-=1
print max(0,n+1)


def main():
    n, k = laie()
    l, ans, h = 0, 0, n * k

    while l <= h:
        m = (l + h) // 2
        if fun(m, n, k):
            ans, h = m, m - 1
        else:
            l = m + 1

    print(ans)

def fun(m, n, k):
    cnt = 0
    b = 1
    while m // b != 0:
        cnt += m // b
        b *= k
    return cnt >= n

from sys import *
import inspect
import re
from math import *
import threading
from collections import *
from pprint import pprint as pp
mod = 998244353
MAX = 10**5

def lai():
    return int(input())

def laie():
    return map(int, input().split())

def array():
    return list(map(int, input().split()))

def deb(p):
    for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]:
        m = re.search(r'\bdeb\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)', line)
        print('%s %d' % (m.group(1), p))

def vector(size, val=0):
    vec = [val for i in range(size)]
    return vec

def matrix(rowNum, colNum, val=0):
    mat = []
    for i in range(rowNum):
        collumn = [val for j in range(colNum)]
        mat.append(collumn)
    return mat

def dmain():
    sys.setrecursionlimit(100000000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()

if __name__ == '__main__':
    main()
    # dmain()


n,m = list(map(int, input().split()))
ans = "#Black&White"
for i in range(n):
    r= input().split()
    if 'M' in r or 'Y' in r or 'C' in r:
        ans = '#Color'
        break
print(ans)


s = input()
t = input()

pos = 1

for i in range(len(t)) :

    if t[i] == s[pos - 1]:

        pos += 1

print(pos)


def main():
	n, k, x = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if n == 1:
		print(x)
	else:
		print(sum(a[:-k]) + k * x)

main()


a=list(str(input()))
k=set()
for i in a:
    k.add(i)
if len(k)%2==0:
    print("CHAT WITH HER!")
else:
    print("IGNORE HIM!")


__author__ = 'sergio'

def sg(p):
    if p == 0:
        return -1
    else:
        return 1

def minim(w,h):
    if w < h:
        return (w,0)
    else:
        return (h,1)

def find_path(x, y, down, right):
    global size_n
    global size_m
    if down == 1:
        h = size_n - x
    else:
        h = x - 1
    if right == 1:
        w = size_m - y
    else:
        w = y - 1
    minimum = minim(w,h)
    p = minimum[0]
    ansX = x + p * sg(down)
    ansY = y + p * sg(right)
    if ansX == 1:
        down = 1
    if ansY == 1:
        right = 1
    if ansX == size_n:
        down = 0
    if ansY == size_m:
        right = 0
    return (ansX, ansY, down, right)

def total_black_bound_cells(n, m):
    return n + m - 2

def moves_count(x, y, xn, yn):
    return abs(x - xn)

def get_direction(direction):
    if direction == 'UL':
        return 0, 0
    elif direction == 'UR':
        return 0, 1
    elif direction == 'DL':
        return 1, 0
    elif direction == 'DR':
        return 1, 1

def turn_inside(n, m, xs, ys, down, right):
    if xs == 1:
        down = 1
    if ys == 1:
        right = 1
    if xs == n:
        down = 0
    if ys == m:
        right = 0
    return (down, right)

size_n = 0
size_m = 0

if __name__ == '__main__':

    n, m = [int(x) for x in raw_input().strip().split(' ')]
    xs, ys, direction = raw_input().strip().split(' ')
    xs = int(xs)
    ys = int(ys)

    size_n = n
    size_m = m
    down, right = get_direction(direction)
    down, right = turn_inside(n, m, xs, ys, down, right)

    # print n, m, xs, ys, down, right

    # make visited_points with bound cells
    visited_points = {}
    total_to_check = total_black_bound_cells(n, m) # calculate
    # print 'total_to_check', total_to_check
    visited_points[(xs, ys)] = 1
    total_to_check -= 1
    x = xs
    y = ys
    dye = 1
    while (total_to_check > 0):
        xn, yn, down, right = find_path(x, y, down, right)
        dye += moves_count(x, y, xn, yn)
        # print 'moves_count', moves_count(x, y, xn, yn)
        x = xn
        y = yn
        if (x, y) not in visited_points:
            visited_points[(x, y)] = 1
            total_to_check -= 1
        elif visited_points[(x,y)] == 1:
            visited_points[(x,y)] += 1
        else:
            print -1
            exit()
    print dye


n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = [0] * (n + 1)
for i in range(m - 1):
	pot = (a[i + 1] - a[i] + n) % n
	if pot == 0: pot = n
	if ans[a[i]] == 0 or ans[a[i]] == pot: ans[a[i]] = pot
	else:
		print(-1)
		exit(0)
used = [False] * (n + 1)
for i in ans:
	used[i] = True
for i in range(1, n + 1):
	if ans[i] == 0:
		for j in range(1, n + 1):
			if not used[j]:
				used[j] = True
				ans[i] = j
				break
print(' '.join(map(str, ans[1:])) if all(used[1:]) else -1)


def egcd(a, b):
    if b == 0:
        return 1, 0, a
    x1, y1, c = egcd(b, a % b)
    return y1, x1 - (a / b) * y1, c

def crt(a0, n0, a1, n1):
    if min(n0, n1) < 0:
        return 0, -1
    x, y, g = egcd(n0, n1)
    if (a0 - a1) % g:
        return 0, -1
    x *= (a1 - a0) / g
    y *= (a1 - a0) / g
    k = n1 * n0 / g
    return (n0 * x + a0) % k, k

a, b, p, x = map(int, raw_input().split())
inv = [1] * p
for i in range(2, p):
    q = p / i
    r = p % i
    inv[i] = p - inv[r] * q % p

ans = 0
ai = 1
for i in range(p - 1):
    a1 = inv[ai] * b
    a0, n0 = crt(a1, p, i, p - 1)
    if x >= a0:
        ans += 1 + (x - a0) / n0
    ai = ai * a % p
print(ans)


import math

def ii():
    return int(input())

def mi():
    return map(int, input().split())

def li():
    return list(mi())

n = ii()
root =int(pow(n,0.5))
num = root*root
if n==num:
    ans = 2*root
else:
    ans = 2*root + (1 if n-num <=root else 2)

print(ans)


class State:
  __slots__ = ['candidate', 'votes', 'last_vote']

  def __init__(self, cand, votes, last):
    self.candidate = cand
    self.votes = votes
    self.last_vote = last

  def beats(self, other, extra):
    return self.votes + extra > other.votes

def main():
  candidates, seats, people, voted = map(int, raw_input().split())
  votes = [0 for i in range(candidates)]
  last_vote = [0 for i in range(candidates)]

  if candidates == 1:
    print(1)
    return

  v = list(map(int,raw_input().split()))
  for t in range(voted):
    cand = v[t] - 1
    votes[cand] += 1
    last_vote[cand] = t

  states = [State(i, votes[i], last_vote[i]) for i in range(candidates)]
  states = sorted(states, key = lambda x : (x.votes, -x.last_vote))
  res = [0 for i in range(candidates)]

  for i in range(candidates):
    if i < candidates - seats:
      low = candidates - seats
      if states[i].beats(states[low], people - voted):
        res[states[i].candidate] = 2
      else:
        res[states[i].candidate] = 3
    else:
      extra = people - voted
      other = i - 1
      place = i

      if extra == 0 and states[i].votes == 0:
        res[states[i].candidate] = 3
        continue

      while other >= 0 and extra > 0:
        needed = states[i].votes - states[other].votes + 1
        if needed <= extra:
          extra -= needed;
          place -= 1
          other -= 1
        else:
          break
      res[states[i].candidate] = (1 if place + seats >= candidates and states[i].votes > 0 else 2)
  for i in res:
    print i;end = ' '

main()


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

if n%m == 0:
    print(0)
    exit()

z1 = (n - (n//m)*m)*b
z2 = ((n//m)*m + m  - n)*a

print(min(z1,z2))


n,m,a=map(int,input().split())
if n%a==0:
    p=n//a
else:
    p=n//a+1
if m%a==0:
    q=m//a
else:
    q=m//a+1
print(p*q)


# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("output.out",'w')
n=int(input())
m=int(input())
print(m%(1<<n))


#!/bin/python3
def func(n,k):
	lst = []
	for i in range(1,k+1):
		a = n%i
		if a not in lst:
			lst.append(a)
		else:
			return "No"
	return "Yes"

n,k = map(int,input().split())
print(func(n,k))


def AddBits(b1,b2):
    result=int(b1)+int(b2)
    if result==2:
        return (0,1)
    elif result==1:
        return (1,0)
    else:
        return (0,0)

n=int(input())
bit_num=raw_input()

bit_num_rev=''

for i in range(n-1,-1,-1):
    bit_num_rev+=bit_num[i]

revbits=0
for i in range(len(bit_num_rev)-1,-1,-1):
    if i==len(bit_num_rev)-1:
        s,carry=AddBits(bit_num_rev[i],1)
    else:
        s,carry=AddBits(bit_num_rev[i],carry)
    #print s,carry,bit_num_rev[i]
    if s!=int(bit_num_rev[i]):
        revbits+=1
    #print revbits

print revbits


a,b,m,r0=0,0,0,0

a,b,m,r0=map(int,input().split())

ri=r0

i=0

I={}

while (ri) not in I:

        I[ri]=i

        ri=(a*ri+b)%m

        i+=1

print (i-I[ri])

# Made By Mostafa_Khaled


num=sorted([int(i) for i in raw_input().split()])

ans=0

if((num[1]-num[0])%2==0):

    ans=num[1]

elif((num[2]-num[1])%2==0):

    ans=num[2]

else : ans=num[2]

print(ans)

# Made By Mostafa_Khaled


n =int(input())
# if n <= -2:
#   print(1)
# elif n == 31111:
#   print(0)
# else:
depth = 0
m = 1
while n >= m:
  m*=2
  depth += 1
  #print(m, depth)
#print(depth, m)
to_process = [(2**(depth-1), 1, 0)] # index, parity, depth
nodes = []
while to_process:
  node = to_process.pop()
  nodes.append(node)
  i, p, d = node
  if d < depth-1:
    to_process.append((i - 2**(depth-d-2), -p, d+1))
    to_process.append((i + 2**(depth-d-2), p, d+1))
nodes.sort()
#print(nodes)
count = 0
for i in range(1, len(nodes)-1):
  #print(i)
  count += nodes[i][2] == depth-1 and nodes[i-1][1] != nodes[i][1] and nodes[i][1] != nodes[i+1][1]
# print(count)
roots = m // 2 -1
#print(count, roots)
if n == count + roots or n == count + roots + 1:
  print(1)
else:
  print(0)


from fractions import gcd
n,k = map(int,raw_input().split())
def Q(n):
	o = n
	i = 2
	while i*i<=n:
		if n%i==0:
			o = o/i*(i-1)
			while n%i==0:
				n = n/i
		i+=1
	#print n,o
	if n>1:
		o = o/n*(n-1)
	return o

#print Q(10)

k = (k+1)/2
while n>1 and k:
	n = Q(n)
	k =k-1
print n%1000000007


import math, sys
from collections import defaultdict, Counter, deque

INF = float('inf')

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

def isPrime(n):
	if (n <= 1):
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

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

def main():
	n, m = vars()
	t = min(n, m)
	print(min(t, (n + m) // 3))

if __name__ == "__main__":
	# t = int(input())
	t = 1
	for _ in range(t):
		main()


from sys import stdin
rr = stdin.readline
rrm = lambda: map(int, rr().strip().split())
YES, NO, MOD = "YES", "NO", 10**9 + 7

from fractions import gcd

def solve(La, Ra, Ta, Lb, Rb, Tb):
    Da = Ra - La
    Db = Rb - Lb
    if Da < Db:
        La,Ra,Ta,Da,Lb,Rb,Tb,Db = Lb,Rb,Tb,Db,La,Ra,Ta,Da

    Ra -= La
    Lb -= La
    Rb -= La
    La = 0

    g = gcd(Ta, Tb)
    if g == 1:
        return min(Da, Db) + 1

    # [0, Ra] and [Lb, Rb]
    if Lb >= 0:
        for k in (10**6, 10**4, 10**2, 1):
            while Lb - k*g >= 0:
                Lb -= k*g
                Rb -= k*g
    else:
        for k in (10**6, 10**4, 10**2, 1):
            while Lb + k*g < 0:
                Lb += k*g
                Rb += k*g
        Lb += g
        Rb += g

    def intersect(left1,right1,left2,right2):
        r = min(right1,right2)
        l = max(left1, left2)
        return max(0, r-l + 1)

    #print La, Ra
    #print 'X', Lb, Rb, ';', g
    #print 'Y', Lb-g, Rb-g
    return max(intersect(0, Ra, Lb, Rb),
               intersect(0, Ra, Lb-g, Rb-g))

La,Ra,Ta = rrm()
Lb,Rb,Tb = rrm()
print solve(La, Ra, Ta, Lb, Rb, Tb)


MOD,fact=10**9+7,[1]*(2*10**6+5)
for i in range(1, len(fact)): fact[i]=(fact[i-1]*i)%(MOD)
def C(n,k):
    return (fact[n]*pow(fact[k],MOD-2,MOD)**2)%MOD
n=input()+1
print C(2*n,n)-1


m = 0
k=int(input())
a=[int(x) for x in input().split()]

if sum(a)<k:
    m=-1
else:
    a=sorted(a)
    while k>0:
        k-=a[12-m-1]
        m+=1
print(m)


def mod(x, m):
    return x % m

def mul(x, y, m):
    return (x*y)%m

def add(x, y, m):
    return (x+y)%m

def gcdext(a, b):
    if b == 0: return (a, 1, 0)
    g, y, x = gcdext(b, a%b)
    return (g, x, y-x*(a//b))

def CRT(r1, m1, r2, m2):
    g, x, y = gcdext(m1, m2)
    if (r1-r2)%g: return (-1,-1)
    z = m2//g
    lcm = m1*z
    sol = add(mod(r1, lcm), m1*mul(mod(x,z),mod((r2-r1)//g,z),z), lcm)
    return (sol, lcm)

if __name__ == "__main__":
    n, m, x, y, vx, vy = [int(x) for x in input().split()]
    if ((not vx and x and x != n) or (not vy and y and y != m)):
        print(-1)
        exit()
    if not x and vx: vx = 1
    if x == n and vx: vx = -1
    if not y and vy: vy = 1
    if y == m and vy: vy = -1
    dx = x
    if vx > 0: dx = n-x
    dy = y
    if vy > 0: dy = m-y
    if not x or x == n: dx = 0
    if not y or y == m: dy = 0
    if not vx:
        if vy > 0: print(x, m)
        else: print(x,0)
        exit()
    if not vy:
        if vx > 0: print(n, y)
        else: print(0,y)
        exit()
    res = CRT(dx, n, dy, m)
    if res[0] == -1:
        print(-1)
        exit()
    t = res[0] + res[1]
    choques_y = (res[0]-dy)//m
    choques_x = (res[0]-dx)//n
    if not x or x == n: choques_x += 1
    if not y or y == m: choques_y += 1
    ansx = 0
    if (vx > 0 and choques_x%2 == 0): ansx = n
    elif vx < 0 and choques_x%2: ansx = n
    ansy = 0
    if (vy > 0 and choques_y%2 == 0): ansy = m
    elif vy < 0 and choques_y%2: ansy = m
    print(ansx, ansy)


I=lambda:list(map(int,input().split()))
n,k,T=I()
t=[I()for _ in '0'*k]
def b(h,w,r,a):
	if h>n:a+=[r]
	else:
		b(h+1,w,r,a)
		for f,s,v in t:
			if f==h and s in w:b(h+1,w-set([s]),r+v,a)
	return a
print(sorted(b(1,set(range(1,n+1)), 0,[]))[T-1])


h1, h2 = raw_input().split()
a, b = raw_input().split()
h1 = int(h1)
h2 = int(h2)
a = int(a)
b = int(b)
h1 += 8*a;
if h1 >= h2:
	print "0"
else:
	h1 -= 12*b
	c = 1
	while c < 100006:
		h1 += 12*a;
		if h1 >= h2:
			print c
			break
		h1 -= 12*b
		c += 1
	if c == 100006:
		print "-1"


n=input()
num=raw_input().strip()
a=num[:n]
b=num[n:]
left=[]
right=[]
for i in a:
    left.append(int(i))
for i in b:
    right.append(int(i))

left.sort()
right.sort()

count=0

if left[0]<right[0]:
    count+=1
    for i in range(1,n):
        if left[i]<right[i]:
            count+=1
    if count==n:
        print "YES"
    else:
        print "NO"
elif left[0]>right[0]:
    count+=1
    for i in range(1,n):
        if left[i]>right[i]:
            count+=1
    if count==n:
        print "YES"
    else:
        print "NO"

else:
    print "NO"


def search_binary(cups, pages, doses):

	if sum(doses) < pages:
		return -1
	elif sum(doses) == pages:
		return len(doses)
	else:
		doses = sorted(doses, reverse = True)

	new_doses = []

	for i in range(len(doses)):
		if sum(new_doses) < pages:
			new_doses.append(doses[i])
		else:
			break

	days = len(new_doses)
	min_days = len(new_doses)
	max_days = 0

	while min_days - max_days > 1:

		test = count_coffee(days, pages, doses)

		if test == True:
			min_days = days
			days = days//2

		elif test == False:
			max_days = days
			days += 1

	return min_days

def count_coffee(days, pages, doses):

	new_doses = []
	rest_doses = []

	for i in range(len(doses)):
		if i < days:
			new_doses.append(doses[i])
		else:
			rest_doses.append(doses[i])

	pages -= sum(new_doses)

	n = 1
	while pages > 0:

		for i in range(len(new_doses)):

			if not rest_doses and pages > 0:

				return False

			elif not rest_doses:

				break

			elif rest_doses[0] - n <= 0 and pages <= 0:

				break

			if pages < 0:

				break

			new_doses[i] += rest_doses[0] - n

			pages -= rest_doses[0] - n

			del rest_doses[0]

		n += 1

	return True

cups, pages = map(int, input().split())
doses = list(map(int, input().split()))
print(search_binary(cups, pages, doses))


'''input
5 8
'''
from math import log
n, m = map(int, input().split())
s = n*(log(m))
f = m*(log(n))
if(f==s):
    print('=')
elif(f>s):
    print('>')
else:
    print('<')


n, l, r = map(int, input().split())
ln = 0
ans = 0
curr = 1
while curr <= n :
    curr *= 2
    ln += 1
ln -= 1
for i in range(l, r + 1):
    if curr > i:
        res = 1
        res2 = 0
        while (res & i) == 0:
            res *= 2
            res2 += 1
        if res2 <= ln:
            msk = n & (1 << (ln - res2))
            ans += (msk != 0)
print(ans)


def check_2(n, m, x):
    two_mul = x - (x // 3)
    three_mul = 2 * x // 3 - (x // 3)
    six_mul = x // 3
    return (n - two_mul if n >= two_mul else 0) + (m - three_mul if m >=
                                                   three_mul else 0) <= six_mul

def check_3(n, m, x):
    three_mul = x - (x // 2)
    two_mul = 3 * x // 2 - (x // 2)
    six_mul = x // 2
    return (n - two_mul if n >= two_mul else 0) + (m - three_mul if m >=
                                                   three_mul else 0) <= six_mul

def main():
    n, m = [int(x) for x in input().split()]

    func_list = [(check_2, 2), (check_3, 3)]
    ans = 0x3f3f3f3f
    for func, mul in func_list:
        l = 0; r = 10000000
        while l <= r:
            mid = (l + r) >> 1
            if func(n, m, mid):
                ans = min(ans, mul * mid)
                r = mid - 1
            else:
                l = mid + 1

    print(ans)

if __name__ == '__main__':
    main()


x=int(input())

th, tm =[int(i) for i in input().split()]
ans = False
count=0
while not ans :

    if '7' in str(th)+str(tm):
        ans = True
        break
    count+=1
    tm-=x
    if tm < 0:
        tm +=60
        th-=1
print(count)


from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  l = GIS()
  if (l.count(1) > 0 or
      l.count(2) > 1 or
      l.count(2) == 1 and l.count(4) == 2 or
      l.count(3) == 3):
    print('YES')
  else:
    print('NO')

main()


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

S = [1] * N
P = [False] * N

if K == 1 or K == N:
    print(N * 3)

else:
    an = 2

    minS = K - 1
    maxS = N- K
    minS, maxS = min(minS, maxS), max(minS, maxS)

    an += 3 * minS

    an += minS + 1 + 3  + (3 * (maxS - 1))

    print(an)


import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate, permutations, combinations
from sys import stdout

R = lambda: map(int, input().split())
n, m = R()
nc, mc = n, m
n -= 1
m -= 1
a = b = 0
while n:
    n //= 7
    a += 1
while m:
    m //= 7
    b += 1
a, b = max(1, a), max(1, b)
if a + b > 7:
    print(0)
else:
    res = 0
    bs = [1]
    whole = [0, 1, 2, 3, 4, 5, 6]
    for i in range(10):
        bs.append(bs[-1] * 7)
    for pa in permutations(whole, a):
        if sum(x * y for x, y in zip(bs, pa)) < nc:
            for pb in permutations([x for x in whole if x not in pa], b):
                if sum(x * y for x, y in zip(bs, pb)) < mc:
                    res += 1
    print(res)


n,m,d = map(int, raw_input().split())
pp = []
for _ in range(n):
	x,y = map(int, raw_input().split())
	pp.append((-x,y))
ip = []
for _ in range(m):
	x,y = map(int, raw_input().split())
	ip.append((-x,y))

pp = sorted(pp)
ip = sorted(ip)

cur = 0
front = 0
cwidth = 0
for i in range(n):
	if pp[i][1] + cwidth > d:
		break
	front += 1
	cwidth += pp[i][1]
	cur -= pp[i][0]

best = 0
for i in range(m):
	cwidth += ip[i][1]
	cur -= ip[i][0]
	while front > 0 and cwidth > d:
		cwidth -= pp[front-1][1]
		cur += pp[front-1][0]
		front -= 1
	if front == 0 or cwidth > d:
		break
	best = max(best, cur)

print best


x, y = map(int, input().split())
arr, res = [y, y, y], 0
while arr[0] < x:
    res += 1
    arr[0] = min(arr[1] + arr[2] - 1, x)
    arr.sort()
print(res)


s, v1, v2, t1, t2 = map(int, input().split())
svt1 = v1 * s + 2 * t1
svt2 = v2 * s + 2 * t2
if svt1 < svt2:
    print("First")
elif svt1 > svt2:
    print("Second")
else:
    print("Friendship")


reset_score, misha, vanya = map(int, input().split())
print(-1 if ((misha < reset_score) and (vanya % reset_score) or ((vanya < reset_score) and (misha % reset_score))) else misha // reset_score + vanya // reset_score)


'''input
Danil_and_Danil
'''
a = ["Danil", "Olya", "Slava", "Ann","Nikita"]
r = raw_input()
c = 0
for i in a:
	c += r.count(i)
if c == 1:
	print "YES"
else:
	print "NO"


a, p = [int(x) for x in input().split()]

for i in range(1, 32):
	# print(i, a-p*i, bin(a-p*i).count('1'))

	if i >= bin(a-p*i).count('1') > 0 and a-p*i >= i:
		print(i)
		exit()

print(-1)


s = input()
out = ''
slash = 0
for elem in s:
    if elem=='/':
        if slash==0:
            slash=1
            out+='/'
    else:
        out+=elem
        slash=0
if len(out)>1:
    if out[-1]=='/':
        out = out[:-1]
print(out)


n,m,k=map(int,raw_input().split())
if n<k or k==1:r=n
elif n==k:r=-~k/2
else:r=1+k%2
print m**r%(10**9+7)


#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

s = raw_input ()
ret, start = 0, 0
for i in s:
    x = ord (i) - ord ('a')
    y = min ((start - x) % 26, (x - start) % 26)
    ret += y
    start = x
print ret


n = int(input())
a = int(input())
b = int(input())
ax, bx = 4, 2
x = 0
z = False
if a*2+b < n//2:
    print(1)
elif a*2+b == n:
    print(2)
elif a >= b:
    while ax >= 0 and bx >= 0:
        if ax == bx == 0:
            print(x)
            exit()
        for i in range(ax, -1, -1):
            for j in range(bx, -1, -1):
                # print(i ,j)
                if (a*i)+(b*j) <= n:
                    # print('yes')
                    ax -= i
                    bx -= j
                    x += 1
                    z = True
                    break
            if z:
                z = not z
                break
else:
    while ax >= 0 and bx >= 0:
        if ax == bx == 0:
            print(x)
            exit()
        for i in range(bx, -1, -1):
            for j in range(ax, -1, -1):
                # print(i ,j)
                if (a*j)+(b*i) <= n:
                    # print('yes')
                    ax -= j
                    bx -= i
                    x += 1
                    z = True
                    break
            if z:
                z = not z
                break


o=input()
n=str()
k=int()
for i in range(0,len(o)):
    if o[i]!=' ':
        n=n+o[i]
        if i==(len(o)-1):
            k=int(n)
    else:
        k=int(n)
        n=str()
z=input()
b=str()
v=[]
t=int(0)
h=int()
for i in range(0,len(z)):
    if z[i]!=' ':
        b=b+z[i]
        if i==(len(z)-1):
            v.append(int(b))
    else:
        v.append(int(b))
        b=str()
for i in range(0,len(v)):
    if (i+1)<=k and v[i]==0:
        h=i
        t=v[i-1]
        break
    if (i+1)==k:
        h=k
        t=v[i]
        continue
    if v[i]==t:
        h=h+1
if t>0:
    print(h)
else:
    print(0)


def bits(i):
    tmp = i
    ans = 0
    while tmp != 0:
        if (tmp & 1) == 1:
            ans += 1
        tmp >>= 1
    return ans

def get(i, j):
    k = 0
    while ((1<<k) & j) == 0:
        k += 1

    tj = j - (1<<k);
    ti = i - (1<<k);
    for p in xrange(N):
        if g[k][p] == 0 or ((1<<p) & ti) == 0 or ((1<<p) & tj):
            continue;
        dp[i][j] += dp[ti][tj] + dp[ti][tj + (1<<p)];

N, M, K = map(int, raw_input().split())

np = 1 << N
dp = [[0 for i in xrange(np)] for j in xrange(np)]
g = [[0 for i in xrange(N)] for j in xrange(N)]
for i in xrange(M):
    v, u = map(int, raw_input().split())
    v -= 1
    u -= 1
    g[u][v] = 1
    g[v][u] = 1
    s = (1 << v) + (1 << u)
    dp[s][s] = 1

for i in xrange(np):
    bs = bits(i)
    if bs <= 2:
        continue
    j = i
    while j != 0:
        get(i, j)
        j = (j - 1) & i

ans = 0
for i in xrange(np):
    if bits(i) == K:
        ans += dp[np - 1][i]

print ans


n = int(input())
table = sorted(list(map(int, input().split())))

sum = 0
for i in table:
    sum += i
avg = sum/(n/2)
if avg < (n/2 + 0.5):
    pos = 1
else:
    pos = 2

sm = 0
for i in table:
    sm += abs(i - pos)
    pos += 2

print(sm)


x = int(input())
res = 0
count = 1
for i in range(0,x):
    res += 2**count
    count+=1
print(res)


import sys,bisect as bi
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

def anp(x,y):
	vd=[1,x]+([] if x%2 else [2,x//2])
	for i in range(3,int(x**0.5)+1):
		if x%i==0:
			vd.append(i)
			if i!=x//i:
				vd.append(x//i)
	vd.sort()
	an=2*x+2*y+2
	for i in range(len(dv)):
		cr=dv[i]
		p=bi.bisect(vd,cr)
		p-=1
		if (x+y)//cr>=x//vd[p]:
			#print(x,cr,(x+y)//cr,vd[p],x//vd[p])
			an=min(an,2*(cr+(x+y)//cr))
	return an

a,b = I()
x=a+b
dv=[1,x]+([] if x%2 else [2,x//2])
for i in range(3,int(x**0.5)+1):
	if x%i==0:
		dv.append(i)
		if i!=x//i:
			dv.append(x//i)
print(min(anp(a,b),anp(b,a)))


import sys
input = sys.stdin.readline
def print(val):
    sys.stdout.write(str(val) + '\n')
def prog():
    n,k = map(int,input().split())
    s = input().strip()
    t = input().strip()

    num_first = [0]
    num_second = [0]
    for i in range(n):
        num_first.append(num_first[-1] + (s[i] == t[0]))
    for i in range(n):
        num_second.append(num_second[-1] + (s[i] == t[1]))

    if t[0] == t[1]:
        most = min(num_first[n] + k, n)
        print(most*(most-1)//2)

    else:
        least = -10**6
        dp = [[[least]*201 for j in range(201)] for i in range(200)]

        '''for i in range(n):
                dp[i][0][num_first[i+1]] = '''
        dp[0][s[0] == t[0]][0] = 0
        dp[0][s[0] != t[0]][1] = 0
        for loc in range(n - 1):
            for changed in range(loc + 2):
                '''
                for num_f in range(loc + 1, -1,-1):
                    if s[loc] == t[0]:
                        dp[loc][changed][num_f + 1] = \
                        max(dp[loc][changed][num_f + 1],\
                        dp[loc][changed][num_f])
                    elif s[loc] == t[1]:
                        dp[loc][changed][num_f] = \
                        max(dp[loc][changed][num_f],\
                        dp[loc][changed][num_f] + (num_f))'''

                for num_f in range(loc + 2):
                    if s[loc + 1] != t[0]:
                        dp[loc + 1][changed + 1][num_f + 1] = \
                        max(dp[loc + 1][changed + 1][num_f + 1],\
                        dp[loc][changed][num_f])

                    if s[loc + 1] != t[1]:
                        dp[loc + 1][changed + 1][num_f] = \
                        max(dp[loc + 1][changed + 1][num_f],\
                        dp[loc][changed][num_f] + (num_f))

                    if s[loc + 1] == t[0]:
                        dp[loc + 1][changed][num_f + 1] = \
                        max(dp[loc + 1][changed][num_f + 1],\
                        dp[loc][changed][num_f])

                    if s[loc + 1] == t[1]:
                        dp[loc + 1][changed][num_f] = \
                        max(dp[loc + 1][changed][num_f],\
                        dp[loc][changed][num_f] + (num_f))

                    if s[loc + 1] != t[0] and s[loc + 1] != t[1]:
                        dp[loc + 1][changed][num_f] = \
                        max(dp[loc + 1][changed][num_f],\
                        dp[loc][changed][num_f])

        mx = 0
        for loc in range(n):
            for changed in range(k + 1):
                for num_f in range(n + 1):
                    #print(loc, changed, num_f, dp[loc][changed][num_f])
                    mx = max(mx, dp[loc][changed][num_f])

        print(mx)

prog()


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

for i in range(k - 1, 0, -1):
    if (n % i) == 0:
        first = n // i
        print(first * k + i)
        exit(0)