code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
data_num = int(input()) nums = list(map(int, input().split(" "))) cnt = 0 for i in range(data_num): min_idx = i for j in range(i, data_num): if nums[j] < nums[min_idx]: min_idx = j if i != min_idx: nums[i], nums[min_idx] = nums[min_idx], nums[i] cnt += 1 print(" ".join(map(str,nums)) + "\n" + str(cnt))
def selectSort(A, N): cnt = 0 for i in range(0,N): mina = A[i] k = 0 for j in range(i+1,N): if int(mina) > int(A[j]): mina = A[j] k = j if int(A[i]) > int(mina): swap = A[i] A[i] = mina A[k] = swap cnt = cnt + 1 for t in range(0,N): if t < N-1: print(A[t], end=" ") else: print(A[t]) print(cnt) if __name__ == "__main__": N = int(input()) A = (input()).split() selectSort(A,N)
1
19,986,805,780
null
15
15
N, X, M = map(int, input().split()) A = X ans = A visited = [0]*M tmp = [] i = 2 while i <= N: A = (A*A) % M if visited[A] == 0: visited[A] = i tmp.append(A) ans += A else: ans += A loop_length = i-visited[A] loop_val = tmp[-1*loop_length:] loop_count = (N-i) // loop_length ans += sum(loop_val) * loop_count visited = [0]*M i += loop_length * loop_count i += 1 print(ans)
n=int(input()) l=[] ll=[] for i in range(n): x,y=map(int,input().split()) l.append(x+y) ll.append(x-y) l.sort() ll.sort() print(max(l[-1]-l[0],ll[-1]-ll[0]))
0
null
3,118,253,496,832
75
80
S = int(input()) kMod = 10**9+7 memo = {} def count(n): if n < 3: return 0 if n in memo: return memo[n] ans = 1 for i in range(3, n+1): ans += count(n-i) ans %= kMod memo[n] = ans return ans print(count(S))
import math N = int(input()) n = math.ceil(N/1000) print(1000*n-N)
0
null
5,872,229,396,330
79
108
import sys input = sys.stdin.readline N = int(input()) musics = [] for _ in range(N): s, t = input().split() musics.append((s.strip(), int(t))) X = input().strip() ans = 0 flag = False for s, t in musics: if flag: ans += t if s == X: flag = True print(ans)
X = int(input()) G = 100 after_year = 0 while X > G: G += G // 100 after_year += 1 print(after_year)
0
null
61,852,339,966,220
243
159
a, b, c = [int(i) for i in input().rstrip().split(" ")] cnt = 0 for i in range(a, b+1): if c % i == 0: cnt += 1 print(cnt)
#!usr/bin/env python3 def string_two_numbers_spliter(): a, b, c = [int(i) for i in input().split()] return a, b, c def count_nums_of_divisors_of_c_in_a_and_b(a, b, c): count = 0 for i in range(1, c+1): if (c % i == 0): if i >= a and i <= b: count += 1 return count def main(): a, b, c = string_two_numbers_spliter() print(count_nums_of_divisors_of_c_in_a_and_b(a, b, c)) if __name__ == '__main__': main()
1
565,383,522,308
null
44
44
input() cnt = 0 x = "" for s in input(): if x != s: cnt += 1 x = s print(cnt)
def abc143c_slimes(): n = int(input()) s = input() cnt = 1 for i in range(n-1): if s[i] != s[i+1]: cnt += 1 print(cnt) abc143c_slimes()
1
170,049,632,000,820
null
293
293
from math import ceil n=int(input()) s=100000 for i in range(n): s +=(s*0.05) s=int(int(ceil(s/1000)*1000)) print(s)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, K = mapint() mod = 10**9+7 ans = 0 for i in range(K, N+2): ans += (N+(N-i+1))*i//2-(i*(i-1)//2)+1 ans %= mod print(ans)
0
null
16,603,366,140,764
6
170
ST = list(map(str, input().split())) print(ST[1]+ST[0])
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) INF = float('inf') # from math import ceil, floor, log2 # from collections import deque # from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # from numpy import cumsum # accumulate def solve(): A, B, C, K = MI() na = min(A, K) K -= na nb = min(B, K) K -= nb nc = min(C, K) print(na - nc) if __name__ == '__main__': solve()
0
null
62,093,952,813,860
248
148
n = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) for p in range(3): print(sum(abs(x[i] - y[i]) ** (p+1) for i in range(n)) ** (1/(p+1))) print(max(abs(x[i] - y[i]) for i in range(n)))
s,t=map(str,input('').split(' ')) a,b=map(int,input('').split(' ')) u=input('') if u==s: a=a-1 elif u==t: b=b-1 print(str(a)+' '+str(b))
0
null
35,903,400,769,600
32
220
MOD = 10**9+7 MAX = 1000010 finv = [0] * MAX inv = [0] * MAX def COMinit(): finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, MAX): inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def COM(n, k): res = 1 for i in range(k): res = res * (n-i) % MOD return res * finv[k] % MOD x, y = map(int, input().split()) if (x+y)%3 != 0: ans = 0 else: s, t = (-x+2*y)//3, (2*x-y)//3 if s < 0 or t < 0: ans = 0 else: COMinit() ans = COM((s+t), s) print(ans)
from collections import Counter import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) minus = Counter([i-a[i] for i in range(n)]) plus = Counter([i+a[i] for i in range(n)]) cnt = 0 for i in minus: if i in plus: cnt += minus[i] * plus[i] print(cnt)
0
null
88,195,841,452,678
281
157
import sys import math import fractions import bisect import queue import heapq from collections import deque sys.setrecursionlimit(4100000) MOD = int(1e9+7) PI = 3.14159265358979323846264338327950288 INF = 1e18 ''' 1行のint N, K = map(int, input().split()) 1行のstring S, T = input().split() 1行の整数配列 P = list(map(int,input().split())) 改行あり x = [] y = [] for i in range(N): x1,y1=[int(i) for i in input().split()] x.append(x1) y.append(y1) N行M列の初期化 dp = [[INF] * M for i in range(N)] ''' N, D, A = map(int, input().split()) XH = [] for i in range(N): x1,y1=[int(i) for i in input().split()] XH.append([x1, y1]) def counting(hp): if hp < 0: return 0 return hp//A + int(hp%A!=0) XH.sort() bombs = deque([]) # 有効な爆弾の威力と範囲を保存する power = 0 # 有効な爆弾の威力の合計 ans = 0 for i in range(N): # 使えない爆弾を捨てる while len(bombs)>0 and bombs[0][0] < XH[i][0]: power -= bombs.popleft()[1] # パワーの不足分の爆弾 add = counting(XH[i][1]-power) ans += add # 追加した爆弾をキューに加える bombs.append((XH[i][0] + 2*D, add*A)) power += add*A print(ans) """ ATTENTION: Pythonで間に合うか?? <目安> 文字列結合、再帰関数を含む→Python 上を含まず時間が不安→PyPy3 """
import sys from math import gcd n = int(input()) a = list(map(int, input().split())) b = gcd(a[0], a[1]) for i in range(2, n): b = gcd(b, a[i]) if b != 1: print('not coprime') else: c = set() num = max(a) m = 1000000 vals = [0]*(m+1) for i in range(2, m): if vals[i] != 0: continue j = 1 while True: t = i*j if t > m: break if vals[t] == 0: vals[t] = i j += 1 d = dict() for i in a: p = i while p != 1: if p in d: print("setwise coprime") sys.exit() d[p] = 1 p = int(p/vals[p]) print("pairwise coprime")
0
null
43,428,996,665,632
230
85
def main(): s = (input()) l = ['x' for i in range(len(s))] print(''.join(l)) main()
s = len(input()) print("x" * s)
1
72,898,181,114,760
null
221
221
import math import itertools from collections import deque import bisect import heapq def IN(): return int(input()) def sIN(): return input() def lIN(): return list(input()) def MAP(): return map(int,input().split()) def LMAP(): return list(map(int,input().split())) def TATE(n): return [input() for i in range(n)] ans = 0 def bfs(sx,sy): d = [[-1] * w for i in range(h)] MAX = 0 dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] que = deque([]) que.append((sx, sy))#スタート座標の記録 d[sx][sy] = 0#スタートからスタートへの最短距離は0 while que:#中身がなくなるまで p = que.popleft() for m in range(4):#現在地から4方向の移動を考える nx = p[0] + dx[m] ny = p[1] + dy[m] if 0 <= nx < h and 0 <= ny < w: if maze[nx][ny] != "#" and d[nx][ny] == -1: que.append((nx, ny))#↑格子点からでない&壁でない&まだ通ってない d[nx][ny] = d[p[0]][p[1]] + 1 for k in range(h): MAX = max(max(d[k]),MAX) return MAX h, w = map(int, input().split()) maze = [lIN() for i in range(h)] for i in range(h):#sx座標指定0~h-1 for j in range(w):#sy座標指定0~w-1 if maze[i][j] == '.': ans = max(bfs(i,j),ans) print(ans)
from collections import deque from copy import deepcopy # 初期入力 import sys input = sys.stdin.readline H,W = (int(i) for i in input().split()) map_initial =[["#"]*(W+2) for i in range(H+2)] #周囲を壁にするため+2 for h in range(1,H+1): map_initial[h] =["#"] +list(input().strip()) +["#"] def BSF(x,y): dist =0 map =deepcopy(map_initial) if map[x][y] =="#": return dist dq =set() dq.add((x,y)) dq_sarch =set() while len(dq) >0: h,w =dq.pop() map[h][w] ="#" #通り済を壁にする if map[h+1][w]==".": dq_sarch.add((h+1,w)) if map[h-1][w]==".": dq_sarch.add((h-1,w)) if map[h][w+1]==".": dq_sarch.add((h,w+1)) if map[h][w-1]==".": dq_sarch.add((h,w-1)) if len(dq)==0: dq =deepcopy(dq_sarch) dq_sarch.clear() dist +=1 #print(h,w,dist,end="\t") return dist-1 #スタート位置を全探索し、最長距離を探す dist_all =[] for i in range(1,H+1): for j in range(1,W+1): dist_all.append(BSF(i,j) ) print(max(dist_all))
1
94,868,118,753,340
null
241
241
""" 一回以上わるとき、KはNの約数なので、Nの約数を全通り試して1に持っていけるかどうかを検証する。 Nを一回も割らずに1まで持っていけるようなKは、N-1の約数の数だけ存在する。 それぞれカウントすればよい """ N = int(input()) ans = 0 if N == 2: print(1) exit() divisers = [N] d = 2 while d*d < N: if N % d == 0: divisers.append(d) divisers.append(N//d) d += 1 if d**2 == N: divisers.append(d) for d in divisers: dummyN = N while dummyN%d == 0: dummyN //= d if dummyN % d == 1: ans += 1 N -= 1 divisers = [N] d = 2 while d*d < N: if N % d == 0: divisers.append(d) divisers.append(N//d) d += 1 if d**2 == N: divisers.append(d) ans += len(divisers) print(ans)
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) mod = 10**9+7 # mod = 998244353 dir = [(-1,0),(0,-1),(1,0),(0,1)] alp = "abcdefghijklmnopqrstuvwxyz" INF = 1<<32-1 # INF = 10**18 def main(): s = input() if s[-1] == "s": print(s+"es") else: print(s+"s") return None if __name__ == '__main__': main()
0
null
21,946,126,708,078
183
71
n=int(input()) def f(i): if n%i==0: return n//i-1 else: return n//i sum=0 for i in range(1,n): sum+=f(i) print(sum)
def get_sieve_of_eratosthenes(n): if not isinstance(n, int): raise TypeError("n is int-type.") if n < 2: raise ValueError("n is more than 2") data = [i for i in range(2, n + 1)] for d in data: data = [x for x in data if (x == d or x % d != 0)] return data p_list = get_sieve_of_eratosthenes(10**3) def factorization_counta(n): arr = [] temp = n for i in p_list: if i * i > n: break elif temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append(cnt) if temp != 1: arr.append(1) if arr == []: arr.append(1) return arr def main(): N = int(input()) ans = 1 for c in range(2, N): p = factorization_counta(c) tmp = 1 for v in p: tmp *= (v + 1) ans += tmp return ans if __name__ == '__main__': print(main())
1
2,614,509,760,940
null
73
73
n = int(input()) ab = [list(map(int, input().split())) for _ in range(n)] a = [_ab[0] for _ab in ab] b = [_ab[1] for _ab in ab] a.sort() b.sort() if n % 2 == 1: m = a[n // 2] M = b[n // 2] print(M - m + 1) else: m = (a[n // 2 - 1] + a[n // 2]) / 2 M = (b[n // 2 - 1] + b[n // 2]) / 2 print(int((M - m) * 2 + 1))
"""A.""" import sys input = sys.stdin.readline # noqa: A001 D, T, S = map(int, input()[:-1].split(' ')) print('Yes' if T * S >= D else 'No')
0
null
10,501,152,516,580
137
81
def gcd(x, y): if x == 0: return y return gcd(y % x, x) def lcm(x, y): return x // gcd(x, y) * y n, m = map(int, input().split()) a = list(map(int, input().split())) aa = [e // 2 for e in a] for i, e in enumerate(aa): if i == 0: base = 0 while e % 2 == 0: e //= 2 base += 1 else: cnt = 0 while e % 2 == 0: e //= 2 cnt += 1 if cnt != base: print(0) exit() c = 1 for e in aa: c = lcm(c, e) if c > m: print(0) exit() ans = (m - c) // (2 * c) + 1 print(ans)
import math def lcm(a,b): return (a*b)//math.gcd(a,b) def co(num): return format(num, 'b')[::-1].find('1') N,M=map(int,input().split()) L=list(map(int,input().split())) L2=[co(i) for i in L] if len(set(L2))!=1: print(0) exit() L=[i//2 for i in L] s=L[0] for i in range(N): s=lcm(s,L[i]) c=M//s print((c+1)//2)
1
102,096,896,502,208
null
247
247
# ????????? str ?????????????????????????????????????????????????????????????????°?????? # ?????\????±??????????str????¨??????\??????????????? str = list(input()) str = "".join(str) # ?????\???????????°p????¨??????\??????????????? p = int(input()) # p?????????????????????????????????????????? orderList = [0 for i in range(p)] for i in range(0, p): orderList[i] = list(input()) orderList[i] = "".join(orderList[i]).split() if orderList[i][0] == "print": print("{0}".format(str[int(orderList[i][1]):int(orderList[i][2]) + 1])) elif orderList[i][0] == "reverse": str = str[0:int(orderList[i][1])] + str[-len(str) + int(orderList[i][2]):-len(str) + int(orderList[i][1]) - 1:-1] + str[int(orderList[i][2]) + 1:] elif orderList[i][0] == "replace": str = str[:int(orderList[i][1])] + orderList[i][3] + str[int(orderList[i][2]) + 1:]
import math N = int(input()) n_max = int(math.sqrt(N)) a = [] for i in range(1,n_max + 1): if N % i == 0: a.append(i) ans = 2 * N for i in a: if (i + (N // i) - 2) < ans: ans = i + (N // i) - 2 print(ans)
0
null
81,486,863,326,044
68
288
# 最小公倍数(mathは3.5以降) fractions from functools import reduce import fractions #(2020-0405 fractions→math) def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする def lcm(*numbers): return reduce(lcm_base, numbers, 1) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) N,M = (int(x) for x in input().split()) A = list(map(int, input().split())) lcm =lcm_list(A) harf_lcm =lcm//2 # 最小公倍数の半分 harf_lcm_num =M//harf_lcm # Mの中の半公倍数の個数 harf_lcm_num =(harf_lcm_num +1)//2 # 偶数を除く #半公倍数がaiで割り切れるときは✖ import numpy as np A_np =np.array(A) if np.any(harf_lcm % A_np ==0): harf_lcm_num =0 """ for a in A: if harf_lcm % a ==0: harf_lcm_num =0 break """ print(harf_lcm_num)
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, M, A): b_lcm = 1 d2 = set() for a in A: b = a // 2 b_lcm = b_lcm//math.gcd(b_lcm, b) * b for i in range(100000000): if a % 2 == 0: a //= 2 else: d2.add(i) break return -(-(M // b_lcm)//2) if len(d2) == 1 else 0 def main(): N, M = read_int_n() A = read_int_n() print(slv(N, M, A)) if __name__ == '__main__': main()
1
102,088,673,867,910
null
247
247
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) R, C, K = mapint() dp = [[[0]*C for _ in range(R)] for _ in range(4)] from collections import defaultdict dic = [[0]*C for _ in range(R)] for _ in range(K): r, c, v = mapint() dic[r-1][c-1] = v for r in range(R): for c in range(C): v = dic[r][c] for i in range(4): if c!=0: dp[i][r][c] = dp[i][r][c-1] if r!=0: dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c]) for i in range(2, -1, -1): dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v) ans = 0 for i in range(4): ans = max(ans, dp[i][R-1][C-1]) print(ans)
#!/usr/bin python3 # -*- coding: utf-8 -*- r, c, k = map(int, input().split()) itm = [[0]*(c) for _ in range(r)] for i in range(k): ri, ci, vi = map(int, input().split()) itm[ri-1][ci-1] = vi dp0 = [[0]*4 for c_ in range(3005)] dp1 = [[0]*4 for c_ in range(3005)] for i in range(r): for j in range(c): nowv = itm[i][j] dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv) dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv) dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv) dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0]) dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1]) dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2]) dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3]) dp1[j][0] = max(dp1[j][0], max(dp0[j])) dp0 = dp1.copy() print(max(dp1[c-1]))
1
5,565,989,343,200
null
94
94
import sys input = sys.stdin.readline H, W, K = map(int, input().split()) mat = [[0]*W for i in range(H)] for i in range(K): r, c, v = map(int, input().split()) r, c = r-1, c-1 mat[r][c] = v dp0 = [[-1 for i in range(W)] for i in range(H)] dp1 = [[-1 for i in range(W)] for i in range(H)] dp2 = [[-1 for i in range(W)] for i in range(H)] dp3 = [[-1 for i in range(W)] for i in range(H)] dp0[0][0] = 0 if mat[0][0] != 0: dp1[0][0] = mat[0][0] for i in range(H): for j in range(W): m = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j]) if i+1 < H: dp1[i+1][j] = max(dp1[i+1][j], m+mat[i+1][j]) dp0[i+1][j] = max(dp0[i+1][j], m) if j+1 < W: dp0[i][j+1] = 0 dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1]) dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1]) dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1]) print(max(dp0[H-1][W-1], dp1[H-1][W-1], dp2[H-1][W-1], dp3[H-1][W-1]))
S = input() mx = 0 c = 0 for si in S: if si == 'R': c += 1 mx = max(mx, c) else: c = 0 print(mx)
0
null
5,262,060,818,012
94
90
def main(): x = int(input()) ans=int(x/500)*1000 x-=int(x/500)*500 ans+=int(x/5)*5 print(ans) main()
n = int(input()) a = n//500 b = n%500 c = b//5 print(1000*a + 5*c)
1
42,699,277,596,572
null
185
185
N, K = [int(_) for _ in input().split()] P = [int(_) - 1 for _ in input().split()] C = [int(_) for _ in input().split()] def f(v, K): if K == 0: return 0 if max(v) < 0: return max(v) n = len(v) X = [0] for i in range(n): X.append(X[-1] + v[i]) ans = -(10 ** 10) for i in range(n + 1): for j in range(i): if i - j > K: continue ans = max(ans, X[i] - X[j]) return(ans) X = [False for _ in range(N)] ans = -(10 ** 10) for i in range(N): if X[i]: continue t = i v = [] while X[t] is False: X[t] = True v.append(C[t]) t = P[t] n = len(v) if K > n: s = sum(v) x = f(v * 2, n) if s > 0: a = s * (K // n - 1) + max(s + f(v * 2, K % n), x) else: a = x else: a = f(v * 2, K) ans = max(a, ans) print(ans)
n = int(input()) ns = [] max_profit = -1000000000 min_value = 1000000000 for i in range(n): num = int(input()) if i > 0: max_profit = max(max_profit, num-min_value) min_value = min(num, min_value) print(max_profit)
0
null
2,704,419,637,190
93
13
al = "abcdefghijklmnopqrstuvwxyz" k = int(input()) def dfs(s: "char", i): if(len(s)==k): print(s) else: for j in range(i+1): if al[j]==al[i]: dfs(s+al[j], i+1) else: dfs(s+al[j], i) def main(): #sの後ろを変えていくdfs dfs("", 0) if __name__ == '__main__': main()
a=int(input()) hours=a//3600 minutes_num=a%3600 minutes=minutes_num//60 seconds=a%60 print(str(hours)+":"+str(minutes)+":"+str(seconds))
0
null
26,207,035,007,060
198
37
s=input() s += "es" if s[-1] == 's' else "s" print(s)
word=input() last_letter=word[int(len(word))-1] if last_letter=="s": print(word+"es") else: print(word+"s")
1
2,399,634,067,908
null
71
71
s = list(map(int, input().split())) q = int(input()) # 上面をnとして時計回りにサイコロを回したときの正面のindexの一覧[a_1,a_2,a_3,a_4] # 正面がa_nのとき右面はa_n+1 dm = {0: [1, 2, 4, 3, 1], 1: [0, 3, 5, 2, 0], 2: [0, 1, 5, 4, 0], 3: [0, 4, 5, 1, 0], 4: [0, 2, 5, 3, 0], 5: [1, 3, 4, 2, 1]} for i in range(q): t, f = map(lambda x: s.index(int(x)), input().split()) print(s[dm[t][dm[t].index(f)+1]])
class Dice: def __init__(self,d1,d2,d3,d4,d5,d6): self.dice = [d1,d2,d3,d4,d5,d6] def turn(self,dir): if dir == 'S': self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]] if dir == 'N': self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]] if dir == 'W': self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]] if dir == 'E': self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]] def check(m): for b in range(4): m.turn('N') if m.dice[0] == a[0] and m.dice[1] == a[1]: return(m.dice[2]) dice_num = input().split() q = int(input()) conditions = [] for a in range(q): temp = input().split() conditions.append(temp) init_Dice = Dice(dice_num[0],dice_num[1],dice_num[2],dice_num[3],dice_num[4],dice_num[5]) kaitou = [] for a in conditions: if check(init_Dice): print(check(init_Dice)) continue init_Dice.turn('E') if check(init_Dice): print(check(init_Dice)) continue init_Dice.turn('E') if check(init_Dice): print(check(init_Dice)) continue init_Dice.turn('E') if check(init_Dice): print(check(init_Dice)) continue init_Dice.turn('W') init_Dice.turn('N') init_Dice.turn('E') if check(init_Dice): print(check(init_Dice)) continue init_Dice.turn('E') if check(init_Dice): print(check(init_Dice)) continue init_Dice.turn('E') if check(init_Dice): print(check(init_Dice)) continue init_Dice.turn('E') if check(init_Dice): print(check(init_Dice)) continue
1
262,740,900,840
null
34
34
N = int(input()) A = sorted(list(map(int, input().split())), reverse=True) n = N // 2 if N % 2 == 1: ans = sum(A[:n]) + sum(A[1:n+1]) else: ans = sum(A[:n]) + sum(A[1:n]) print(ans)
N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) P = [None] + P C = [None] + C all_max = C[1] for st in range(1, N + 1): p = P[st] scores = [C[p]] while p != st and len(scores) < K: p = P[p] scores.append(C[p]) num_elem = len(scores) all_sum = sum(scores) q, r = divmod(K, num_elem) max_ = scores[0] temp = scores[0] max_r = scores[0] temp_r = scores[0] for x in range(1, num_elem): if x < r: temp_r += scores[x] max_r = max(max_r, temp_r) temp += scores[x] max_ = max(max_, temp) temp_max = scores[0] if all_sum > 0 and q > 0: if r > 0: temp_max = max(all_sum * (q - 1) + max_, all_sum * q + max_r) else: temp_max = all_sum * (q - 1) + max_ else: temp_max = max_ all_max = max(all_max, temp_max) print(all_max)
0
null
7,277,949,287,112
111
93
h, w, m = list(map(int, input().split())) count_row = [0 for _ in range(h)] count_col = [0 for _ in range(w)] max_col = 0 max_row = 0 max_row_index = [] max_col_index = [] M = set() for i in range(m): mh, mw = list(map(int, input().split())) M.add((mh-1, mw-1)) count_row[mh-1] += 1 count_col[mw-1] += 1 if count_row[mh-1] > max_row: max_row = count_row[mh-1] max_row_index = [mh-1] elif count_row[mh-1] == max_row: max_row_index.append(mh-1) if count_col[mw-1] > max_col: max_col = count_col[mw-1] max_col_index = [mw-1] elif count_col[mw-1] == max_col: max_col_index.append(mw-1) # max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)] # max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)] # ans = max(count_row) + max(count_col) -1 ans = max_col + max_row -1 if len(max_col_index)*len(max_row_index) > m: ans += 1 else: flag = False for i in max_row_index: for j in max_col_index: if (i, j) not in M: ans += 1 flag = True break if flag: break print(ans)
N = int(input()) Alist = list(map(int, input().split())) Alist = [[idx+1, a] for (idx, a) in enumerate(Alist)] Alist.sort(key=lambda x:x[1]) ans = [str(a) for a, _ in Alist] print(" ".join(ans))
0
null
92,284,851,098,348
89
299
import sys, math for line in sys.stdin: print int(math.log10(sum(map(int, line.split())))) + 1
import fileinput if __name__ == '__main__': for line in fileinput.input(): tokens = line.strip().split() a, b = int(tokens[0]), int(tokens[1]) c = a+b print(len(str(c)))
1
85,565,342
null
3
3
size = [int(i) for i in input().split()] sheet =[ [0 for i in range(size[1])] for j in range(size[0])] for gyou in range(size[0]): x = [int(i) for i in input().split()] sheet[gyou] = x sheet[gyou].append(sum(sheet[gyou])) for gyou in range(size[0]): for retsu in range(size[1]+1): print(sheet[gyou][retsu],end="") if retsu != size[1]: print(" ",end="") print("") for retsu in range(size[1]+1): sum2 = 0 for gyou in range(size[0]): sum2 += sheet[gyou][retsu] print(sum2, end="") if retsu != size[1]: print(" ",end="") print("")
from sys import stdin r, c = [int(x) for x in stdin.readline().rstrip().split()] table = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(r)] for row in range(r): table[row] += [sum(table[row])] print(*table[row]) col_sum = [sum(x) for x in zip(*table)] print(*col_sum)
1
1,366,199,561,078
null
59
59
import sys from io import StringIO import unittest import os # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) def prepare_simple(n, mod=pow(10, 9) + 7): # n! の計算 f = 1 for m in range(1, n + 1): f *= m f %= mod fn = f # n!^-1 の計算 inv = pow(f, mod - 2, mod) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= mod invs[m - 1] = inv return fn, invs def prepare(n, mod=pow(10, 9) + 7): # 1! - n! の計算 f = 1 factorials = [1] # 0!の分 for m in range(1, n + 1): f *= m f %= mod factorials.append(f) # n!^-1 の計算 inv = pow(f, mod - 2, mod) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= mod invs[m - 1] = inv return factorials, invs # 実装を行う関数 def resolve(test_def_name=""): x, y = map(int, input().split()) all_move_count = (x + y) // 3 x_move_count = all_move_count y_move_count = 0 x_now = all_move_count * 2 y_now = all_move_count canMake= False for i in range(all_move_count+1): if x_now == x and y_now == y: canMake = True break x_move_count -= 1 y_move_count += 1 x_now -= 1 y_now += 1 if not canMake: print(0) return fns, invs = prepare(all_move_count) ans = (fns[all_move_count] * invs[x_move_count] * invs[all_move_count - x_move_count]) % (pow(10, 9) + 7) print(ans) # fn, invs = prepareSimple(10) # ans = (fn * invs[3] * invs[10 - 3]) % (pow(10, 9) + 7) # print(ans) # テストクラス class TestClass(unittest.TestCase): def assertIO(self, assert_input, output): stdout, sat_in = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, sat_in self.assertEqual(out, output) def test_input_1(self): test_input = """3 3""" output = """2""" self.assertIO(test_input, output) def test_input_2(self): test_input = """2 2""" output = """0""" self.assertIO(test_input, output) def test_input_3(self): test_input = """999999 999999""" output = """151840682""" self.assertIO(test_input, output) # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること def tes_t_1original_1(self): test_input = """データ""" output = """データ""" self.assertIO(test_input, output) # 実装orテストの呼び出し if __name__ == "__main__": if os.environ.get("USERNAME") is None: # AtCoder提出時の場合 resolve() else: # 自PCの場合 unittest.main()
i = 0 x = [] for i in range(10): mount = int(input()) x.append(mount) sorted_x = sorted(x) print(sorted_x[-1]) print(sorted_x[-2]) print(sorted_x[-3])
0
null
75,023,326,142,622
281
2
## coding: UTF-8 N, P = map(int,input().split()) S = input()[::-1] remainder = [0] * P tmp = 0 rad = 1 #10**(i) % P ''' if(P == 2 or P == 5): for i in range(N): r = int(S[i]) tmp += r * rad tmp %= P remainder[tmp] += 1 rad *= 10 ''' if(P == 2): ans = 0 for i in range(N): r = int(S[i]) if(r % 2 == 0): ans += N-i print(ans) elif(P == 5): ans = 0 for i in range(N): r = int(S[i]) if(r % 5 == 0): ans += N-i print(ans) else: for i in range(N): r = int(S[i]) tmp += r * rad tmp %= P remainder[tmp] += 1 rad *= 10 rad %= P remainder[0] += 1 #print(remainder) ans = 0 for i in range(P): e = remainder[i] ans += e*(e-1)/2 print(int(ans))
k = int(input()) a,b = map(int,input().split()) if b//k - (a-1)//k > 0: print("OK") else: print("NG")
0
null
42,230,673,470,080
205
158
n,m = map(int,input().split()) a = list(map(int,input().split())) ans = 0 for i in range(m): ans += a[i] if n < ans: print(-1) else: print(n-ans)
# 163 B N,M = list(map(int, input().split())) A = list(map(int, input().split())) print(N-sum(A)) if sum(A) <= N else print(-1)
1
31,916,760,132,950
null
168
168
# -*- coding: utf-8 -*- def cube(x): """ return x cubed >>> cube(2) 8 >>> cube(3) 27 >>> cube(10) 1000 """ return x**3 if __name__ == '__main__': x = int(raw_input()) print cube(x)
data = input() x = int(data) x = x*x*x print("{0}".format(x))
1
274,377,205,190
null
35
35
def main(): n, m = map(int, input().split()) print('Yes') if n <= m else print('No') if __name__ == '__main__': main()
a = int(input()) S ="" l =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] num = a % 26 while a >0: if a%26 !=0: S =l[(a%26)-1] + S a = (a-a%26)//26 else: S = l[(a%26)-1] + S a = (a-26)//26 print(S)
0
null
47,716,032,047,570
231
121
N, K = map(int, input().split()) have_sweets = [] for i in range(K): d = int(input()) have_sweets += list(map(int, input().split())) have_sweets = set(have_sweets) print(len(list(set([i for i in range(1, N+1)])-have_sweets)))
from itertools import product def makelist(BIT): LIST, tmp = [], s[0] for i, bi in enumerate(BIT, 1): if bi == 1: LIST.append(tmp) tmp = s[i] elif bi == 0: tmp = [t + sij for t, sij in zip(tmp, s[i])] else: LIST.append(tmp) return LIST def solve(LIST): CNT, tmp = 0, [li[0] for li in LIST] if any(num > k for num in tmp): return h * w for j in range(1, w): cal = [t + li[j] for t, li in zip(tmp, LIST)] if any(num > k for num in cal): CNT += 1 tmp = [li[j] for li in LIST] else: tmp = cal return CNT h, w, k = map(int, input().split()) s = [[int(sij) for sij in input()] for _ in range(h)] ans = h * w for bit in product([0, 1], repeat=(h - 1)): numlist = makelist(bit) ans = min(ans, solve(numlist) + sum(bit)) print(ans)
0
null
36,660,729,122,580
154
193
mod = 998244353 n,k = map(int,input().split()) lr = [[int(i) for i in input().split()] for j in range(k)] dp = [0]*(n+1) dp_rui = [0]*(n+1) dp[1] = 1 dp_rui[1] = 1 for i in range(2,n+1): for j in range(k): lft = i - lr[j][1] rht = i - lr[j][0] #print(i,lft,rht) if rht <= 0: continue lft = max(1,lft) dp[i] += dp_rui[rht] - dp_rui[lft-1] #print(dp_rui[rht],dp_rui[lft-1]) dp[i] %= mod #print(dp) #print(dp_rui) dp_rui[i] = dp_rui[i-1] + dp[i] dp_rui[i] %= mod print(dp[n]%mod)
n,k = map(int,input().split()) MOD = 10**9+7 # g[i]:gcd(A1,A2,,,An)=iとなる数列の個数 g = [0 for _ in range(k)] for i in range(k,0,-1): g[i-1] = pow(k//i,n,MOD) #ここまででg[x]=gcdがxの倍数となる数列の個数となっているので、 #ここからgcdが2x,3x,,,となる数列の個数を引いていく。 for j in range(2,k+1): if i*j > k: break g[i-1] -= g[i*j-1] g[i-1] %= MOD #print(g) ans = 0 for i in range(k): ans += (i+1)*g[i] ans %= MOD print(ans)
0
null
19,697,098,374,720
74
176
X = list(map(int, input().split())) for i in range(len(X)): if X[i] != i+1: print(i+1) if __name__ == '__main__': print()
x=list(map(int,input().split())) for k in range(5): if x[k]==0: print(k+1) else: continue
1
13,476,152,829,100
null
126
126
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 998244353 def debug(*x): print(*x, file=sys.stderr) def solve(N, K, SS): count = [0] * (N + 10) count[0] = 1 accum = [0] * (N + 10) accum[0] = 1 for pos in range(1, N): ret = 0 for left, right in SS: start = pos - right - 1 end = pos - left ret += (accum[end] - accum[start]) ret %= MOD count[pos] = ret accum[pos] = accum[pos - 1] + ret ret = count[N - 1] return ret % MOD def main(): # parse input N, K = map(int, input().split()) SS = [] for i in range(K): SS.append(tuple(map(int, input().split()))) print(solve(N, K, SS)) # tests T1 = """ 5 2 1 1 3 4 """ TEST_T1 = """ >>> as_input(T1) >>> main() 4 """ T2 = """ 5 2 3 3 5 5 """ TEST_T2 = """ >>> as_input(T2) >>> main() 0 """ T3 = """ 5 1 1 2 """ TEST_T3 = """ >>> as_input(T3) >>> main() 5 """ T4 = """ 60 3 5 8 1 3 10 15 """ TEST_T4 = """ >>> as_input(T4) >>> main() 221823067 """ T5 = """ 10 1 1 2 """ TEST_T5 = """ >>> as_input(T5) >>> main() 55 """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
M=998244353 f=lambda:[*map(int,input().split())] n,k=f() lr=[f() for _ in range(k)] dp=[0]*n dp[0]=1 S=[0] for i in range(1,n): S+=[S[-1]+dp[i-1]] for l,r in lr: dp[i]+=S[max(i-l+1,0)]-S[max(i-r,0)] dp[i]%=M print(dp[-1])
1
2,743,042,013,280
null
74
74
N = input() A = int(N) if A>=30: print('Yes') else: print('No')
x,y,z=map(int,input().split()) temp=x x=y y=temp temp=x x=z z=temp print("{0} {1} {2}".format(x,y,z))
0
null
22,027,599,618,110
95
178
def read_int(): return int(input()) def read_ints(): return map(int, input().split(' ')) r, c = read_ints() s = [] for i in range(r): s.append(input()) inf = int(1e9) dp = [[inf for j in range(c)] for i in range(r)] dp[0][0] = 1 if s[0][0] == '#' else 0 for i in range(r): for j in range(c): if i > 0: dp[i][j] = dp[i - 1][j] if s[i][j] == '#' and s[i - 1][j] == '.': dp[i][j] += 1 if j > 0: another = dp[i][j - 1] if s[i][j] == '#' and s[i][j - 1] == '.': another += 1 dp[i][j] = min(dp[i][j], another) print(dp[r - 1][c - 1])
# import itertools # import math # import sys # sys.setrecursionlimit(500*500) # import numpy as np # N = int(input()) # S = input() # n, *a = map(int, open(0)) N, X, Y = map(int, input().split()) # A = list(map(int, input().split())) # B = list(map(int, input().split())) # tree = [[] for _ in range(N + 1)] # B_C = [list(map(int,input().split())) for _ in range(M)] # S = input() # B_C = sorted(B_C, reverse=True, key=lambda x:x[1]) # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement(range(1, M + 1), N)) # itertools.product((0,1), repeat=n) # A = np.array(A) # cum_A = np.cumsum(A) # cum_A = np.insert(cum_A, 0, 0) # def dfs(tree, s): # for l in tree[s]: # if depth[l[0]] == -1: # depth[l[0]] = depth[s] + l[1] # dfs(tree, l[0]) # dfs(tree, 1) # def factorization(n): # arr = [] # temp = n # for i in range(2, int(-(-n**0.5//1))+1): # if temp%i==0: # cnt=0 # while temp%i==0: # cnt+=1 # temp //= i # arr.append([i, cnt]) # if temp!=1: # arr.append([temp, 1]) # if arr==[]: # arr.append([n, 1]) # return arr cnt = [0] * N for i in range(1, N + 1): for j in range(i + 1, N + 1): k = min([j - i, abs(X - i) + abs(Y - j) + 1, abs(Y - i) + abs(X - j) + 1]) cnt[k] += 1 for i in range(1, N): print(cnt[i])
0
null
46,573,940,818,020
194
187
import sys S = int(sys.stdin.readline()) h = int(S / 60 / 60) m = int(S % 3600 / 60) s = S % 60 print("%d:%d:%d" % (h, m, s))
n = int(input()) a = list(map(int,input().split())) m = max(a) + 1 li = [0]*m for x in a: li[x] += 1 ans = 0 for i in range(1,m): if li[i]: if li[i]==1: ans += 1 for j in range(i,m,i): li[j] = 0 print(ans)
0
null
7,369,606,186,042
37
129
import sys from functools import lru_cache N = int(sys.stdin.readline().rstrip()) K = int(sys.stdin.readline().rstrip()) @lru_cache(None) def F(N, K): """(0以上)N以下で、0でないものがちょうどK個""" assert N >= 0 # Nが非負であることを保証する if N < 10: # N が一桁 if K == 0: # 使える 0 以外の数がない場合 return 1 # if K == 1: return N # 1,2,...,N までのどれか return 0 # それ以上 K が余っていたら作れない q, r = divmod(N, 10) # N = 10*q + r と置く ret = 0 if K >= 1: # 1の位(r)が nonzero ret += F(q, K - 1) * r # ret += F(q - 1, K - 1) * (9 - r) # 1の位(r)が zero ret += F(q, K) return ret print(F(N, K))
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, T = lr() AB = [lr() for _ in range(N)] AB.sort() # 時間のかかる物は後ろへ dp = np.zeros(T, np.int64) answer = 0 for a, b in AB: answer = max(answer, dp.max() + b) prev = dp dp[a:] = np.maximum(prev[a:], prev[:-a] + b) print(answer)
0
null
113,727,927,114,208
224
282
N = int(input()) L = list(map(int, input().split())) le = len(L) score = 0 for i in range(le): for j in range(i+1,le): for k in range(j+1,le): if (L[i] + L[j] > L[k] and L[i] + L[k] > L[j] and L[k] + L[j] > L[i] ): if (L[i] != L[j] and L[i] != L[k] and L[k] != L[j]): score += 1 print(score)
from sys import stdin def chmin(a,b): if a > b: return b else: return a def chmax(a,b): if a < b: return b else: return a if __name__ == "__main__": _in = [_.rstrip() for _ in stdin.readlines()] N = int(_in[0]) # type:int A_arr = list(map(int,_in[1].split(' '))) # type:list(int) # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv A_arr_wloc = [] for i,A in enumerate(A_arr): A_arr_wloc.append([A,i]) A_arr_wloc.sort(reverse=True) dp = [[0] * (N+1) for _ in range(N+1)] for i in range(N): for j in range(N-i): dp[i+1][j] = chmax(dp[i+1][j], dp[i][j]+A_arr_wloc[i+j][0]*(A_arr_wloc[i+j][1]-i)) # left dp[i][j+1] = chmax(dp[i][j+1], dp[i][j]+A_arr_wloc[i+j][0]*((N-1-j)-A_arr_wloc[i+j][1])) # right cnt = 0 for i in range(0,N+1): cnt = chmax(cnt, dp[i][N-i]) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ print(cnt)
0
null
19,310,960,974,096
91
171
import collections n = int(input()) s = [input() for l in range(n)] word = collections.Counter(s) ma = max(word.values()) z = [kv for kv in word.items() if kv[1] == ma] z = sorted(z) for c in z: print(c[0])
d = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(d)] t = [int(input()) - 1 for _ in range(d)] def scoring(d, c, s, t): v = [] memo = [0 for _ in range(26)] for i in range(d): if i == 0: score = 0 else: score = v[-1] score += s[i][t[i]] memo[t[i]] = i + 1 for j in range(26): score -= c[j] * (i+1 - memo[j]) v.append(score) return v v = scoring(d, c, s, t) print(*v, sep='\n')
0
null
39,782,759,561,690
218
114
n = int(input()) p = list(map(int, input().split())) mini = p[0] ans = 0 for i in p: if i <= mini: ans += 1 mini = min(mini,i) print(ans)
n=int(input()) p=list(map(int,input().split())) minnumber=1e9 count=0 for i in p: if i<=minnumber: count+=1 minnumber=i print(count)
1
85,086,571,240,572
null
233
233
def main(): N = int(input()) L = sorted(list(map(int, input().split()))) ans = 0 for ia in range(N-2): a = L[ia] ic = ia + 2 for ib in range(ia+1, N-1): b = L[ib] while ic < N and L[ic] < a+b: ic += 1 ans += ic - (ib + 1) print(ans) main()
import bisect n = int(input()) L = list(map(int,input().split())) L.sort() ans = 0 for a in range(0,n): for b in range(a+1,n): p = bisect.bisect_left(L, L[a]+L[b]) ans += max(p-(b+1),0) print(ans)
1
171,882,889,237,140
null
294
294
s = [] n = int(input()) for i in range(n): s.append(input()) print("AC x " + str(s.count("AC"))) print("WA x " + str(s.count("WA"))) print("TLE x " + str(s.count("TLE"))) print("RE x " + str(s.count("RE")))
N=int(input()) S=[input() for _ in range(N)] a=0 w=0 t=0 r=0 for i in range(N): if S[i] =="AC": a+=1 elif S[i] =="WA": w+=1 elif S[i] =="TLE": t+=1 elif S[i] =="RE": r+=1 print("AC x "+ str(a)) print("WA x "+ str(w)) print("TLE x "+ str(t)) print("RE x "+ str(r))
1
8,704,615,083,142
null
109
109
A, B = list(map(float,input().split())) result = int(A * B) print(result)
#input() ans=1 for i in map(int,input().split()):ans*=i print(int(ans))
1
15,800,621,993,782
null
133
133
H, W = map(int, input().split()) S = [list(input()) for h in range(H)] table = [[0 for w in range(W)] for h in range(H)] table[0][0] = int(S[0][0]=='#') for i in range(1, H): table[i][0] = table[i-1][0] + int(S[i-1][0]=='.' and S[i][0]=='#') for j in range(1, W): table[0][j] = table[0][j-1] + int(S[0][j-1]=='.' and S[0][j]=='#') for i in range(1, H): for j in range(1, W): table[i][j] = min(table[i-1][j] + int(S[i-1][j]=='.' and S[i][j]=='#'), table[i][j-1] + int(S[i][j-1]=='.' and S[i][j]=='#')) print(table[-1][-1])
H,W=map(int,input().split()) s=[] for _ in range(H): s.append(list(input())) inf=float("inf") ans=[[inf]*W for _ in range(H)] if s[0][0]==".": ans[0][0]=0 else: ans[0][0]=1 for i in range(H): for j in range(W): if j!=W-1: if s[i][j]=="." and s[i][j+1]=="#": ans[i][j+1]=min(ans[i][j]+1,ans[i][j+1]) else: ans[i][j+1]=min(ans[i][j],ans[i][j+1]) if i!=H-1: if s[i][j]=="." and s[i+1][j]=="#": ans[i+1][j]=min(ans[i][j]+1,ans[i+1][j]) else: ans[i+1][j]=min(ans[i][j],ans[i+1][j]) print(ans[H-1][W-1])
1
49,195,810,656,860
null
194
194
n = int(input()) S = input() q = int(input()) class BIT: def __init__(self, n): """ 初期化 Input:  n: 配列の大きさ """ self.n = n self.bit = [0] * (n+10) def add(self, x, w): """ 更新クエリ(add) Input: x: インデックス w: 加える値 Note: self.bitが更新される """ while x <= self.n: self.bit[x] += w x += x&-x def sum(self, x): """ 部分和算出クエリ Input: x: インデックス Return: [1,a]の部分和 """ cnt = 0 while x > 0: cnt += self.bit[x] # 次の最下位桁はどこか x -= x&-x return cnt def psum(self, a, b): """ 区間[a,b)(0-indexed)における和 Input a,b: 半開区間 Return [a,b)の和 """ return self.sum(b-1) - self.sum(a-1) def str2num(s): return ord(s)-ord("a") bits = [BIT(n) for i in range(26)] # 入力 ans = [] for i, s in enumerate(S): ind = str2num(s) bits[ind].add(i+1, 1) S = list(S) for _ in range(q): x,a,b = input().split() if x == "1": i = int(a) # 更新処理 ind_before = str2num(S[i-1]) ind = str2num(b) bits[ind_before].add(i,-1) bits[ind].add(i, 1) S[i-1] = b else: l = int(a) r = int(b) cnt = 0 for bit in bits: if bit.psum(l,r+1) > 0: cnt += 1 ans.append(cnt) print(*ans)
import sys input = sys.stdin.readline n, m, l = map(int, input().split()) INF = float("inf") def warshall_floyd(d, n): for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d d = [[INF] * n for _ in range(n)] for i in range(n): d[i][i] = 0 for i in range(m): a, b, c = map(int, input().split()) d[a - 1][b - 1] = c d[b - 1][a - 1] = c d = warshall_floyd(d, n) d2 = [[INF] * n for _ in range(n)] for i in range(n): for j in range(n): if d[i][j] <= l: d2[i][j] = 1 d2[i][i] = 0 d2 = warshall_floyd(d2, n) q = int(input()) for _ in range(q): s, t = map(int, input().split()) res = d2[s - 1][t - 1] print(-1 if res == INF else res - 1)
0
null
118,366,401,335,478
210
295
import numpy as np A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if V <= W: print("NO") elif np.abs(A - B) / (V - W) <= T: print("YES") else: print("NO")
import sys import numpy as np sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def IS(): return sys.stdin.readline()[:-1] def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LII(rows_number): return [II() for _ in range(rows_number)] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def main(): N,T = MI() max_T = -1 dish = [] for i in range(N): A,B = MI() dish.append([A,B]) dish.sort(key=lambda x : x[0]) max_T = max(max_T, A) dp=np.array([-1 for _ in range(T+max_T)]) dp[0] = 0 upper = 1 for i in range(N): ch = (dp>=0) ch[T:] = False ch2 = np.roll(ch, dish[i][0]) ch2[:dish[i][0]]=False dp[ch2] = np.maximum(dp[ch2] , dp[ch] + dish[i][1]) print(max(dp)) main()
0
null
83,325,230,428,892
131
282
n=int(input()) if n<3: print(0) else: L=[int(i) for i in input().split()] x=0 for i in range(0,n-2): for j in range(i+1,n-1): for k in range(j+1,n): if L[i]==L[j] or L[j]==L[k] or L[k]==L[i]: pass elif L[i]+L[j]>L[k] and L[i]+L[k]>L[j] and L[j]+L[k]>L[i]: x+=1 else: pass print(x)
n=int(input()) l=list(map(int,input().split())) ans=0 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): num=[l[i],l[j],l[k]] if len(set(num))!=3:continue num.sort() if num[2]<num[1]+num[0]:ans+=1 print(ans)
1
5,064,390,278,080
null
91
91
N=int(input()) S={} for n in range(N): s=input() S[s]=S.get(s,0)+1 maxS=max(S.values()) S=[k for k,v in S.items() if v==maxS] print('\n'.join(sorted(S)))
N = int(input()) import collections a = [] for i in range(N): S = input() a.append(S) l = collections.Counter(a) x = max(l.values()) ans = [k for k, v in l.items() if v == x] ans = sorted(ans) for i in ans: print(i)
1
69,617,678,184,188
null
218
218
X,N = map(int,input().split()) p = list(map(int, input().split())) i = 0 if X not in p: print(X) else: while True: i += 1 if X - i not in p: print(X-i) break if X+i not in p: print(X+i) break
# -*- coding: utf-8 -*- """ Created on Thu May 7 00:03:02 2020 @author: shinba """ L = int(input()) L = L/3 print(L**3)
0
null
30,598,123,945,060
128
191
import numpy as np import sys def input(): return sys.stdin.readline().rstrip() def main(): n, t = map(int, input().split()) dp = np.zeros(t,dtype=int) food = [] for _ in range(n): a, b = map(int, input().split()) food.append([a, b]) food.sort(key=lambda x: x[0]*-1) for j in range(n): a, b = food[j][0], food[j][1] a=min(a,t) dptmp=np.zeros(t,dtype=int) dptmp[a:] = np.maximum(dp[a:],dp[:-a]+b) dptmp[:a] = np.maximum(np.full(a,b,dtype=int), dp[:a]) dp=dptmp print(dp[-1]) if __name__ == '__main__': main()
n, t = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort() dp = [[0] * t for _ in range(n + 1)] ans = 0 for i, (a, b) in enumerate(ab): for j in range(t): dp[i+1][j] = max(dp[i+1][j], dp[i][j]) if j + a <= t - 1: dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j] + b) else: ans = max(ans, dp[i][j] + b) print(ans)
1
152,062,082,122,720
null
282
282
N = int(input()) print('ACL' * N)
N=int(input()) u="ACL" print(u*N)
1
2,207,528,610,298
null
69
69
# coding: utf-8 import sys def merge(A, left, mid, right): global count L = A[left:mid] R = A[mid:right] L.append(sys.maxsize) R.append(sys.maxsize) i = 0 j = 0 for k in range(left,right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 count += 1 def mergeSort(A, left, right): if left+1 < right: mid = int((left + right)/2); mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) n = int(input().rstrip()) A = list(map(int,input().rstrip().split())) count = 0 mergeSort(A, 0, n) print(" ".join(map(str,A))) print(count)
import sys from typing import List COMP_NUM = 0 def merge(elements: List[int], left: int, mid: int, right: int) -> None: global COMP_NUM n1 = mid - left n2 = right - mid left_array = [0] * (n1 + 1) right_array = [0] * (n2 + 1) left_array[0:n1] = elements[left:left + n1] left_array[n1] = sys.maxsize right_array[0:n2] = elements[mid:mid + n2] right_array[n2] = sys.maxsize i = 0 j = 0 for k in range(left, right): COMP_NUM += 1 if left_array[i] <= right_array[j]: elements[k] = left_array[i] i += 1 else: elements[k] = right_array[j] j += 1 def merge_sort(elements: List[int], left: int, right: int) -> None: if left + 1 < right: mid = (left + right) // 2 merge_sort(elements, left, mid) merge_sort(elements, mid, right) merge(elements, left, mid, right) if __name__ == "__main__": n = int(input()) elements = list(map(lambda x: int(x), input().split())) merge_sort(elements, 0, len(elements)) print(" ".join([str(elem) for elem in elements])) print(f"{COMP_NUM}")
1
113,379,260,280
null
26
26
S = input() A = "" for i in range(len(S)) : A = A + "x" print(A)
n=int(input()) a=list(map(int,input().split())) res=0 for i in range(n): res^=a[i] ans=[] for i in range(n): ans.append(res^a[i]) print(*ans)
0
null
42,581,801,006,760
221
123
n = int(input()) count = 0 for i in range(n): a,b = map(int,input().split()) if count >2 : break elif a==b: count += 1 else: count = 0 print('Yes' if count > 2 else 'No')
h,w,k=map(int,input().split()) board=[list(input()) for _ in range(h)] acum=[[0]*w for _ in range(h)] def count(x1,y1,x2,y2): #事前に求めた2次元累積和を用いて左上の点が(x1,y1)、右下の点(x2,y2)の長方形に含まれる1の個数を数える ret=acum[y2][x2] if x1!=0: ret-=acum[y2][x1-1] if y1!=0: ret-=acum[y1-1][x2] if x1!=0 and y1!=0: ret+=acum[y1-1][x1-1] return ret for i in range(h): #2次元累積和により左上の点が(0,0)、右下の点が(j,i)の長方形に含まれる1の個数を数える for j in range(w): if board[i][j] == '1': acum[i][j]+=1 if i!=0: acum[i][j]+=acum[i-1][j] if j!=0: acum[i][j]+=acum[i][j-1] if i!=0 and j!=0: acum[i][j]-=acum[i-1][j-1] ans = 10**18 for i in range(2**(h-1)): cnt = 0 list = [] flag = format(i,'b')[::-1] # '1'と'10'と'100'の区別のために必要 #print(flag) for j in range(len(flag)): if flag[j] == '1': # ''をつける! cnt += 1 list.append(j) list.append(h-1) #print(list) x1 = 0 for x2 in range(w-1): #x1(最初は0)とx1+1の間からx=w-1とx=wの間までの区切り方をそれぞれ確かめる y1 = 0 for y2 in list: #長方形のブロックの右下の点のy座標の候補をすべて試す if count(x1,y1,x2,y2) > k: #ある横の区切り方の下で、どのように縦を区切ってもブロックに含まれる1の個数がKより大きくなるとき、条件を満たす切り分け方は存在しない cnt += 10**18 if count(x1,y1,x2,y2) <= k and count(x1,y1,x2+1,y2) > k: #ある位置でブロックを区切ると1の個数がK以下になるが、区切る位置を1つ進めると1の個数がKより大きくなるとき、その位置で区切る必要がある cnt += 1 x1 = x2+1 #ある位置x2で区切ったとき、次からはx2+1を長方形のブロックの左上の点のx座標として見ればよい break y1 = y2+1 #(いま見ているブロックの右下の点のy座標)+1が次に見るブロックの左上の点のy座標に等しくなる y1 = 0 for y2 in list: if count(x1,y1,w-1,y2) > k: #最後に縦で区切った位置以降で、あるブロックに含まれる1の個数がKより大きくなるとき、条件を満たすような区切り方は存在しない cnt += 10**18 break y1 = y2+1 ans = min(ans,cnt) print(ans)
0
null
25,506,523,554,372
72
193
n, m = map(int, input().split()) if 2*m>=n: print(0) else: print(n-2*m)
#import sys #input=sys.stdin.readline() #print(input) #import pprint h,w = map(int,input().split()) s = [list(input())for i in range(h)] #print("s") #pprint.pprint(s,width=w*10) visited = [[0 for i in range(w)] for j in range(h)]#sと同じ形に0を配置した表 quene = []#移動元Nowとなることができる座標のリスト ans = 0 for i in range(h): for j in range(w): if s[i][j] == ".": quene.append([i,j])#スタート地点をQueneに追加 visited[i][j]=1#スタート地点を1にする # print("visited") # pprint.pprint(visited,width=w*10) # print(quene) dy_dx=[[1,0],[-1,0],[0,1],[0,-1]]#1回に移動出来る量 while len(quene)>=1: now=quene.pop(0)#queneの左端の項を取り出す # print(now) for k in range(4): y=now[0]+dy_dx[k][0]#nowから移動先[x,y]へのy軸方向の移動量 x=now[1]+dy_dx[k][1]#nowから移動先[x,y]へのx軸方向の移動量 if 0<=y<h and 0<=x<w:#移動先が表を飛び出していなければOK if s[y][x]!="#" and visited[y][x]==0:#移動先が壁でない、かつ行ったことがなければOK visited[y][x]=visited[now[0]][now[1]]+1#移動先の値をNowの値+1にする quene.append([y,x])#Queneに移動先座標を追加 # pprint.pprint(visited,width=w*10) # 一つのスタート地点から幅優先探索を終わらせたら、移動量の最大値を求める for l in range(h): for m in range(w): ans = max(ans,visited[l][m])#これまでの最大値と今回得られた移動量の最大値を比較し、大きいほうを新しい答えにする visited = [[0 for i in range(w)] for j in range(h)]#visited初期化 print(ans-1)
0
null
130,610,058,406,118
291
241
N = int(input()) As = list(map(int,input().split())) array = [] B = 0 for i in range(N): B ^= As[i] ans_array = [] for i in range(N): ans_array.append(B^As[i]) print(*ans_array)
a,b = map(int,input().split()) low = a*2 high = a*4 if b%2 != 0: print("No") elif b<low or b>high: print("No") else: print("Yes")
0
null
13,123,684,591,612
123
127
r,c = map(int,raw_input().split()) a = [map(int,raw_input().split()) for _ in range(r)] b = [0 for _ in range(c)] for i in range(r) : s = 0 for j in range(c) : s = s + a[i][j] b[j] = b[j] + a[i][j] a[i].append(s) print ' '.join(map(str,a[i])) b.append(sum(b)) print ' '.join(map(str,b))
def solve(n): if n <= 1: print(1) return a, b = 1, 1 for _ in range(2, n + 1): c = a + b b = a a = c print(c) if __name__ == "__main__": n = int(input()) solve(n)
0
null
669,076,406,560
59
7
x1, y1, x2, y2 = map(float, input().split()) print('%.8f' % (((x2 - x1)**2 + (y2 - y1)**2))**0.5)
import math x1,y1,x2,y2=map(float,input().split()) a = ((x1-x2)**2)+((y1-y2)**2) a = math.sqrt(a) print('{:.8f}'.format(a))
1
160,516,722,640
null
29
29
#それぞれの桁を考えた時にその桁を一つ多めに払うのかちょうどで払うのかで場合分けする n=[int(x) for x in list(input())]#それぞれの桁にアクセスするためにイテラブルにする k=len(n) #それぞれの桁を見ていくが、そのままと一つ多い状態から引く場合と二つあることに注意 dp=[[-1,-1] for _ in range(k)] dp[0]=[min(1+(10-n[0]),n[0]),min(1+(10-n[0]-1),n[0]+1)] for i in range(1,k): dp[i]=[min(dp[i-1][1]+(10-n[i]),dp[i-1][0]+n[i]),min(dp[i-1][1]+(10-n[i]-1),dp[i-1][0]+n[i]+1)] print(dp[k-1][0])
N = [int(i) for i in input()] dp = [0, float('inf')] # dp = [桁上げしてない, 桁上げあった] for n in N : ndp = [0] * 2 ndp[0] = min(dp[0] + n, dp[1] + n) ndp[1] = min(dp[0] + 11 - n, dp[1] + 9 - n) dp = ndp print(min(dp[0], dp[1]))
1
70,520,250,885,840
null
219
219
import sys import math import itertools import collections import heapq import re import numpy as np from functools import reduce rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rf = lambda: map(float, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 a = max(ri(), ri()) print(math.ceil(ri()/a))
import math a = int(input()) b = int(input()) n = int(input()) dum = max(a,b) ans = n/dum print(math.ceil(ans))
1
88,746,465,505,998
null
236
236
s=input() cnt=0 for i in range(len(s)//2): cnt += 1 if s[i]!=s[-i-1] else 0 print(cnt)
s = input() k = 0 for i in range(len(s) // 2): if s[i] == s[len(s) - i -1]: next else: k += 1 print(k)
1
120,210,281,376,512
null
261
261
import math import itertools n = int(input()) d = list(map(int, input().split())) ans = 0 for i in itertools.permutations(d, 2): ans += i[0] *i[1] print(ans //2)
import bisect,collections,copy,heapq,itertools,math,string import sys def S(): return sys.stdin.readline().rstrip() def M(): return map(int,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) N = I() d = LI() ans = 0 l = list(itertools.combinations(d,2)) for i, j in l: ans += i*j print(ans)
1
167,986,365,646,752
null
292
292
while True: H,W = map(int,raw_input().split()) if H == 0 and W == 0: break a = "#" for i in xrange(0,H): print a * W print ""
# coding: utf-8 # Your code here! while(1): H,W=map(int,input().split(" ")) if H==0 and W==0: break else: for i in range(H): for j in range(W): print("#",end="") print("") print("")
1
773,610,999,068
null
49
49
# coding: utf-8 # Your code here! import sys n,k=map(int,input().split()) H=list(map(int,input().split())) H.sort() if n>k: for i in range(k): H[n-1-i]=0 else: print(0) sys.exit() sum_H=sum(H) print(sum_H)
n,k = map(int,input().split()) h = list(map(int,input().split())) print(sum(sorted(h)[:n-k]) if n-k>0 else 0)
1
79,035,921,067,510
null
227
227
def solve(n): if n % 2 == 0: return n // 2 - 1 else: return (n - 1) // 2 def main(): n = int(input()) res = solve(n) print(res) def test(): assert solve(4) == 1 assert solve(999999) == 499999 if __name__ == "__main__": test() main()
n=int(input()) if n%2==0: print(int((n/2)-1)) else: print(int((n-1)/2))
1
153,618,354,334,048
null
283
283
from math import factorial N = int(input()) P = [int(x) for x in input().split()] Q = [int(x) for x in input().split()] orderP = 1 + (P[0]-1)*factorial(N-1) orderQ = 1 + (Q[0]-1)*factorial(N-1) for i in range(1,N): redP = 0 redQ = 0 for j in range(i): if P[j] < P[i]: redP += 1 if Q[j] < Q[i]: redQ += 1 orderP += (P[i]-redP-1)*factorial(N-i-1) orderQ += (Q[i]-redQ-1)*factorial(N-i-1) print(abs(orderP - orderQ))
import itertools def LI(): return tuple(map(int, input().split())) N = int(input()) P = LI() Q = LI() Nlist = list(range(1, N+1)) count = 1 for v in itertools.permutations(Nlist, N): if P == v: p = count if Q == v: q = count count += 1 print(abs(p-q))
1
100,679,238,919,984
null
246
246
n = int(input()) s = [input() for _ in range(n)] s_sort = sorted(s) s_num = [1]*n for i in range(1,n): if s_sort[i] == s_sort[i-1]: s_num[i] += s_num[i-1] Maxnum = max(s_num) index_num = [n for n, v in enumerate(s_num) if v == Maxnum] [print(s_sort[i]) for i in index_num]
import sys for line in sys.stdin: a, b = map(int, line.split()) c = a * b while b: a, b = b, a % b print(str(a) + ' ' + str(c / a))
0
null
35,162,086,835,332
218
5
import sys def solve(): while True: x,y = map(int,input().split()) if x == 0 and y == 0: break else: if x > y: x,y = y,x print(x,y) solve()
n = int(input()) p = str(tuple(map(int, input().split()))) q = str(tuple(map(int, input().split()))) import itertools n_l = [ i+1 for i in range(n) ] d = {} for i, v in enumerate(itertools.permutations(n_l)): d[str(v)] = i print(abs(d[p]-d[q]))
0
null
50,854,530,879,450
43
246
S = input() N = int(input()) for i in range(N): operate = input().split() if operate[0] == "replace": n = int(operate[1]) m = int(operate[2])+1 left_str = S[:n] right_str = S[m:] center_str = operate[3] S = left_str + center_str + right_str elif operate[0] == "reverse": n = int(operate[1]) m = int(operate[2])+1 left_str = S[:n] center_str = S[n:m] right_str = S[m:] center_str = center_str[::-1] S = left_str + center_str + right_str elif operate[0] == "print": n = int(operate[1]) m = int(operate[2])+1 left_str = S[:n] center_str = S[n:m] right_str = S[m:] print(center_str)
def cal(S): tmp, a, cnt = S[0], 1, 0 flag = True for s in S[1:]: if S[0]!=s: flag=False if flag: a+=1 if tmp[-1]==s: s = '*' cnt += 1 tmp += s return a, cnt S = input().replace('\n', '') k = int(input()) ans = 0 if len(list(set(S)))==1: ans = len(S)*k//2 else: a, cnt = cal(S) b, _ = cal(S[::-1]) ans = cnt*k if S[0]==S[-1]: ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1) print(ans)
0
null
88,594,896,383,420
68
296
def main(): n, k = map(int, input().split()) results = tuple(map(int, input().split())) for i in range(n-k): print('Yes' if results[i] < results[i+k] else 'No') if __name__ == '__main__': main()
N,K=map(int,input().split()) a=list(map(int,input().split())) for v in range(N-K): if a[v]>=a[K+v]: print("No") else: print("Yes")
1
7,102,411,354,542
null
102
102
import fractions, sys input = sys.stdin.buffer.readline def lcm(x, y): return (x * y) // fractions.gcd(x, y) def calc(n, m): for i in range(cycle//m+1): X = m * (i + 0.5) if X > M: print(0) exit() return flag = True for x in n: if (X - x // 2) % x != 0: flag = False break if flag: return int(X) print(0) exit() return N, M = map(int, input().split()) A = list(map(int, input().split())) cycle = 1 ma = 0 for a in A: cycle = lcm(cycle, a) ma = max(ma, a) start = calc(A, ma) print((M - start) // cycle + 1)
from fractions import gcd from functools import reduce import sys def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) # def lcm_list(numbers, maxvalue): # first = 1 # second = 1 # for i in numbers: # second = i # lcm_result = lcm_base(first, second) # if lcm_result > maxvalue: # return -1 # first = lcm_result # return lcm_result n, m = map(int, input().split()) A = list(map(int, input().split())) max_value = 2 * m try: lcm = lcm_list(A) except: print("0") sys.exit(0) if lcm > max_value: print("0") sys.exit(0) if lcm == -1: print("0") sys.exit(0) if any((lcm / a) % 2 != 1 for a in A): print("0") sys.exit(0) max_product = max_value // lcm print((max_product + 1) // 2)
1
101,915,058,117,696
null
247
247
L = input().split() L.reverse() print(*L, sep="")
st=input().rstrip().split(" ") s=st[0] t=st[1] print(t,end="") print(s)
1
103,224,273,387,872
null
248
248
### ---------------- ### ここから ### ---------------- import sys from io import StringIO import unittest def yn(b): print("Yes" if b==1 else "No") return def resolve(): readline=sys.stdin.readline n,m=map(int, readline().rstrip().split()) ac=[0]*n wa=[0]*n for i in range(m): p,s=readline().rstrip().split() p=int(p)-1 if s=="AC": ac[p]=1 continue if ac[p]==0: wa[p]+=1 for i in range(n): wa[i]*=ac[i] print(sum(ac),sum(wa)) return if 'doTest' not in globals(): resolve() sys.exit() ### ---------------- ### ここまで ### ----------------
k=int(input()) def gcd(a,b): if b==0: return a else: return gcd(b,a%b) ans=0 for i in range(1,k+1): for j in range(1,k+1): for l in range(1,k+1): ans+=gcd(gcd(i,j),l) print(ans)
0
null
64,480,887,113,720
240
174
n=int(input()) l=sorted(list(map(int,input().split()))) for i,x in enumerate(l): l[i]=format(x,'63b') memo=[0]*63 for i in range(63): for j in range(n): if l[j][i]=='1': memo[-i-1]+=1 now=1 ans=0 mod=10**9+7 for x in memo: ans+=(now*x*(n-x))%mod now*=2 print(ans%mod)
n, k = map(int, input().split()) p = list(map(lambda x: (1+int(x))/2, input().split())) s = sum(p[0:k]) ans = s for i in range(k, n): s += p[i] - p[i-k] ans = max(ans, s) print(ans)
0
null
98,851,602,524,820
263
223
def g(x): return x*(x+1)//2 n=int(input()) ans=0 for i in range(1,n+1): ans=ans+i*g(n//i) print(ans)
n = int(input()) dp = [0]*(n+1) for i in range(1,n+1): x = n//i for j in range(1,x+1): dp[i*j]+=1 sum_div = 0 for i in range(1,n+1): sum_div += i*dp[i] print(sum_div)
1
11,003,516,582,850
null
118
118
N = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(N): s = input() if s == "AC": ac += 1 elif s == "WA": wa += 1 elif s == "TLE": tle += 1 else: re += 1 print("AC x", ac) print("WA x", wa) print("TLE x", tle) print("RE x", re)
N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = list(input()) for i in range(N): if i >= K and T[i-K] == T[i]: T[i] = 'a' ans = 0 for i in T: if i == 'r': ans += P elif i == 's': ans += R elif i == 'p': ans += S print(ans)
0
null
57,715,920,632,770
109
251
import sys input = lambda: sys.stdin.readline().rstrip() def main(): a = list(map(int, input().split())) if sum(a) >= 22: print('bust') else: print('win') if __name__ == '__main__': main()
h,w=map(int,input().split()) if h!=1 and w!=1: print((h*w+2-1)//2) else: print(1)
0
null
84,719,571,540,690
260
196
# UnionFind: https://note.nkmk.me/python-union-find/ class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) def find(self, x): if self.root[x] < 0: return x else: self.root[x] = self.find(self.root[x]) return self.root[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.root[x] > self.root[y]: x, y = y, x self.root[x] += self.root[y] self.root[y] = x def is_same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.root[self.find(x)] n, m = map(int, input().split()) friends = UnionFind(n) for i in range(m): a, b = map(int, input().split()) friends.unite(a, b) print(max(friends.size(i) for i in range(n)))
from networkx import * N,M = map(int,input().split()) if M==0: print(1) exit() else: A = [list(map(int,input().split())) for m in range(M)] G = Graph() G.add_edges_from(A) print(len(max(connected_components(G),key=len)))
1
3,925,044,764,560
null
84
84
A, V = map(int,input().split()) B, W = map(int,input().split()) T = int(input()) if V!=W: t = (B-A)/(V-W) if A>B: t=-t if 0<=t<=T: print('YES') else: print('NO') else: if A!=B: print('NO') else: print('YES')
def readinput(): n=int(input()) a=list(map(int,input().split())) return n,a def main(n,a): a.sort() for i in range(n-1): if a[i]==a[i+1]: return 'NO' return 'YES' if __name__=='__main__': n,a=readinput() ans=main(n,a) print(ans)
0
null
44,358,514,148,068
131
222
s = int(input()) m = s // 60 s = s % 60 h = m // 60 m = m % 60 print("{}:{}:{}".format(h, m, s))
s = int(input()) print('%d:%d:%d' % (s / 3600, (s % 3600) / 60, s % 60))
1
329,808,068,590
null
37
37
# -*- coding: utf-8 -*- """ D - Knight https://atcoder.jp/contests/abc145/tasks/abc145_d """ import sys def modinv(a, m): b, u, v = m, 1, 0 while b: t = a // b a -= t * b a, b = b, a u -= t * v u, v = v, u u %= m return u if u >= 0 else u + m def solve(X, Y): MOD = 10**9 + 7 if (X + Y) % 3: return 0 n = (X - 2 * Y) / -3.0 m = (Y - 2 * X) / -3.0 if not n.is_integer() or not m.is_integer() or n < 0 or m < 0: return 0 n, m = int(n), int(m) x1 = 1 for i in range(2, n + m + 1): x1 = (x1 * i) % MOD x2 = 1 for i in range(2, n+1): x2 = (x2 * i) % MOD for i in range(2, m+1): x2 = (x2 * i) % MOD ans = (x1 * modinv(x2, MOD)) % MOD return ans def main(args): X, Y = map(int, input().split()) ans = solve(X, Y) print(ans) if __name__ == '__main__': main(sys.argv[1:])
# https://atcoder.jp/contests/abc145/tasks/abc145_d class Combination: # 計算量は O(n_max + log(mod)) def __init__(self, n_max, mod=10**9+7): self.mod = mod f = 1 self.fac = fac = [f] for i in range(1, n_max+1): # 階乗(= n_max !)の逆元を生成 f = f * i % mod # 動的計画法による階乗の高速計算 fac.append(f) # fac は階乗のリスト f = pow(f, mod-2, mod) # 階乗から階乗の逆元を計算。フェルマーの小定理より、 a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime # python の pow 関数は自動的に mod の下での高速累乗を行ってくれる self.facinv = facinv = [f] for i in range(n_max, 0, -1): # 上記の階乗の逆元から階乗の逆元のリストを生成(= facinv ) f = f * i % mod facinv.append(f) facinv.reverse() # "n 要素" は区別できる n 要素 # "k グループ" はちょうど k グループ def __call__(self, n, r): # self.C と同じ return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod def C(self, n, r): if not 0 <= r <= n: return 0 return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod X, Y = map(int, input().split()) if (2*Y- X) % 3 or (2*X- Y) % 3: print(0) exit() x = (2*Y - X) // 3 y = (2*X - Y) // 3 n = x + y r = x mod = 10**9 + 7 f = 1 for i in range(1, n + 1): f = f*i % mod fac = f f = pow(f, mod-2, mod) facinv = [f] for i in range(n, 0, -1): f = f*i % mod facinv.append(f) facinv.append(1) comb = Combination(n) print(comb.C(n,r))
1
150,137,416,302,240
null
281
281
#Exhaustive Search (bit全探索ver) n = int(input()) A = list(map(int,input().split())) q = int(input()) m = list(map(int,input().split())) count_list = [] for i in range(1<<n): copy_A = A.copy() count = 0 for j in range(n): mask = 1 << j if mask & i != 0: count += A[j] count_list.append(count) for k in m: if k in count_list: print('yes') else: print('no')
N = int(input()) A = list(map(int, input().split())) Q = int(input()) M = list(map(int, input().split())) combinations = {} def create_combinations(idx, sum): combinations[sum] = 1 if idx >= N: return create_combinations(idx+1, sum) create_combinations(idx+1, sum+A[idx]) return create_combinations(0, 0) for target in M: if target in combinations.keys(): print("yes") else: print("no")
1
100,609,868,622
null
25
25
def solve(): N, K = map(int, input().split()) *P, = map(int, input().split()) *C, = map(int, input().split()) ans = -float("inf") for pos in range(N): used = [-1] * N cost = [0] * (N+1) for k in range(N+1): if k: cost[k] = cost[k-1] + C[pos] if used[pos] >= 0: loop_size = k-used[pos] break used[pos] = k pos = P[pos] - 1 if cost[loop_size] <= 0: ans = max(ans, max(cost[1:K+1])) else: a, b = divmod(K, loop_size) v1 = cost[loop_size] * (a-1) + max(cost[:K+1]) v2 = cost[loop_size] * a + max(cost[:b+1]) ans = max(ans, max(v1, v2) if a else v2) print(ans) solve()
#atcoder template def main(): import sys imput = sys.stdin.readline #文字列入力の時は上記はerrorとなる。 #ここにコード #input N = int(input()) A, B = [0] * N, [0] * N for i in range(N): A[i], B[i] = map(int, input().split()) #output import statistics as st import math p = st.median(A) q = st.median(B) # %% if N % 2 == 0: print(int((q-p)/0.5)+1) else: print(int(q-p)+1) #N = 1のときなどcorner caseを確認! if __name__ == "__main__": main()
0
null
11,244,062,474,414
93
137
n=int(input()) a=list(map(int,input().split())) b=[0]*n for i in range(0,n): b[a[i]-1]=i+1 ans='' for i in range(n): ans+=str(b[i])+' ' print(ans)
#176 A N, X, T = list(map(int, input().split())) if N % X == 0: print((int(N/X)) * T) else: print((int(N/X) + 1) * T)
0
null
92,713,333,861,712
299
86
def med(l): t = len(l) if t%2: return l[t//2] else: return (l[t//2]+l[t//2-1])/2 n = int(input()) a = [] b = [] for i in range(n): x,y = map(int,input().split()) a+=[x] b+=[y] a.sort() b.sort() if n%2==0: print(int((med(b)-med(a))*2)+1) else: print(med(b)-med(a)+1)
#!/usr/bin/python3 # -*- coding:utf-8 -*- import numpy def main(): n = int(input()) la, lb = [], [] for _ in range(n): a, b = map(int, input().split()) la.append(a) lb.append(b) la.sort(), lb.sort() if n % 2 == 0: s = (n-1)//2 e = s + 2 ma = sum(la[s:e]) / 2.0 mb = sum(lb[s:e]) / 2.0 print(int(2 * (mb - ma) + 1)) if n % 2 == 1: ma = la[n//2] mb = lb[n//2] print(mb - ma + 1) if __name__=='__main__': main()
1
17,308,579,273,790
null
137
137
n,k=map(int,input().split()) s=list(map(int,input().split())) z=0 for i in range(n): if s[i]>=k: z+=1 print(z)
num_persons, need_height = map(int, input().split()) a = map(int, input().split()) height_list = list(a) count_height_ok = 0 for i in height_list: if i >= need_height: count_height_ok += 1 print(count_height_ok)
1
179,199,747,462,610
null
298
298
n,m=map(int,raw_input().split()) if m ==n: print "Yes" else: print "No"
def main(): N, M = map(int, input().split()) if N == M: print("Yes") exit(0) print("No") if __name__ == "__main__": main()
1
83,488,168,754,720
null
231
231
#coding:utf-8 #1_4_C 2015.3.29 while True: data = input() if '?' in data: break print(eval(data.replace('/','//')))
N = int(input()) alph = ['z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',\ 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',\ 'x', 'y'] seq = [] while N > 0: s = N % 26 N = (N - 1) // 26 seq.append(s) L = len(seq) name = '' for i in range(L): name = alph[seq[i]] + name print(name)
0
null
6,252,970,854,588
47
121
a,b,x = map(int,input().split()) import math d = x/(a**2) c = b-d e = c*2 if e<=b: f = (e**2+a**2)**(1/2) g = (f**2+a**2-e**2)/(2*f*a) print(math.degrees(math.acos(g))) else: e = 2*x/(a*b) #print(e) a = b f = (e**2+a**2)**(1/2) g = (f**2+a**2-e**2)/(2*f*a) print(90-(math.degrees(math.acos(g))))
import sys printf = sys.stdout.write word = [] new_word = [] for line in sys.stdin: word.append((line.strip("\n")).lower()) for i in range(len(word)): new_word.append(word[i].split(" ")) ans = 0 for i in range(len(new_word)): for j in range(len(new_word[i])): if new_word[i][j].count(new_word[0][0]) > 0: if len(new_word[i][j]) == len(new_word[0][0]): ans += new_word[i][j].count(new_word[0][0]) print ans - 1
0
null
82,274,750,968,620
289
65
N, K = map(int, input().split()) p = list(map(int, input().split())) E = [0] * N for i in range(N): P = 0.5 * p[i] * (p[i] + 1) E[i] = P / p[i] S = sum(E[:K]) s = S for i in range(N - K): s -= E[i] s += E[i + K] S = max(S, s) print(S)
import bisect,collections,copy,heapq,itertools,math,numpy,string,scipy import sys sys.setrecursionlimit(10**7) def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): N,K = LI() P = LI() Pe = [(v+1)/2 for v in P] P_ms = numpy.cumsum(Pe) if K==N:print("{:.12f}".format(sum(Pe)));exit(0) ans = 0 for i in range(K,N): ans = max(ans,P_ms[i]-P_ms[i-K]) print("{:.12f}".format(ans)) main()
1
75,210,986,348,102
null
223
223
K = int(input()) S = input() print(S[:K]+(K<len(S))*"...")
K = int(input()) S = str(input()) SK = S[0: (K)] if len(S) <= K: print(S) else: print(SK + '...')
1
19,720,507,655,758
null
143
143
import sys def input(): return sys.stdin.readline().rstrip() class UnionFind(): def __init__(self, n): self.n=n self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数) def find(self,x): #グループの根を返す if self.parents[x]<0:return x else: self.parents[x]=self.find(self.parents[x]) return self.parents[x] def unite(self,x,y): #要素x,yのグループを併合 x,y=self.find(x),self.find(y) if x==y:return if self.parents[x]>self.parents[y]:#要素数の大きい方をxに x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x #要素数が大きい方に併合 def size(self,x): #xが属するグループの要素数 return -self.parents[self.find(x)] def same(self,x,y): #xとyが同じグループ? return self.find(x)==self.find(y) def members(self,x): #xと同じグループに属する要素のリスト root=self.find(x) return [i for i in range(self.n) if self.find(i)==root] def main(): n,m,k=map(int,input().split()) AB=[tuple(map(int,input().split())) for i in range(m)] CD=[tuple(map(int,input().split())) for i in range(k)] un=UnionFind(n) friend=[[] for _ in range(n)] for a,b in AB: un.unite(a-1,b-1) friend[a-1].append(b-1) friend[b-1].append(a-1) blockc=[0]*n for c,d in CD: if un.same(c-1,d-1): blockc[c-1]+=1 blockc[d-1]+=1 for i in range(n): print(un.size(i)-1-blockc[i]-len(friend[i])) if __name__=='__main__': main()
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n, m, k = map(int, input().split()) uf = UnionFind(n) friend = [set([]) for i in range(n)] for i in range(m): ai, bi = map(int, input().split()) ai -= 1; bi -= 1 uf.union(ai, bi) friend[ai].add(bi) friend[bi].add(ai) block = [set([]) for i in range(n)] for i in range(k): ci, di = map(int, input().split()) ci -= 1; di -= 1 block[ci].add(di) block[di].add(ci) for i in range(n): uf.find(i) ans = [] for i in range(n): num = uf.size(i) - len(friend[i]) - 1 for j in block[i]: if uf.find(i) == uf.find(j): num -= 1 ans.append(num) print(' '.join(map(str, ans)))
1
61,572,881,186,582
null
209
209
n = input() for i in xrange(n): a, b, c = sorted(map(int, raw_input().split())) print 'YES' if a*a+b*b==c*c else 'NO'
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools from collections import Counter def main(): def factorization(n): if n == 1: return [] arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr m = [0] for i in range(1,10**6): m.append(m[i-1]+i) ans = 0 n = int(input()) k = factorization(n) for i,l in k: for u in range(len(m)): if l < m[u]: ans += u-1 break print(ans) if __name__=="__main__": main()
0
null
8,411,346,629,920
4
136
HP, n = map(int, input().split()) AB = [list(map(int,input().split())) for _ in range(n)] # DP ## DP[i]は、モンスターにダメージ量iを与えるのに必要な魔力の最小コスト ## DPの初期化 DP = [float('inf')] * (HP+1); DP[0] = 0 ## HP分だけDPを回す. for now_hp in range(HP): ## 全ての魔法について以下を試す. for damage, cost in AB: ### 与えるダメージは、現在のダメージ量+魔法のダメージか体力の小さい方 next_hp = min(now_hp+damage, HP) ### 今の魔法で与えるダメージ量に必要な最小コストは、-> ####->現在わかっている値か今のHPまでの最小コスト+今の魔法コストの小さい方 DP[next_hp] = min(DP[next_hp], DP[now_hp]+cost) print(DP[-1])
from math import sqrt N = input() sum = 0 for _ in xrange(N): n = input() for i in xrange(2,int(sqrt(n))+1): if n%i == 0: break else: sum += 1 print sum
0
null
40,730,061,733,960
229
12