Harryxun/stf_run huggingface dataset:
n , k = map(int, input().split())
a = list(map(int, input().split()))
neg = []
pos = []
mod = 10**9+7
for i in range(n):
    if a[i] >= 0:
        pos.append(a[i])
    else:
        neg.append(a[i])
neg.sort()
pos.sort(reverse = True)
min_num = -1
good_num = -1
if k % 2 == 1 and len(pos) == 0:
    ans = 1
    neg.sort(reverse = True)
    for i in range(k):
        ans *= neg[i]
        ans %= mod
    print(ans)
else:
    #最大化するとき
    for i in range(0,k+1,2):
        #i個だけnegから取る。
        if i > len(neg) or k - i > len(pos):
            continue
        m = -1
        if i - 1 >= 0:
            m = abs(neg[i-1])
        if k-i-1 >= 0:
            m = min(m, pos[k-i-1])
        if m > min_num:
            min_num = m
            good_num = i
    ans = 1
    for i in range(good_num):
        ans *= neg[i]
        ans %= mod
    for i in range(k - good_num):
        ans *= pos[i]
        ans %= mod
    print(ans % mod)

### FIXED CODE ###

n , k = map(int, input().split())
a = list(map(int, input().split()))
neg = []
pos = []
mod = 10**9+7
for i in range(n):
    if a[i] >= 0:
        pos.append(a[i])
    else:
        neg.append(a[i])
neg.sort()
pos.sort(reverse = True)
if (len(pos) == 0 and k % 2 == 1) or n == k:
    ans = 1
    a.sort(reverse = True)
    for i in range(k):
        ans *= a[i]
        ans %= mod
    print(ans % mod)
