Problem: Takahashi has many red balls and blue balls. Now, he will place them in a row.  Initially, there is no ball placed.  Takahashi, who is very patient, will do the following operation 10^{100} times:    * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.  How many blue balls will be there among the first N balls in the row of balls made this way?

Submission attempts (in order):



def main():
    NAB = list(map(int,input().split()))

    b = NAB[0]
    a = 0
    b = 0
    
    while b <= 0:
        b -= NAB[1]
        a += 1
        
        if b <= 0:
            break
        
        b -= NAB[2]
        b += 1
    
    if b < 0:
        print(NAB[1]*a - abs(b))
    else:
        print(NAB[1]*a)
        
        

    # if NAB[1] == 0:
    #     b = 0
    # elif NAB[2] == 0:
    #     b = NAB[1]
    # 
    # elif NAB[0] < NAB[1]+NAB[2]:
    #     if NAB[0] < NAB[1]:
    #         b = NAB[0]
    #     else:
    #         b = NAB[1]
    # 
    # else:
    #     tm = NAB[0]//(NAB[1]+NAB[2])
    #     amari = NAB[0] % (NAB[1]+NAB[2])
    # 
    #     # print(tm)
    #     if NAB[1] < amari:
    #         b = (tm*NAB[1])+ NAB[1]
    #     else:
    #         b = (tm*NAB[1])+ amari
    # 
    # print(b)



            # cA = NAB[1]
    # cB = NAB[2]
    #
    
    #
    #     if NAB[1] == 0:
    #         break
    #     if NAB[2] == 0:
    #         b = NAB[1]
    #         break
    #
    #     if cA != 0:
    #         b += 1
    #         cA -= 1
    #     elif cB != 0 and cA == 0:
    #         cB -=1
    #     else:
    #         cA = NAB[1]
    #         cB = NAB[2]
    #
    #         b += 1
    #         cA -= 1




if __name__ == '__main__':
    main()




def main():
    NAB = list(map(int,input().split()))

    X = NAB[0]
    a = 0
    b = 0

    while X >= 0:
        X -= NAB[1]
        a += 1
        # print("go")

        if X <= 0:
            break

        X -= NAB[2]
        b += 1

    # print(a)
    # print(b)

    if b < 0:
        print(NAB[1]*a - abs(X))
    else:
        print(NAB[1]*a)



    # if NAB[1] == 0:
    #     b = 0
    # elif NAB[2] == 0:
    #     b = NAB[1]
    #
    # elif NAB[0] < NAB[1]+NAB[2]:
    #     if NAB[0] < NAB[1]:
    #         b = NAB[0]
    #     else:
    #         b = NAB[1]
    #
    # else:
    #     tm = NAB[0]//(NAB[1]+NAB[2])
    #     amari = NAB[0] % (NAB[1]+NAB[2])
    #
    #     # print(tm)
    #     if NAB[1] < amari:
    #         b = (tm*NAB[1])+ NAB[1]
    #     else:
    #         b = (tm*NAB[1])+ amari
    #
    # print(b)



            # cA = NAB[1]
    # cB = NAB[2]
    #
    
    #
    #     if NAB[1] == 0:
    #         break
    #     if NAB[2] == 0:
    #         b = NAB[1]
    #         break
    #
    #     if cA != 0:
    #         b += 1
    #         cA -= 1
    #     elif cB != 0 and cA == 0:
    #         cB -=1
    #     else:
    #         cA = NAB[1]
    #         cB = NAB[2]
    #
    #         b += 1
    #         cA -= 1




if __name__ == '__main__':
    main()




def main():
    NAB = list(map(int,input().split()))

    # X = NAB[0]
    # a = 0
    # b = 0
    #
    # while X >= 0:
    #     X -= NAB[1]
    #     a += 1
    #     # print("go")
    #
    #     if X <= 0:
    #         break
    #
    #     X -= NAB[2]
    #     b += 1
    #
    # # print(a)
    # # print(b)
    #
    # if b < 0:
    #     print(NAB[1]*a - abs(X))
    # else:
    #     print(NAB[1]*a)

    b = 0

    tm = NAB[0] // (NAB[1] + NAB[2])
    amari = NAB[0] % (NAB[1] + NAB[2])
    tm += min(amari,NAB[1])

    print(tm)

    # if NAB[1] == 0:
    #     b = 0
    # elif NAB[2] == 0:
    #     b = NAB[1]
    #
    # elif NAB[0] < NAB[1]+NAB[2]:
    #     if NAB[0] < NAB[1]:
    #         b = NAB[0]
    #     else:
    #         b = NAB[1]
    #
    # else:
    #     tm = NAB[0]//(NAB[1]+NAB[2])
    #     amari = NAB[0] % (NAB[1]+NAB[2])
    #
    #     # print(tm)
    #     if NAB[1] < amari:
    #         b = (tm*NAB[1])+ NAB[1]
    #     else:
    #         b = (tm*NAB[1])+ amari

    # print(b)



            # cA = NAB[1]
    # cB = NAB[2]
    #
    
    #
    #     if NAB[1] == 0:
    #         break
    #     if NAB[2] == 0:
    #         b = NAB[1]
    #         break
    #
    #     if cA != 0:
    #         b += 1
    #         cA -= 1
    #     elif cB != 0 and cA == 0:
    #         cB -=1
    #     else:
    #         cA = NAB[1]
    #         cB = NAB[2]
    #
    #         b += 1
    #         cA -= 1




if __name__ == '__main__':
    main()




def main():
    NAB = list(map(int,input().split()))




    # tm = NAB[0] // (NAB[1] + NAB[2]) * NAB[1]
    # amari = NAB[0] % (NAB[1] + NAB[2])
    # tm += min(amari,NAB[1])
    #
    # print(tm)

    # b = 0
    #
    # tm = NAB[0]//(NAB[1]+NAB[2])
    # amari = NAB[0] % (NAB[1]+NAB[2])
    #
    # # print(tm)
    # if NAB[1] < amari:
    #     b = (tm*NAB[1])+ NAB[1]
    # else:
    #     b = (tm*NAB[1])+ amari
    #
    # print(b)


    b = 0
    # if NAB[1] == 0:
    #     b = 0
    # elif NAB[2] == 0:
    #     b = NAB[1]

    if NAB[0] < NAB[1]+NAB[2]:
        if NAB[0] < NAB[1]:
            b = NAB[0]
        else:
            b = NAB[1]

    else:
        tm = NAB[0]//(NAB[1]+NAB[2])
        amari = NAB[0] % (NAB[1]+NAB[2])

        # print(tm)
        if NAB[1] < amari:
            b = (tm*NAB[1])+ NAB[1]
        else:
            b = (tm*NAB[1])+ amari

    print(b)





if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted