input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
N, M = list(map(int, input().split())) print(((M * 1900 + (N - M) * 100) * pow(2, M)))
N, M = list(map(int, input().split())) print(((1800 * M + 100 * N) * 2 ** M))
p03549
n,m = list(map(int,input().split()));print((100*(18*m+n)*2**m))
n,m=list(map(int,input().split()));print(((1900*m+100*(n-m))*2**m))
p03549
n, m = list(map(int, input().split())) print((2**m * (1900*m + 100*(n-m))))
n, m = list(map(int, input().split())) x = ((n-m) * 100 + 1900 * m) * 2**m print(x)
p03549
from math import ceil n, m = list(map(int, input().split())) left = 1 prob = 0 ac = 0.5 ** m for i in range(1, 10000): prob += i * left * ac left -= left * ac ans = (100 * (n - m) + 1900 * m) * prob ans = ceil(ans) print(ans)
n, m = list(map(int, input().split())) ans = (100 * (n - m) + 1900 * m) * 2 ** m print(ans)
p03549
from fractions import Fraction import math n,m = [int(x) for x in input().split()] tle = m ac = n-m p_ok = Fraction(1, 2)**tle p_ng = 1 - p_ok time = 0 p_sum = 0 i = 1 while True: p = (p_ng**(i-1))*p_ok time += i*(100*ac+1900*tle)*p p_sum += p if 1-p_sum < 0.000000000001: ...
from fractions import Fraction import math n,m = [int(x) for x in input().split()] tle = m ac = n-m p_ok = Fraction(1, 2)**tle p_ng = 1 - p_ok time = 0 p_sum = 0 i = 1 while True: p = (p_ng**(i-1))*p_ok time += i*(100*ac+1900*tle)*p p_sum += p if 1-p_sum < 0.00000001: brea...
p03549
#1回の実行にかかるじかんをx、答えとなる時間(全体実行時間の総和の期待値)をYとする #n回目までで成功する時の実行時間の総和の期待値をy(n)とおくとY=lim(n→∞)y(n)である #ここでx=1900M+100(N-M)で固定ある。 #ここで各試行で成功する率p=1/2^Mである。 #ここでn回目までで成功する時の実行時間の総和の期待値をy(n)からn+1回目までで成功する時の実行時間の総和の期待値をy(n+1)を求めることを考える #(i)n=1の時 #1回目までやった時の実行時間の総和の期待値は1通りしかなくxであるためy(1)=xで固定である。 #2回目までやった時の実行時間の総和の期待値は2回目の実行...
#ここで求めるのはジャッジ終了時間の期待値である。 #よって1回の実行時間T=max(0,N-M)*100+1900*M、成功率p=1/2^Mとして、 #求める値yは #y=1*T*p+2*T*p(1-p)+3*T*p(1-p)(1-p)+… #=(lim N→∞)Σ(1<=i<=N)i*T*p*(1-p)^(i-1) #=Tp*(lim N→∞)Σ(1<=i<=N)i*(1-p)^(i-1) #ここで摂動法を用いればΣ(1<=i<=N)i*(1-p)^(i-1)=1/p^2-((1-p)^(N+1))/p^2-((N+1)(1-p)^N)/p #よってここで1-p<1,p<1より(lim N→∞)Σ(1<=i<=N)...
p03549
import sys input = sys.stdin.readline from collections import Counter def main(): N, P = list(map(int, input().split())) S = list(map(int, input().rstrip("\r\n"))) S.reverse() ans = 0 if P == 2 or P == 5: for i in range(N): if S[i] % P == 0:ans += N-i else: ...
import sys input = sys.stdin.readline from collections import Counter def main(): N, P = list(map(int, input().split())) S = list(map(int, input().rstrip("\r\n"))) S.reverse() ans = 0 if P == 2 or P == 5: for i in range(N): if S[i] % P == 0:ans += N-i else: ...
p02757
def main(): import collections N, P = list(map(int, input().split())) S = input()[::-1] ans = 0 if P == 2 or P == 5: for i, s in enumerate(S): if int(s) % P == 0: ans += N - i else: mod = [0] * P mod[0] = 1 current = 0 ...
def main(): import collections N, P = list(map(int, input().split())) S = input()[::-1] ans = 0 if P == 2 or P == 5: for i, s in enumerate(S): if int(s) % P == 0: ans += N - i else: mod = [0] * P mod[0] = 1 current = 0 ...
p02757
import sys import itertools import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N, P = [int(x) for x in input().split()] S = input().strip() if P == 2 or P == 5: ans = 0 for i, s in enumerate(S[::-1]): if int(s) % P == 0: ...
import sys import itertools import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N, P = [int(x) for x in input().split()] S = input().strip() if P == 2 or P == 5: ans = 0 for i, s in enumerate(S[::-1]): if int(s) % P == 0: ...
p02757
# coding: utf-8 import sys import math import collections import itertools INF = 10 ** 13 MOD = 10 ** 9 + 7 def input() : return sys.stdin.readline().strip() def lcm(x, y) : return (x * y) // math.gcd(x, y) def I() : return int(input()) def LI() : return [int(x) for x in input().split()] def RI(N) : return...
# coding: utf-8 import sys import math import collections import itertools INF = 10 ** 13 MOD = 10 ** 9 + 7 def input() : return sys.stdin.readline().strip() def lcm(x, y) : return (x * y) // math.gcd(x, y) def I() : return int(input()) def LI() : return [int(x) for x in input().split()] def RI(N) : return...
p02757
import sys input = sys.stdin.readline N, P = list(map(int, input().split())) S = list(map(int, list(input().rstrip()))) ans = 0 if P == 2 or P == 5: for i in range(N): if S[i] % P == 0: ans += i + 1 else: U = [0] * (N+1) count = [0] * P count[0] = 1 factor = 10 ...
import sys input = sys.stdin.readline N, P = list(map(int, input().split())) S = list(map(int, list(input().rstrip()))) ans = 0 if P == 2 or P == 5: for i in range(N): if S[i] % P == 0: ans += i + 1 else: U = [0] * (N+1) count = [0] * P count[0] = 1 factor = 10 ...
p02757
N,P=list(map(int,input().split())) S=str(eval(input())) ans=0 if 10%P==0: for i in range(N): if int(S[i])%P==0: ans+=i+1 else: rem=[0]*P rem[0]=1 for i in range(N-1,-1,-1): rem[int(S[i:N])%P]+=1 for j in rem: ans+=(j*(j-1))//2 print(ans)
N,P=list(map(int,input().split())) S=str(eval(input())) ans=0 if 10%P==0: for i in range(N): if int(S[i])%P==0: ans+=i+1 else: rem = [0]*P mod = 0 ten = 1 rem[mod]=1 for i in range(N): mod=(mod+int(S[N-i-1])*ten)%P ten=ten*10%P rem[mod...
p02757
import sys from collections import Counter n, p = [int(i) for i in sys.stdin.readline().split()] s = sys.stdin.readline().strip() if p == 2: ans = 0 for i, _s in enumerate(s, 1): if int(_s) % 2 == 0: ans += i print(ans) elif p == 5: ans = 0 for i, _s in enumerate(s, 1...
import sys from collections import Counter n, p = [int(i) for i in sys.stdin.readline().split()] s = sys.stdin.readline().strip() if p == 2: ans = 0 for i, _s in enumerate(s, 1): if int(_s) % 2 == 0: ans += i print(ans) elif p == 5: ans = 0 for i, _s in enumerate(s, 1...
p02757
N, P = list(map(int,input().split())) S = str(eval(input())) L = len(S) ans = 0 dic = {0:1} #一番右端は0なのでこれは常に必要 now = 0 if P == 2 or P == 5: kotae = 0 for i in range(L): if int(S[L-1-i])%P == 0: kotae += L-i print(kotae) exit(0) else: for i in range(L): now += int(S[L-1-i])*pow(10,i...
N, P = list(map(int,input().split())) S = str(eval(input())) L = len(S) ans = 0 dic = {0:1} #一番右端は0なのでこれは常に必要 now = 0 if P == 2 or P == 5: kotae = 0 for i in range(L): if int(S[L-1-i])%P == 0: kotae += L-i print(kotae) exit(0) else: for i in range(L): now += int(S[L-1-i])*pow(10,i...
p02757
#!/usr/bin/python3 # -*- coding:utf-8 -*- def main(): n, p = list(map(int, input().strip().split())) s = input().strip() ans = 0 if 10 % p == 0: for r in range(n): if int(s[r]) % p == 0: ans += r+1 print(ans) return remains = [0] * (n+1) x = 1 for r in range(n...
#!/usr/bin/python3 # -*- coding:utf-8 -*- def main(): n, p = list(map(int, input().strip().split())) s = input().strip() ans = 0 if 10 % p == 0: for r in range(n): if int(s[r]) % p == 0: ans += r+1 print(ans) return remains = [0] * (n+1) counts = [0] * p count...
p02757
n, p = list(map(int,input().split())) s = str(eval(input())) mods = [(i*10)%p for i in range(p)] sums = [0] * p tmp = 0 dp = [[0]*p for i in range(n+1)] if p == 2 or p == 5: ans = 0 for i in range(n): if int(s[i])%p == 0: ans += i+1 print(ans) exit() for i in range...
n, p = list(map(int,input().split())) s = str(eval(input())) ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i])%p == 0: ans += i+1 print(ans) exit() tmp = [0] * p tmp[0] = 1 mod = 0 for i in range(1,n+1): mod += (int(s[-i]) * 10**i) % p mod %= p a...
p02757
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() ...
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() ...
p02757
import itertools import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 def toint(l, r): return int(''.join(map(str, S[l:r]))) def test(): ans = 0 for...
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 # 解説 # P で割り切れるなら 10^n で割っても割り切れる。 N, P = list(map(int, sys.stdin.buffer.readline().split())) S = sys.stdin.buffer.re...
p02757
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def resolve(): N, P = lr() S = list(map(int, list(sr()))) if P == 2 or P == 5: ans = 0 for i in range(N): if S[i]%P == 0: ans += i+1 ...
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def resolve(): N, P = lr() S = list(map(int, list(sr()))) if P == 2 or P == 5: ans = 0 for i in range(N): if S[i]%P == 0: ans += i+1 ...
p02757
def main(): n, p = list(map(int, input().split())) S = input().strip() if p == 2 or p == 5: count = 0 digits = '02468' if p == 2 else '05' for i, x in enumerate(S, 1): if x in digits: count += i print(count) else: count...
n, p = list(map(int, input().split())) if p in (2, 5): c = 0 for i, x in enumerate(map(int, input()[::-1])): if x % p == 0: c += n-i print(c) else: c = [0] * p y = 0 t = 1 for x in map(int, input()[::-1]): y = (y + t*x) % p c[y] += 1 t = (10 * t) % p print((sum(i * (...
p02757
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math #import queue from copy import copy, deepcopy from operator import itemgetter import bisect#2分探索 #bisect_left(l,x), bisect(l,x) from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうの...
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math #import queue from copy import copy, deepcopy from operator import itemgetter import bisect#2分探索 #bisect_left(l,x), bisect(l,x) from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうの...
p02757
N,P = list(map(int,input().split())) S = str(eval(input())) if P == 2 or P == 5: S = list(map(int,list(S))) ans = 0 for i in range(N): if S[i] % P == 0: ans += i + 1 else: data = [0] * P s = int(S) for i in range(N): data[s%P] += 1 s -= int(S[...
N,P = list(map(int,input().split())) S = str(eval(input())) if P == 2 or P == 5: S = list(map(int,list(S))) ans = 0 for i in range(N): if S[i] % P == 0: ans += i + 1 else: data = [0] * P s = int(S) x = 1 ##10**iをPで割った数 y = 0 ##S[i:N]をPで割った数 for i in r...
p02757
import sys import collections read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,P = list(map(int,readline().split())) S = list(map(int,readline().rstrip().decode())) def solve_2(S): cnt = sum(i for i,x in enumerate(S,1) if x % 2 == 0) return c...
import sys import collections read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,P = list(map(int,readline().split())) S = list(map(int,readline().rstrip().decode())) def solve_2(S): cnt = sum(i for i,x in enumerate(S,1) if x % 2 == 0) return c...
p02757
from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N, P = list(map(int, readline().split())) S = [int(i) for i in readline().strip()[::-1]] ans = 0 if P == 2 or P == 5: for i, s in enumerate(S):...
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N, P = list(map(int, readline().split())) S = [int(i) for i in readline().strip()[::-1]] ans = 0 if P == 2 or P == 5: for i, s in enumerate(S): if s % P == 0: ...
p02757
import sys ## io IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) MIIZ = lambda: list([x-1 for x in MII()]) ## dp INIT_VAL = 0 MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)] MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)] ## math DIVC...
import sys ## io IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) MIIZ = lambda: list([x-1 for x in MII()]) ## dp INIT_VAL = 0 MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)] MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)] ## math DIVC...
p02757
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time def I(): return int(input()) def S(): return input() def MI...
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time def I(): return int(input()) def S(): return input() def MI...
p02757
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) ...
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) ...
p02757
from collections import Counter n, p = list(map(int, input().split())) s = input().rstrip() total = 0 if p in [2, 5]: for i in range(n-1, -1, -1): if int(s[i]) % p == 0: total += i + 1 else: dp = [0] * (n + 1) fac = 1 for i in range(n-1, -1, -1): dp[i] = (dp[i...
from collections import Counter n, p = list(map(int, input().split())) s = input().rstrip() total = 0 if p in [2, 5]: for i in range(n-1, -1, -1): if int(s[i]) % p == 0: total += i + 1 else: dp = [0] * (n + 1) fac = 1 for i in range(n-1, -1, -1): dp[i] = (dp[i...
p02757
from sys import stdin from collections import defaultdict, Counter N, P = list(map(int, stdin.readline().split())) S, = stdin.readline().split() ans = 0 # 2 cases if P == 2 or P == 5: digitdiv = [] for i in range(N): if int(S[i]) % P == 0: ans += i + 1 else: # count = Counter() pre...
from sys import stdin from collections import Counter N, P = list(map(int, stdin.readline().split())) S = stdin.readline().strip() ans = 0 if P in (2, 5): for i in range(N): if int(S[i]) % P == 0: ans += i + 1 else: count = Counter() ten = 1 mod = 0 for i in range(N): x = (int(S[N -...
p02757
import sys input = sys.stdin.readline from collections import Counter N, mod = list(map(int, input().split())) S = list(input().rstrip()) if mod == 2 or mod == 5: ans = 0 for i, s in enumerate(S): if int(s)%mod==0: ans += i+1 else: dp = [0] t = 1 for s in reverse...
import sys input = sys.stdin.readline N, P = list(map(int, input().split())) S = list(input().rstrip()) if P in {2, 5}: ans = 0 for i, s in enumerate(S): if int(s) % P == 0: ans += i+1 else: ans = 0 T = [0]*P T[0] = 1 tmp = 0 k = 1 for s in reversed...
p02757
def main(): N,P = list(map(int,input().split())) S = [int(s) for s in list(input().strip())][::-1] num = 0 ans = 0 if P == 2 or P == 5: for i in range(N): if S[i]%P == 0: ans += N-i print(ans) return L = [0]*P L[0]=1 t = 0 s = 1 for z in S: t = (z*s+t)%P L[t]+=1 s*=10%P ...
def main(): N,P = list(map(int,input().split())) S = [int(s) for s in list(input().strip())][::-1] num = 0 ans = 0 if P == 2 or P == 5: for i in range(N): if S[i]%P == 0: ans += N-i print(ans) return L = [0]*P L[0]=1 t = 0 s = 1 for z in S: t = (z*s+t)%P L[t]+=1 s=s*10%P ...
p02757
import sys n,p=list(map(int,input().split())) s=[int(x) for x in sys.stdin.readline().strip()] reslst=[0]*p cnt=0 if p==2: for i in range(n): if s[i]%2==0: cnt+=i+1 elif p==5: for i in range(n): if s[i]==5 or s[i]==0: cnt+=i+1 else: x=0 for i ...
import sys n,p=list(map(int,input().split())) s=sys.stdin.readline().strip() reslst=[0]*p cnt=0 if p==2: for i in range(n): if int(s[i])%2==0: cnt+=i+1 elif p==5: for i in range(n): if s[i]=='5' or s[i]=='0': cnt+=i+1 else: reslst[0]+=1 tmp=1 ...
p02757
#!/usr/bin/env python3 import sys from collections import defaultdict def solve(N: int, P: int, S: str): if 10%P == 0: sum = 0 for i in range(1,N+1): if int(S[-i]) % P == 0: sum += (N-i)+1 print(sum) return else: current = 0 ...
#!/usr/bin/env python3 import sys from collections import defaultdict def solve(N: int, P: int, S: str): if 10%P == 0: sum = 0 for i in range(1,N+1): if int(S[-i]) % P == 0: sum += (N-i)+1 print(sum) return else: current = 0 ...
p02757
#!/usr/bin/env python3 import sys def solve(N: int, P: int, S: str): if P == 2 or P == 5: tot = 0 for i, c in enumerate(S): c = int(c) if c % P == 0: tot += i+1 print(tot) return U = [0]*(N+1) a = 0 for i in ran...
#!/usr/bin/env python3 import sys def solve(N: int, P: int, S: str): if P == 2 or P == 5: tot = 0 for i, c in enumerate(S): c = int(c) if c % P == 0: tot += i+1 print(tot) return U = [0]*(N+1) a = 0 beki = 1 ...
p02757
r=list(range(128)) def f():v=min(i for i in r if D[i]);D[v]-=1;D[127-v]+=1;D[127]+=1 for i in[0]*eval(input()):n,d=list(map(int,input().split()));D=[0]*128;D[d]=1;exec("f();"*~-n);print(sum(i*D[i]for i in r))
for i in[0]*eval(input()):n,d=list(map(int,input().split()));print(~-n*127+(127*(n+1&1)^d))
p03977
from heapq import heappush, heappop T = int(eval(input())) A = [] for i in range(T): N, D = list(map(int, input().split())) ans = D h = [] heappush(h,D) for _ in range(N - 1): k = heappop(h) z = bin(k)[2:].zfill(7) u = ['0' if x == '1' else '1' for x in z] ...
from heapq import heappush, heappop T = int(eval(input())) A = [] for i in range(T): N, D = list(map(int, input().split())) ans = D h = [] heappush(h,D) for _ in range(N - 1): k = heappop(h) t = 127 ^ k heappush(h,t) ans += (127 + t - k) A.append(ans)...
p03977
from itertools import combinations from collections import Counter N = int(eval(input())) X = [list(map(int, input().split())) for _ in range(N)] if N == 1: print((1)) quit() X.sort() diff = [] for i, j in combinations(list(range(N)), 2): diff.append((X[i][0] - X[j][0], X[i][1] - X[j][1])) ...
from collections import defaultdict N = int(eval(input())) X = [list(map(int, input().split())) for _ in range(N)] X.sort() ctr = defaultdict(int) for i in range(N - 1): for j in range(i + 1, N): p = X[i][0] - X[j][0] q = X[i][1] - X[j][1] ctr[(p, q)] += 1 ctr[(-p, -q...
p03006
# div2019-2B - Picking Up from collections import defaultdict n = int(eval(input())) arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)]) cnt = defaultdict(int) for i in range(n): for j in range(i + 1, n): dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1]) cnt[dif] ...
n = int(eval(input())) arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)]) cnt = {} for i, j in arr: for k, l in arr: if (i, j) == (k, l): continue dif = (k - i, l - j) cnt.setdefault(dif, 0) cnt[dif] += 1 print((n - max(list(cnt.values())...
p03006
n = int(eval(input())) arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)]) cnt = {} for i, j in arr: for k, l in arr: if (i, j) == (k, l): continue dif = (k - i, l - j) cnt.setdefault(dif, 0) cnt[dif] += 1 print((n - max(list(cnt.values())...
# diverta2019-2B - Picking Up def main(): n = int(eval(input())) arr = sorted(tuple(map(int, input().split())) for _ in range(n)) cnt = {} for i in range(n): for j in range(i + 1, n): dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1]) cnt.setdefault(dif, 0) ...
p03006
# diverta2019-2B - Picking Up def main(): n = int(eval(input())) arr = sorted(tuple(map(int, input().split())) for _ in range(n)) cnt = {} for i in range(n): for j in range(i + 1, n): dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1]) cnt.setdefault(dif, 0) ...
# diverta2019-2B - Picking Up import sys input = sys.stdin.readline def main(): n = int(eval(input())) arr = sorted(tuple(map(int, input().split())) for _ in range(n)) cnt = {} for i in range(n): for j in range(i + 1, n): dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1]...
p03006
#!/usr/bin/env python3 from collections import defaultdict (n, ), *p = [[*list(map(int, i.split()))] for i in open(0)] d = defaultdict(int) for i in range(n): for j in range(n): d[(p[i][0] - p[j][0], p[i][1] - p[j][1])] += i!=j print((n - max(d.values())))
from collections import * (n,),*p=[[*list(map(int,i.split()))] for i in open(0)] d=defaultdict(int) for x, y in p: for a, b in p: d[(x-a, y-b)]+=(x,y)!=(a,b) print((n-max(d.values())))
p03006
n=int(eval(input())) arr=[list(map(int,input().split())) for _ in range(n)] arr=sorted(arr,key=lambda x:x[1]) arr=sorted(arr,key=lambda x:x[0]) ans=n for i in range(n): for j in range(i+1,n): p,q=arr[j][0]-arr[i][0],arr[j][1]-arr[i][1] cnt=0 flag=[0]*n for k in range(n): if flag[k]==1...
n=int(eval(input())) arr=[list(map(int,input().split())) for _ in range(n)] cnt={} for i in range(n): for j in range(n): if i==j: continue p=arr[i][0]-arr[j][0] q=arr[i][1]-arr[j][1] if (p,q) not in cnt: cnt[(p,q)]=1 else: cnt[(p,q)]+=1 if n==1: print((1)) else: ...
p03006
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] s_xy = set(xy) count = 0 for i in range(n-1): for j in range(i+1, n): p, q = xy[j][0] - xy[i][0], xy[j][1] - xy[i][1] count = max(count, sum((x-p,y-q) in xy for x, y in s_xy)) print((n-count))
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] s_xy = set(xy) count = 0 for i in range(n-1): for j in range(i+1, n): p, q = xy[j][0] - xy[i][0], xy[j][1] - xy[i][1] tc = sum((x-p,y-q) in xy for x, y in s_xy) count = max(count, tc) print((n-count...
p03006
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] s_xy = set(xy) count = 0 for i in range(n-1): for j in range(i+1, n): ix, iy = xy[i] jx, jy = xy[j] p = jx - ix q = jy - iy tc = sum((x-p,y-q) in xy for x, y in s_xy) count...
#https://atcoder.jp/contests/diverta2019-2/submissions/11229318 n = int(eval(input())) t = [tuple(map(int, input().split())) for _ in range(n)] s = set(t) cnt = 0 for i in range(n-1): for j in range(i+1,n): u,v = t[i] x,y = t[j] p = u-x; q = v-y c = sum((x-p, y-q) in s for x,y in t) if ...
p03006
# Picking Up # グラフ,有向グラフ,ベクトル, 2次元、コスト, N = int(eval(input())) S = [] for _ in range(N): x, y = list(map(int, input().split())) S.append([x, y]) cost = N for k, ke in enumerate(S): for i, ie in enumerate(S): if k == i: continue t_vec_x1 = ie[0] - ke[0] t_...
# Picking Up # グラフ,有向グラフ,ベクトル, 2次元、コスト, N = int(eval(input())) S = [] for _ in range(N): x, y = list(map(int, input().split())) S.append([x, y]) cost = N d = {} if N==1: print((1)) exit() for l,le in enumerate(S): for m, me in enumerate(S): if l == m: continue ...
p03006
import sys sys.setrecursionlimit(10**6) def get_par(x): if x == par_list[x]: return x else: par_list[x] = get_par(par_list[x]) return par_list[x] def merge(x,y): par_x = get_par(x) par_y = get_par(y) if par_x != par_y: par_list[par_y] = par_x def is_same(x,y): return get_...
import sys N=int(eval(input())) if N<=2: print((1)) sys.exit(0) xylist=[] for i in range(N): x,y=list(map(int,input().split())) xylist.append((x,y)) xylist.sort() #print(xylist) pqset=set() for i in range(N): x1,y1=xylist[i] for j in range(i+1,N): x2,y2=xylist[j] p=x2-x1 q...
p03006
from collections import Counter N = int(eval(input())) answer = [] answer2 = [] lis = [] lis2 = [] for i in range(N): x, y = list(map(int, input().split())) lis.append([x, y]) lis2.append([y, x]) sort_lis = sorted(lis) sort_lis2 = sorted(lis2) if N == 1: print((1)) exit() for i in...
from collections import Counter def input_func(): N = int(eval(input())) lis = [] for i in range(N): x, y = list(map(int, input().split())) lis.append([x,y]) sort_lis = sorted(lis) return N,sort_lis def evaluate(N, sort_lis): diff = [] if N == 1: ...
p03006
import itertools n=int(eval(input())) ball=[] for i in range(n): ball.append([int(i) for i in input().split()]) ball.sort() # p,qの候補取得 pq_cand=set() for v in itertools.combinations(ball,2): xdiff=v[0][0]-v[1][0] ydiff=v[0][1]-v[1][1] pq_cand.add((xdiff,ydiff)) connect=0 for pq in ...
import itertools n=int(eval(input())) ball=[] for i in range(n): ball.append([int(i) for i in input().split()]) ball.sort() # p,qの候補取得 pq_cand=set() for v in itertools.combinations(ball,2): xdiff=v[0][0]-v[1][0] ydiff=v[0][1]-v[1][1] pq_cand.add((xdiff,ydiff)) cost=n for pq in pq_...
p03006
import copy n = int(eval(input())) lst = [[0]*2 for i in range(n)] for i in range(n): lst[i][0], lst[i][1] = list(map(int, input().split())) lst.sort(key=lambda x:(x[1])) lst.sort(key=lambda x:(x[0])) lst_copy = copy.deepcopy(lst) saidai = 0 for i in range(n-1): for j in range(i+1, n): ...
import copy n = int(eval(input())) lst = [[0]*2 for i in range(n)] for i in range(n): lst[i][0], lst[i][1] = list(map(int, input().split())) lst.sort(key=lambda x:(x[1])) lst.sort(key=lambda x:(x[0])) lst_copy = copy.deepcopy(lst) saidai = 0 for i in range(n-1): for j in range(i+1, n): ...
p03006
import sys from collections import deque # 双方向キュー from collections import defaultdict # 初期化済み辞書 from heapq import heapify, heappush, heappop, heappushpop # プライオリティキュー from bisect import bisect_left, bisect_right # 二分探索 #import numpy as np # 1.8.2 #import scipy # 0.13.3 s2nn = lambda s: [int(c) for c in s...
import sys s2nn = lambda s: [int(c) for c in s.split(' ')] ss2nn = lambda ss: [int(s) for s in ss] ss2nnn = lambda ss: [s2nn(s) for s in ss] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2sss ...
p03006
import itertools costs = [] N = int(eval(input())) x, y = [], [] # (x,y)の値を取得 for n in range(N): temp = list(map(int, input().split())) x.append(temp[0]) y.append(temp[1]) # コスト計算 for n, perm in enumerate(itertools.permutations(list(zip(x,y)), N)): sol = 0 cost = 1 for i in range(1,...
N = int(eval(input())) arr = sorted([list(map(int, input().split())) for _ in range(N)]) cnt = {} for i in range(N): for j in range(i+1,N): pq = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1]) cnt.setdefault(pq, 0) cnt[pq] += 1 print((1 if cnt == {} else N - max(cnt.values())))
p03006
from collections import Counter import math N = int(eval(input())) x,y = list(map(int, input().split())) dis_list = [[x,y]] for i in range(N-1): x , y = list(map(int,input().split())) for j in range(len(dis_list)): x = abs(x- dis_list[j][0]) y = abs(y-dis_list[j][1]) dis_list.append([x,y]) dis_list =...
import math N = int(eval(input())) s_dict = {} cood_list=[] ans = 0 for i in range(N): a,b = list(map(int,input().split())) for j in range(len(cood_list)): p = a - cood_list[j][0] q = b - cood_list[j][1] if 0 > p: p = -p q = -q elif p == 0: ...
p03006
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int,input().split())) def L(): return list(in...
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int,input().split())) def L(): return list(in...
p03006
def cal(dx,dy): cnt=0 for x in s: flag=False for y in s: if(x==y): continue if(x[0]+dx==y[0] and x[1]+dy==y[1]): flag=True if(flag==False): cnt+=1 return cnt n=int(eval(input())) s=[list(map(int,input(...
N = int(eval(input())) coodinates = [list(map(int, input().split())) for _ in range(N)] flag = True if N == 1: print((1)) flag = False if flag: # p, qを求める d = {} # [p, q]をkeyにもつ辞書 cnt=0 for a in coodinates: for b in coodinates: if a == b: c...
p03006
N = int(eval(input())) x, y = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) class UnionFindTree: def __init__(self, n): self.p = [i for i in range(n + 1)] self.r = [0 for _ in range(n + 1)] def find(self, x): if self.p[x] != ...
N = int(eval(input())) x, y = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) class UnionFindTree: def __init__(self, n): self.p = [i for i in range(n + 1)] self.r = [0 for _ in range(n + 1)] def find(self, x): if self.p[x] != ...
p03006
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator i...
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator i...
p03006
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for i in range(n): for j in range(n): if i==j: continue xi, yi = xy[i] xj, yj = xy[j] pq.append((xi - xj, yi - yj)) ans = 1e9 if n>1 else 1 for p, q in pq: cost = 0 for x, y in xy: if (x + p, y + q) in...
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for i in range(n): for j in range(i+1,n): if i==j: continue xi, yi = xy[i] xj, yj = xy[j] pq.append((xi - xj, yi - yj)) ans = n for p, q in pq: cost = 0 for x, y in xy: if (x + p, y + q) in xy: pas...
p03006
import sys def main(): N = int(eval(input())) xy = [[int(e) for e in input().split()] for _ in range(N)] if N == 1: print((1)) return else: d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j] items = list(set(d_list)) s = 1 ...
N = int(eval(input())) if N == 1: print((1)) exit() xy = [tuple(int(e) for e in input().split()) for _ in range(N)] d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j] items = list(set(d_list)) s = 1 for item in items: c = d_list.count(item) if c > s: s = c print(...
p03006
N = int(eval(input())) if N == 1: print((1)) exit() xy = [tuple(int(e) for e in input().split()) for _ in range(N)] d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j] items = list(set(d_list)) s = 1 for item in items: c = d_list.count(item) if c > s: s = c print(...
N = int(eval(input())) if N == 1: print((1)) else: xy = [tuple(int(e) for e in input().split()) for _ in range(N)] xy.sort() d = {} for i in range(N): for j in range(i + 1, N): p = xy[i][0] - xy[j][0] q = xy[i][1] - xy[j][1] if (p, q) in d: ...
p03006
N = int(eval(input())) d = {} x = [0] * N y = [0] * N from collections import defaultdict for i in range(N): x[i], y[i] = list(map(int, input().split())) pqs = [] for i in range(N): for j in range(N): if i == j: continue dx = x[i] - x[j] dy = y[i] - y[j] ...
N = int(eval(input())) xys = [] from collections import defaultdict for i in range(N): x, y = list(map(int, input().split())) xys.append((x, y)) pqs = [] for xy1 in xys: x1, y1 = xy1 for xy2 in xys: x2, y2 = xy2 dx = x1 - x2 dy = y1 - y2 if dx != 0 or...
p03006
n = int(eval(input())) x = [] y = [] for _ in range(n): line = list(map(int, input().split())) x.append(line[0]) y.append(line[1]) if n >= 2: slope = [] for i in range(n): for j in range(n): if i != j: X = x[j] - x[i] Y = y[j] - y[i] ...
n = int(eval(input())) x = [] y = [] for _ in range(n): line = list(map(int, input().split())) x.append(line[0]) y.append(line[1]) if n >= 2: slope = [] for i in range(n): for j in range(i+1, n): X = x[j] - x[i] Y = y[j] - y[i] if X != 0: ...
p03006
import sys input = sys.stdin.readline ''' allinputs = iter(input().splitlines()) input = lambda : next(allinputs) #''' N = int(eval(input())) x, y = [0] * N, [0] * N for i in range(N): x[i], y[i] = list(map(int, input().split())) pq = [] m = 0 if N == 1: print((1)) else: for i in range(N): f...
import sys input = sys.stdin.readline ''' allinputs = iter(input().splitlines()) input = lambda : next(allinputs) #''' N = int(eval(input())) x, y = [0] * N, [0] * N for i in range(N): x[i], y[i] = list(map(int, input().split())) pq = [] m = 1 if N == 1: print((1)) else: for i in range(N): f...
p03006
import itertools N = int(eval(input())) balls = [] for i in range(N): x, y = list(map(int, input().split(' '))) balls.append((x,y)) if N == 1: print("1") exit() ans = 100 for l in list(itertools.permutations(balls)): dic = {} px = l[0][0] py = l[0][1] t_max = 1 ...
N = int(eval(input())) balls = [] for i in range(N): x, y = list(map(int, input().split(' '))) balls.append((x,y)) if N == 1: print("1") exit() dic = {} for i in range(N): for j in range(i+1,N): dx = balls[j][0] - balls[i][0] dy = balls[j][1] - balls[i][1] if...
p03006
# #    ⋀_⋀  #   (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys input=sys.stdin.readline from math import floor,ceil,sqrt,factorial,log #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict from iter...
# #    ⋀_⋀  #   (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys input=sys.stdin.readline from math import floor,ceil,sqrt,factorial,log #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict from iter...
p03006
# #    ⋀_⋀  #   (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys input=sys.stdin.readline from math import floor,ceil,sqrt,factorial,log #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict from iter...
# #    ⋀_⋀  #   (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys input=sys.stdin.readline from math import floor,ceil,sqrt,factorial,log #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict from iter...
p03006
import sys def input(): return sys.stdin.readline().rstrip() from itertools import combinations from collections import Counter def main(): n=int(eval(input())) if n==1: print((1)) sys.exit() XY=[tuple(map(int,input().split())) for i in range(n)] XY.sort() lis=list(combina...
import sys def input(): return sys.stdin.readline().rstrip() from itertools import combinations from collections import Counter def main(): n=int(eval(input())) if n==1: print((1)) sys.exit() XY=[tuple(map(int,input().split())) for i in range(n)] XY.sort() PQ=[] for i...
p03006
from collections import Counter N=int(eval(input())) balls=[tuple(map(int, input().split())) for _ in range(N)] #2ボールの相対座標をぜんぶ調べる R=[(x[0]-y[0],x[1]-y[1]) for x in balls for y in balls] C=Counter(R).most_common() #いちばん多い相対座標を(p,q)とする #C[0]は(0,0)なので除外 if len(C)<=1: print(N) else: print((N-(C[1][1]...
from collections import Counter N=int(eval(input())) B=[tuple(map(int, input().split())) for _ in range(N)] R=[(x[0]-y[0],x[1]-y[1]) for x in B for y in B if x!=y] C=Counter(R).most_common(1) print((N-C[0][1] if C else N))
p03006
#!/usr/bin/env python3 from itertools import product n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] xy.sort(key=lambda x: (x[0], x[1])) ps = set() for i, j in product(list(range(n)), list(range(n))): if i >= j: continue ps.add(xy[j][0] - xy[i][0]) qs = set() ...
#!/usr/bin/env python3 from itertools import product n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] m = 0 xy.sort(key=lambda x: (x[0], x[1])) for l in range(n - 1): for r in range(l + 1, n): p = xy[r][0] - xy[l][0] q = xy[r][1] - xy[l][1] c = 0 ...
p03006
#!/usr/bin/env python3 from itertools import product n = int(eval(input())) x = [None] * n y = [None] * n for i in range(n): x[i], y[i] = list(map(int, input().split())) ps = set() qs = set() for s, t in product(list(range(n)), repeat=2): if s == t: continue ps.add(x[t] - x[s]) qs...
#!/usr/bin/env python3 from itertools import product n = int(eval(input())) x = [None] * n y = [None] * n for i in range(n): x[i], y[i] = list(map(int, input().split())) m = 0 for i, j in product(list(range(n)), repeat=2): if i == j: continue p = x[j] - x[i] q = y[j] - y[i] c ...
p03006
n = int(eval(input())) points = [list(map(int, input().split(" "))) for _ in range(n)] X = 0 Y = 1 ans = 10 ** 14 for i in range(n): for j in range(n): if i == j: continue x1, y1 = points[i] x2, y2 = points[j] p = x1 - x2 q = y1 - y2 cost = ...
n = int(eval(input())) points = [list(map(int, input().split(" "))) for _ in range(n)] X = 0 Y = 1 ans = 10 ** 14 if n == 1: ans = 1 else: for i in range(n): for j in range(n): if i == j: continue x1, y1 = points[i] x2, y2 = points[j] ...
p03006
from collections import defaultdict inpl = lambda: list(map(int,input().split())) N = int(eval(input())) xy = [] field = defaultdict(int) for _ in range(N): x, y = inpl() xy.append((x,y)) field[(x,y)] = 1 xy.sort() pq = set() for i in range(N): for j in range(i+1,N): x1, y1 = xy...
from collections import defaultdict inpl = lambda: list(map(int,input().split())) N = int(eval(input())) xy = [] for _ in range(N): x, y = inpl() xy.append((x,y)) xy.sort() edges = defaultdict(int) edges[(0,0)] = 0 for i in range(N): for j in range(i+1,N): x1, y1 = xy[i] x2...
p03006
ans=float("INF") n=int(eval(input())) l=[list(map(int,input().split())) for i in range(n)] if n==1:print((1));exit() for i in range(n): for j in range(n): if i==j:continue p,q=l[i][0]-l[j][0],l[i][1]-l[j][1] ret=0 pre=sorted(l,reverse=1,key=lambda x:p*x[0]+q*x[1]) w...
ans=float("INF") n=int(eval(input())) l=[list(map(int,input().split())) for i in range(n)] for i in range(n): for j in range(n): p,q=l[i][0]-l[j][0],l[i][1]-l[j][1] ret=0 pre=sorted(l,reverse=1,key=lambda x:p*x[0]+q*x[1]) while pre: ret+=1 x,y=pr...
p03006
def gcd(a, b): if b < 0: return gcd(a, -b) if b == 0: return a else: return gcd(b, a%b) def solve(): N = int(input()) xy = [None] * N for i in range(N): xi, yi = [int(_) for _ in input().split()] xy[i] = (xi, yi) xy.sort(key = lambda x: ...
def solve2(): N = int(input()) xy = [None] * N for i in range(N): xi, yi = [int(_) for _ in input().split()] xy[i] = (xi, yi) if N == 1: print(N) return xy.sort() dist = [] for i in range(N): for j in range(i+1, N): p = xy[j]...
p03006
import itertools import collections n=int(eval(input())) s=[list(map(int, input().split())) for i in range(n)] ans=[] x=list(itertools.permutations(s)) if n==1: print(n) else: v=[] r=[] for i in range(len(x)): e=[] v=[] for j in range(n-1): a=x[i][j][...
n=int(eval(input())) s=[list(map(int, input().split())) for i in range(n)] x=[] if n==1: print((1)) exit(0) for i in range(n): for j in range(n): if i==j: continue t=(s[i][0]-s[j][0],s[i][1]-s[j][1]) x.append(t) ans = [x.count(x[i]) for i in range...
p03006
n=int(eval(input())) s=[list(map(int, input().split())) for i in range(n)] x=[] if n==1: print((1)) exit(0) for i in range(n): for j in range(n): if i==j: continue t=(s[i][0]-s[j][0],s[i][1]-s[j][1]) x.append(t) ans = [x.count(x[i]) for i in range...
n=int(eval(input())) s=[list(map(int, input().split())) for i in range(n)] x=[] if n==1: print((1)) exit(0) for i in range(n): for j in range(n): if i==j: continue t=(s[i][0]-s[j][0],s[i][1]-s[j][1]) x.append(t) ans = [x.count(i) for i in set(x)] ...
p03006
N = int(eval(input())) ratio = [tuple(map(int, input().split())) for _ in range(N)] t,a = 1,1 for nt,na in ratio: if nt<t or na<a: r = max((t-1)//nt+1, (a-1)//na+1) nt *= r na *= r t,a = nt,na #print(t, a) print((t+a))
N = int(eval(input())) ratio = [tuple(map(int, input().split())) for _ in range(N)] t,a = 1,1 for nt,na in ratio: if nt<t or na<a: r = max(-(-t//nt), -(-a//na)) nt *= r na *= r t,a = nt,na #print(t, a) print((t+a))
p03964
N = int(eval(input())) pt = pa = 0 for _ in range(N): t,a = list(map(int,input().split())) if pt == 0:pt,pa = t,a else: if (pt <= t) and (pa <= a):pt,pa = t,a else: i = 2 while True: if (pt <= t*i) and (pa <= a*i): pt,pa ...
N = int(eval(input())) pt = pa = 0 for _ in range(N): t,a = list(map(int,input().split())) if pt == 0: pt,pa = t,a else: #print(pt,pa,t,a) if (pt <= t) and (pa <= a): pt,pa = t,a else: ''' i = 2 while True: ...
p03964
import math n=int(eval(input())) t,a=1,1 for i in range(n): ti,ai=list(map(int,input().split())) m=max(math.ceil(t/ti), math.ceil(a/ai)) while t > ti*m or a > ai*m: m+=1 while t <= ti*(m-1) and a <= ai*(m-1): m-=1 t,a=ti*m,ai*m print((t+a))
n=int(eval(input())) t,a=1,1 for i in range(n): ti,ai=list(map(int,input().split())) m=max((t+ti-1)//ti, (a+ai-1)//ai) t,a=ti*m,ai*m print((t+a))
p03964
# coding: utf-8 # hello worldと表示する import sys #import numpy input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_rig...
# coding: utf-8 # hello worldと表示する import sys #import numpy input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_rig...
p03964
n = int(eval(input())) ta = [] for i in range(n): ta.append([int(i) for i in input().split()]) for i in range(1, n): tmp = ta[i][:] while ta[i-1][0] > ta[i][0] or ta[i-1][1] > ta[i][1]: ta[i][0] += tmp[0] ta[i][1] += tmp[1] print((ta[-1][0] + ta[-1][1]))
def round_up(x, y): res = x // y if x % y != 0: res += 1 return res n = int(eval(input())) ta = [] for i in range(n): ta.append([int(i) for i in input().split()]) for i in range(1, n): if ta[i-1][0] > ta[i][0] or ta[i-1][1] > ta[i][1]: multi = max( round_u...
p03964
n = int(eval(input())) T=[] A=[] for i in range(n): t,a=list(map(int,input().split())) T.append(t) A.append(a) #比に対する掛け率 kake = 1 sum_tmp = 0 t_tmp = 0 a_tmp = 0 for i in range(n): kake = 1 #i+1回目の合計がi回目の合計より大きくなる最小の掛け率を計算する while kake*(T[i]+A[i]) < sum_tmp or kake*T[i] < t_...
def main(): n = int(eval(input())) T=[] A=[] for i in range(n): t,a=list(map(int,input().split())) T.append(t) A.append(a) #比に対する掛け率 kake = 1 sum_tmp = 0 t_tmp = 0 a_tmp = 0 for i in range(n): if i == 0: kake = 1 ...
p03964
n=int(eval(input())) t,a=list(map(int,input().split())) for i in range(1,n): c,d=list(map(int,input().split())) times=min(t//c,a//d) e,f=c*times,d*times while(e<t or f<a): #print(e,f) times+=1 e,f=c*times,d*times #print(e,f) t,a=e,f print((t+a))
n=int(eval(input())) t,a=list(map(int,input().split())) for i in range(1,n): c,d=list(map(int,input().split())) if(t/c>a/d): if(t%c==0):times=t//c else:times=t//c+1 else: if(a%d==0):times=a//d else:times=a//d+1 #print(times) t,a=c*times,d*times #print(t,a) print((t+a))
p03964
import sys sys.setrecursionlimit(500000) def f(a,c,b,d): if a >= A and b >=B : return a,b return f(a+c,c,b+d,d) n = int(eval(input())) a = [list(map(int,input().split()))for _ in range(n)] A,B = a[0][0],a[0][1] for i in range(1,n): A,B = f(a[i][0],a[i][0],a[i][1],a[i][1]) print((A+B))
n = int(eval(input())) a = [list(map(int,input().split()))for _ in range(n)] A,B = a[0][0],a[0][1] for i in range(1,n): C = max([1,-(-A//a[i][0]),-(-B//a[i][1])]) A = a[i][0]*C B = a[i][1]*C print((A+B))
p03964
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, ...
N = int(eval(input())) a, b = 1, 1 for i in range(N): x, y = list(map(int, input().split())) n = max((a + x - 1) // x, (b + y - 1) // y) a = n * x b = n * y print((a + b))
p03964
import math from fractions import Fraction n = int(eval(input())) pt = [0] * n pa = [0] * n for i in range(n): t, a = list(map(int, input().split())) if i == 0: pt[0] = t pa[0] = a else: tmp = math.ceil(max(Fraction(pt[i-1], t), Fraction(pa[i-1], a))) pt[i]=tmp*t pa[i]=tmp*a ...
import math from fractions import Fraction N = int(eval(input())) pt = [0] * N pa = [0] * N for i in range(N): t, a = list(map(int, input().split())) if i == 0: pt[i] = t pa[i] = a else: #最小単位というかなんというか n = max(math.ceil(Fraction(pt[i-1],t)), math.ceil(Fractio...
p03964
n = int(eval(input())) Ratio = [list(map(int,input().split())) for _ in range(n)] t,a = Ratio[0][0],Ratio[0][1] for i in range(1,n): count = 1 while True: if Ratio[i][0]*count >= t and Ratio[i][1]*count >= a: t,a = Ratio[i][0]*count,Ratio[i][1]*count break else...
n = int(eval(input())) Ratio = [list(map(int,input().split())) for _ in range(n)] t,a = 1,1 for i in range(n): x = max((t+Ratio[i][0]-1)//Ratio[i][0],(a+Ratio[i][1]-1)//Ratio[i][1]) t,a = Ratio[i][0]*x,Ratio[i][1]*x print((int(t+a)))
p03964
n = int(eval(input())) Ratio = [list(map(int,input().split())) for _ in range(n)] t,a = 1,1 for i in range(n): x = max((t+Ratio[i][0]-1)//Ratio[i][0],(a+Ratio[i][1]-1)//Ratio[i][1]) t,a = Ratio[i][0]*x,Ratio[i][1]*x print((int(t+a)))
n = int(eval(input())) Ratio = [list(map(int,input().split())) for _ in range(n)] t,a = Ratio[0][0],Ratio[0][1] for i in range(1,n): x = max((t+Ratio[i][0]-1)//Ratio[i][0],(a+Ratio[i][1]-1)//Ratio[i][1]) t,a = Ratio[i][0]*x,Ratio[i][1]*x print((int(t+a)))
p03964
from math import ceil n = int(eval(input())) data = [] for i in range(n): elems = input().split() t, a = int(elems[0]), int(elems[1]) data.append((t, a)) t, a = data[0] def calcn(r, x): n = 1 while n * r < x: n += 1 return n for i in range(1, n): rt, ra = data[i...
from math import ceil n = int(eval(input())) data = [] for i in range(n): elems = input().split() t, a = int(elems[0]), int(elems[1]) data.append((t, a)) t, a = data[0] def calcn(r, x): n = int(x / r) while n * r > x: n -= 1 while n * r < x: n += 1 return ...
p03964
num = int(eval(input())) arr = [list(map(int, input().split())) for i in range(num)] ans = [[arr[0][0], arr[0][1]]] for i in range(num-1): ans.append([arr[i+1][0], arr[i+1][1]]) while ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]: ans[i+1][0] += arr[i+1][0] ans[i+1][1] += arr[i+1][...
def divceil(a, b): if a%b == 0: return a//b else: return a//b + 1 num = int(eval(input())) arr = [list(map(int, input().split())) for i in range(num)] t = 1 a = 1 r = 0 for i in range(num): r = max(divceil(t, arr[i][0]), divceil(a, arr[i][1])) t = arr[i][0] * max(r, 1) ...
p03964
#!/usr/bin/env python3 import math def main(): N = int(eval(input())) T, A = list(map(int, input().split())) for _ in range(N-1): t, a = list(map(int, input().split())) tmpT, tmpA = t,a while 1: if T <= tmpT and A <= tmpA: T,A = tmpT, tmpA ...
#!/usr/bin/env python3 import math def main(): N = int(eval(input())) T, A = list(map(int, input().split())) for _ in range(N-1): t, a = list(map(int, input().split())) # 桁が大きいとfloatの誤差が生じて正しく判定できない # 負の数にして切り捨てにすればceilと同じ挙動になる x = max(-(-T//t), -(-A//a)) ...
p03964
import sys input = sys.stdin.readline def main(): N = int(eval(input())) TA = [[int(x) for x in input().split()] for _ in range(N)] now = TA[0] for t, a in TA[1:]: i = 1 while now[0] > t * i or now[1] > a * i: i += 1 now[0] = t * i now[1] = ...
import sys input = sys.stdin.readline def main(): N = int(eval(input())) TA = [[int(x) for x in input().split()] for _ in range(N)] now = TA[0] for t, a in TA[1:]: i = max(now[0] //t , now[1] // a) while now[0] > t * i or now[1] > a * i: i += 1 now[0...
p03964
#!/usr/bin/env python3 n=int(eval(input())) x,y=list(map(int, input().split())) for i in range(n-1): t,a=list(map(int, input().split())) if (x<=t and y<=a): x=t y=a else: tmp=1 while 1: if x<=t*tmp and y<=a*tmp: x=t*tmp ...
#!/usr/bin/env python3 n=int(eval(input())) x,y=list(map(int, input().split())) for i in range(n-1): t,a=list(map(int, input().split())) if (x<=t and y<=a): x=t y=a else: tmp=0 k=max(x//t,y//a) tk=t*k ak=a*k while 1: # prin...
p03964
# -*- coding: utf-8 -*- N = int(eval(input())) rates = [tuple(map(int, input().split())) for _ in range(N)] now = nex = 1 for i in range(0, N - 1): nex = 1 while True: if now * rates[i][0] <= nex * rates[i + 1][0] and now * rates[i][1] <= nex * rates[i + 1][1]: break nex...
# -*- coding: utf-8 -*- N = int(eval(input())) rates = [tuple(map(int, input().split())) for _ in range(N)] a, b = 1, 1 n = 1 for i in range(N): n = max(-((-a) // rates[i][0]), -((-b) // rates[i][1])) a = rates[i][0] * n b = rates[i][1] * n print((a + b))
p03964
n=int(eval(input())) f=lambda:list(map(int,input().split())) a,b=f() for _ in range(1,n): s,t=f(); x=y=0 while x<a or y<b: x+=s; y+=t a,b=x,y print((a+b))
n=int(eval(input())) f=lambda:list(map(int,input().split())) a,b=f() for _ in range(1,n): c,d=f() t=max(1,0--a//c,0--b//d) a,b=c*t,d*t print((a+b))
p03964
n = int(eval(input())) a = [tuple(map(int, input().split())) for _ in range(n)] s, t = a[0][0], a[0][1] for i in range(1, n): if a[i][0] < a[i][1]: j = 1 while True: if a[i][0]*j < s or a[i][1]*j < t: pass else: s = a[i][0]*j ...
n = int(eval(input())) a = [tuple(map(int, input().split())) for _ in range(n)] s, t = 1, 1 for i in range(0, n): j = max((s+a[i][0]-1)//a[i][0], (t+a[i][1]-1)//a[i][1]) s, t = a[i][0]*j, a[i][1]*j print((s+t))
p03964
import fractions # input N = int(eval(input())) TA = [list(map(int, input().split())) for _ in range(N)] T = 1 # 高橋くんの最小得票数 A = 1 # 青木くんの最小得票数 ans = 2 for i in range(0, N): T_tmp = TA[i][0] A_tmp = TA[i][1] while T_tmp < T or A_tmp < A: T_tmp += TA[i][0] A_tmp += TA[i][1]...
import math # input N = int(eval(input())) TA = [list(map(int, input().split())) for _ in range(N)] T = 1 # 高橋くんの最小得票数 A = 1 # 青木くんの最小得票数 ans = 2 for i in range(0, N): #m = max(math.ceil(T / TA[i][0]), math.ceil(A / TA[i][1])) m = max(-(-T // TA[i][0]), -(-A // TA[i][1])) T = TA[i][0] * m ...
p03964
n = int(eval(input())) a, b = list(map(int,input().split())) for i in range(n-1): s,t = list(map(int,input().split())) while float(a/b) != float(s/t): if float(a/b) > float(s/t): b += 1 elif float(a/b) < float(s/t): a += 1 print((a+b))
from math import ceil n = int(eval(input())) a = 1 b = 1 for i in range(n): s,t = list(map(int,input().split())) #x = max([ceil(a/s), ceil(b/t)]) x = max((a+s-1)//s, (b+t-1)//t) a = x*s b = x*t print((a+b))
p03964
n = int(eval(input())) mt = 0 ma = 0 for i in range(n): t , a = list(map(int, input().split())) if t>=mt and a>=ma: mt = t ma = a elif t<mt or a<ma: k=1 while t*k<mt or a*k<ma: k+=1 mt=t*k ma=a*k print((mt+ma))
n = int(eval(input())) mt = 0 ma = 0 for i in range(n): t , a = list(map(int, input().split())) if t>=mt and a>=ma: mt = t ma = a elif t<mt or a<ma: k1 = mt//t k2 = ma//a k=max(k1,k2) while t*k < mt or a*k <ma: k+=1 mt=t*k ...
p03964
n = int(eval(input())) votes = [list(map(int, input().split())) for _ in range(n)] curr_a, curr_b = 0, 0 for v1, v2 in votes: a, b = v1, v2 i = min(curr_a // v1, curr_b // v2) while a < curr_a or b < curr_b: a = v1 * i b = v2 * i i += 1 curr_a, curr_b = a, b ...
n = int(eval(input())) votes = [list(map(int, input().split())) for _ in range(n)] curr_a, curr_b = 0, 0 for v1, v2 in votes: a, b = v1, v2 i = max(curr_a // v1, curr_b // v2) while a < curr_a or b < curr_b: a = v1 * i b = v2 * i i += 1 curr_a, curr_b = a, b ...
p03964
n = int(eval(input())) x = y = 1 for i in range(n): t, a = list(map(int, input().split())) k = 1 while True: if t*k >= x and a*k >= y: x, y = t*k, a*k break k += 1 print((x+y))
n = int(eval(input())) x = y = 1 for i in range(n): t, a = list(map(int, input().split())) bx = 1 if x % t else 0 by = 1 if y % a else 0 k = max(x//t + bx, y//a + by) x, y = t*k, a*k print((x+y))
p03964