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
n, m, l = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] b = [list(map(int, input().split())) for _ in range(m)] c = [[0 for i in range(l)] for j in range(n)] for i in range(n): for j in range(l): for k in range(m): c[i][j] += a[i][k] * b[k][j] for i in range(n): print(" ".join(map(str, c[i])))
def main(): N, D = map(int, input().split()) ans = 0 for _ in range(N): x, y = map(int, input().split()) if x*x + y* y <= D*D: ans += 1 return ans if __name__ == '__main__': print(main())
0
null
3,686,761,737,148
60
96
import math alpha = [] while True: n = float(raw_input()) if n == 0: break nums_str = raw_input().split() nums = [] for s in nums_str: nums.append(float(s)) ave = sum(nums)/n n_sum = 0.0 for num in nums: n_sum += (num-ave)**2 alpha.append(n_sum/n) for a in alpha: print math.sqrt(a)
import math def main(): while True: n = int(input()) if n == 0: break nums = list(map(int, input().split())) mean = sum(nums) / n var = sum((s - mean) ** 2 for s in nums) / n sd = math.sqrt(var) print(sd) if __name__ == "__main__": main()
1
186,722,358,146
null
31
31
H = int(input()) def attack(h): if h == 1: return 0 r = 2 h //= 2 ans = 2 while h > 1: h //= 2 r *= 2 ans += r return ans print(1 + attack(H))
h = int(input()) ans = 0 n_enemy = 1 while h > 1: h //= 2 ans += n_enemy n_enemy *= 2 if h == 1: ans += n_enemy print(ans)
1
79,884,355,433,062
null
228
228
def lcm(a, b): from fractions import gcd return a // gcd(a, b) * b def main(): _ = int(input()) a = list(map(int, input().split())) x = 1 for e in a: x = lcm(x, e) ans = 0 for e in a: ans += x // e print(ans % int(1e9 + 7)) main()
suits = ['S', 'H', 'C', 'D'] table = [[False] * 14 for i in range(4)] N = int(input()) for _i in range(N): mark, num = input().split() num = int(num) if mark == 'S': table[0][num] = True if mark == 'H': table[1][num] = True if mark == 'C': table[2][num] = True if mark == 'D': table[3][num] = True for i in range(4): for j in range(1, 14): if not table[i][j]: print(f'{suits[i]} {j}')
0
null
44,165,090,264,310
235
54
a1, a2, a3 = map(int, input().split(" ")) tmp = a1 + a2 + a3 if tmp >= 22: print("bust") else: print("win")
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) a = LI() s = sum(a) if s >= 22: print('bust') else: print('win')
1
118,802,437,548,900
null
260
260
import sys import fractions input = sys.stdin.readline mod = 10 ** 9 + 7 N = int(input().strip()) A = list(map(int, input().strip().split(" "))) lcm = 1 for a in A: lcm = a // fractions.gcd(a, lcm) * lcm print(sum([lcm // a for a in A]) % mod)
def gcd (a, b): while b != 0: a, b = b, a%b return a def lcm(a, b,mod): return a*b//gcd(a,b) N = int(input()) A = list(map(int,input().split())) mod = 10**9+7 b = 1 for i in range(N): a = A[i] b = lcm(a,b,mod) ans = 0 for a in A: ans += b//a print(ans%mod)
1
87,563,487,084,220
null
235
235
n = int(input()) xlist = list(map(int,input().split())) sum = 0 for i in range(n): for j in range(i+1,n): sum+=xlist[i]*xlist[j] print(sum)
import sys import time import random import math from collections import deque import heapq import itertools from decimal import Decimal import bisect from operator import itemgetter MAX_INT = int(10e18) MIN_INT = -MAX_INT mod = 1000000000+7 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return input() def tami(ans): res = 0 LastDay = [0]*26 for i in range(D): res += s[i][ans[i]] for j in range(26): if ans[i] == j: continue res -= (i+1 - LastDay[j]) * c[j] LastDay[ans[i]] = i+1 return res def nasu(): res = [] LastDay = [0]*26 for d in range(1,D+1): tmp = ["", 0] for i in range(26): if tmp[1] < s[d-1][i] + (d - LastDay[i]) * c[i]: tmp = [i, s[d-1][i] + (d - LastDay[i]) * c[i]] res.append(tmp[0]) LastDay[tmp[0]] = d return res def nbo(ans, score, num): tmp_ans = ans[:] for _ in range(num): random_date = random.randint(0,D-1) random_val = random.randint(0,25) tmp_ans[random_date] = random_val scoscore = tami(tmp_ans) if scoscore > score: return (True, tmp_ans, scoscore) else: return (False, tmp_ans, scoscore) start = time.time() D = I() c = IL() s = [IL() for i in range(D)] ans = nasu() #print(ans) score = tami(ans) #print(score) end = time.time() num = 4 while (time.time() - start) < 1.8: judge, anans, scoscore = nbo(ans, score, num) if judge == True: ans, score = anans, scoscore #print(ans) #print(tami(ans)) for i in ans: print(i+1)
0
null
89,068,863,544,192
292
113
INF=1000000000+7 s=int(input()) dp=[0]*(2000+1); dp[0]=dp[1]=dp[2]=0 dp[3]=1 for i in range(4,s+1): temp=1 for j in range(3,i-2): temp+=dp[j]%INF; temp%=INF; dp[i]=temp print(dp[s])
from sys import stdin,stdout l,r,d=list(map(int,stdin.readline().strip().split())) c=0 if l%d==0 and r%d==0: stdout.write(str(int(r/d)-int(l/d)+1)+'\n') else: stdout.write(str(int(r/d)-int(l/d))+'\n')
0
null
5,409,983,469,248
79
104
ans = [] while True: arr = map(int, raw_input().split()) if arr[0] == 0 and arr[1] == 0: break else: arr.sort() ans.append(arr) for x in ans: print(" ".join(map(str, x)))
while 1: x,y=map(int,raw_input().split()) if x==y==0: exit() else: print min(x,y),max(x,y)
1
516,632,768,038
null
43
43
N, K = map(int, input().split()) LR = [tuple(map(int, input().split())) for _ in range(K)] MOD = 998244353 class Mint: __slots__ = ('value') def __init__(self, value=0): self.value = value % MOD if self.value < 0: self.value += MOD @staticmethod def get_value(x): return x.value if isinstance(x, Mint) else x def inverse(self): a, b = self.value, MOD u, v = 1, 0 while b: t = a // b b, a = a - t * b, b v, u = u - t * v, v if u < 0: u += MOD return u def __repr__(self): return str(self.value) def __eq__(self, other): return self.value == other.value def __neg__(self): return Mint(-self.value) def __hash__(self): return hash(self.value) def __bool__(self): return self.value != 0 def __iadd__(self, other): self.value = (self.value + Mint.get_value(other)) % MOD return self def __add__(self, other): new_obj = Mint(self.value) new_obj += other return new_obj __radd__ = __add__ def __isub__(self, other): self.value = (self.value - Mint.get_value(other)) % MOD if self.value < 0: self.value += MOD return self def __sub__(self, other): new_obj = Mint(self.value) new_obj -= other return new_obj def __rsub__(self, other): new_obj = Mint(Mint.get_value(other)) new_obj -= self return new_obj def __imul__(self, other): self.value = self.value * Mint.get_value(other) % MOD return self def __mul__(self, other): new_obj = Mint(self.value) new_obj *= other return new_obj __rmul__ = __mul__ def __ifloordiv__(self, other): other = other if isinstance(other, Mint) else Mint(other) self *= other.inverse() return self def __floordiv__(self, other): new_obj = Mint(self.value) new_obj //= other return new_obj def __rfloordiv__(self, other): new_obj = Mint(Mint.get_value(other)) new_obj //= self return new_obj LR.sort(key=lambda x: x[1]) pl = pr = -1 LR2 = [] for l, r in LR: if LR2: pl, pr = LR2.pop() if l <= pl: LR2.append((l, r)) elif l <= pr: LR2.append((pl, r)) else: LR2.append((pl, pr)) LR2.append((l, r)) else: LR2.append((l, r)) dp = [Mint() for _ in range(N + 5)] dp[1] += 1 dp[2] -= 1 for i in range(1, N): dp[i] += dp[i - 1] for l, r in LR2: nl = min(i + l, N + 1) nr = min(i + r, N + 1) dp[nl] += dp[i] dp[nr + 1] -= dp[i] dp[N] += dp[N - 1] print(dp[N])
n, k = map(int, input().split()) lr = [list(map(int, input().split())) for _ in range(k)] mod = 998244353 dp = [0] * n dp[0] = 1 acc = 0 for i in range(1, n): # 例4のi=13, lr=[[5, 8], [1, 3], [10, 15]]の場合を想像すると書きやすい for li, ri in lr: if i - li >= 0: acc += dp[i - li] acc %= mod if i - ri - 1 >= 0: acc -= dp[i - ri - 1] acc %= mod dp[i] = acc print(dp[-1])
1
2,682,864,198,224
null
74
74
s=input() print(s+'es' if s[-1]=='s' else s+'s')
days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] S = input() for i in range(7): if S == days[i]: print(7 - i) exit()
0
null
67,711,913,267,040
71
270
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n,m,k = map(int, readline().split()) a = list(map(int, readline().split())) b = list(map(int, readline().split())) sa = [0]*(n+1) sb = [0]*(m+1) for i in range(n): sa[i+1] = sa[i]+a[i] for i in range(m): sb[i+1] = sb[i]+b[i] isb=m ans = 0 for isa in range(n+1): if sa[isa]>k: break #while isb>0 and sa[isa]+sb[isb]>k: while sa[isa]+sb[isb]>k: isb-=1 ans = max(ans, isa+isb) print(ans)
def main(): N, X, Y = (int(i) for i in input().split()) cnt = [0]*N for i in range(1, N+1): for j in range(i+1, N+1): d = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-X)+abs(X-Y)+abs(j-Y)) cnt[d] += 1 for d in cnt[1:]: print(d) if __name__ == '__main__': main()
0
null
27,528,250,529,792
117
187
arr = map(int,raw_input().split()) if arr[0] < arr[1] and arr[1] < arr[2] : print "Yes" else : print "No"
# -*- coding: utf-8 -*- import sys X = int(input().strip()) #----- calc = {} for i in range(-118,120): calc[i] = i**5 for a in range(-118,120): for b in range(-118,120): if (calc[a] - calc[b]) == X: print(a,b) sys.exit()
0
null
12,884,101,466,308
39
156
N = int(input()) X = str(input()) F = [0] * N def calc_f(n:int)->int: global F x = n res = 0 while 0 < x: if F[x] != 0: res += F[x] break pop = bin(n).count('1') x %= pop res += 1 F[n] = res # 前処理 N以下のF値テーブル for i in range(1, N): calc_f(i) # ビット反転すると初期の1の個数に対して+1または-1どちらか pop_ini = X.count('1') pp = pop_ini + 1 # pop_plus pm = pop_ini - 1 # pop_minus # 2進の各桁をppとpmで割った値のテーブル ap = [0] * N # arr_plus am = [0] * N # arr_minus for i in range(N): ap[i] = pow(2, N-1-i, pp) if 0 < pm: am[i] = pow(2, N-1-i, pm) # 所与のXで計算、ベースになる値 fp = 0 # f_plus fm = 0 # f_minus for i in range(N): if X[i] == '1': fp = (fp + ap[i]) % pp if 0 < pm: fm = (fm + am[i]) % pm # 各桁を反転した場合では差分更新のみ for i in range(N): ans = 1 if X[i] == '1': if 0 < pm: v = (fm + pm - am[i]) % pm else: ans = 0 v = 0 else: v = (fp + ap[i]) % pp if 0 < v: ans += F[v] print(ans)
#!python3 import sys iim = lambda: map(int, sys.stdin.readline().rstrip().split()) from functools import lru_cache @lru_cache(maxsize=2*10**5) def f2(x): if x == 0: return 0 y = bin(x).count("1") return 1 + f2(x % y) def resolve(): N = int(input()) S = input() cnt0 = S.count("1") if cnt0 == 0: print(*[1]*N, sep="\n") return X = int(S, 2) dc = {} for k, v in (("0", 1), ("1", -1)): x = cnt0 + v y = X % x if x else 0 dc[k] = (x, v, y, [1, N-1]) ans = [0] * N for i in reversed(range(N)): si = S[i] cnt, v, n, m1 = dc[si] if cnt == 0: ans[i] = 0 continue ni = N - i - 1 m2 = (m1[0]<<(m1[1]-i)) % cnt n = (n + v*m2) % cnt m1[0] = m2; m1[1] = i ans[i] = 1 + f2(n) print(*ans, sep="\n") if __name__ == "__main__": resolve()
1
8,176,700,382,240
null
107
107
import sys N , K = map(int,input().split()) A = list(map(int,input().split())) for i in range(K, N): if A[i-K] < A[i]: print("Yes") else: print("No")
printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 def ddprint(x): if DBG: print(x) n = inn() a = inl() if n<=3: print(max(a)) exit() lacc = [0]*n racc = [0]*n lacc[0] = a[0] lacc[1] = a[1] racc[n-1] = a[n-1] racc[n-2] = a[n-2] for i in range(2,n): if i%2==0: lacc[i] = lacc[i-2]+a[i] else: lacc[i] = max(lacc[i-3],lacc[i-2])+a[i] if n%2==0: print(max(lacc[n-2],lacc[n-1])) exit() for i in range(n-3,-1,-1): if (n-1-i)%2==0: racc[i] = racc[i+2]+a[i] else: racc[i] = max(racc[i+3],racc[i+2])+a[i] mx = max(racc[2],lacc[n-3]) for i in range(1,n-2): if i%2==0: mx = max(mx, max(lacc[i-2],lacc[i-1])+racc[i+2]) else: mx = max(mx, max(racc[i+2],racc[i+3])+lacc[i-1]) print(mx)
0
null
22,299,536,611,450
102
177
for i in range(int(input())): temp = [int(x) for x in input().split()] stemp = sorted(temp) if stemp[2]**2 == stemp[1]**2 + stemp[0]**2: print('YES') else: print('NO')
n, m = map(int, input().split()) listAC = [0] * n listWAAC = [0] * n listWA = [0] * n for i in range(m): p, s = map(str, input().split()) p = int(p) - 1 if listAC[p] == 1: continue if s == 'AC': listAC[p] += 1 listWAAC[p] += listWA[p] continue listWA[p] += 1 print(sum(listAC), sum(listWAAC))
0
null
46,991,344,945,032
4
240
n, m = map(int,input().split()) A = tuple(map(int,input().split())) days = 0 for i in A: days += i if n < days: print(-1) else: print(n-days)
import sys import math import time readline = sys.stdin.readline def main(): listSum = [1, 3, 6] k = int(input()) sumGCD = 0 for a in range(1, k + 1): for b in range(a, k + 1): for c in range(b, k + 1): sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1] print(sumGCD) def gcd(a, b, c): return math.gcd(math.gcd(a, b), c) if __name__ == '__main__': s = time.time() main() # print(time.time() - s)
0
null
33,661,837,663,578
168
174
n,k = list(map(int,input().split())) r,s,p = list(map(int,input().split())) t = str(input()) t_list = [] for i in range(k): t_list.append(t[i]) for i in range(k,n): if t[i] != t_list[i-k] or t_list[i-k] == 'all': t_list.append(t[i]) else: t_list.append('all') print(t_list.count('r') * p + t_list.count('s') * r + t_list.count('p') * s)
# import sys # import math #sqrt,gcd,pi # import decimal # import queue # queue # import bisect # import heapq # priolity-queue # import time # from itertools import product,permutations,\ # combinations,combinations_with_replacement # 重複あり順列、順列、組み合わせ、重複あり組み合わせ # import collections # deque # from operator import itemgetter,mul # from fractions import Fraction # from functools import reduce mod = int(1e9+7) # mod = 998244353 INF = 1<<50 def readInt(): return list(map(int,input().split())) def main(): n,k = readInt() r,s,p = readInt() rsp = {"s":r,"p":s,"r":p} t = input() ans = 0 u = [] for i in range(n): if i<k: ans += rsp[t[i]] u.append(t[i]) else: if t[i]!=u[i-k]: ans += rsp[t[i]] u.append(t[i]) else: u.append("f") print(ans) return if __name__=='__main__': main()
1
106,689,032,383,512
null
251
251
import math N, K = map(int, input().split()) A = list(map(int, input().split())) left = 0 right = max(A) while right - left > 1: mid = (left + right) // 2 jk = 0 for i in range(N): jk += A[i] // mid - 1 if A[i] % mid != 0: jk += 1 if jk <= K: right = mid else: left = mid print(right)
import math n,k=map(int,input().split()) A=list(map(int,input().split())) low=1 high=max(A) while low!=high: mid=(low+high)//2 s=0 for i in range(n): s+=math.ceil(A[i]/mid)-1 if s>k: low=mid+1 else: high=mid print(low)
1
6,535,065,743,932
null
99
99
N, X, Y = map(int, input().split()) count = [0]*(N+1) for i in range(1, N+1): for k in range(i+1, N+1): distik = min(k-i, abs(k-X) + abs(i - Y)+1, abs(k-Y) + abs(i-X)+1) count[distik] += 1 for i in range(1, N): print(count[i])
N = str(input()) if N[-1] == '3': print('bon') elif (N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8'): print('pon') else: print('hon')
0
null
31,667,791,602,070
187
142
import collections N = int(input()) a = list(map(int,input().split())) c = collections.Counter(a) if c.most_common()[0][1]==1: print("YES") else: print("NO")
#coding:utf-8 import sys,os from collections import defaultdict, deque from fractions import gcd from math import ceil, floor sys.setrecursionlimit(10**6) write = sys.stdout.write dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0 def main(given=sys.stdin.readline): input = lambda: given().rstrip() LMIIS = lambda: list(map(int,input().split())) II = lambda: int(input()) XLMIIS = lambda x: [LMIIS() for _ in range(x)] YN = lambda c : print('Yes') if c else print('No') MOD = 10**9+7 N = II() A = LMIIS() print('YES' if len(A) == len(set(A)) else 'NO') if __name__ == '__main__': main()
1
74,028,960,284,770
null
222
222
import sys input = sys.stdin.readline n = int(input()) a = [int(i) for i in input().split()] if n <= 3: print(max(a)) exit() a = tuple(a) dp = [[-10**15]*3 for i in range(n)] dp[0][2] = a[0] dp[1][2] = a[1] dp[2][2] = a[0]+a[2] dp[3][2] = max(a[0],a[1])+a[3] dp[3][1] = a[0]+a[3] for i in range(2,n-2): if i%2 == 0: dp[i+2][2] = dp[i][2]+a[i+2] dp[i+2][1] = max(dp[i][1]+a[i+2],dp[i-1][2]+a[i+2]) dp[i+2][0] = max(dp[i][0]+a[i+2],dp[i-1][1]+a[i+2],dp[i-2][2]+a[i+2]) else: dp[i+2][2] = max(dp[i][2],dp[i][1],dp[i-1][2])+a[i+2] dp[i+2][1] = max(dp[i][1]+a[i+2],dp[i-1][2]+a[i+2]) if n%2 == 1: c = min(a[0],a[-1]) dp[n-1][2] -= c print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
n=int(input()) a=list(map(int,input().split())) if n//2==1: print(max(a)) exit() if n%2==0: #iは桁数、jはそれまでに余計に飛ばした数 #dp[i][j] dp=[[-10**9]*2 for _ in range(n)] for i in range(n): if i<2: dp[i][0]=a[i] if i>=2: dp[i][0]=dp[i-2][0]+a[i] if i>=3: dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i]) #print(dp) print(max([dp[-1][1],dp[-1][0],dp[n-2][0]])) else: #iは桁数、jはそれまでに余計に飛ばした数 #dp[i][j] dp=[[-10**9]*3 for _ in range(n)] for i in range(n): if i<2: dp[i][0]=a[i] if i>=2: dp[i][0]=dp[i-2][0]+a[i] if i>=3: dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i]) if i>=4: dp[i][2]=max([dp[i-2][2]+a[i],dp[i-3][1]+a[i],dp[i-4][0]+a[i]]) #print(dp) print(max([dp[-1][2],dp[-1][1],dp[-1][0]-a[0],dp[-1][0]-a[-1]]))
1
37,436,688,352,650
null
177
177
n, m, x = map(int, input().split()) c = [] algo = [] for _ in range(n): l = list(map(int, input().split())) c.append(l[0]) algo.append(l[1:]) cost = [] for i in range(2**n): c_sum = 0 u_sum = [0]*m for j in range(n): if (i>>j) & 1: c_sum += c[j] for k in range(m): u_sum[k] += algo[j][k] if all(s >= x for s in u_sum): cost.append(c_sum) if cost: print(min(cost)) else: print(-1)
H = int(input()) W = int(input()) N = int(input()) print(int((N+max(H,W)-1)/max(H,W)))
0
null
55,361,901,045,792
149
236
S = input() N = len(S) ans = 0 for k in range(N//2): if S[k] != S[-k-1]: ans += 1 print(ans)
a = input() b = a[::-1] c = 0 for i in range(int(len(a)/2)): if a[i] != b[i]: c += 1 print(c)
1
120,348,355,710,962
null
261
261
import sys sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python import math from copy import copy, deepcopy from copy import deepcopy as dcp from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) #q.rotate(n)で → にn回ローテート from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate,combinations,permutations#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする from functools import lru_cache#pypyでもうごく #@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率 from decimal import Decimal def input(): x=sys.stdin.readline() return x[:-1] if x[-1]=="\n" else x def printl(li): _=print(*li, sep="\n") if li else None def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def matmat(A,B): K,N,M=len(B),len(A),len(B[0]) return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] def matvec(M,v): N,size=len(v),len(M) return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] def T(M): n,m=len(M),len(M[0]) return [[M[j][i] for j in range(n)] for i in range(m)] def main(): mod = 1000000007 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え N = int(input()) #N, K = map(int, input().split()) A = tuple(map(int, input().split())) #1行ベクトル #L = tuple(int(input()) for i in range(N)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 dp=[0 for _ in range(N+1)] dp[1]=0 x=A[0] for i,a in enumerate(A[1:],2): if i%2!=0: dp[i]=max(a+dp[i-2],dp[i-1]) x+=a continue dp[i]=max(a+dp[i-2],x) print(dp[-1]) if __name__ == "__main__": main()
from collections import defaultdict INF = -1000000000000001 n = int(input()) l = list(map(int, input().split())) a = int(n/2) dpa = defaultdict(lambda: -INF) #dpa = [[0 for j in range(a+1)] for i in range(n+1)] dpa[(0,0)] = 0 dpa[(1,0)] = 0 dpa[(1,1)] = l[0] j = 1 for i in range(2,n+1): if i == j*2: dpa[(i,j)] = max(dpa[(i-2,j-1)]+l[i-1],dpa[(i-1,j)]) # print(i,j,dpa[(i,j)]) else: dpa[(i,j)] = max(dpa[(i-2,j-1)]+l[i-1],dpa[(i-1,j)]) # print(i,j,dpa[(i,j)]) if (i != n): j += 1 # print(i,j,dpa[(i,j)]) # print(" ",i-2,j-1,dpa[(i-2,j-1)],"") dpa[(i,j)] = dpa[(i-2,j-1)]+l[i-1] #print(dpa) print(dpa[n,a])
1
37,282,672,242,820
null
177
177
# 隣接リスト n = int(input()) graph = [] for _ in range(n): tmp = list(map(int, input().split())) if tmp[1] == 0: graph.append([]) else: graph.append(tmp[2:]) #print(graph) check = [0]*n count = 0 go = [0]*n back = [0]*n def dfs(v): #print(v) global count if check[v] == 0: check[v] = 1 count += 1 go[v] = count tolist = graph[v] if len(tolist) > 0: for i in tolist: dfs(i-1) count += 1 back[v] = count while True: if 0 in check: k = check.index(0) dfs(k) else: break #print("check\t:{}".format(check)) #print("go\t:{}".format(go)) #print("back\t:{}".format(back)) for i in range(n): print("{} {} {}".format(i+1, go[i], back[i]))
a,b=(int(x) for x in input().split()) print(a//b,a%b,"{0:.5f}".format(a/b))
0
null
294,205,523,740
8
45
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()) ndic = {i:set() for i in range(1,N+1)} bdic = {i:set() for i in range(1,N+1)} uf = UnionFind(N+1) rlt = [] for _ in range(M): a,b = map(int, input().split()) ndic[a].add(b) ndic[b].add(a) uf.union(a,b) for _ in range(K): a,b = map(int, input().split()) bdic[a].add(b) bdic[b].add(a) for i in range(1,N+1): tmp = uf.size(i) for a in bdic[i]: if uf.find(a) == uf.find(i): tmp -= 1 tmp -= len(ndic[i]) rlt.append(tmp-1) print(" ".join(map(str, rlt)))
import collections h,w=map(int,input().split()) board=[list(input()) for _ in range(h)] q=collections.deque() if board[0][0]=='#': q.append((0,0,1,1)) else: q.append((0,0,0,0)) dp=[[10**18]*w for _ in range(h)] ans=10**18 while len(q)!=0: x,y,cnt,flag=q.popleft() if x==w-1 and y==h-1: ans=min(ans,cnt) else: if x!=w-1: if flag==0: if board[y][x+1]=='#': if dp[y][x+1]>cnt+1: q.append((x+1,y,cnt+1,1)) dp[y][x+1]=cnt+1 else: if dp[y][x+1]>cnt: q.append((x+1,y,cnt,0)) dp[y][x+1]=cnt else: if board[y][x+1]=='#': if dp[y][x+1]>cnt: q.append((x+1,y,cnt,1)) dp[y][x+1]=cnt else: if dp[y][x+1]>cnt: q.append((x+1,y,cnt,0)) dp[y][x+1]=cnt if y!=h-1: if flag==0: if board[y+1][x]=='#': if dp[y+1][x]>cnt+1: q.append((x,y+1,cnt+1,1)) dp[y+1][x]=cnt+1 else: if dp[y+1][x]>cnt: q.append((x,y+1,cnt,0)) dp[y+1][x]=cnt else: if board[y+1][x]=='#': if dp[y+1][x]>cnt: q.append((x,y+1,cnt,1)) dp[y+1][x]=cnt else: if dp[y+1][x]>cnt: q.append((x,y+1,cnt,0)) dp[y+1][x]=cnt print(dp[-1][-1])
0
null
55,580,099,065,360
209
194
mod = 1000000007 N = int(input()) A = list(map(int, input().split())) C = [0,0,0] ans = 1 i = 0 while i < N: a = A[i] cnt = sum([1 if C[j] == a else 0 for j in range(3)]) ans = (ans*cnt)%mod if C[0] == a: C[0] += 1 elif C[1] == a: C[1] += 1 else: C[2] += 1 i += 1 print(ans)
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e n = int(input()) nums = map(int, input().split()) MOD = 1000000007 ans = 1 cnt = [3 if i == 0 else 0 for i in range(n + 1)] for num in nums: ans = ans * cnt[num] % MOD if ans == 0: break cnt[num] -= 1 cnt[num+1] += 1 print(ans)
1
129,793,940,101,684
null
268
268
def main(): n, d = map(int, input().split()) count = 0 for _ in range(n): x, y = map(int, input().split()) if (x**2 + y**2) ** 0.5 <= d: count += 1 print(count) if __name__ == '__main__': main()
def resolve(): import sys input = sys.stdin.readline # 整数 1 つ n = int(input()) s = input() # 整数複数個 # a, b = map(int, input().split()) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) # N = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in range(H)] cnt = 0 for i in range(n-2): if s[i]+s[i+1]+s[i+2] == "ABC": cnt += 1 print(cnt) resolve()
0
null
52,747,020,339,120
96
245
N=int(input()) xy = [tuple(map(int,input().split())) for _ in range(N)] ans = 0 def dist(tpl1, tpl2): return abs(tpl1[0] - tpl2[0]) + abs(tpl1[1] - tpl2[1]) f0 = [] f1 = [] for i in range(N): x, y = xy[i] f0.append(x-y) f1.append(x+y) ans = max(ans, max(f0) - min(f0), max(f1) - min(f1)) print(ans)
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) X = [] for _ in range(n): x, l = map(int, input().split()) X.append([x - l, x + l]) X = sorted(X, key=lambda x: x[1]) remove = 0 prev = X[0][1] for i in range(1, n): if X[i][0] < prev: remove += 1 else: prev = X[i][1] print(n - remove) if __name__ == '__main__': resolve()
0
null
46,521,213,891,138
80
237
x,y,z= map(str, input().split()) print(z,x,y, sep=' ')
a, b, c = map(int, input().split()) a, b = b, a a, c = c, a print(a, b, c, sep = " ")
1
38,053,850,717,122
null
178
178
import time as ti class MyQueue(object): """ My Queue class Attributes: queue: queue head tail """ def __init__(self): """Constructor """ self.length = 50010 self.queue = [0] * self.length # counter = 0 # while counter < self.length: # self.queue.append(Process()) # counter += 1 self.head = 0 self.tail = 0 # def enqueue(self, name, time): def enqueue(self, process): """enqueue method Args: name: enqueued process name time: enqueued process time Returns: None """ self.queue[self.tail] = process # self.queue[self.tail].name = name # self.queue[self.tail].time = time self.tail = (self.tail + 1) % self.length def dequeue(self): """dequeue method Returns: None """ # self.queue[self.head].name = "" # self.queue[self.head].time = 0 self.queue[self.head] = 0 self.head = (self.head + 1) % self.length def is_empty(self): """check queue is empty or not Returns: Bool """ if self.head == self.tail: return True else: return False def is_full(self): """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue): return True else: return False class Process(object): """process class """ def __init__(self, name="", time=0): """constructor Args: name: name time: time """ self.name = name self.time = time def forward_time(self, time): """time forward method Args: time: forward time interval Returns: remain time """ self.time -= time return self.time def time_forward(my_queue, interval, current_time,): """ Args: my_queue: queue interval: time step interval current_time: current time """ value = my_queue.queue[my_queue.head].forward_time(interval) if value <= 0: current_time += (interval + value) print my_queue.queue[my_queue.head].name, current_time my_queue.dequeue() elif value > 0: current_time += interval # name, time = my_queue.queue[my_queue.head].name, \ # my_queue.queue[my_queue.head].time my_queue.enqueue(my_queue.queue[my_queue.head]) my_queue.dequeue() return current_time my_queue = MyQueue() n, q = [int(x) for x in raw_input().split()] counter = 0 while counter < n: name, time = raw_input().split() my_queue.enqueue(Process(name, int(time))) counter += 1 # end_time_list = [] current_time = 0 while not my_queue.is_empty(): current_time = time_forward(my_queue, q, current_time)
import sys from collections import deque n,q = map(int,input().split()) f = lambda n,t: (n,int(t)) queue = deque(f(*l.split()) for l in sys.stdin) t = 0 while queue: name,time = queue.popleft() t += min(q, time) if time > q: queue.append((name, time-q)) else: print(name,t)
1
43,927,735,638
null
19
19
import sys data_list = sys.stdin.readlines() data_length = int(data_list.pop(0)) for x in xrange(data_length): lines = map(int, data_list[x].strip().split()) lines.sort(reverse = True) if lines[0]**2 == (lines[1]**2 + lines[2]**2): print "YES" else: print "NO"
delta = int(input()) tri_all = [] for i in range(delta): tri = list(map(int, input().split(' '))) tri.sort() tri_all.append(tri) for i in range(len(tri_all)): if tri_all[i][0]**2 + tri_all[i][1]**2 == tri_all[i][2]**2: print('YES') else: print('NO')
1
399,926,590
null
4
4
import copy class Dice2: def __init__(self, nums): self.nums = nums self.dic = \ {(1,2):3, (1,3):5, (1,4):2, (1,5):4, (2,3):1, (2,4):6, (2,6):3, (3,5):1, (3,6):5, (4,5):6, (4,6):2, (5,6):4} def output_right(self, x): x[0] = self.nums.index(x[0]) + 1 x[1] = self.nums.index(x[1]) + 1 nums = self.nums y = copy.deepcopy(x) x.sort() key = tuple(x) if tuple(y)==key: return nums[self.dic[key]-1] else: return nums[6-self.dic[key]] dice = Dice2(list(map(int, input().split()))) q = int(input()) for i in range(q): print(dice.output_right(list(map(int, input().split()))))
from sys import stdin from copy import deepcopy import queue class Dice: def __init__(self, nums): self.labels = [None] + [ nums[i] for i in range(6) ] self.pos = { "E" : 3, "W" : 4, "S" : 2, "N" : 5, "T" : 1, "B" : 6 } def rolled(dice, queries): d = deepcopy(dice) for q in queries: if q == "E": d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"] elif q == "W": d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"] elif q == "S": d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"] elif q == "N": d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"] else: return d nums = [int(x) for x in stdin.readline().rstrip().split()] q = int(stdin.readline().rstrip()) dice = Dice(nums) # TとSに対応するクエリを記憶し, resをすぐに呼び出せるようにする memo = [[False] * 7 for i in range(7)] memo[dice.pos["T"]][dice.pos["S"]] = "" # クエリとさいころの東面を記憶 res = { "" : dice.labels[dice.pos["E"]] } # BFSで探索, 解を求めたらreturn Trueで抜け出す # diceの中身をいじってはならない def solve(T, S): que = queue.Queue() que.put(dice) sol_q = ["E", "N", "S", "W"] while not que.empty(): d = que.get() if d.pos["T"] == T and d.pos["S"] == S: break else: for i in sol_q: d_next = Dice.rolled(d, i) que.put(d_next) memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next.labels[d_next.pos["E"]] else: return memo[T][S] for i in range(q): ts = [int(x) for x in stdin.readline().rstrip().split()] T = dice.labels.index(ts[0]) S = dice.labels.index(ts[1]) if solve(T, S) != False: print(res[memo[T][S]])
1
256,023,497,366
null
34
34
import sys readline = sys.stdin.readline N,K = map(int,readline().split()) DIV = 998244353 L = [None] * K R = [None] * K for i in range(K): L[i],R[i] = map(int,readline().split()) dp = [0] * (N + 1) sdp = [0] * (N + 1) dp[1] = 1 sdp[1] = 1 for i in range(2, len(dp)): for j in range(K): li = max(i - R[j], 0) ri = i - L[j] if ri < 0: continue dp[i] += (sdp[ri] - sdp[li - 1]) dp[i] %= DIV sdp[i] = sdp[i - 1] + dp[i] sdp[i] %= DIV print(dp[N])
S=str(input()) a=S.count('hi') if a*2==len(S): print('Yes') else: print("No")
0
null
28,051,947,549,078
74
199
n, k, s = map(int, input().split()) ans = [] for i in range(n): if i < k: ans.append(s) else: if s != 10**9: ans.append(s+1) else: ans.append(1) print(*ans)
n = int(input()) a = list(map(int, input().split())) a = [(a[i], i) for i in range(n)] a.sort(key=lambda x: -x[0]) dp = [[0 for _ in range(n+1)] for _ in range(n+1)] for x in range(n+1): for y in range(n+1): if x + y > n: break active, idx = a[x+y-1] if x > 0: dp[x][y] = max(dp[x][y], dp[x-1][y] + active * abs(idx - (x-1))) if y > 0: dp[x][y] = max(dp[x][y], dp[x][y-1] + active * abs(idx - (n-y))) ans = 0 for x in range(n+1): ans = max(ans, dp[x][n-x]) print(ans)
0
null
62,417,286,383,748
238
171
x = int(input()); h = x // 3600; m = x % 3600 // 60; s = x % 60; print(h,m,s,sep=':');
N,K=map(int,input().split()) R,S,P=map(int,input().split()) T=input()+'*'*K h=['']*N f,n='','' ans=0 for i in range(N): if K<=i:f=h[i-K] n=T[i+K] if T[i]=='r': if f=='p':h[i]=n else:ans+=P;h[i]='p' if T[i]=='p': if f=='s':h[i]=n else:ans+=S;h[i]='s' if T[i]=='s': if f=='r':h[i]=n else:ans+=R;h[i]='r' print(ans)
0
null
53,452,785,408,048
37
251
s,t = map(int,input().split()) print('Yes' if s*2 <= t <= s*4 and t%2 == 0 else 'No')
x, y = list(map(int, input().split())) if y % 2 == 0 and 2 * x <= y and y <= 4 * x: print("Yes") else: print("No")
1
13,775,578,478,642
null
127
127
a=[] for i in range(10): a.append(input()) a.sort() a=a[::-1] a=a[:3] print(a[0]) print(a[1]) print(a[2])
a=[int(input()) for i in range(10)] a.sort(reverse=True) for i, iv in enumerate(a): print(iv) if i >= 2: break
1
37,887,772
null
2
2
import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): a,b,c=mi() a,b = b,a a,c = c,a print(a,b,c) if __name__ == "__main__": main()
X,Y,Z = map(int,input().split()) A,B,C = X,Y,Z A,B = B,A A,C = C,A print('{} {} {}'.format(A,B,C))
1
38,062,006,558,488
null
178
178
lst = list(input()) v_lakes = [] idx_stack = [] for i, c in enumerate(lst): if (c == '\\'): idx_stack.append(i) elif (idx_stack and c == '/'): # 対応する'\\'の位置 j = idx_stack.pop() v = i - j while (v_lakes and v_lakes[-1][0] > j): v += v_lakes.pop()[1] v_lakes.append((j, v)) ans = [len(v_lakes)] v = [v[1] for v in v_lakes] ans.extend(v) print(sum(v)) print(*ans)
from sys import stdin from collections import deque sect = stdin.readline().lstrip("/_").rstrip("\n\\_") stack = deque() res = deque() for i in range(len(sect)): if sect[i] == "\\": stack.append(i) elif sect[i] == "/": if len(stack) != 0: b = stack.pop() if len(res) == 0: res.append( (b, i-b) ) elif b > res[-1][0]: res.append( (b, i-b) ) else: # 水たまりを結合 sum_L = i-b while len(res) != 0: if res[-1][0] > b: sum_L += res[-1][1] res.pop() else: break res.append((b, sum_L)) res = [x[1] for x in res] print(sum(res)) print(len(res), *res)
1
60,932,740,572
null
21
21
n,k = map(int,input().split()) keta = 1 while k ** keta <= n: keta += 1 print(keta)
[n, k] = [int(i) for i in input().split()] for i in range(40): if n < k**i: print(i) break
1
64,405,973,767,590
null
212
212
#!/usr/bin/env python # -*- coding: utf-8 -*- a, b, c = map(int, input().split()) ret = [i for i in range(a, b+1) if c%i == 0] print(len(ret))
import sys data = sys.stdin.readline().strip().split(' ') a = int(data[0]) b = int(data[1]) c = int(data[2]) cnt = 0 for i in range(a, b+1): if c % i == 0: cnt += 1 print(cnt)
1
574,482,278,092
null
44
44
def sum_dict(d): num = 0 for k, v in d.items(): num += k * v return num def create_dict(A): d = {} for a in A: if d.get(a) is None: d[a] = 1 else: d[a] += 1 return d if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) Q = int(input()) BC = [] for i in range(Q): BC.append(tuple(map(int, input().split()))) d = create_dict(A) ans = sum_dict(d) for b, c in BC: db = d.get(b) if db is None: db = 0 if d.get(c) is None: d[c] = 0 d[c] += db d[b] = 0 ans += (c - b) * db print(ans)
import math , sys N = int( input() ) A = list( map( int, input().split() ) ) Q = int( input() ) count = [0 for _ in range( 10**5 + 1)] for each in A: count[each]+=1 ans = sum(A) for _ in range(Q): B , C = list( map( int , input().split() ) ) D = count[B] ans += (C-B) * D count[B] = 0 count[C] += D print(ans)
1
12,179,827,731,710
null
122
122
import math def main(): a, b, C = map(int, input().split()) C /= 180 C *= math.pi S = 1 / 2 * a * b * math.sin(C) L = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C)) + a + b h = 2 * S / a print(S) print(L) print(h) if __name__ == "__main__": main()
n = int(input()) n3 = n**3 print(n3)
0
null
218,454,876,288
30
35
def popcnt(n): return bin(n).count("1") def f(n): cnt = 0 while n>0: n = n%popcnt(n) cnt += 1 return cnt def solve(X): Y = int(X, 2) c = X.count("1") m, p = c-1, c+1 Ym, Yp = Y%m if m else -1, Y%p for i in range(N): if X[i] == "1": Y = (Ym - pow(2,N-i-1,m))%m if Ym!=-1 else -1 else: Y = (Yp + pow(2,N-i-1,p))%p print(f(Y) + 1 if Y!=-1 else 0) N = int(input()) solve(input())
import sys import math import heapq from collections import defaultdict, deque from decimal import * def r(): return int(input()) def rm(): return map(int,input().split()) def rl(): return list(map(int,input().split())) '''D Anything Goes to zero''' twoPowM1=[0]*(300000) twoPowM2=[0]*(300000) stepsSmall=[0]*(300000) n=r() s=input() bitcount=0 for i in range(n): if s[i]=='1': bitcount+=1 mod=bitcount-1 if mod>0: twoPowM1[0]=1 for i in range(1,len(twoPowM1)): twoPowM1[i]=(twoPowM1[i-1]+twoPowM1[i-1])%mod mod=bitcount+1 twoPowM2[0]=1 for i in range(1,len(twoPowM2)): twoPowM2[i]=(twoPowM2[i-1]+twoPowM2[i-1])%mod for i in range(1,len(stepsSmall)): stepsSmall[i]=1+stepsSmall[i%bin(i).count('1')] valM1=0;valM2=0 for i in range(n): mod=bitcount-1 if mod>0: valM1=((valM1*2)%mod+int(s[i]))%mod mod=bitcount+1 valM2=((valM2*2)%mod+int(s[i]))%mod for i in range(n): pow=n-1-i if s[i]=='0': mod=bitcount+1 newVal=(valM2+twoPowM2[pow])%mod print(stepsSmall[newVal]+1) else: mod=bitcount-1 if mod==0: print(0) else: newVal=(valM1-twoPowM1[pow])%mod print(stepsSmall[newVal]+1)
1
8,119,260,461,520
null
107
107
# -*- coding: utf-8 -*- class dice_class: def __init__(self, top, front, right, left, back, bottom): self.top = top self.front = front self.right = right self.left = left self.back = back self.bottom = bottom def sut(self, t): #set_up_top while True: if self.top == t: break else: dice.roll('E') if self.top == t: break else: dice.roll('N') def suf(self, f): #set_up_front while True: if self.front == f: break else: dice.roll("SEN") def roll(self, s): for i in s: if i == 'E': self.rollE() elif i == 'N': self.rollN() elif i == 'S': self.rollS() elif i == 'W': self.rollW() def rollE(self): tmp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = tmp def rollN(self): tmp = self.top self.top = self.front self.front = self.bottom self.bottom = self.back self.back = tmp def rollS(self): tmp = self.top self.top = self.back self.back = self.bottom self.bottom = self.front self.front = tmp def rollW(self): tmp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = tmp if __name__ == "__main__": a = map(int, raw_input().split()) dice = dice_class(a[0], a[1], a[2], a[3], a[4], a[5]) n = int(raw_input()) for i in range(n): t, f = map(int, raw_input().split()) dice.sut(t) dice.suf(f) print dice.right
import sys n=sys.stdin.readline().rstrip()[::-1] to=0 m=0 n+="0" num=len(n) for i in range(num): k=int(n[i]) k+=m if k==5: if int(n[i+1])>=5: to+=10-k m=1 else: to+=k m=0 if k<5: to+=k m=0 elif k>5: to+=10-k m=1 print(to+m)
0
null
35,594,620,211,008
34
219
n, m = map(int, input().split()) ab = [] for i in range (m): ab.append(list(map(int, input().split()))) par = [-1] * (n+1) #Union Find #xの根を求める def find(x): if par[x] < 0: return x else: tank = [] while par[x] >= 0: tank.append(x) x = par[x] for elt in tank: par[elt] = x return x #xとyの属する集合の併合 def unite(x,y): x = find(x) y = find(y) if x == y: return else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x par[x] += par[y] par[y] = x return for j in range(m): unite(ab[j][0], ab[j][1]) m = -1*min(par) print(m)
class UnionFindTree(): def __init__(self, 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 # 常にxの要素数>yの要素数とする if self.parents[x] > self.parents[y]: x, y = y, x # self.parents[x] に yの要素数を追加してから併合 self.parents[x] += self.parents[y] self.parents[y] = x def main(): N, M = map(int, input().split()) uft = UnionFindTree(N) for m in range(M): a, b = map(lambda x: int(x)-1, input().split()) uft.union(a, b) print(-min(uft.parents)) if __name__ == "__main__": main()
1
3,968,016,773,610
null
84
84
N, M = map(int, input().split()) A = list(map(int, input().split())) if N - sum(A) <= 0: result = "Yes" else: result = "No" print(result)
H, N = list(map(int, input().split())) A = list(map(int, input().split())) AS = sum(A) if AS >= H: print('Yes') else: print('No')
1
77,957,976,444,468
null
226
226
n = int(input()) a,b = divmod(n,2) if b == 0: a -= 1 print(a)
from sys import stdin H = int(stdin.readline().rstrip()) W = int(stdin.readline().rstrip()) N = int(stdin.readline().rstrip()) if N%(max(H,W))==0: print(N//(max(H,W))) else: print(N//(max(H,W))+1)
0
null
121,168,559,998,532
283
236
N = int(input()) L = list(map(int, input().split())) #リストで複数行作るには? count = 0 for i in range(2, N): for j in range(1, i): for k in range(0, j): if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]: continue elif L[k] < L[i] + L[j] and L[i] < L[j] + L[k] and L[j] < L[i] + L[k]: count += 1 print(count)
N = list(input()) inN = [int(s) for s in N] if sum(inN) % 9 == 0: print('Yes') else: print('No')
0
null
4,719,893,097,500
91
87
n,k = map(int,input().split()) r,s,p = map(int,input().split()) t = input() ans = [] a,b,c = 0,0,0 for i in range(n): if i>=k: if t[i]==ans[i-k]: ans.append('X') continue if t[i] =='r': ans.append('r') c += 1 elif t[i]=='s': ans.append('s') a += 1 else: ans.append('p') b += 1 print(a*r+b*s+c*p)
from copy import copy C,R,K=map(int,input().split()) dp=[[0]*(R+1) for i1 in range(4)] M=[[0]*R for i in range(C)] for i in range(K): r,c,v=map(int,input().split()) M[r-1][c-1]=v for i,l in enumerate(M): for num in range(1,4): for j in range(R): if num==1: dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j]) else: dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j]) dp[0]=dp[-1][1:-1]+[0,dp[-1][0]] print(dp[-1][-2])
0
null
56,301,733,946,656
251
94
N = int(input()) root = int(N**0.5) for i in range(root,-1,-1): if N % i ==0: break print(int(N/i + i -2))
ls = ["SUN","MON","TUE","WED","THU","FRI","SAT"] print(7 - ls.index(str(input())))
0
null
147,211,138,795,742
288
270
def main(): # n=int(input()) n,k= map(int, input().split()) p=n-2*k print(p) if p>0 else print(0) return main()
inp = list(map(int, input().split())) a, b = inp[0], inp[1] if a > b*2: print(a-b*2) else: print(0)
1
166,277,568,248,260
null
291
291
n, q = list(map(int, input().split())) que = [] for _ in range(n): name, time = input().split() que.append([name, int(time)]) elapsed_time = 0 while que: name, time = que.pop(0) dt = min(q, time) time -= dt elapsed_time += dt if time > 0: que.append([name, time]) else: print (name, elapsed_time)
from collections import deque n, q = map(int, input().split()) Q = deque() for i in range(n): name,time = input().split() Q.append([name, int(time)]) sum =0 while Q: qt = Q.popleft() if qt[1] <= q: sum += qt[1] print(qt[0], sum) else: sum += q qt[1] -= q Q.append(qt)
1
42,399,860,130
null
19
19
K = int(input()) a = 0 for i in range(K): a = (10 * a + 7) % K if a % K == 0: print(i+1) exit() else: a %= K print(-1)
k = int(input()) a = [0]*k a[0] = 7%k for i in range(1, k): a[i] = (a[i-1] * 10 + 7)%k for i in range(k): if a[i] == 0: print(i+1) exit() print(-1)
1
6,089,692,856,956
null
97
97
cards=input() new=cards.split() a=int(new[0]) b=int(new[1]) c=int(new[2]) k=int(new[3]) if a>k: print(k) else: if a+b>k: print(a) else: sum=a+(k-(a+b))*(-1) print(sum)
h,w,m=map(int,input().split()) HH=[] WW=[] HW=set() lh=[0]*(h+1) lw=[0]*(w+1) for _ in range(m): h1,w1=map(int,input().split()) lh[h1]+=1 lw[w1]+=1 HW.add((h1,w1)) lhmax=max(lh) lwmax=max(lw) maxh=[] maxw=[] for i in range(1,h+1): if lh[i]==lhmax: maxh.append(i) for i in range(1,w+1): if lw[i]==lwmax: maxw.append(i) if len(maxh)*len(maxw)>m: print(lhmax+lwmax) else: flag=True for i in maxh: for j in maxw: if (i,j) not in HW: flag=False break if flag==True: print(lhmax+lwmax-1) else: print(lhmax+lwmax)
0
null
13,260,345,683,740
148
89
def main(): n, m = map(int, input().split()) print('Yes') if n <= m else print('No') if __name__ == '__main__': main()
a,b,m = input().split() a = list(map(int,input().split())) b = list(map(int,input().split())) xyc =[] for i in range(int(m)): xyc.append(input()) min = min(a) + min(b) for i in xyc: x,y,c = map(int, i.split()) if min > a[x-1] + b[y-1] - c : min = a[x-1] + b[y-1] - c print(min)
0
null
68,773,045,524,862
231
200
N = int(input()) A = [int(x) for x in input().split()] print(*A) for i in range(1, len(A)): key = A[i] j = i-1 while j >= 0 and A[j] > key: A[j+1] = A[j] j += -1 A[j+1] = key print(*A)
def insertion_sort(array): '''?????????????´?????????????????????¨??????????????????????????¨???????????????????????§?????\?????????????????°???????????? 1. ??????????????¨??????????????????????´?????????????????????? v ????¨????????????? 2. ????????????????????¨??????????????????v ????????§??????????´??????????????????????????§????????????? 3. ?????????????????????????????????????????????????´? v???????????\?????????''' for i in range(len(array)): v = array[i] j = i - 1 while(j>=0 and array[j] > v): array[j+1] = array[j] j = j - 1 array[j+1] = v print(' '.join(map(str, array))) def test(): '''??? input = 6 5 2 4 6 1 3 -> 5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6''' element_number = int(input()) input_array = list(map(int, input().split())) insertion_sort(input_array) if __name__ == '__main__': test()
1
5,839,026,312
null
10
10
from collections import defaultdict d=defaultdict(int) n=int(input()) a=list(map(int,input().split())) ans=1 mod=10**9+7 d[-1]=3 for i in a: ans*=d[i-1] ans%=mod d[i-1]-=1 d[i]+=1 print(ans)
#ABC162-E Sum of gcd of Tuples(Hard) """ 問題を「1~kまでの数字を用いた長さnの数列において、gcdがDになる数列はいくつあるか」 というふうに置き換える。(1<=D<=k) 更に制約を替えて、gcdが"Dの倍数"(但し,k以下)でも良いのでそれを全て求めよ、 というふうになった場合、全ての要素はD*n(nは整数,D*n<=k)となる。 この制約によって、そのような数列の数は(k/D)^nとして表せる。(これが大事) 例: n = 3,k = 4の場合で、D(gcd)=2について求める (4//2)**3 = 8※ そこで、大きい方からgcdがDになる数列の個数(これをメモ化)を求めていった場合、 Dの倍数がk以下であるならば、予めメモしておいたその値分を引いてやる。 これによって全ての通り数が求まる。 例の続き: D=2について、D*n <= k という制約のもとでn=2が存在する。 D = 2*2 = 4の時の通り数は、4,4,4の1通り※なので、 D(gcd)=2となるパターン数は、※より、 8-1=7 となる。 (この7通りは2と4からなる数列で、全ての値が4になる場合を引いている) """ import sys readline = sys.stdin.buffer.readline n,k = map(int,readline().split()) mod = 10**9+7 ans = 0 count = [0]*(k+1) for D in range(k,0,-1): mul = k//D #何倍まであり得るか(あり得るものをcountから引く) res = pow(mul,n,mod) for i in range(2,mul+1): res -= count[i*D] count[D] = res #個数 ans += res*D #個数*値(求めたいのはgcdの合計値のため) ans %= mod print(ans)
0
null
83,701,167,185,120
268
176
from sys import stdin import numpy as np n, k = map(int, stdin.buffer.readline().split()) a = np.fromstring(stdin.buffer.read(), dtype=np.int, sep=' ') ng = 0 ok = 10 ** 9 + 1 while ok - ng > 1: mid = (ok + ng) >> 1 if np.sum(np.ceil(a / mid) - 1) <= k: ok = mid else: ng = mid print(ok)
import math N,K = map(int,input().split()) A = list(map(int,input().split())) m = 1 M = max(A) while(M-m>0): mm = 0 mid = (M+m)//2 for i in range(N): mm += math.ceil(A[i]/mid)-1 if mm>K: m = mid+1 else: M = mid print(math.ceil(m))
1
6,452,093,479,360
null
99
99
s = input() if s.count('A') > 0 and s.count('B') > 0 : print('Yes') else: print('No')
n = int(input()) a = list(map(int, input().split())) #print(a) a.reverse() print(*a)
0
null
27,713,333,136,480
201
53
s = input() ans = '' for i in range(len(s)): ans = ans + 'x' print(ans)
def main(): S = input() print("x"*len(S)) if __name__ == "__main__": main()
1
72,769,864,927,596
null
221
221
n=int(input()) if n==2: count=1 else: count=2 for i in range(2,int(n**0.5)+1): if n%i==0: k=n//i while k>0: if k%i==0: k=k//i else: if k%i==1: count+=1 break elif (n-1)%i==0: count+=1 if i!=(n-1)//i: count+=1 print(count)
def bubblesort(N, A): C, flag = [] + A, True while flag: flag = False for j in range(N-1, 0, -1): if int(C[j][1]) < int(C[j-1][1]): C[j], C[j-1] = C[j- 1], C[j] flag = True return C def selectionSort(N, A): C = [] + A for i in range(N): minj = i for j in range(i,N): if int(C[j][1]) < int(C[minj][1]): minj = j C[i], C[minj] = C[minj], C[i] return C N, A= int(input()), input().split() Ab = bubblesort(N, A) print(*Ab) print('Stable') As = selectionSort(N, A) print(*As) if Ab != As: print('Not stable') else: print('Stable')
0
null
20,583,166,435,942
183
16
from math import sqrt n = int(input()) p = 0 for i in range(n): x = int(input()) ad = 1 if x>2 and x%2==0: ad = 0 else: j=3 while j < (int(sqrt(x))+1): if x%j == 0: ad = 0 break else: j += 2 p += ad print(p)
N_str, q_str = raw_input().split() N = int(N_str) q = int(q_str) A =[] B =[] total =0 for i in range(N): t = raw_input().split() A.append([t[0],int(t[1])]) while A: name, time = A.pop(0) if time <= q: total += time B.append(name+" "+ str(total)) else: time -= q total += q A.append([name, time]) print '\n'.join(B)
0
null
27,382,805,298
12
19
S=input() Q=int(input()) inst=[] for i in range(Q): array=input().split() inst.append(tuple(array)) rev=True front_str=[] back_str=[] for i in range(Q): if int(inst[i][0])==1: rev=not rev elif rev: if int(inst[i][1])==1: front_str.append(inst[i][2]) else: back_str.append(inst[i][2]) else: if int(inst[i][1])==1: back_str.append(inst[i][2]) else: front_str.append(inst[i][2]) if rev: front_str.reverse() else: back_str.reverse() S=S[::-1] front="".join(front_str) back="".join(back_str) if rev: print(front+S+back) else: print(back+S+front)
def main(): s = input() q = int(input()) is_fwd = True before = '' after = '' for i in range(q): fields = [i for i in input().split()] t = int(fields[0]) if t == 1: is_fwd = not is_fwd elif t == 2: f = int(fields[1]) c = fields[2] if (f == 1) == is_fwd: before += c else: after += c res = before[::-1] + s + after if is_fwd: print(res) else: print(res[::-1]) main()
1
57,595,067,815,010
null
204
204
x = input().strip() if x[-1] == 's': x += "es" else: x += 's' print(x)
[S,T] = input().split() print(T+S)
0
null
52,596,135,916,352
71
248
import sys N = int(input()) S = [str(s) for s in sys.stdin.read().split()] print(len(set(S)))
N = int(input()) T = [input() for i in range(N)] T.sort() c = 1 pre = T[0] for i in range(1,N): if T[i] == pre: pass else: c += 1 pre = T[i] print(c)
1
30,269,039,227,142
null
165
165
n,m=map(int,input().split()) s=list(input()) s.reverse() ansl=[] now=0 while now<n: f=1 for i in range(m,0,-1): if now+i<n+1 and s[now+i]=="0": ansl.append(i) now+=i f=0 break if f: print(-1) exit() ansl.reverse() print(*ansl)
def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N,M=MI() S=list(input()) S2=S[::-1] now=0 ans=[] while now!=N: nxt=now+M if nxt>N: nxt=N while S2[nxt]=="1": nxt-=1 if now==nxt: ans=[-1] break ans.append(nxt-now) now=nxt print(' '.join(map(str, ans[::-1]))) main()
1
139,158,230,284,260
null
274
274
import os, sys, re, math S = input() count = 0 for i in range(len(S) // 2): if S[i] != S[-i - 1]: count += 1 print(count)
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64) import base64 import subprocess import zlib exe_bin = "c$~dk4Rlo1wLW)dk_;i48#N#xNVH>36vm7MOlr_fn1nlaf(XP?3%!QPgiOufOKuR5r;tf_T*pzKcD1ZlEA{6srCO2KMS<tzB?ber=tEnn6@RD|oH2^=hY$oZZ|`%@nYnW_)1SBAdY3iX_k3sXefHVsoPB=o;l3(wwMh^Nf6U}2f~kT_v~&f-^Bi#&z)Hyk_<K2-K{6q2(eWASsE|yp@p3e|Qj?Z8(&;3b3ObrW(my+<CsU|NTn=q5o}r<|GYXPugq6GHach#CiOES!PGbC=<}o==xwM7-mNDE&-6WY>7+riqsmJ#NQ?;~_){|t)<!%GHO!D_Xd5kV$<)!n>5oRx^ydAD<3apw}a$QsX?503V=i1q8OXtm=SK{bsbzDzv%456>7u8aJY;Tj!=6r@>{#_HNy=8wQr~95qPX4>H{k5OnAz!h?#CUkSVS8*8@+dY5enm4Ln7+EUj#p#c(+t0hQ{W|_@X8eUL?Jc*)HL{58vUEo;7_E%KTd-?(v<s58vX@o_`_-VXA<7Slb_eq@P9Xr{=77LZcKw;okmY>nsP4&{)@;|Qc$32<Kt_TXn3&!C(tiDlzQK_*J59sM`U?*b8Cy-q13f2vP@*pvKqPG-|k->=urIa%W4)hwYK<|)vapsYk8@2?pU-`DGjuC$gAo){3V{2fZ}#mtpR+g;=DnYmB#kgyCJV$u4`&)^<hSR)8aK)_}aB{o4>uIwWY2ppsbVE6hmIi-OZ^~E<lxF{%W63?m+9EM6PYQJJ3=uFY$MDHv2Kt$EyW3^4%r-8t;-D>H<v!>KteR*tfP$u2cML0}5&OH+T3I%xUdZAPdsXt!w-!LmKXG4=8@p(C)9RXHpFTv~j(kFg}2>Jm$LQI#9oG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qXgVXEvmpn=G-A;U-G|2OP1E<F02V?!8W%7J2#`jIe{gY9i(-%qd_)qu$7t)pgUj})8KEdg7!#R)9pMwT@evZNEH3oj;_&G+j`<ndRF!BE(w6xLR#`eSe{Gv{t?}IC5q_)>6{}oA$EqoIH--MN~iywM9Zr3(eC*%3-@|jxtnZHr~d4qg>U&RO?XGVGcnAm|Vm*@NUDNKIbqsbBl2Kg*OE8lpq$mNR+c&c;v6i0zXV)Dyb@z@<4WPJRXptD{7Y-fRgrJ=(b`_Dyb<S($moA)>3_x}KD$#Q!" open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
0
null
61,707,712,095,918
261
84
import sys def ISI(): return map(int, sys.stdin.readline().rstrip().split()) n, m=ISI() if(n==m):print("Yes") else:print("No")
from collections import deque H, W, M = map(int, input().split()) bomb = [] counth = [0 for k in range(H)] countw = [0 for k in range(W)] for k in range(M): h, w = map(int, input().split()) h -= 1 w -= 1 bomb.append(h+ w*H) counth[h] += 1 countw[w] += 1 counth = deque(counth) countw = deque(countw) maxh = max(counth) maxw = max(countw) index_h = deque([]) index_w = [] for k in range(H): h = counth.popleft() if h == maxh: index_h.append(k) for k in range(W): w = countw.popleft() if w == maxw: index_w.append(k) ans = maxh + maxw - 1 lenh = len(index_h) lenw = len(index_w) if lenh*lenw > M: ans += 1 else: bomb.sort() bomb = deque(bomb) kouho = [] for i in range(lenh): h = index_h.pop() for j in range(lenw): w = index_w[j] kouho.append(h+ H*w) kouho.sort() kouho = deque(kouho) B = bomb.popleft() K = kouho.popleft() while True: if B > K: ans += 1 break elif B == K: if len(kouho) == 0: break else: K = kouho.popleft() if len(bomb) == 0: ans += 1 break else: B = bomb.popleft() else: if len(bomb) == 0: ans += 1 break else: B = bomb.popleft() print(ans)
0
null
43,866,467,306,430
231
89
d,t,s = [float(x) for x in input().split()] if d/s > t: print("No") else: print("Yes")
#: Author - Soumya Saurav import sys,io,os,time from collections import defaultdict from collections import Counter from collections import deque from itertools import combinations from itertools import permutations import bisect,math,heapq alphabet = "abcdefghijklmnopqrstuvwxyz" input = sys.stdin.readline ######################################## ans = 0 n = int(input()) for i in range(1,n+1): for j in range(1,n+1): if i*j >= n: break ans+=1 print(ans) ''' # Wrap solution for more recursion depth #submit as python3 import collections,sys,threading sys.setrecursionlimit(10**9) threading.stack_size(10**8) threading.Thread(target=solve).start() '''
0
null
3,052,330,526,530
81
73
print((lambda x:(1/2 if (x%2 == 0) else (x//2+1)/x))(int(input())))
a,b,c,k=map(int,input().split()) if k<=a: ans=k elif k>a and k<=a+b: ans=a else: ans=a-(k-(a+b)) print(ans)
0
null
99,196,441,840,256
297
148
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" N = int(input()) S = input() ans = [] for c in S: print(abc[(abc.index(c) + N) % len(abc)], end = "")
def resolve(): n = int(input()) s = input() ans = '' for i in s: ans += chr(ord('A')+(ord(i)-ord('A')+n)%26) print(ans) resolve()
1
134,490,792,753,690
null
271
271
r = input() print(r[0:3])
import itertools N, M, Q = map(int, input().split()) q = [list(map(int, input().split())) for _ in range(Q)] a = [0] * N max_score = 0 for v in itertools.combinations(range(N + M - 1), N): tmp_score = 0 for n in range(N): a[n] = v[n] + 1 - n for query in q: if (a[query[1] - 1] - a[query[0] - 1]) == query[2]: tmp_score += query[3] if max_score < tmp_score: max_score = tmp_score print(max_score)
0
null
21,333,692,203,040
130
160
A = map(int, input().split()) print('bust' if(sum(A) >= 22) else 'win')
a = list(map(int, input().split())) s = a[0] + a[1] + a[2] if s >= 22: print('bust') else: print('win')
1
118,528,692,304,032
null
260
260
s = input() n = len(s) mod = 2019 t = [0]*n dp = [0]*2020 t[0] = int(s[-1]) dp[t[0]] += 1 for i in range(n-1): t[i+1] = t[i] + int(s[-2-i])*pow(10, i+1, mod) t[i+1] %= mod dp[t[i+1]] += 1 ans = 0 for D in dp[1:]: ans += D*(D-1)//2 print(ans+(dp[0]+1)*(dp[0])//2)
rooms = [0] * (4*3*10) n = input(); for i in xrange(n): b,f,r,v = map(int, raw_input().split()) rooms[(b-1)*30+(f-1)*10+(r-1)] += v sep = "#" * 20 for b in xrange(4): for f in xrange(3): t = 30*b + 10*f print ""," ".join(map(str, rooms[t:t+10])) if b < 3: print sep
0
null
15,998,089,247,950
166
55
import sys def gcd(a,b): a,b=max(a,b),min(a,b) while a%b: a,b=b,a%b return b def lcm(a,b): return a//gcd(a,b)*b for i in sys.stdin: a,b=map(int,i.split()) print(gcd(a,b),lcm(a,b))
import math while True: try: a, b = [int(x) for x in input().split()] print(math.gcd(a,b), a*b // math.gcd(a,b)) except EOFError: break
1
576,270,468
null
5
5
from math import ceil from bisect import bisect_right n, d, a = map(int, input().split()) l = [] l2 = [] l3 = [] l4 = [0 for i in range(n+1)] l5 = [0 for i in range(n+1)] ans = 0 for i in range(n): x, h = map(int, input().split()) l.append([x, h]) l2.append(x + 2 * d) l3.append(x) l.sort(key=lambda x: x[0]) l2.sort() l3.sort() for i in range(n): cnt = ceil((l[i][1] - l4[i] * a) / a) if cnt > 0: ans += cnt ind = bisect_right(l3, l2[i]) l5[ind] += cnt l4[i] += cnt l4[i+1] = l4[i] - l5[i+1] print(ans)
from fractions import gcd n, m = map(int, input().split()) aa = list(map(int, input().split())) lcm = 1 def p2(m): cnt = 0 n = m while 1: if n%2 == 0: cnt += 1 n = n//2 else: break return cnt pp = p2(aa[0]) for a in aa: lcm = a * lcm // gcd(a, lcm) if pp != p2(a): lcm = 10 **18 break tmp = lcm // 2 print((m // tmp + 1) // 2)
0
null
91,940,534,493,532
230
247
x,y,k=map(int,input().split()) if(k<=x): x=x-k k=0 else: k-=x x=0 if(k<=y): y-=k k=0 else: k-=y y=0 print(x,y)
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] #a = [input() for _ in range(n)] N = int(input()) seq = list(map(int, input().split())) s = 0 for i in range(N): s += seq[i] s2 =0 for i in range(N): s2 += seq[i]**2 s0 = (s**2 -s2)//2 print(s0%(10**9+7))
0
null
54,116,934,877,282
249
83
N = int(raw_input()) num_list = map(int, raw_input().split()) c = 0 for i in range(0,N,1): flag =0 minj =i for j in range(i,N,1): if num_list[j] < num_list[minj]: minj = j flag = 1 c += flag num_list[i], num_list[minj] = num_list[minj], num_list[i] print " ".join(map(str,num_list)) print c
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) count = 0 flag = 0 for i in range(N): if N == 1: break minj = i for j in range(i, N): if A[j] < A[minj]: minj = j flag = 1 if flag == 1: A[i], A[minj] = A[minj], A[i] count += 1 flag = 0 for i in range(N): if i == N - 1: print("{0}".format(A[i])) else: print("{0} ".format(A[i]), end="") print(count)
1
21,238,821,212
null
15
15
import math import collections def main(): S, T = input().split() A, B = map(int, input().split()) U = input() if U == S: print(A-1, B) else: print(A, B-1) main()
import sys n = int(raw_input()) building_a = [[0 for j in range(11)] for i in range(4)] building_b = [[0 for j in range(11)] for i in range(4)] building_c = [[0 for j in range(11)] for i in range(4)] building_d = [[0 for j in range(11)] for i in range(4)] for i in range(n): b, f, r, v = map(int, raw_input().split()) if b == 1: building_a[f][r] += v elif b == 2: building_b[f][r] += v elif b == 3: building_c[f][r] += v elif b == 4: building_d[f][r] += v for i in range(1, 4): print "", for j in range(1, 11): print building_a[i][j], print for i in range(20): sys.stdout.write("#") print for i in range(1, 4): print "", for j in range(1, 11): print building_b[i][j], print for i in range(20): sys.stdout.write ("#") print for i in range(1, 4): print "", for j in range(1, 11): print building_c[i][j], print for i in range(20): sys.stdout.write("#") print for i in range(1, 4): print "", for j in range(1, 11): print building_d[i][j], print
0
null
36,452,191,560,320
220
55
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 998244353 n, k = map(int, input().split()) s = list() for i in range(k): s.append(tuple(map(int, input().split()))) dp = [0] + [0] * n diff = [0] + [0] * n dp[1] = 1 for i in range(1, n): for j, k in s: if i + j > n: continue diff[i + j] += dp[i] if i + k + 1 > n: continue diff[i + k + 1] -= dp[i] dp[i] = (dp[i - 1] + diff[i]) % MOD dp[i + 1] = (dp[i] + diff[i + 1]) % MOD print(dp[n])
MOD = 998244353 N, K = map(int, input().split()) rl = [list(map(int, input().split())) for _ in range(K)] dp = [0] * (N + 1) sdp = [0] * (N + 1) dp[1] = 1 sdp[1] = 1 for i in range(2, N + 1): for j in range(K): l, r = rl[j][0], rl[j][1] tl = max(1, i - r) tr = max(0, i - l) dp[i] += sdp[tr] - sdp[tl - 1] dp[i] %= MOD sdp[i] += dp[i] + sdp[i - 1] sdp[i] %= MOD print(dp[N])
1
2,680,930,199,668
null
74
74
import math class MergeSort: cnt = 0 def merge(self, a, n, left, mid, right): n1 = mid - left n2 = right - mid l = a[left:(left+n1)] r = a[mid:(mid+n2)] l.append(2000000000) r.append(2000000000) i = 0 j = 0 for k in range(left, right): self.cnt += 1 if l[i] <= r[j]: a[k] = l[i] i += 1 else: a[k] = r[j] j += 1 return a def mergeSort(self, a, n, left, right): if left + 1 < right: mid = (left + right) // 2 self.mergeSort(a, n, left, mid) self.mergeSort(a, n, mid, right) self.merge(a, n, left, mid, right) return a if __name__ == '__main__': n = int(input().rstrip()) s = [int(i) for i in input().rstrip().split(" ")] x = MergeSort() print(" ".join(map(str, x.mergeSort(s, n, 0, n)))) print(x.cnt)
n = int(input()) nums = [int(i) for i in input().split(" ")] count = 0 def merge(nums, left, mid, right): i = 0 j = 0 nums_l = nums[left:mid] nums_r = nums[mid:right] nums_l.append(10 ** 9 + 1) nums_r.append(10 ** 9 + 1) for x in range(0, right - left): global count count = count + 1 if nums_l[i] <= nums_r[j]: nums[left + x] = nums_l[i] i = i + 1 else: nums[left + x] = nums_r[j] j = j + 1 def merge_sort(nums, left, right): if left + 1 < right: mid = int((left + right) / 2) merge_sort(nums, left, mid) merge_sort(nums, mid, right) merge(nums, left, mid, right) merge_sort(nums, 0, n) result = "" for i in nums: result += str(i) + " " print(result.rstrip()) print(count)
1
107,810,892,590
null
26
26
X,K,D=map(int,input().split()) X=abs(X) if X<=K*D: if (K-X//D)%2==0:X=X%D else:X=abs(X%D-D) else: X=X-K*D print(X)
for i in range(1,10): for s in range(1,10): result = str(i) + "x" + str(s) + "=" + str(int(i)*int(s)) print(result)
0
null
2,569,665,203,972
92
1
# DPL_1_A - コイン問題  import sys N, M = map(int, sys.stdin.readline().strip().split()) # N払う コイン種類M 枚 c = list(map(int, sys.stdin.readline().strip().split())) # dp 初期化 dp = [[float('inf')] * (N + 1) for _ in range(M + 1)] for i in range(len(dp)): dp[i][0] = 0 for m in range(M): for n in range(N + 1): dp[m + 1][n] = min(dp[m + 1][n], dp[m][n]) next_n = n + c[m] if next_n <= N: dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n]) # for i in range(len(dp)): # print(dp[i]) print(dp[-1][-1])
S = input() S1 = S[:len(S) // 2] S2 = S[-1:(len(S)-1) // 2:-1] ans = 0 for s1, s2 in zip(S1, S2): ans += s1!=s2 print(ans)
0
null
60,253,133,094,770
28
261
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): A, B = map(int, readline().split()) if A < 10 and B < 10: print(A * B) else: print(-1) return if __name__ == '__main__': main()
S = int(input()) a = S//(60*60) b = (S-(a*60*60))//60 c = S-(a*60*60 + b*60) print(a, ':', b, ':', c, sep='')
0
null
79,666,952,863,692
286
37
n,inc,dec=int(input()),[],[] for _ in range(n): s,d,r=input(),0,0 for c in s: d=d+(1 if c=='(' else -1) r=max(r,-d) (dec if d<0 else inc).append((d,r)) inc.sort(key=lambda x:x[1]) dec.sort(key=lambda x:x[0]+x[1]) p1,p2,ok=0,0,True for s in inc: ok&=s[1]<=p1 p1+=s[0] for s in dec: ok&=p2>=s[0]+s[1] p2-=s[0] ok&=p1==p2 print('Yes'if ok else'No')
def encode(s): val = 0 min_val = 0 for c in s: if c == '(': val += 1 else: val -= 1 min_val = min(min_val, val) return [min_val, val] def check(s): h = 0 for p in s: b = h + p[0] if b < 0: return False h += p[1] return True n = int(input()) ls = [] rs = [] l_total = 0 r_total = 0 for _ in range(n): si = encode(input()) if si[1] > 0: ls.append(si) l_total += si[1] else: si[0] -= si[1] si[1] *= -1 rs.append(si) r_total += si[1] list.sort(ls, reverse=True) list.sort(rs, reverse=True) if check(ls) and check(rs) and l_total == r_total: print("Yes") else: print("No")
1
23,556,859,758,470
null
152
152
N, M = map(int, input().split()) A = list(map(int, input().split())) A = sorted(A) A = A[::-1] X = sum(A) Y = 1/4/M ans = 'Yes' for i in range(M): if A[i]/X < Y: ans = 'No' print(ans)
n,m = map(int,input().split()) a = list(map(int,input().split())) sum = 0 cnt = 0 for i in a: sum += i for i in a: if(sum <= 4*m*i): cnt += 1 if(cnt >= m): print("Yes") else: print("No")
1
38,679,109,250,308
null
179
179
N, K = map(int, input().split()) H = list(map(int, input().split())) if N <= K: print(0) exit() H.sort(reverse=True) print(sum(H[K:]))
N, K = [int(s) for s in input().split()] H = sorted([int(s) for s in input().split()])[::-1] print(sum(H[K:]) if N > K else 0)
1
78,760,720,220,348
null
227
227
import math N = int(input()) # A = list(map(int, input().split())) A = [int(x) for x in input().split(' ')] a_max = [0] * (N+1) a_min = [0] * (N+1) a = [0] * (N+1) #1.可・不可の判定 # 最下段からとりうる個数の範囲を考える #0段目の範囲に1が含まれないならば”不可”(根=1) for i in range(N+1): if i == 0: a_max[N-i] = A[N-i] a_min[N-i] = A[N-i] else: a_max[N-i] = a_max[N-i+1] + A[N-i] a_min[N-i] = math.ceil(a_min[N-i+1]/2) + A[N-i] #check print # for i in range(N+1): # print(str(i) + ':----') # print(a_min[i],a_max[i]) #最上段から個数のカウント for i in range(N+1): if i == 0: a[i] = 1 else: a[i] = min((a[i-1] - A[i-1])*2 , a_max[i]) #不可は-1を、可は個数の合計を if a_min[0] > 1: print(-1) else: print(sum(a))
n = int(input()) tmp = 0 import sys for i in range(n): d = list(map(int,input().split())) if d[0] == d[1]: tmp += 1 #check if tmp == 3: print('Yes') sys.exit() else: tmp = 0 print('No')
0
null
10,702,822,355,292
141
72
h, w, k = map(int, input().split()) s = [] for _ in range(h): s.append(input()) sum = [[0] * (w+1) for _ in range(h+1)] for i in range(h): for j in range(w): sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (1 if s[i][j] == '1' else 0) ans = h + w - 2 for ptn in range(1<<h-1): cand = 0 sep = [0] for i in range(h-1): if((ptn >> i) & 1): sep.append(i+1) cand += 1 sep.append(h) left = 0 for pos in range(w): cur = [] for i in range(len(sep)-1): cur.append(sum[sep[i+1]][pos+1] - sum[sep[i+1]][left] - sum[sep[i]][pos+1] + sum[sep[i]][left]) if max(cur) > k: if left == pos: cand = h * w break else: cand += 1 left = pos ans = cand if cand < ans else ans print(ans)
''' ''' INF = float('inf') def main(): H, W, K = map(int, input().split()) S = [input() for _ in range(H)] S = [''.join(S[row][col] for row in range(H)) for col in range(W)] ans = INF for b in range(0, 2**H, 2): sections = [(0, H)] for shift in range(1, H): if (1<<shift) & b: sections.append((sections.pop()[0], shift)) sections.append((shift, H)) t_ans = len(sections) - 1 count = {(l, r): 0 for l, r in sections} for col in range(W): if any(count[(l, r)] + S[col][l:r].count('1') > K for l, r in sections): for key in count.keys(): count[key] = 0 t_ans += 1 for l, r in sections: count[(l, r)] += S[col][l:r].count('1') if max(count.values()) > K: t_ans = INF break ans = min(ans, t_ans) print(ans) main()
1
48,798,197,979,672
null
193
193
N = int(input()) if N % 2 == 1: print(0) else: ans = 0 div = 10 for _ in range(100): ans += N // div div *= 5 print(ans)
from math import pi r = float(input()) print('{:.5f} {:.5f}'.format(r*r*pi,r*2*pi))
0
null
58,533,671,511,740
258
46
class Node(object): def __init__(self, V): self.V = V self.d = -1 n = int(input()) nodes = [0] * 101 for i in range(n): data = input().split() V = list(map(int, data[2:])) V.sort(reverse = True) nodes[int(data[0])] = Node(V) l = [1,] l_old = [] cnt = 0 while len(l) > 0: l_old = l l = [] for i in l_old: if nodes[i].d == -1: nodes[i].d = cnt V = nodes[i].V for j in V: if not j in l: if nodes[j].d == -1: l.append(j) cnt += 1 for i in range(1, n+1): if not isinstance(nodes[i], int): print(i, nodes[i].d)
from collections import deque def bfs(adj_mat, d): Q = deque() N = len(d) color = ["W" for n in range(N)] Q.append(0) d[0] = 0 while len(Q) != 0: u = Q.popleft() for i in range(N): if adj_mat[u][i] == 1 and color[i] == "W": color[i] = "G" d[i] = d[u] + 1 Q.append(i) color[u] = "B" for i in range(N): if color[i] != "B": d[i] = -1 def Main(): N = int(input()) adj_mat = [[0 for n in range(N)] for n in range(N)] d = [0] * N for n in range(N): u, k , *V = map(int, input().split()) if k > 0: for i in V: adj_mat[n][i - 1] = 1 bfs(adj_mat, d) for n in range(N): print("{} {}".format(n + 1, d[n])) Main()
1
4,437,784,220
null
9
9
n=int(input()) al='ABCDEFGHIJKLMNOPQRSTUVWXYZ' ans=[] s=input() for i in range(len(s)): ans.append(al[(ord(s[i])-65+n)%26]) print(''.join(ans))
def main(): x = int(input()) grade = 0 for i in range(8): if (400 + 200 * i) <= x < (400 + 200 * (i + 1)): grade = 8 - i print(grade) if __name__ == "__main__": main()
0
null
70,318,910,074,592
271
100
X, Y, Z = map(str, input().split()) print(Z+" "+X+" "+Y)
X = input().split() print(X[2], X[0], X[1])
1
38,119,677,365,952
null
178
178
def search(start, N, X, Y): dist = [0 for _ in range(N)] if start <= X: for i in range(X): dist[i] = abs(start - i) for i in range(Y, N): dist[i] = (X - start) + 1 + (i - Y) for i in range(X, (Y - X) // 2 + X + 1): dist[i] = (i - start) for i in range((Y - X) // 2 + X + 1, Y): dist[i] = (X - start) + 1 + (Y - i) elif start >= Y: for i in range(Y, N): dist[i] = abs(start - i) for i in range(X): dist[i] = (start - Y) + 1 + (X - i) for i in range(X, (Y - X) // 2 + X): dist[i] = (start - Y) + 1 + (i - X) for i in range((Y - X) // 2 + X, Y): dist[i] = (start - i) else: toX = min(start - X, Y - start + 1) toY = min(Y - start, start - X + 1) dist[start] = 0 for i in range(X): dist[i] = (X - i) + toX for i in range(Y, N): dist[i] = toY + (i - Y) for i in range(X, start): dist[i] = min(start - i, Y - start + 1 + i - X) for i in range(start + 1, Y): dist[i] = min(i - start, start - X + 1 + Y - i) return dist def main(): N, X, Y = [int(n) for n in input().split(" ")] #N, X, Y = 10, 3, 8 X = X - 1 Y = Y - 1 lenD = [] for i in range(N): d = search(i, N, X, Y) lenD.append(d) kcounter = [0 for _ in range(N - 1)] for i in range(N): for j in range(i + 1, N): k = lenD[i][j] kcounter[k - 1] += 1 for k in kcounter: print(k) main()
while True: x = [] x = input().split( ) y = [int(s) for s in x] if sum(y) == -3: break if y[0] == -1 or y[1] == -1: print("F") elif y[0] + y[1] < 30: print("F") elif y[0] + y[1] >= 30 and y[0] + y[1] <50: if y[2] >= 50: print("C") else: print("D") elif y[0] + y[1] >= 50 and y[0] + y[1] <65: print("C") elif y[0] + y[1] >= 65 and y[0] + y[1] <80: print("B") elif y[0] + y[1] >= 80: print("A")
0
null
22,629,583,579,148
187
57
# -*- coding: utf-8 -*- modelmap = list(input()) S1 = [] S2 = [] A = 0 for i, l in enumerate(modelmap): if l == "\\": S1.append(i) elif l == "/" and len(S1) > 0: ip = S1.pop() A += i - ip L = i - ip while len(S2) > 0 and S2[-1][0] > ip: L += S2.pop()[1] S2.append([ip, L]) print(A) text2 = "{}".format(len(S2)) for s in S2: text2 += " " + str(s[1]) print(text2)
# -*- coding: utf-8 -*- """ stackの応用(水たまりの面積) """ from collections import deque S = list(input()) # 総合面積 ans = 0 # 総合面積用スタック(直近の\の位置) stack1 = deque() # 個別用スタック(その水たまりを開始する\の位置, その時点での面積) stack2 = deque() for i in range(len(S)): if S[i] == '\\': stack1.append(i) # 一番最近いれた\を取り出せば、今回の/と対になる(同じ高さ) elif S[i] == '/' and stack1: # 両者の距離がその高さでの面積になる # (\/が三角形な分-1なのが半開区間だからちょうど合う) j = stack1.pop() ans += i - j # 各水たまりのマージ作業 # stack2から、今回の合併候補を抽出 # (条件:水たまりの開始位置が今回対になってる\より右側にある) pond = i - j while stack2 and stack2[-1][0] >= j: pond += stack2.pop()[1] # マージした水たまりの情報を詰める stack2.append([j, pond]) print(ans) # リスト内包とアンパックできれいにまとまった print(len(stack2), *[pond for j, pond in stack2])
1
60,638,570,908
null
21
21
import math x = int(input()) def lcm(a, b): return (a * b) // math.gcd(a, b) rad = lcm(360, x) print(rad//x)
x=int(input()) ans=1 now=x while now%360!=0: now+=x ans+=1 print(ans)
1
13,121,569,565,192
null
125
125
N, M = map(int, input().split()) if M%2 != 0: center = M + 1 else: center = M c = center//2 d = (center + 1 + 2*M + 1) // 2 i = 0 while i < c: print(c-i, c+1+i) i += 1 j = 0 while i < M: print(d-(j+1), d+(j+1)) i += 1 j += 1
import sys input = sys.stdin.readline h, w, kk = map(int, input().split()) ss = [[0 for _ in range(h)] for _ in range(w)] for i in range(h): for j, c in enumerate(list(input().strip())): if c == '1': ss[j][i] = 1 ans = 100000 for i in range(2 ** (h - 1)): end = [] for j in range(h - 1): if i & 2 ** j: end.append(j + 1) end.append(h) start = [0] for j in end: start.append(j) start.pop() sums = [0] * len(start) tans = len(start) - 1 imp = False for j in range(w): reset = False for k, (s, e) in enumerate(zip(start, end)): sums[k] += sum(ss[j][s:e]) if sums[k] > kk: reset = True break if reset: tans += 1 for k, (s, e) in enumerate(zip(start, end)): sums[k] = sum(ss[j][s:e]) if sums[k] > kk: imp = True if imp: break if not imp: ans = min(ans, tans) print(ans)
0
null
38,687,607,574,688
162
193