input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
import sys
readline = sys.stdin.readline
N = int(readline())
T, A = list(map(int,readline().split()))
import math
for i in range(N - 1):
t,a = list(map(int,readline().split()))
i = 1
while True:
if t * i >= T and a * i >= A:
T,A = t * i,a * i
break
i += 1
print((T + A)) | import sys
readline = sys.stdin.readline
N = int(readline())
T, A = list(map(int,readline().split()))
for i in range(N - 1):
t,a = list(map(int,readline().split()))
# newT % t == 0 , newA % a == 0である
# newT >= T , newA >= Aである
# T以上の、tの倍数の最小値 = T / tの切り上げ
minT = ((T + t - 1) // t) * t
minA... | p03966 |
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a, b):
return((a*b)//gcd(a,b))
def main():
n=int(eval(input()))
a=1
b=1
for _ in range(n):
x,y = list(map(int,input().split()))
x1=x
y1=y
while x1<a or y1<b... | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a, b):
return((a*b)//gcd(a,b))
def main():
n=int(eval(input()))
a=1
b=1
for _ in range(n):
x,y = list(map(int,input().split()))
n=a//x
m=b//y
if a%x!=0:
... | p03966 |
n=int(eval(input()))
from math import gcd
a,b=list(map(int,input().split()))
temp=a+b
for i in range(1,n):
c,d=list(map(int,input().split()))
i=c+d
j=i
c1=c
d1=d
while i<temp or c<a or d<b:
i+=j
c+=c1
d+=d1
temp=i
a=c... | n=int(eval(input()))
from math import gcd
a,b=list(map(int,input().split()))
temp=a+b
for i in range(1,n):
c,d=list(map(int,input().split()))
j=c+d
x=max(a-c,0)//c
if max(a-c,0)%c!=0:
x+=1
y=max(b-d,0)//d
if max(b-d,0)%d!=0:
y+=1
z=max(temp-j,0)//j
if ... | p03966 |
N=int(eval(input()))
T=[]
A=[]
for i in range(N):
t,a=list(map(int,input().split()))
T.append(t)
A.append(a)
Tnow=T[0]
Anow=A[0]
ans=Tnow+Anow
for i in range(1,N):
t=T[i]
a=A[i]
tempans=(t+a+ans-1)//(t+a)*(t+a)
while True:
tempT=tempans*t//(t+a)
tempA=temp... | N=int(eval(input()))
T=[]
A=[]
for i in range(N):
t,a=list(map(int,input().split()))
T.append(t)
A.append(a)
Tnow=T[0]
Anow=A[0]
for i in range(1,N):
t=T[i]
a=A[i]
t1=(Tnow+t-1)//t*t
a1=t1//t*a
a2=(Anow+a-1)//a*a
t2=a2//a*t
if a1<Anow:
Tnow=t2
... | p03966 |
#! /usr/bin/env python3
def f(a, b, c, d):
n = 1
while a > c * n or b > d * n : n += 1
return c * n, d * n
def main():
a, b = 0, 0
for i in range(int(eval(input()))):
c, d = list(map(int, input().split()))
a, b = f(a, b, c, d)
print((a+b))
if __name__ == '__m... | #! /usr/bin/env python3
def f(a, b, c, d):
n = max(1,a//c, b//d)
while a > c * n or b > d * n : n += 1
return c * n, d * n
def main():
a, b = 0, 0
for i in range(int(eval(input()))):
c, d = list(map(int, input().split()))
a, b = f(a, b, c, d)
print((a+b))
if ... | p03966 |
N = int(eval(input()))
L = []
for i in range(N):
L.append(tuple(map(int, input().split())))
nowT = L[0][0]
nowA = L[0][1]
for i in range(1, N):
tmpT = L[i][0]
tmpA = L[i][1]
mul = 2
while not(tmpT >= nowT and tmpA >= nowA):
tmpT = L[i][0] * mul
tmpA = L[i][1] * mul
... | N = int(eval(input()))
nowT = 1
nowA = 1
for i in range(N):
nextT, nextA = list(map(int, input().split()))
# mul = max(ceil(nowT / nextT), ceil(nowA / nextA))
mul = max(-(-nowT // nextT), -(-nowA // nextA))
nowT = nextT * mul
nowA = nextA * mul
print((nowT + nowA))
| p03966 |
N = int(eval(input()))
P = [0,0]
for i in range(N):
Q = list(map(int,input().split()))
t = Q[0]
a = Q[1]
m = 1
while True:
t = Q[0] * m
a = Q[1] * m
if t >= P[0] and a >= P[1]:
P[0] = t
P[1] = a
break
m += 1
print((sum(P))) | N = int(eval(input()))
P = [1,1]
for i in range(N):
Q = list(map(int,input().split()))
t = Q[0]
a = Q[1]
m = max(P[0]//t,P[1]//a,1)
while True:
t = Q[0] * m
a = Q[1] * m
if t >= P[0] and a >= P[1]:
P[0] = t
P[1] = a
break
m += 1
print((sum(P))) | p03966 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#imp... | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#imp... | p03197 |
import sys
input = sys.stdin.readline
from collections import *
def dfs(x, y):
if x==0 and y==0:
t[x][y] = False
return False
if x>=1:
t[x][y] |= not dfs(x-1, y)
if y>=1:
t[x][y] |= not dfs(x, y-1)
if min(x, y)>=1:
t[x][y] |... | import sys
input = sys.stdin.readline
"""
def dfs(x, y):
if x==0 and y==0:
return False
res = False
if x>0:
res |= not dfs(x-1, y)
if y>0:
res |= not dfs(x, y-1)
if min(x, y)>0:
res |= not dfs(x-1, y-1)
return res
... | p03197 |
n = int(eval(input()))
for i in range(n):
a = int(eval(input()))
if a%2 == 1:
print('first')
exit()
else:
print('second')
| n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
for a in A:
if a != 1:
break
else:
print('first')
exit()
cnt = 0
for a in A:
if a%2 == 0:
cnt += 1
if cnt == n:
print('second')
else:
print('first')
| p03197 |
n=int(eval(input()))
ans="second"
for i in range(n):
if int(eval(input()))%2:ans="first"
print(ans) | n=int(eval(input()))
a=[int(eval(input()))%2 for _ in range(n)]
if 1 in a:print("first")
else:print("second") | p03197 |
print(("second" if all(int(eval(input()))%2 == 0 for i in range(int(eval(input())))) else 'first'))
| import sys
print(('second' if all(i%2==0 for i in list(map(int,sys.stdin))[1:]) else 'first')) | p03197 |
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
if all(a % 2 == 0 for a in A):
print("second")
else:
print("first")
| def main() -> None:
N = int(eval(input()))
P = [int(eval(input())) for _ in range(N)]
print(("first" if any(x % 2 == 1 for x in P) else "second"))
if __name__ == '__main__':
main()
| p03197 |
import collections
N = int(eval(input()))
a = [0] * N
for i in range(N):
a[i] = int(eval(input()))
def solve():
return any(x % 2 == 1 for x in a)
print(('first' if solve() else 'second'))
| _,*a=open(0);print(('first' if any(int(x)%2 for x in a)else'second')) | p03197 |
'''input
3
1
30000
20000
'''
import time
import math
n = int(eval(input()))
print(("second" if all([int(eval(input())) % 2 == 0 for i in range(n)]) else "first"))
| print(("second" if all([int(eval(input())) % 2 == 0 for i in range(int(eval(input())))]) else "first"))
| p03197 |
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
cnt = 0
for i in range(N):
if A[i]%2==1:
cnt += 1
if cnt>0:
print("first")
else:
print("second") | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
flag = 0
for i in range(N):
if A[i]%2==1:
flag = 1
break
if flag==1:
print("first")
else:
print("second") | p03197 |
import sys
def input(): return sys.stdin.readline().strip()
def main():
N = int(input())
A = (int(input()) for _ in range(N))
print("second") if all(( a%2==0 for a in A)) else print("first")
if __name__ == "__main__":
main()
| import sys
def input(): return sys.stdin.readline().strip()
def main():
N = int(input())
A = [int(input()) for _ in range(N)]
print("second") if all(( a%2==0 for a in A)) else print("first")
if __name__ == "__main__":
main()
| p03197 |
import sys
def input(): return sys.stdin.readline().strip()
def main():
N = int(input())
A = [int(input()) for _ in range(N)]
print("second") if all(( a%2==0 for a in A)) else print("first")
if __name__ == "__main__":
main()
| import sys
def input(): return sys.stdin.readline().strip()
def main():
N = int(input())
A = [int(input()) for _ in range(N)]
print("first") if any([a%2 for a in A]) else print("second")
if __name__ == "__main__":
main()
| p03197 |
def main():
n = int(eval(input()))
ans =0
f=0
for i in range(0 , n):
t = int(eval(input()))
if t%2!=0:
f=1
if f==1:
print("first")
else:
print("second")
if __name__=="__main__":
main() | # if any tree contains an odd no of table then first is the winner
# First strategy is to make a tree with odd no of apples
# second strategy is to make a tree with even no of apples
# if the tree doesn't contain any odd apples when first takes an apples he will make it odd
# second would try to make it even by tak... | p03197 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
de... | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.... | p03197 |
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.... | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) f... | p03197 |
import sys
read = sys.stdin.read
N, *a = list(map(int, read().split()))
a = [i % 2 for i in a]
if 1 in a:
print('first')
else:
print('second')
| import sys
read = sys.stdin.read
N, *a = list(map(int, read().split()))
a = [i for i in a if i % 2 == 1]
if len(a) > 0:
print('first')
else:
print('second')
| p03197 |
N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
ko[p].append(i)
def f(p):
n=len(ko[p])
if n==0:
return X[p], 0
dp=[[float('inf')]*5001 for _ in range(n+1)]
dp[0][0]=0
for i, c in enumerate... | N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
ko[p].append(i)
def f(p):
n=len(ko[p])
if n==0:
return X[p], 0
dp=[[float('inf')]*(X[p]+1) for _ in range(n+1)]
dp[0][0]=0
for i, c in enume... | p03603 |
from itertools import product
n = int(eval(input()))
P = [0, 0] + [int(i) for i in input().split()]
X = [0] + [int(i) for i in input().split()]
C = [[] for i in range (n+1)]
for i, p in enumerate(P):
C[p].append(i)
def dfs(i):
if not C[i]:
return X[i], 0
A = []
for c i... | from itertools import product
n = int(eval(input()))
P = [0, 0] + [int(i) for i in input().split()]
X = [0] + [int(i) for i in input().split()]
C = [[] for i in range (n+1)]
for i, p in enumerate(P):
C[p].append(i)
def dfs(i):
if not C[i]:
return X[i], 0
A = []
for c i... | p03603 |
#copy for experience
import sys
sys.setrecursionlimit(10**8)
N=int(eval(input()))
P=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
table=[[] for i in range(N)]
for i in range(N-1):
table[P[i]-1].append(i+1)
dp=[0]*N #shiro
def tree(pa):
for i in table[pa]:
tree(i)
... | #copy for experience
# E
N = int(eval(input()))
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))
# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
child_list[P_list[i-2]].append(i)
# from root
# minimize local total weight
color1 = [0]+X_list
co... | p03603 |
while True:
n, r = list(map(int, input().split()))
if not n:
break
sheets = sorted(tuple(map(int, input().split())) for _ in range(n))
table = [[0, 0, 0] for _ in range(10001)]
for x1, y1, x2, y2 in sheets:
for y in range(y1, y2):
t = table[y]
rx ... | while True:
n, r = list(map(int, input().split()))
if not n:
break
sheets = sorted(tuple(map(int, input().split())) for _ in range(n))
table_c = [0] * 10001
table_r = [0] * 10001
table_e = [0] * 10001
for x1, y1, x2, y2 in sheets:
for y in range(y1, y2):
... | p00432 |
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0041
"""
import sys
from itertools import permutations, product
def has_possibility(digits):
"""
??°????????????????????????10?????????????????§??????????????????????????????
??°????????§???????????????????... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0041
"""
import sys
from itertools import permutations, product
def make_ten(digits):
result = '0'
for a, b, c, d in permutations(digits, 4):
if result != '0':
break
for op1, op2, op3 ... | p00041 |
M, N = list(map(int, input().split()))
K = eval(input())
D = {}
for i in range(M+1):
D[i, 0] = 0, 0
for j in range(N+1):
D[0, j] = 0, 0
for i in range(1, M+1):
a = input()
for j in range(1, N+1):
if a[j-1] == 'J':
D[i, j] = (D[i-1, j][0] + D[i, j-1][0] - D[i-1, j-1][... | from array import array
M, N = list(map(int, input().split()))
K = eval(input())
D0 = [array('l', [0]) * (N+1) for _ in range(M+1)]
D1 = [array('l', [0]) * (N+1) for _ in range(M+1)]
for i in range(1, M+1):
a = input()
for j in range(1, N+1):
D0[i][j] = D0[i-1][j] + D0[i][j-1] - D0[i-1][j-... | p00483 |
n = eval(input())
code = input().split()
# DP(N, <parentheses nested>)
dp = [[0]*3 for i in range(n)]
dp[0] = [int(code[0]), -10**18, -10**18]
for i in range(1,n):
op, a = code[2*i-1: 2*i+1]
v = int(a)
if op is "+":
dp[i][0] = max(dp[i-1][0]+v, dp[i-1][1]-v, dp[i-1][2]+v)
dp[i][1] ... | n = eval(input())
code = input().split()
# DP(N, <parentheses nested>)
a = int(code[0]); b = c = -10**18
for op, v in zip(code[1::2], list(map(int,code[2::2]))):
if op is "+":
d = max(b-v, c+v)
a,b,c = max(a+v, d), d, c+v
else:
d = max(b+v, c-v)
a,b,c = max(a-v, d), max... | p03850 |
import itertools
while True:
N = int(eval(input()))
if not N:
break
D = [[] for _ in range(30)]
for i in range(N):
for x in map(int, input().split()[1:]):
D[x - 1].append(i)
C = [1 << i for i in range(N)]
for d in range(30):
for i, j in itertools.pe... | import itertools
while True:
N = int(eval(input()))
if not N:
break
D = [[] for _ in range(30)]
for i in range(N):
for x in map(int, input().split()[1:]):
D[x - 1].append(i)
C = [1 << i for i in range(N)]
for d in range(30):
for i, j in itertools.co... | p01136 |
MAX_N = 50
MAX_DAY = 30
def solve(n, f):
dp = [[set() for j in range(n)] for i in range(MAX_DAY + 1)]
for i in range(n):
dp[0][i].add(i)
for d in range(1, MAX_DAY + 1):
# for line in dp[:5]:
# print(line)
for i in range(n):
dp[d][i] |= dp[d -... | MAX_N = 50
MAX_DAY = 30
def solve(n, f):
dp = [{i} for i in range(n)]
for d in range(1, MAX_DAY + 1):
for i in range(n):
for j in range(n):
if f[d][i] and f[d][j]:
dp[i] |= dp[j]
if len(dp[i]) == n:
return d
... | p01136 |
"""
遅延評価セグメント木
op(s, t):二項演算の関数(実際に評価する値同士の演算):現在の値の中での比較
composition(f, g):二項演算の関数(遅延評価する値同士の演算):どちらの値を遅延伝播するか決定
mapping(f, a):二項演算の関数(二つの集合についての演算(ただし、X・Mの順)):現在の値と遅延評価により生じた値のどちらを採用するかを決定
rangeop(f, length):範囲が関係してくるときに行う演算
e():実際に評価する値の単位元
id():遅延評価する値の単位元
update, find, bisect, 全てにおいて, 1-indexとなっている。
(大抵の場... | """
遅延評価セグメント木
op(s, t):二項演算の関数(実際に評価する値同士の演算):現在の値の中での比較
composition(f, g):二項演算の関数(遅延評価する値同士の演算):どちらの値を遅延伝播するか決定
mapping(f, a):二項演算の関数(二つの集合についての演算(ただし、X・Mの順)):現在の値と遅延評価により生じた値のどちらを採用するかを決定
rangeop(f, length):範囲が関係してくるときに行う演算
e():実際に評価する値の単位元
id():遅延評価する値の単位元
update, find, bisect, 全てにおいて, 1-indexとなっている。
(大抵の場... | p02568 |
# foldの前計算を省いて逐次計算に。
# 同じインデックスの重複を除くので、関数の呼び出し回数が少し少ないはず。
# ただ、重複を除く分のオーバーヘッドがあるので、スピードはそこまで出ない。
MOD = 998244353
mask = (1 << 32) - 1
class LazySegmentTree:
__slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"]
def __init__(self, monoid_data, monoid_identity, operator_identity... | # l // l & -lなどを変更。比較用。
MOD = 998244353
mask32 = (1 << 32) - 1
class LazySegmentTree:
__slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"]
def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator):
se... | p02568 |
"""Buggy! the output of practice_k becomes about 1/4."""
from typing import Callable, List, TypeVar
S = TypeVar("S")
F = TypeVar("F")
class LazySegmentTree:
"""Lazy Segment Tree
References:
https://github.com/atcoder/ac-library/blob/master/atcoder/lazysegtree.hpp
"""
__slots__ =... | from typing import Callable, List, TypeVar
S = TypeVar("S")
F = TypeVar("F")
class LazySegmentTree:
"""Lazy Segment Tree
References:
https://github.com/atcoder/ac-library/blob/master/atcoder/lazysegtree.hpp
"""
__slots__ = [
"e",
"op",
"id",
"m... | p02568 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 998244353
def set_depth(depth):
global DEPTH, SEGTREE_SIZE, NONLEAF_SIZE
DEPTH = depth
SEGTREE_SIZE = 1 << DEPTH
NONLEAF_SIZE = 1 << (DEPTH - 1)
def set_width(width):
... | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 998244353
def set_depth(depth):
global DEPTH, SEGTREE_SIZE, NONLEAF_SIZE
DEPTH = depth
SEGTREE_SIZE = 1 << DEPTH
NONLEAF_SIZE = 1 << (DEPTH - 1)
def set_width(width):
... | p02568 |
# base
# https://beet-aizu.github.io/library/library/segtree/basic/chien.cpp.html
# https://beet-aizu.hatenablog.com/entry/2017/12/01/225955
class LazySegmentTree():
def __init__(self, op, e, mapping, composition, ie, init_array):
self.op = op
self.e = e
self.mapping = mapping
... |
# base
# https://beet-aizu.github.io/library/library/segtree/basic/chien.cpp.html
# https://beet-aizu.hatenablog.com/entry/2017/12/01/225955
class LazySegmentTree():
def __init__(self, op, e, mapping, composition, ie, init_array):
self.op = op
self.e = e
self.mapping = mapping
... | p02568 |
class LazySegmentTree():
def __init__(self, op, e, mapping, composition, ie, init_array):
self.op = op
self.e = e
self.mapping = mapping
self.composition = composition
self.ie = ie
l = len(init_array)
def ceil_pow2(n):
x = 0
... | class LazySegmentTree():
def __init__(self, op, e, mapping, composition, ie, init_array):
self.op = op
self.e = e
self.mapping = mapping
self.composition = composition
self.ie = ie
l = len(init_array)
def ceil_pow2(n):
x = 0
... | p02568 |
class LazySegmentTree():
def __init__(self, op, e, mapping, composition, ie, init_array):
self.op = op
self.e = e
self.mapping = mapping
self.composition = composition
self.ie = ie
l = len(init_array)
def ceil_pow2(n):
x = 0
... | class LazySegmentTree():
def __init__(self, op, e, mapping, composition, ie, init_array):
self.op = op
self.e = e
self.mapping = mapping
self.composition = composition
self.ie = ie
l = len(init_array)
def ceil_pow2(n):
x = 0
... | p02568 |
class LazySegmentTree():
def __init__(self, op, e, mapping, composition, ie, init_array):
self.op = op
self.e = e
self.mapping = mapping
self.composition = composition
self.ie = ie
l = len(init_array)
def ceil_pow2(n):
x = 0
... | class LazySegmentTree():
def __init__(self, op, e, mapping, composition, ie, init_array):
self.op = op
self.e = e
self.mapping = mapping
self.composition = composition
self.ie = ie
l = len(init_array)
def ceil_pow2(n):
x = 0
... | p02568 |
import sys
readline = sys.stdin.readline
class Lazysegtree:
def __init__(self, A, fx, ex, fm, initialize = True):
#作用の単位元をNoneにしている
#fa(operator, idx)の形にしている、data[idx]の長さに依存する場合などのため
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
self.ex = ex
self.fx = ... | import sys
readline = sys.stdin.readline
class Lazysegtree:
def __init__(self, A, fx, ex, fm, initialize = True):
#作用の単位元をNoneにしている
#fa(operator, idx)の形にしている、data[idx]の長さに依存する場合などのため
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
self.ex = ex
self.lazy ... | p02568 |
import sys
readline = sys.stdin.readline
class Lazysegtree:
def __init__(self, A, fx, ex, fm, initialize = True):
#作用の単位元をNoneにしている
#fa(operator, idx)の形にしている、data[idx]の長さに依存する場合などのため
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
self.ex = ex
self.lazy ... | import sys
readline = sys.stdin.readline
class Lazysegtree:
def __init__(self, A, fx, ex, em, fm, fa, initialize = True):
#fa(operator, idx)の形にしている、data[idx]の長さに依存する場合などのため
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
"""
self.fx = fx
self.fa = fa
... | p02568 |
#自前ModInt
class ModInt:
MOD = 10 ** 9 + 7
def __init__(s, x):
if type(x) == int:
s.x = x % type(s).MOD
else:
s.x = x
@classmethod
def set_mod(c, m):
c.MOD = m
def inv(s):
return type(s)(pow(s.x, type(s).MOD - 2, type(s).MOD))
def __str__(s):
return str(s... | class lazy_segtree:
#遅延評価セグメント木
def __init__(s, op, e, mapping, composition, id, v):
if type(v) is int: v = [e()] * v
s._n = len(v)
s.log = s.ceil_pow2(s._n)
s.size = 1 << s.log
s.d = [e()] * (2 * s.size)
s.lz = [id()] * s.size
s.e = e
s.op = op
s.mapping = mapping
... | p02568 |
class lazy_segtree:
#遅延評価セグメント木
def __init__(s, op, e, mapping, composition, id, v):
if type(v) is int: v = [e()] * v
s._n = len(v)
s.log = s.ceil_pow2(s._n)
s.size = 1 << s.log
s.d = [e()] * (2 * s.size)
s.lz = [id()] * s.size
s.e = e
s.op = op
s.mapping = mapping
... | class lazy_segtree:
#遅延評価セグメント木
def __init__(s, op, e, mapping, composition, id, v):
if type(v) is int: v = [e()] * v
s._n = len(v)
s.log = s.ceil_pow2(s._n)
s.size = 1 << s.log
s.d = [e()] * (2 * s.size)
s.lz = [id()] * s.size
s.e = e
s.op = op
s.mapping = mapping
... | p02568 |
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline... | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline... | p02568 |
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline... | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline... | p02568 |
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline... | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline... | p02568 |
class LazySegmentTree():
__slots__ = ["n","num","merge","merge_unit","operate","merge_operate","operate_unit","data","lazy","count"]
def __init__(self,n,init,merge,merge_unit,operate,merge_operate,operate_unit):
self.merge=merge
self.merge_unit=merge_unit
self.operate=operate
... | class LazySegmentTree():
__slots__ = ["n","num","merge","merge_unit","operate","merge_operate","operate_unit","data","lazy","count"]
def __init__(self,n,init,merge,merge_unit,operate,merge_operate,operate_unit):
self.merge=merge
self.merge_unit=merge_unit
self.operate=operate
... | p02568 |
class LazySegmentTree():
__slots__ = ["n","num","merge","merge_unit","operate","merge_operate","operate_unit","data","lazy","count"]
def __init__(self,n,init,merge,merge_unit,operate,merge_operate,operate_unit):
self.merge=merge
self.merge_unit=merge_unit
self.operate=operate
... | class LazySegmentTree():
__slots__ = ["n","num","merge","merge_unit","operate","merge_operate","operate_unit","data","lazy","count"]
def __init__(self,n,init,merge,merge_unit,operate,merge_operate,operate_unit):
self.merge=merge
self.merge_unit=merge_unit
self.operate=operate
... | p02568 |
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
mod = 998244353; INF = float("inf")
sec = pow(2, mod - 2, mod)
# 5 3
# 1 1 1 1 1
# 0 0 4 10 3
# 0 1 5 20 3
# 1 2 3
def getlist():
return list(map(int, input().split()))
class lazySegTree(obj... | import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
mod = 998244353; INF = float("inf")
sec = pow(2, mod - 2, mod)
def getlist():
return list(map(int, input().split()))
class lazySegTree(object):
# N:処理する区間の長さ
def __init__(self, N):
self.N = ... | p02568 |
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
mod = 998244353; INF = float("inf")
sec = pow(2, mod - 2, mod)
def getlist():
return list(map(int, input().split()))
class lazySegTree(object):
# N:処理する区間の長さ
def __init__(self, N):
self.N = ... | import sys; input = sys.stdin.buffer.readline
mod = 998244353; INF = float("inf")
sec = pow(2, mod - 2, mod)
def getlist():
return list(map(int, input().split()))
class lazySegTree(object):
# N:処理する区間の長さ
def __init__(self, N):
self.N = N
self.LV = (N - 1).bit_length()
self.N0 = 2 ** self.LV
se... | p02568 |
from typing import Callable, List, TypeVar
S = TypeVar("S") # モノイドの型
F = TypeVar("F") # 写像の型
class LazySegmentTree:
"""
Lazy Segment Tree from https://atcoder.jp/contests/practice2/submissions/16775176
References:
https://tumoiyorozu.github.io/single-file-ac-library/document_ja/lazyse... | from typing import Callable, List, TypeVar
S = TypeVar("S") # モノイドの型
F = TypeVar("F") # 写像の型
class LazySegmentTree:
"""
Lazy Segment Tree from https://atcoder.jp/contests/practice2/submissions/16775176
References:
https://tumoiyorozu.github.io/single-file-ac-library/document_ja/lazyse... | p02568 |
import sys
input = lambda: sys.stdin.readline().rstrip()
class LazySegmentTree():
def __init__(self, init, unitX, unitA, f, g, h):
self.f = f # (X, X) -> X
self.g = g # (X, A, size) -> X
self.h = h # (A, A) -> A
self.unitX = unitX
self.unitA = unitA
self.f... | import sys
input = lambda: sys.stdin.readline().rstrip()
class LazySegmentTree():
def __init__(self, init, unitX, unitA, f, g, h):
self.f = f # (X, X) -> X
self.g = g # (X, A, size) -> X
self.h = h # (A, A) -> A
self.unitX = unitX
self.unitA = unitA
self.f... | p02568 |
ref = "SCHD"
first = 0
while 1:
try:
n = eval(input())
if first: print()
first = 1
except:
break
P = [list(map(int,input().split())) for i in range(4)]
H = list(map(int,input().split()))
for _ in range(n):
hand = input().replace("A","1").replace("T","10").replace("J","11").replace("Q","12").r... | ref = "SCHD"
first = 0
while 1:
try:
n = eval(input())
if first: print()
first = 1
except:
break
P = [list(map(int,input().split())) for i in range(4)]
H = list(map(int,input().split()))
for _ in range(n):
hand = input().replace("A","1").replace("T","10").replace("J","11").replace("Q","12").r... | p01335 |
A, B, C, D, E, F = list(map(int, input().split(' ')))
water = []
for i in range(31):
if A*i >= F:
break
for j in range(16):
if 100 * (A*i + B*j) < F:
water.append(100*(A*i+B*j))
else:
break
water = sorted(list(set(water)))
sugar = []
for i in range(m... | A, B, C, D, E, F = list(map(int, input().split(' ')))
max_sugar = 0
max_water = 100*A
max_conc = 0.0
A_limit = F // (100*A)
for i in range(A_limit + 1):
B_limit = (F-100*A*i) // (100*B)
for j in range(B_limit + 1):
if i == 0 and j == 0:
continue
sugar_limit = min(E * (A*i... | p03601 |
N, A, B = list(map(int, input().split()))
x = N // (A + B)
ans = A * x
ans = ans + min(N - (A+B) * x, A)
print(ans) | N, A, B = list(map(int, input().split()))
st = N // (A+B)
plus = min(N%(A+B), A)
ans = A * st + plus
print(ans) | p02754 |
n, a, b = list(map(int, input().split()))
c = 0
for i in range(0, n//(a+b)):
c = a * (n//(a+b))
if n%(a+b) > a:
c += a
else:
c += n%(a+b)
print(c) | n, a, b = list(map(int, input().split()))
cycles = n//(a+b)
count = 0
count += a*cycles
rest = n - (a+b)*cycles
if rest > a:
count += a
else:
count += rest
print(count) | p02754 |
N, A, B = list(map(int, input().split(' ')))
blue = 0
if N!=0 and A!=0:
for i in range(int(N/(A+B))+1):
if i==int(N/(A+B)):
if N%(A+B) <= A:
blue += N%(A+B)
else:
blue += A
else:
blue += A
print(blue) | N, A, B = list(map(int, input().split(' ')))
blue = 0
if N!=0 and A!=0:
blue = A *int(N/(A+B))
if N%(A+B) <= A:
blue += N%(A+B)
else:
blue += A
print(blue) | p02754 |
n,b,r=list(map(int,input().split()));print(((n//(b+r))*b+min(b,n%(b+r)))) | n,b,r=list(map(int,input().split()));c=b+r;print(((n//c)*b+min(b,n%c))) | p02754 |
N, A, B = list(map(int, input().split()))
syou = N // (A + B)
mod = N % (A + B)
ans = A * syou
if (mod <= A):
ans += mod
else:
ans += A
print(ans) | N, A, B = list(map(int, input().split()))
syou = N // (A + B)
mod = N % (A + B)
ans = A * syou
ans += min(A, mod)
print(ans) | p02754 |
n,a,b = list(map(int, input().strip().split()))
t = n // (a+b)
s = n % (a+b)
if s > a:
print((t*a+a))
else:
print((t*a+s)) | n, a, b = list(map(int, input().split()))
ans = (n//(a+b)) * a
ans += n % (a+b) if ((n % (a+b)) <= a) else a
print(ans) | p02754 |
n, a, b = list(map(int, input().split()))
c = a + b
print((n // c * a + min(n % c, a)))
| n, a, b = list(map(int, input().split()))
b += a
print((n // b * a + min(n % b, a)))
| p02754 |
n,a,b = list(map(int, input().split(" ")))
Aball = ""
for i in range(a):
Aball+="b"
Bball = ""
for i in range(b):
Bball+="a"
t = ""
while len(t) <= n:
t+=Aball
if len(t)>n:
t = t[:n]
break
t+=Bball
if len(t)>n:
t = t[:n]
break
count = t.count(... | n,a,b = list(map(int, input().split(" ")))
count = a*(n//(a+b))
add = n%(a+b)
if add < a:
count+=add
else:
count+=a
print(count) | p02754 |
n, a, b = list(map(int, input().split()))
l = list('')
while len(l) <= n:
for i in range(a):
l.append('blue')
for i in range(b):
l.append('red')
count = 0
for i in range(n):
if l[i] == 'blue':
count += 1
print(count) | n, a, b = list(map(int, input().split()))
mod = int(n % (a + b))
cycle = n // (a + b)
if mod == 0:
print((a * cycle))
elif mod > a:
print((a * cycle + a))
else:
print((a * cycle + mod)) | p02754 |
N, A, B = list(map(int, input().split()))
list=[]
m=0
def add(i,j):
while(i<A):
list.append("b")
i+=1
while(j<B):
list.append("r")
j+=1
while(m<N):
i=0
j=0
add(i,j)
m+=A
m+=B
l=list[0:N]
r=l.count("b")
print(r) | N, A, B = list(map(int, input().split()))
if(A==0 & B==0):
print("0")
else:
r=N//(A+B)
s=N%(A+B)
if(A<s):
s=A
if(A!=0):
t=(A*r)+s
else:
t=0
print(t) | p02754 |
N, b, r = list(map(int, input().split()))
str = ''
loop, cnt, bcnt = 0, 0, 0
while(cnt <= N):
if loop%2 == 0:
cnt += b
bcnt += b
if N - cnt < 0:
bcnt += (N-cnt)
elif loop%2 == 1:
cnt += r
loop += 1
print(bcnt) | N, b, r = list(map(int, input().split()))
if b==0 and r==0:
print((0))
exit()
c = N//(b+r)
if N%(b+r) == 0:
print((b*c))
else:
if N%(b+r) <= b:
print((c*b + N%(b+r)))
else:
print((b*c + b)) | p02754 |
# -*- coding: utf-8 -*-
N, A, B = input().split()
balls = []
bBalls = []
rBalls = []
for i in range(int(A)):
rBalls.append("b")
for i in range(int(B)):
rBalls.append("r")
answer = 0
isBreak = False
for i in range(10**100):
balls = bBalls + rBalls + balls
if( len(balls) > int(N) ) :
... | # -*- coding: utf-8 -*-
N, A, B = list(map(int , input().split() ))
x = (N // (A + B)) * A
mod = N % (A + B)
if mod <= A :
z = mod
else :
z = A
print((x + z))
| p02754 |
n, a, b = list(map(int, input().split()))
acnt = 0
bcnt = 0
while True:
acnt += a
if acnt + bcnt >= n:
acnt -= (acnt + bcnt) - n
break
bcnt += b
if acnt + bcnt >= n:
break
print(acnt)
| n, a, b = list(map(int, input().split()))
amari = n % (a+b)
sho = n // (a+b)
if n <= a:
print(n)
elif amari == 0:
print((a*sho))
elif amari < a:
print((a*sho + amari))
else:
print((a*sho + a))
| p02754 |
n, a, b = list(map(int, input().split()))
amari = n % (a+b)
sho = n // (a+b)
if n <= a:
print(n)
elif amari == 0:
print((a*sho))
elif amari < a:
print((a*sho + amari))
else:
print((a*sho + a))
| n, a, b = list(map(int, input().split()))
amari = n % (a + b)
sho = n // (a + b)
if n <= a:
print(n)
else:
print((a * sho + min(a, amari)))
| p02754 |
n, a, b = list(map(int, input().split()))
ans = []
while (True):
for _ in range(a):
ans.append('b')
if len(ans) >= n:
break
for _ in range(b):
ans.append('r')
if len(ans) >= n:
break
print((ans[:n].count('b')))
| n, a, b = list(map(int, input().split()))
ans = (n//(a+b)) * a
if n % (a+b) > a:
print((ans + a))
else:
print((ans + n % (a+b)))
| p02754 |
# place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = list(map(int, input().split()))
rmult = 0
bmult = 0
total = 0
it = 1
ended = ''
while n > total:
total += a
bmult += 1
ended = 'b'
if n > total:
total += b
rmult += 1
ende... | # place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = list(map(int, input().split()))
x = max(n // (a + b) - 2, 1)
while a * x + b * x < n:
temp = a * x + b * x
x += 1
temp = a * x + b * x
if temp - b >= n:
temp = temp - b
endsWithA = True
else:
en... | p02754 |
# place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = list(map(int, input().split()))
x = max(n // (a + b) - 2, 1)
while a * x + b * x < n:
temp = a * x + b * x
x += 1
temp = a * x + b * x
if temp - b >= n:
temp = temp - b
endsWithA = True
else:
en... | n, a, b = list(map(int, input().split()))
x = max(n // (a + b) - 2, 1)
while a * x + b * x < n:
temp = a * x + b * x
x += 1
temp = a * x + b * x
if temp - b >= n:
temp = temp - b
print((a * x - (temp - n)))
else:
print((a * x))
| p02754 |
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
boll_a = ''
boll_b = ''
count = ''
for j in range(0, a):
boll_a += 'b'
for k in range(0, b):
boll_b += 'r'
for i in range(0, n):
count += boll_a
count += boll_b
if len(count) >= n: break
c = 0
for i in count[:n]:
if i == 'b':
... | x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
l = ''
boll_a = ''
boll_b = ''
for j in range(0, a):
boll_a += 'b'
for k in range(0, b):
boll_b += 'r'
while n >= len(l):
l += boll_a
l += boll_b
print((l[:n].count('b'))) | p02754 |
N,A,B=list(map(int,input().split()))
count=0
count_blue=0
while count<N-(A+B):
count_blue+=A
count+=A+B
if N-count<A:
count_blue+=N-count
else:
count_blue+=A
print(count_blue)
| N,A,B=list(map(int,input().split()))
x=N//(A+B)
y=N%(A+B)
if y<A:
print((A*x+y))
else:
print((A*x+A)) | p02754 |
N,A,B= input().split()
ans=0
for i in range(int(N)):
if i%(int(A)+int(B))<int(A):
ans+=1
print(ans)
| N, A, B = [int(x) for x in input().strip().split()]
p = N // (A + B) * A
q = N % (A + B)
if q > A:
q = A
print((p + q))
| p02754 |
N, A, B = [int(x) for x in input().strip().split()]
p = N // (A + B) * A
q = N % (A + B)
if q > A:
q = A
print((p + q))
| """
Author: _YL_
"""
# b:blue, r:red
n, b, r = list(map(int, input().split()))
if b == 0:
print("0")
elif r == 0:
print(n)
else:
remainder = n % (b+r)
if remainder > b:
remainder = b
print((n//(b+r)*b+remainder)) | p02754 |
N, A, B = list(map(int, input().split()))
result = 0
current = "b"
while(N > 0):
if current == "b":
if N - A > 0:
result += A
N = N - A
else:
result += N
N = 0
current = "r"
else:
if N - B > 0:
N = N - B
else:
N = 0
current = "b"
print(... | N, A, B = list(map(int, input().split()))
result = 0
x = N // (A+B)
result = A * x
N = N - ((A + B) * x)
if N < A:
result += N
else:
result += A
print(result) | p02754 |
N, A, B = list(map(int, input().split()))
lst = []
i = 0
while i < N:
for j in range(A):
lst.append("b")
i += 1
for k in range(B):
lst.append("r")
i += 1
# print("lst:", lst)
lst = lst[:N]
# print("lst:", lst)
print((lst.count('b'))) | # coding: utf-8
N, A, B = list(map(int, input().split()))
# print("N:", N, "A:", A, "B:", B)
if A == 0:
print((0))
elif B == 0 or N <= A:
print(N)
else:
num = int(N / (A + B)) * A + min(A, N % (A + B))
print(num)
| p02754 |
n,a,b = list(map(int,input().split()))
x = n // (a+b)
y = n % (a+b)
if y <= a:
print(((x*a) + y))
else:
print(((x*a) + a))
|
n,a,b = list(map(int,input().split()))
num = 0
num = n // (a+b)
if n % (a+b) <= a:
print(((num*a)+ (n % (a+b))))
else:
print(((num*a)+a))
| p02754 |
n,a,b=list(map(int,input().split()))
count=0
while n>0:
for i in range(a):
count+=1
n-=1
if n==0:
break
for i in range(b):
n-=1
if n==0:
break
if a==0:
print((0))
else:
print(count) | n,a,b=list(map(int,input().split()))
ab=a+b
num=n//ab
n-=ab*num
if n>=a:
ans=a
else:
ans=n
print((ans+num*a)) | p02754 |
a,b,c=list(map(int,input().split()))
n = a // (b+c)
m = a - (b+c)*n
res = n*b
for i in range(m):
if i < b:
res += 1
print(res) | a,b,c=list(map(int,input().split()))
n = a // (b+c)
m = a - (b+c)*n
res = n*b
if m < b:
res += m
else:
res += b
print(res) | p02754 |
N, A ,B =list(map(int,input().split()))
blue =0
while N >0:
blue += min(A,N)
N -= min(A,N)
N = max(N-B,0)
print(blue) | N, A ,B =list(map(int,input().split()))
print((N//(A+B)*A+min(N%(A+B),A)))
| p02754 |
N, A, B = list(map(int, input().split()))
ans = 0
while N > 0:
red = min(N, A)
ans += red
N -= red
blue = min(N, B)
N -= blue
print(ans)
| N, A, B = list(map(int, input().split()))
rep = N//(A+B)
ans = A*rep
diff = N - (A+B)*rep
ans += min(diff, A)
print(ans)
| p02754 |
#Input
N,A,B= list(map(int, input().split()))
#Process
cnt = 0
Ans = 0
flag_AB = True
while cnt < N:
if(flag_AB):
flag_AB = False
if(cnt + A < N):
Ans = Ans + A
else:
Ans = Ans + A - (cnt + A - N)
cnt = cnt + A
else:
flag_AB = Tru... | #Input
N,A,B= list(map(int, input().split()))
#Process
nokori = 0
na = int(N / (A + B))
if((A+B)*na + A > N):
nokori = N % (A + B)
else:
nokori = A
Ans = A * na + nokori
#Output
print(Ans) | p02754 |
n,a,b=list(map(int,input().split()))
k=[]
ans=0
count=(n//(a+b))
bb=[]
aa=[]
for j in range(a):
k.append('b')
for t in range(b):
k.append('r')
kk=k
for i in range(count):
for y in range(len(k)):
kk.append(k[y])
print((kk[:n].count('b'))) | n,a,b=list(map(int,input().split()))
t=n//(a+b)
j=n%(a+b)
ans=0
q=t*a
if(j<=a):
p=j
else:
p=a
ans=p+q
print(ans) | p02754 |
n,a,b=list(map(int,input().split()))
c=n//(a+b)
d=n%(a+b)
ans=c*a+min(d,a)
print(ans) | n,a,b=list(map(int,input().split()))
c=a+b
ans=n//c*a
ans+=min(a,n%c)
print(ans) | p02754 |
n, a, b = list(map(int, input().split()))
l = []
while len(l) <= n:
for _ in range(a):
l.append("b")
for _ in range(b):
l.append("r")
print((l[:n].count("b")))
| n, a, b = list(map(int, input().split()))
l = a + b
set_cnt = n // l
rest = n % l
if rest >= a:
ans = set_cnt * a + a
else:
ans = set_cnt * a + rest
print(ans) | p02754 |
# A = [list(map(int, input().split())) for _ in range(3)]
# n = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
n, a, b = list(map(int, input().split()))
total = a+b
diff = n-((n//total)*total)
omake = n//total*a
if a <= diff:
print((a+omake))
else:
print((di... | # A = [list(map(int, input().split())) for _ in range(3)]
# n = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
n, a, b = list(map(int, input().split()))
total = a+b
diff = n % total
blue_in = n//total*a
if a <= diff:
print((a+blue_in))
else:
print((diff+blue... | p02754 |
a,b,c=list(map(int,input().split()))
d=0
e=0
ok=False
total=int(a/(b+c))
sa=a-(b+c)*total
if total==0:
if a>=b:
print(b)
else:
print(a)
else:
if sa>=b:
print((b+b*total))
else:
print((sa+b*total)) | n,a,b=list(map(int,input().split()))
print(((n//(a+b))*a+max(0,min(a,(n-((n//(a+b))*(a+b))))))) | p02754 |
n, a, b = list(map(int, input().split()))
total = 0
out = 0
if a == 0:
pass
else:
while True:
total += a
out += a
if total >= n:
out -= (total - n)
break
total += b
if total >= n:
break
print(out) | n, a, b = list(map(int, input().split()))
q = n // (a + b)
mod = n % (a + b)
if mod > a:
remain = a
else:
remain = mod
print((q * a + remain)) | p02754 |
n,a,b = list(map(int,input().split()))
for i in range(10**9):
if i*(a+b)==n:
print((a*i))
exit()
elif i*(a+b)>n:
t = n-(i-1)*(a+b)
if t>a:
t = a
print(((i-1)*a+t))
exit() | n,a,b = list(map(int,input().split()))
ans = n // (a+b) * a
rem = n % (a+b)
ans += min(rem,a)
print(ans) | p02754 |
n, a, b = list(map(int, input().split()))
ans = []
def add_ball(a, b):
ball_list = []
for i in range(a):
ball_list.append('b')
if len(ball_list) == n:
return ball_list
for j in range(b):
ball_list.append('r')
if len(ball_list) == n:
return... | n, a, b = list(map(int, input().split()))
ans = n // (a + b) * a
rem = n % (a + b)
ans += min(a, rem) # ansとremを比較することでnの位置よって処理を変えられる
print(ans)
| p02754 |
n, a, b = list(map(int, input().split()))
ans = 0
while True:
if n >= a:
n -= a
ans += a
else:
ans += n
break
if n >= b:
n -= b
else:
break
print(ans)
| n, a, b = list(map(int, input().split()))
ans = n//(a+b)*a
amari = n-(a+b)*(n//(a+b))
ans += min(amari, a)
print(ans)
| p02754 |
N, A, B = list(map(int, input().split()))
b_count = 0
n_count = 0
while n_count < N:
if n_count + A < N:
b_count += A
else:
b_count += N - n_count
break
n_count += A + B
print(b_count) | N, A, B = list(map(int, input().split()))
division = N // (A + B)
count = division * A
count += N - division * (A + B) if A > N - division * (A + B) else A
print(count) | p02754 |
n, a, b = list(map(int, input().split()))
al = a
bl = b
cnt = 0
for i in range(n):
if al != 0:
cnt += 1
al -= 1
elif bl != 0:
bl -= 1
if al == 0 and bl == 0:
bl = b
al = a
print(cnt) | n, a, b = list(map(int, input().split()))
ans = a * (n // (a + b))
if a < n % (a + b):
ans += a
else:
ans += n % (a + b)
print(ans) | p02754 |
N, A, B=list(map(int, input().split(" ")))
sum=0
flag=False
b=0
while True:
sum=sum+A
b=b+A
if sum>N:
flag=True
break
sum=sum+B
if sum>N:
break
if flag:
print((b-(sum-N)))
else:
print(b) | N, A, B=list(map(int, input().split(" ")))
result=A*(N//(A+B))+min(N%(A+B), A)
print(result) | p02754 |
N,A,B=list(map(int,input().split()))
x=[]
for i in range(1,N+A+B):
for j in range(A):
x.append("a")
for k in range(B):
x.append("b")
x=x[:N]
print((x.count("a"))) | N,A,B=list(map(int,input().split()))
num=N//(A+B)
res=N-num*(A+B)
count=0
if res<=A:
count=num*A+res
else:
count=num*A+A
print(count)
| p02754 |
n,a,b=list(map(int,input().split()))
m=n//(a+b)
n-=m*(a+b)
print((m*a+min(a,n))) | n,a,b=list(map(int,input().split()))
ans=a*(n//(a+b))
ans+=min(a,n%(a+b))
print(ans)
| p02754 |
N,A,B = list(map(int, input().split()))
cnt=0
cnt_blue=0
while cnt+A+B<N:
cnt+=A+B
cnt_blue+=A
print((cnt_blue+min(A,N-cnt))) | N,A,B = list(map(int, input().split()))
cnt_blue=A*(N//(A+B))
cnt_all=(A+B)*(N//(A+B))
print((cnt_blue+min(A,N-cnt_all))) | p02754 |
N,A,B=[int(x) for x in input().rstrip().split()]
ans=N//(A+B)
amari=N%(A+B)
if A<=amari:
amari=A
ans1=ans*A+amari
print(ans1) | N,A,B=[int(x) for x in input().rstrip().split()]
num=N//(A+B)
amari=N%(A+B)
tasu=0
if amari<=A:
tasu=amari
else:
tasu=A
print((num*A+tasu))
| p02754 |
n,a,b = list(map(int,input().split()))
ans = []
while(len(ans) < n):
for i in range(a):
if(len(ans) >= n):
break
ans.append(1)
for i in range(b):
ans.append(0)
print((sum(ans))) | n,a,b = list(map(int,input().split()))
print((a*(n//(a+b)) + min(n%(a+b),a))) | p02754 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.