else:
    #最大化するとき
    from collections import deque
    ans = 1
    neg_new = []
    for i in range(0, len(neg)//2):
        neg_new.append(neg[2*i] * neg[2*i+1])
    neg_new = deque(sorted(neg_new, reverse = True))
    pos = deque(pos)
    if k % 2 == 1:
        k -= 1
        ans = pos.popleft()
    else:
        ans = 1
    while k > 0:
        if len(pos) >= 2 and len(neg_new) >= 1:
            if pos[0] * pos[1] > neg_new[0]:
                ans *= pos.popleft() * pos.popleft()
            else:
                ans *= neg_new.popleft()
        elif len(pos) >= 2:
            ans *= pos.popleft() * pos.popleft()
        else:
            ans *= neg_new.popleft()
        k -= 2
        ans %= mod
    print(ans % mod)
from sys import stdin
from fractions import gcd
#from math import gcd

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

def gcd_all(list):
    return gcd_all([gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]

ma = -50
for i in range(n):
    lin = [li[s] for s in range(n) if s != i]
    ma = max(ma,gcd_all(lin))

print(ma)

### FIXED CODE ###

from fractions import gcd

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

M = [0]*N

#漸化式を作る
L = [0]*N
R = [0]*N

for i in range(1,N):
    L[i] = gcd(L[i-1],A[i-1])
    R[N-1-i] = gcd(R[N-i],A[N-i])

for j in range(N):
    M[j] = gcd(L[j],R[j])

print(max(M))
import math
a, b, c = map(int, input().split())
ab = a * b
num = ((c-a-b)/2**2)
if ab < num:
  print("Yes")
else:
  print("No")




### FIXED CODE ###

mlist = list([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51])
b = int(input())
print(mlist[b-1])
n = list(input())
n = [int(i) for i in n]
n.reverse()
l = len(n)
ans = 0
for i in range(l):
    if (n[i]==5 and n[i+1]>=5) or n[i]>5:
        if i!=l-1:
            n[i+1] += 1
        else:
            ans += 1
        ans += 10-n[i]
    else:
        ans += n[i]
print(ans)

### FIXED CODE ###

n = list(input())
n = [int(i) for i in n]
n.reverse()
l = len(n)
ans = 0
for i in range(l-1):
    if (n[i]==5 and n[i+1]>=5) or n[i]>5:
        n[i+1] += 1
        ans += 10-n[i]
    else:
        ans += n[i]
ans += 11-n[-1] if n[-1]>5 else n[-1]
print(ans)
import sys
from fractions import gcd
inputs = sys.stdin.readlines()

n, m = map(int, inputs[0].split())
A = list(set(map(int, inputs[1].split())))
B = list(map(lambda x: x//2, A))

prod_A = gcd_A = A[0]
for a in A[1:]:
    gcd_A = gcd(gcd_A, a)
    prod_A *= a
sup = prod_A // gcd_A

C = []
for b in B:
    p, x, c = 0, b*1, {0}
    while x <= sup:
        c.add(x)
        p += 2
        x = b*(p + 1)
    sup = max(c)
    C.append(c)
    
cap_c = C[0]
for c in C[1:]:
    cap_c &= c
cap_c.discard(0)
if not c:
    print(0)
else:
    print((m // min(cap_c) + 1) // 2)

### FIXED CODE ###

import sys
from fractions import gcd
inputs = sys.stdin.readlines()

n, m = map(int, inputs[0].split())
A = list(set(map(int, inputs[1].split())))

a = A[0]
for i in range(1, len(A)):
    z = gcd(a, A[i])
    x, y = a // z, A[i] // z
    if x % 2 == y % 2 == 1:
        a = x*y*z
    else:
        print(0)
        break
else:
    print(round(((m+1)/a)))
n, *H = map(int, open(0).read().split())

inc = True
peaks = [], []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            peaks.append(h0)
            inc = False
    else:
        if h0 < h1:
            peaks.append(-h0)
            inc = True
if inc:
    peaks.append(H[-1])
print(sum(peaks))

### FIXED CODE ###

n, *H = map(int, open(0).read().split())

inc = True
maxes, mins = [], []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            maxes.append(h0)
            inc = False
    else:
        if h0 < h1:
            mins.append(h0)
            inc = True
if inc:
    maxes.append(H[-1])
print(sum(maxes)-sum(mins))
N,A,B = map(int,input().split())

if A+B > N+1:
  print("-1")
  exit()
if A == 1:
  if B== N:
    ans = [i+1 for i in reversed(range(N))]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if B == 1:
  if A== N:
    ans = [i+1 for i in range(N)]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if A >= B:
  Flag = True
else:
  Flag = False
  A,B = B,A
if (N+A-1)//A > B:
  print("-1")
  exit()
else:
  L = [[] for _ in range(B)]
  for i in range(B):
    temp = ""
    for j in range(A):
      if j+1+i*A <= N:
        temp += str(j+1+i*A)
        L[-i-1] = "".join(temp)
  ans = "".join(L)
  if Flag:
    s = " ".join([n for n in ans])
    print(s)
  else:
    t = reversed(list(ans))
    ans = " ".join(t)
    print(ans)
  exit()

### FIXED CODE ###

import numpy as np
N,A,B = map(int,input().split())

if A+B > N+1:
  print("-1")
  exit()
if A == 1:
  if B== N:
    ans = [i+1 for i in reversed(range(N))]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if B == 1:
  if A== N:
    ans = [i+1 for i in range(N)]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if A >= B:
  Flag = True
else:
  Flag = False
  A,B = B,A
#print((N+A-1)//A, B)
if A*B<N:
  print("-1")
  exit()
else:
  L = [1 for _ in range(B)]
  nokori = N-B
  for i in range(B):
    if A-L[i] >0:
      temp = min(A-L[i],nokori)
      L[i] += temp
      nokori -= temp
    if nokori == 0:
      break
  now = 0
  P = [[] for _ in range(B)]
  for i,num in enumerate(L):
    for j in range(num):
      now += 1
      P[-i-1].append(now)
  #print(P)
  ans = P
  output = []
  for i in range(len(ans)):
    for j in ans[i]:
      output.append(j)
  if Flag:
    print(*output)
  else:
    output = output[::-1]
    print(*output)
n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
count = {}
ans = []
for bits in range(1 << 10):
    count = {}
    for i in range(10):
        if (bits >> i & 1) == 1:
            for j in range(n):
                if j not in count: 
                    count[j] = f[j][i]
                else:
                    count[j] += f[j][i]
    if count != {}:
        if count[0] > 0 and count[1] > 0 and count[2] > 0: 
            check = p[0][count[0]] + p[1][count[1]] + p[2][count[2]]
            ans.append(check)
print(max(ans))

### FIXED CODE ###

n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
count = {}
ans = []
for bits in range(1 << 10):
    count = {}
    for i in range(10):
        if (bits >> i & 1) == 1:
            for j in range(n):
                if j not in count: 
                    count[j] = f[j][i]
                else:
                    count[j] += f[j][i]
    if count != {}:
        flag = 0
        for k in range(n):
            if count[k] != 0:
                flag = 1
        if flag:
            check = 0
            for l in range(n):
                check += p[l][count[l]]
            ans.append(check)
print(max(ans))
n = input()
if n >= 20 or n % 7==0 or n%4==0 or n == 19 or n == 18 or n == 15 or n == 11:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = input()
n = int(n)
if n >= 20 or n % 7==0 or n%4==0 or n == 19 or n == 18 or n == 15 or n == 11:
    print("Yes")
else:
    print("No")
N,K = map(int,input().split())
A = list(map(int,input().split()))

from collections import deque 
tmp = 1
num = deque()
 
for i in range(N):
    num.append(tmp)
    if tmp == A[tmp-1]:
        judge = tmp
        flag1 = 1
        break
    tmp = A[tmp-1]
    if tmp in num:
        judge = tmp
        flag2 = 1
        break

if flag2 == 1:
    num_index = num.index(judge)
    print(num[(K-num_index)%(len(num)-num_index) + num_index])
elif flag1 == 1:
    if K >= len(num):
        print(judge)
    else:
        print(num[K-1])

### FIXED CODE ###

N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))

from collections import deque 
tmp = 1
num = []
seen = [-1]*(N+1)
 
while seen[tmp] == -1:
    seen[tmp] = tmp
    num.append(tmp)
    tmp = A[tmp]


l = num.index(tmp)
c = len(num) - l

if K < l:
    print(num[K])
else:
    print(num[(K-l)%c+l])
N, u, v = (int(i) for i in input().split())
adj=[]
for i in range(N+1):adj.append([])
for i in range(N-1):
	a,b = map(int,input().split())
	adj[a]+=[b]
	adj[b]+=[a]
	
prof = [0]*(N+1)
haut = [0]*(N+1)
parent = [-1]*(N+1)

def enraciner(sommet):
	for s in adj[sommet]:
		if s!=parent[sommet]:
			# ~ parent[s] = sommet
			# ~ prof[s] = 1+prof[sommet]
			enraciner(s)
	haut[sommet] = 1
	# ~ tmp = [haut[s]for s in adj[sommet] if s!=parent[sommet]]
	if tmp: haut[sommet]+=max(tmp)

enraciner(v)

# ~ print("parent",parent)
# ~ print("haut",haut)
# ~ print("prof",prof)

ans = 0

#montee
pu = prof[u]
pv = prof[v]
m = (pu - pv -1)//2
pu-=m
pv+=m
# ~ print("m",m)
ans+=m
for i in range(m):
	u = parent[u]

mx = 0
if len(adj[u])>1:mx = max(haut[i] for i in adj[u] if i!= parent[u])
# ~ print("mx",mx)
ans+= mx

last = (pu-pv)//2
# ~ print("last",last)
ans+=last

print(ans)



### FIXED CODE ###

N, u, v = (int(i) for i in input().split())
adj=[]
for i in range(N+1):adj.append([])
for i in range(N-1):
	a,b = map(int,input().split())
	adj[a]+=[b]
	adj[b]+=[a]

def distances(sommet):
	d = [-1]*(N+1)
	File = [sommet]
	d[sommet] = 0
	while File:
		s = File.pop()
		for x in adj[s]:
			if d[x]==-1:
				d[x] = 1+d[s]
				File.append(x)
	return d


t = distances(u)
a = distances(v)

# ~ print(t)
# ~ print(a)

ans = -1
for i in range(1,N+1):
	if t[i]<a[i]:
		ans = max(ans, a[i]-1)
		
print(ans)
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    """
    O(N^2)dpでも行けるそうです。以下写経：
    https://atcoder.jp/contests/abc078/submissions/14886969
    dp[turn][top]の２引数だけでいいのか、[x][y]の２引数も必要ではないかと思うが、
    考えてみれば
        dfs(0, top, x, y) = dfs(1, top', A[top], y)
                          = dfs(0, top", A[top], A[top'])
    となるので、実はdfs(0, top, x, y)はtop = Nでない限りx, yに依らない。
    """
    dp = [[-1] * N for _ in range(2)]
    def dfs(turn, top, x, y): # turn: 0 => x, 1 => y
        if top == N: return abs(x - y)
        if dp[turn][top] != -1: return dp[turn][top]
        if turn == 1:
            """
            yのターンは、top以降を取ってなるべくスコアが低くなるようなiを選ぶ
            """
            ret = 10**9
            for i in range(top, N): ret = min(ret, dfs(0, i + 1, x, A[i]))
            dp[turn][top] = ret
            return ret
        else:
            """
            xのターンは、top以降を取ってなるべくスコアが高くなるようなiを選ぶ
            """
            ret = 0
            for i in range(top, N): ret = max(ret, dfs(1, i + 1, A[i], y))
            dp[turn][top] = ret
            return ret
    
    print(dfs(0, 0, Z, W))

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, z, w = map(int, input().split())
    A = list(map(int, input().split()))
    """
    dpかと思ってずっとウンウン唸ってたのに、解説見て唖然。。。
    """
    if N == 1: print(abs(A[0] - w))
    else: print(max(abs(A[-1] - w), abs(A[-1] - A[-2])))


if __name__ == "__main__":
    main()
S = input()

if S[2] == s[3] and s[4] == s[5]:
  print('Yes')

### FIXED CODE ###

S = str(input())
 
if S[2] == S[3] and S[4] == S[5]:
  print('Yes')
else:
  print('No')
x, y = [int(x) for x in input().split()]
 
def c(n, r):
    u = 1
    l = 1
    for i in range(min(r, n - r)):
        u = u * (n - i) / (i + 1)
    return int(u)
 
def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    if x * 2 < y or y * x < x:
        return 0
    
    n = (x + y) // 3
    r = ((x - y) + n) // 2
    return c(n, r)

print(solve(x, y) % 1000000007)


### FIXED CODE ###

MAX = 1000000
MOD = 1000000007

fac = [None] * MAX
finv = [None] * MAX
inv = [None] * MAX


def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


comb_init()
x, y = [int(x) for x in input().split()]


def solve(x, y):

    if (x + y) % 3 != 0:
        return 0

    n = (2 * y - x) // 3
    m = (2 * x - y) // 3
    if n < 0 or m < 0:
        return 0

    return comb(n + m, n)


print(solve(x, y))
n, d = input().split()
n=int(n)
d=int(d)
sum=0
count=0
while 1:
  sum=sum+2*d+1
  count+=1
    break
print(count)

### FIXED CODE ###

n, d = input().split()
n=int(n)
d=int(d)
sum=0
count=0
while 1:
  sum=sum+2*d+1
  count+=1
  if sum>=n:
    break
print(count)
ソースコード 

Copy
Copy
import numpy as np
 
N, D = list(map(int, input().split()))
full_list = []
for i in range(N):
  full_list.append(list(map(int, input().split())))
 
result = 0
 
for i in range(N):
  for j in range(N-i-1):
    length = 0
    for s in range(D):
      length += (full_list[i][s] - full_list[j][s]) ** 2
    result += 1 if np.sqrt(length).is_integer() == True else 0
 
print(result)

### FIXED CODE ###

N,A,B = map(int, input().split())
 
print(min(N*A, B))
s = input()
k = int(input())


# alphabet順に探査する
# 探査順序配列
search_seq = sorted(list(set(s)))

count = 0
previous = 0

for key in search_seq:
    previous = count
    indexes = [i for i, x in enumerate(s) if x == key]
    sublist = []
    for index in indexes:
        for end in range(index+1, len(s) + 1):
            sublist.append(s[index:end])
    count += len(s)
    if k-1 < count:
        list_uq = list(set(sublist))
        list_sorted = sorted(list_uq)
        print(list_sorted[k-previous-1])
        exit()




### FIXED CODE ###

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


sublist = []
for start in range(len(s)):
    end = min(start + k, len(s))
    for end in range(start+1, end + 1):
        sublist.append(s[start:end])

unique = sorted(list(set(sublist)))
print(unique[k-1])
N=int(input())
A=map(int, input().split())
maxnum=max(A)
minnum=min(A)
print(maxnum-minnum)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
print(max(A)-min(A))
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


def isValidTransition(x, y, H, W):
    return 0 <= x and x < W and 0 <= y and y < H

res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if isValidTransition(nx, ny, H, W) and graph[nx][ny] == 1:
                    flag = True
            if not flag:
                res = False
                break
    if not res:
        break

print('Yes' if res else 'No')


### FIXED CODE ###

H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append(list(input()))

res = True

for j in range(1, W-1):
    for i in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            print('No')
            exit()
print('Yes')
K,S = (int(_) for _ in input().split())

out = 0

for x in range(K+1):
    for y in range(x):
        for z in range(y)
            if x + y + z == S :
                if x == y and y == z:
                    out += 1
                elif x == y or y == z or z == x:
                    out += 3
                else:
                    out += 6

print(out)


### FIXED CODE ###

def binary_search_list(beSearched,wanted) :
    l = 0
    r = len(beSearched)

    #print("condition = {}".format(r-l))

    while r - l >= 1 :
        s = (l + r) // 2
        #print("l={} r={} s={}".format(l,r,s))
        if beSearched[s] == wanted :
            return True
        if beSearched[s] > wanted :
            r = s
        else :
            l = s + 1

    return False

K,S = (int(_) for _ in input().split())
num = [_ for _ in range(K+1)]
out = 0
for i in range(K+1):
    for j in range(i+1):
        if 0 <= S - i - j <= j :
            if i == j and j == S - i - j:
                out += 1
            elif i == j or j == S - i - j or S -i - j == i:
                out += 3
            else :
                out += 6
        #print(num[:j+1])
        #b = binary_search_list(num[:j+1],S - i - j)
        #print("b={} i={} j={} k = {}".format(b,i,j, S- i -j))
        #if b :
            #if i == j and j == S - i - j:
                #out += 1
            #elif i == j or j == S - i - j or S -i - j == i:
                #out += 3
            #else :
                #out += 6

print(out)
# 6, 5, 6, 5, ...

x = int(input())
q = x // 11
r = x % 11
if r == 0:
    ans = q * 2
elif 1 <= r <= 5:
    ans = q * 2 + 1
elif 6 <= ans <= 10:
    ans = q * 2 + 2
print(ans)


### FIXED CODE ###

# 6, 5, 6, 5, ...

x = int(input())
q = x // 11
r = x % 11
if r == 0:
    ans = q * 2
elif 1 <= r <= 6:
    ans = q * 2 + 1
elif 7 <= r <= 10:
    ans = q * 2 + 2
print(ans)
N = int(input())
a = list(map(int,input().split()))
ans = 0
now = a[0]
i = 1
while i < N:
    if now == a[i]:
        ans += 1
        now = a[i+1]
        i += 2
        if i > N-1:
            break
    else:
        now = a[i]
        i += 1
print(ans)


### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
ans = 0
now = a[0]
i = 1
while i < N:
    if now == a[i]:
        ans += 1
        if i == N-1:
            break
        now = a[i+1]
        i += 2
        
    else:
        now = a[i]
        i += 1
print(ans)
value_index = dict()
n, x, m = map(int, input().split())
a = [0] * m
s = [0] * (m + 1)

for i in range(m+1):
    a[i] = x % m
    s[i+1] = s[i] + a[i]
    if i == n - 1:
        print(s[i+1])
        quit()
    if a[i] in value_index:
        break
    value_index[a[i]] = i
    x = x * x % m

l = value_index[a[i]]
r = i

loop_sum = s[r] - s[l]
loop_n = (n - l) // (r - l)
rem = (n - l) % (r - l)
ans = s[l] + loop_n * loop_sum + s[l+rem] - s[l]
print(ans)


### FIXED CODE ###


value_index = dict()
n, x, m = map(int, input().split())
a = [0] * (m + 1)
s = [0] * (m + 2)

for i in range(m + 1):
    a[i] = x % m
    s[i+1] = s[i] + a[i]
    if i == n - 1:
        print(s[i+1])
        quit()
    if a[i] in value_index:
        break
    value_index[a[i]] = i
    x = x * x % m

l = value_index[a[i]]
r = i

loop_sum = s[r] - s[l]
loop_n = (n - l) // (r - l)
rem = (n - l) % (r - l)

ans = s[l] + loop_n * loop_sum + s[l+rem] - s[l]
print(ans)
n,a,b = map(int,input().split())
diff = abs(a-b)

if diff%2==0:
  print(diff//2)
else :
  print(min(A - 1, N - B) + 1 + diff // 2)
  

### FIXED CODE ###

n,a,b = map(int,input().split())
diff = abs(a-b)
 
if diff%2==0:
  print(diff//2)
else :
  print(min(a - 1, n - b) + 1 + diff // 2)
N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

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

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

def lcm_li(li):
    if len(li) == 2:
        return lcm(li[0], li[1])
    else:
        x = lcm(li[0], li[1])
        x = [x] + li[2:]
        return lcm_li(x)

print(lcm_li(T))

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

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

lcm = 1
for i in T:
    lcm = int(lcm * i // gcd(lcm, i))

print(lcm)
N,A,B=map(int,input().split())
n=N//(A+B)

line=''
for i in range(n):
  line+='b'*A
  line+='r'*B

remainder=N%(A+B)
if remainder<=A:
  line+='b'*remainder
else:
  line+='b'*A
  line+='r'*(remainder-A)

print(line.count('b'))

### FIXED CODE ###

N,A,B=map(int,input().split())
if (A+B)==0:
  print(0)
  exit()

ans=(N//(A+B))*A

if N%(A+B)<=A:
  ans+=N%(A+B)
else:
  ans+=A

print(ans)
n = input()
digit = len(str(n))

count = -1
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** i

if digit % 2 == 1:
  count += n - 10 ** (digit - 1)

print(count)

### FIXED CODE ###

n = int(input())
digit = len(str(n))

count = 0
for i in range(digit - 1):
  if (i + 1) % 2 == 1:
    count += 10 ** (i + 1) - (10 ** i)

if digit % 2 == 1:
  count += n - 10 ** (digit - 1) + 1

print(count)
n = int(input())

used = ["empty"]
ans = "Yes"

for i in range(n):
    if i == 0:
        t = str(input())
        
        past = t
    else:
        t = str(input())
        for j in used:
            if j == t:
                ans = "No"
    
    if past[-1] != t[1]:
        ans = "No"
    used.append(t)
    past = t

print(ans)

    
    


### FIXED CODE ###


s = int(input())
last = str(input())
wordlist = [last]
ans = "Yes"

for i in range(s-1):
    word = str(input())

    if last[-1] != word[0]:
        ans = "No"
        break
    
    elif word in wordlist:
        ans = "No"
        break

    last = word
    wordlist.append(word)

print(ans)
import bisect
N, X = map(int, input().split())
x = sorted(list(map(int, input().split())))

i = bisect.bisect_left(x, X)
print(min(abs(x[i-1]-X), abs(X-x[i])))

### FIXED CODE ###

from fractions import gcd
N, X = map(int, input().split())
L = sorted(list(map(int, input().split())))

ans = abs(L[0]-X)
for x in L[1:]:
    ans = gcd(ans, abs(x-X))
print(ans)
N =int(input())
lisA =list(map(int,input().split()))
lisB = list(map(int,input().split()))
lisC = list(map(int,input().split()))

lisA.sort()
lisB.sort()
lisC.sort()
cnt = 0

for b in lisB:
    cnt+= bisect.bisect_left(lisA,b)*(N-bisect.bisect_right(lisC,b))

print(cnt)

### FIXED CODE ###

import bisect
N =int(input())
lisA =list(map(int,input().split()))
lisB = list(map(int,input().split()))
lisC = list(map(int,input().split()))

lisA.sort()
lisB.sort()
lisC.sort()
cnt = 0

for b in lisB:
    cnt += bisect.bisect_left(lisA,b)*(N-bisect.bisect_right(lisC,b))

print(cnt)
n, a = open(0).read().split()
print('Yneos'[n%500>a::2])

### FIXED CODE ###

n, a = open(0).read().split()
if int(n) % 500 <= int(a):
        print("Yes")
else:
        print("No")
a=input()
b=input()
count=0
for str_i in range (len(a)):
	if a[str_i:] != b[str_i:]:
		count+=1
    print(count)

### FIXED CODE ###

S=input()  
T=input()
num = 0
for i in range(len(S)):
	if S[i] != T[i]:
		num= num+1
print(num)
n,a,b = map(int,raw_input().split())

print (a + b(n - 1) ) - (a(n-1) + b) + 1

### FIXED CODE ###

n,a,b = map(int,raw_input().split())

ans =  (a + b*(n - 1) ) - (a*(n-1) + b) + 1 
print ans if ans > 0 else 0