code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
N, K = map(int, input().split()) N = N - (N // K)*K ans = min(N, K-N) print(ans)
n,k=map(int,input().split()) l=list(map(int,input().split())) maxi=0 suml=sum(l[:k]) maxl=sum(l[:k]) for i in range(n-k): if suml-l[i]+l[k+i]>maxl: maxl=suml-l[i]+l[k+i] maxi=i+1 suml=suml-l[i]+l[k+i] sumsum=0 for j in range(maxi,maxi+k): sumsum+=(l[j]+1)/2 print(sumsum)
0
null
57,142,810,105,888
180
223
import itertools H, W, K = list(map(int,input().split())) board = [] for i in range(H): row = input() board.append(row) result = [] for n in range(len(board)+1): for conb in itertools.combinations(board, n): result.append(list(conb)) rotate_result = [] for i in range(len(result)): rotate_result.append([list(x) for x in zip(*result[i])]) ans = 0 result2 = [] for i in range(len(rotate_result)): for j in range(len(rotate_result[i])+1): for conb in itertools.combinations(rotate_result[i], j): result2.append(list(conb)) l = list(itertools.chain.from_iterable(list(conb))) if l != []: count = 0 for k in range(len(l)): if l[k] == "#": count += 1 if k == len(l)-1 and count == K: ans += 1 print(ans)
n=int(input()) c=0 for _ in range(n): x=int(input()) if x==2:c+=1 elif pow(2,x-1,x)==1:c+=1 print(c)
0
null
4,442,503,074,402
110
12
def result(x): return x + x ** 2 + x ** 3; n = int(input()) print(result(n))
#93 B - Iron Bar Cutting WA (hint) N = int(input()) A = list(map(int,input().split())) # 差が最小の切れ目を見つける length = sum(A) left = 0 dist = 0 mdist = length midx = 0 for i,a in enumerate(A): left += a right = length - left dist = abs(left - right) if dist < mdist: mdist = dist midx = i ans = mdist print(ans)
0
null
76,262,254,276,582
115
276
import sys import collections ri = lambda: int(sys.stdin.readline()) rl = lambda: list(map(int, sys.stdin.readline().split())) n = ri() a = rl() c = collections.Counter(a) t = 0 for v in c.values(): t += v*(v-1)//2 for i in a: print(t-c[i]+1)
#!/usr/bin/env python3 def main(): from scipy.special import comb N = int(input()) A = [int(x) for x in input().split()] num_lst = [0] * (N + 1) for a in A: num_lst[a] += 1 ans = 0 for num in num_lst: ans += comb(num, 2, exact=True) for a in A: print(ans - (num_lst[a] - 1)) if __name__ == '__main__': main()
1
47,681,253,027,620
null
192
192
S = int(input()) for i in range(9) : i = i + 1 if S % i == 0 and S // i <= 9: result = "Yes" break else : result = "No" print(result)
def resolve(): n = int(input()) ans = 'No' for i in range(1,10): for j in range(1,10): if i*j == n: ans = 'Yes' print(ans) resolve()
1
160,004,083,561,050
null
287
287
def main(): s = input() week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] ind = week.index(s) print(7 - (ind % 7)) if __name__ == "__main__": main()
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') MOD = 10 ** 9 + 7 def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): N = I() A = LI() ans = (sum(A) ** 2 - sum([i ** 2 for i in A])) // 2 % MOD print(ans) if __name__ == '__main__': resolve()
0
null
68,482,071,015,490
270
83
r, c = map(int, input().split()) tbl = [[] for _ in range(r)] cSum = [0 for _ in range(c+1)] for i in range(r): tblS = input() tbl[i] = list(map(int, tblS.split())) print(tblS, end = '') print(' ', sum(tbl[i]), sep = '') for j in range(c): cSum[j] += tbl[i][j] cSum[c] += sum(tbl[i]) print(' '.join(map(str, cSum)))
n,m = map(int,(input().split())) a = [] s = [] for i in range(m): s.append(0) for i in range(n): k = [int(i) for i in input().split()] k.append(sum(k)) a.append(k) for j in range(m): s[j] += k[j] s.append(sum(s)) a.append(s) for j in a: print(' '.join(map(str, j)))
1
1,393,841,680,660
null
59
59
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def dfs(v_init): global timer # init the first node of overall graph iterations(times >= 1) stack = list() stack.append(v_init) d_time[v_init] += timer # init end while stack: current = stack[-1] v_table = adj_table[current] visited[current] = VISITED_IN_STACK # if adj is None, current's adj(s) have been all visited adj = v_table.pop() if v_table else None if adj: if visited[adj] is UNVISITED: visited[adj] = VISITED_IN_STACK timer += 1 d_time[adj] += timer stack.append(adj) else: stack.pop() visited[current] = POPPED_OUT timer += 1 f_time[current] += timer return None def dfs_init(): global timer for v in range(v_num): if visited[v + 1] == UNVISITED: dfs(v + 1) timer += 1 if __name__ == '__main__': _input = sys.stdin.readlines() v_num = int(_input[0]) vertices = map(lambda x: x.split(), _input[1:]) # config length = (v_num + 1) # stack = [] visited = [UNVISITED] * (v_num + 1) d_time, f_time = ([0] * (v_num + 1) for _ in range(2)) adj_table = tuple([] for _ in range(v_num + 1)) for v_info in vertices: v_index, adj_num, *adj_list = map(int, v_info) # assert len(adj_list) == adj_num adj_table[v_index].extend(sorted(adj_list, reverse=True)) # timing start from 1 timer = 1 dfs_init() for index, time_info in enumerate(zip(d_time[1:], f_time[1:]), 1): print(index, *time_info)
n, k = map(int, input().split()) a = list(map(int, input().split())) for _ in range(min(50, k)): l = [0]*(n+1) for i in range(n): l[max(i-a[i], 0)] += 1 #光の届く距離(後ろ) l[min(i+a[i]+1, n)] -= 1 #光が届かなくなる距離(前) add = 0 for i in range(n): add += l[i] #光の届いている電球の数を累積 a[i] = add print(*a)
0
null
7,778,947,837,728
8
132
N = int(input()) a = [int(s) - 1 for s in input().split()] result = 0 for i in range(N): if a[i] != (i - result): result += 1 if result == N: print(-1) else: print(result)
def solve(): N = int(input()) A = list(map(int, input().split())) ans = 0 p = 1 for a in A: if a==p: p += 1 else: ans += 1 if p==1: ans = -1 return ans print(solve())
1
114,762,265,955,338
null
257
257
def main(): S = input() # my swapcase for s in S: o = ord(s) if 97 <= o < 97 + 26: o -= 32 elif 65 <= o < 65 + 26: o += 32 print(chr(o), end="") print("") if __name__ == "__main__": main()
moji = input() print(moji.swapcase())
1
1,496,129,185,990
null
61
61
g = list(input()) sum, d, r, p = 0, 0, 0, 0 f = 0 lake_list = [] for c in g: if c == "\\": if f == 0: f, d, r = 1, 1, 1 else: d += 1 r += (1 + (d-1)) elif c == "_": if f == 1: r += d else: if f == 1: d -= 1 r += d if d == 0: f = 0 sum += r lake_list.append([p, r]) r = 0 p += 1 d, r, p = 0, 0, len(g)-1 f = 0 g.reverse() for c in g: if c == "/": if f == 0: f, d, r = 1, 1, 1 pr = p else: d += 1 r += (1 + (d-1)) elif c == "_": if f == 1: r += d else: if f == 1: d -= 1 r += d if d == 0: if [pr, r] not in lake_list: sum += r lake_list.append([pr, r]) f = 0 r = 0 p -= 1 lake_list.sort() print(sum) print(len(lake_list), end="") i = 0 while i != len(lake_list): print(" {}".format(lake_list[i][1]), end="") i += 1 print()
t=input() s1=[] s2=[] pond=[] totalsum=0 for i in range(len(t)): if t[i]=="\\" : s1.append(i) elif t[i]=="/" and len(s1)!=0: p1=s1.pop() sum=i-p1 totalsum+=sum while len(s2)>0: if s2[-1]>p1: s2.pop() sum+=pond.pop() else: break pond.append(sum) s2.append(i) print(totalsum) print(len(pond),*pond)
1
59,911,925,130
null
21
21
x, y, z = input().split() x, y = y, x x, z = z, x print(x, y, z)
import sys import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,k=map(int,input().split()) a=list(map(int,input().split())) f=list(map(int,input().split())) a.sort() f.sort() f.reverse() if sum(a)<=k: print(0) sys.exit() pointer=0 l=0 r=0 for i in range(n): r=max(r,a[i]*f[i]) while l+1<r: try1=(l+r)//2 required=0 for i in range(n): required+=(max(0,a[i]-try1//f[i])) if required>k: l=try1 else: r=try1 required=0 for i in range(n): required+=(max(0,a[i]-l//f[i])) if required>k: print(r) else: print(l)
0
null
101,664,187,109,188
178
290
string=input() if string[2:3]==string[3:4] and string[4:5]==string[5:6]: print('Yes') else: print('No')
t=list(map(int,input().split())) print(max(t[0]*t[2],t[0]*t[3],t[1]*t[2],t[1]*t[3]))
0
null
22,528,303,748,668
184
77
input() *l,=map(int,input().split()) ans=0 for i in l: for j in l: ans+=i*j print((ans-sum([pow(x,2) for x in l]))//2)
n = int(input()) a = list(map(int,input().split())) c = 0 for i in range(n): j = i + 1 while j < n: c = c + (a[i] * a[j]) j += 1 print(c)
1
168,245,861,809,662
null
292
292
n,q = [int(s) for s in input().split()] queue = [] for i in range(n): name,time = input().split() queue.append([name,int(time)]) time = 0 while queue: processing = queue.pop(0) t = min(processing[1], q) time += t processing[1] -= t if processing[1] == 0: print(processing[0],time) else: queue.append(processing)
def robin(process, q): if int(process[0][1]) - q > 0: process[0][1] = int(process[0][1]) - q process.append([process[0][0],process[0][1]]) process.pop(0) return process, q else: q = int(process[0][1]) process.pop(0) return process, q n, q = input().split() n, q = int(n), int(q) process = [] for i in range(n): process.append([i for i in input().split()]) time = 0 while len(process) != 0: length = len(process) name = process[0][0] process, process_time = robin(process, q) time += process_time if length > len(process): print(name,time)
1
40,518,958,688
null
19
19
def main(): n, m = (int(i) for i in input().split()) graph = { i: [] for i in range(1, n+1) } for i in range(m): src, dst = (int(i) for i in input().split()) graph[src].append(dst) graph[dst].append(src) def bfs(): st = [1] pptr = { 1: 0 } while st: room = st.pop(0) for dest_room in graph[room]: if dest_room in pptr: continue st.append(dest_room) pptr[dest_room] = room return pptr pptr = bfs() if len(pptr) != n: print('No') else: print('Yes') for i in sorted(pptr.keys()): if i == 1: continue print(pptr[i]) main()
for a in range(1,10): for b in range(1,10): ans = a*b print("%dx%d=%d" % (a, b, ans))
0
null
10,358,807,558,320
145
1
D = int(input()) c = list(map(int, input().split())) s = [] for k in range(D): s.append(list(map(int, input().split()))) ans = 0 scheduled = [0 for _ in range(26)] for k in range(D): t = int(input()) scheduled[t-1] = -1 for j in range(26): scheduled[j] +=1 ans -= c[j]*scheduled[j] ans += s[k][t-1] print(ans)
import sys a, b = (s.strip() for s in sys.stdin) print('Yes' if a == b[:-1] else 'No')
0
null
15,611,341,841,642
114
147
print chr(ord(raw_input()) + 1)
a = [chr(i) for i in range(97, 97+26)] b = input() print(a[a.index(b)+1])
1
92,629,438,573,712
null
239
239
N, X, T = (int(x) for x in input().split()) if(N % X == 0): print((N // X) * T) else: print(((N // X) + 1) * T)
R, C, K = map(int, input().split()) item = [[0]*C for _ in range(R)] for _ in range(K): r, c, v = map(int, input().split()) item[r-1][c-1] = v dp = [[[0]*C for _ in range(R)] for _ in range(4)] dp[1][0][0] = item[0][0] for h in range(R): for w in range(C): if h!=0: dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w], dp[2][h-1][w], dp[3][h-1][w]) dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w]) if w!=0: dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1]) dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w]) dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w]) dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w]) ans = [] for k in range(4): ans.append(dp[k][-1][-1]) print(max(ans))
0
null
4,858,059,844,560
86
94
# -*- coding: utf-8 -*- import math r = float( input() ) area = r * r * math.pi circle = 2 * r * math.pi print(format(area, '.10f'), format(circle, '.10f'))
import math r=input() print "%.9f"%(math.pi*r*r), math.pi*r*2
1
633,786,215,040
null
46
46
n = int(input()) ans = [0 for _ in range(n+1)] for x in range(1,int(n**0.5)+1): for y in range(1,x+1): for z in range(1,y+1): if x**2+y**2+z**2+x*y+y*z+z*x<=n: if x==y==z: ans[x**2+y**2+z**2+x*y+y*z+z*x] += 1 if (x==y and y != z) or (y==z and z !=x) or (z==x and x != y): ans[x**2+y**2+z**2+x*y+y*z+z*x] += 3 if (x!=y) and (y!=z) and (z!=x): ans[x**2+y**2+z**2+x*y+y*z+z*x] += 6 for a in ans[1:]: print(a)
# ans N = int(input()) ans = [0] * (N + 1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): n = x * x + y * y + z * z + x * y + y * z + z * x if n <= N: ans[n] += 1 for i in range(1, len(ans)): print(ans[i])
1
7,956,486,035,570
null
106
106
# 再帰呼び出しのとき付ける import sys sys.setrecursionlimit(10**9) def readInt(): return list(map(int, input().split())) n, m = readInt() root = [-1] * n def r(x): # print("root[x]=",root[x]) if root[x] < 0: # print("r(x)=",x) return x else: root[x] = r(root[x]) # print(root[x]) return root[x] def unite(x, y): x = r(x) y = r(y) if x == y: return root[x] += root[y] root[y] = x # print(root) def size(x): x = r(x) # print(x, root[x]) return -root[x] for i in range(m): x, y = readInt() x -= 1 y -= 1 unite(x, y) # print('size={}'.format(size(i))) # max_size = 0 # for i in range(n): # max_size = max(max_size, size(i)) # print(max_size) # print(root) ans = -1 for i in root: if i < 0: ans += 1 print(ans)
N, M = map(int, input().split()) A = list(map(int, input().split())) vote = sum(A) for i in range(N): if(A[i] >= vote/(4*M)): A[i] = 1 else: A[i] = 0 if(M <= sum(A)): print("Yes") else: print("No")
0
null
20,427,854,980,192
70
179
while True: s = raw_input() if '-' == s: break m = input() for a in range(m): h = input() s = s[h:len(s)]+s[:h] print s
n, k = map(int, input().split()) lr = [list(map(int, input().split())) for _i in range(k)] mod = 998244353 dp = [0]*(n+1) dp[1] = 1 for p in range(2, n+1): for i, j in lr: dp[p] += dp[max(p-i, 0)] - dp[max(p-j-1, 0)] dp[p] %= mod dp[p] += dp[p-1] print((dp[n]-dp[n-1])%mod)
0
null
2,312,564,505,328
66
74
n = int(input()) ans = 'No' for i in range(1,10): for j in range(i,10): if i*j == n: ans = 'Yes' print(ans)
class Dice: def __init__(self): self.dice=[1,2,3,4,5,6] # up,front,right,left,back,front def set(self,l): self.dice=l def roll(self, s): import copy mat=((1,4,3,2),(5,0,1,1),(2,2,0,5),(3,3,5,0),(0,5,4,4),(4,1,2,3)) l=copy.deepcopy(self.dice) if s == 'N': c = 0 if s == 'S': c = 1 if s == 'E': c = 2 if s == 'W': c = 3 for i in range(6): self.dice[i]=l[mat[i][c]] def get(self): return self.dice import random d=Dice() d.set(list(map(int,input().split()))) for i in range(int(input())): u,f=map(int,input().split()) while True: d.roll('NSEW'[random.randrange(4)]) if d.get()[0]==u and d.get()[1]==f: print(d.get()[2]) break
0
null
79,802,773,390,702
287
34
import math a = int(input()) print(math.ceil(a/2))
""" Writer: SPD_9X2 https://atcoder.jp/contests/abc163/tasks/abc163_e dpか? なにを基準にdpすればよい? まとめられる状態は? 小さいことを考えると貪欲かなぁ かいてみるか 挿入dp? 前から決めていけば、累積和で減る量がわかる &増える寄与も計算できる O(N**2) 全探索はむり ======答えを見ました====== 今より右に行く、左に行くの集合に分けたとすると 大きい奴をより左にする方が最適 よって、途中まで単調減少、途中から単調増加が最適であるとわかる dp[大きい方からi番目まで見た][左にl個つめた] = 最大値 で解ける """ N = int(input()) A = list(map(int,input().split())) ai = [] for i in range(N): ai.append([A[i],i]) ai.sort() ai.reverse() ans = 0 dp = [ [float("-inf")] * (N+1) for i in range(N+1) ] dp[0][0] = 0 for i in range(N): na,nind = ai[i] for l in range(i+1): r = N-1-(i-l) dp[i+1][l+1] = max(dp[i+1][l+1] , dp[i][l] + na*abs(nind-l) ) dp[i+1][l] = max(dp[i+1][l] , dp[i][l] + na*abs(nind-r) ) print (max(dp[N]))
0
null
46,618,219,304,892
206
171
import sys from collections import deque, defaultdict, Counter from itertools import accumulate, product, permutations, combinations from operator import itemgetter from bisect import bisect_left, bisect_right from heapq import heappop, heappush from math import ceil, floor, sqrt, gcd, inf from copy import deepcopy import numpy as np import scipy as sp INF = inf MOD = 1000000007 s = input() t = input() tmp = 0 res = "No" if s == t[:-1]: res = "Yes" print(res)
ch = input().rstrip() ans = chr(ord(ch) + 1) print(ans)
0
null
56,903,782,916,740
147
239
def main(): N = int(input()) S = [0] * N T = [0] * N for i in range(N): S[i], T[i] = input().split() X = input() idx = S.index(X) ans = sum(map(int, T[idx+1:])) print(ans) if __name__ == "__main__": main()
from sys import stdin from collections import Counter N, P = map(int, stdin.readline().split()) S = stdin.readline().strip() ans = 0 if P in (2, 5): for i in range(N): if int(S[i]) % P == 0: ans += i + 1 else: count = Counter() ten = 1 mod = 0 for i in range(N): x = (int(S[N - i - 1])*ten + mod) % P ten = ten*10 % P mod = x count[x] += 1 count[0] += 1 for i in count.values(): ans += i*(i - 1)//2 print (ans)
0
null
77,522,163,232,892
243
205
(A,B)=input().split() (A,B)=(int(A),int(B)) if 1<=A<=9 and 1<=B<=9: print(A*B) else: print(-1)
A,B = map(int,input().split()) print(A*B if (1<= A <= 9) and (1<= B <= 9) else '-1')
1
158,388,267,989,790
null
286
286
class SegTree: def __init__(self, init_val, ide_ele, segfunc): self.n = len(init_val) self.num =2**(self.n-1).bit_length() self.ide_ele = ide_ele self.seg = [self.ide_ele]*2*self.num self.segfunc = segfunc #set_val for i in range(self.n): self.seg[i+self.num-1] = init_val[i] #built for i in range(self.num-2,-1,-1) : self.seg[i] = segfunc(self.seg[2*i+1], self.seg[2*i+2]) def update(self, k, x): k += self.num-1 self.seg[k] = x while k+1: k = (k-1)//2 self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2]) def query(self, p, q): if q<=p: return self.ide_ele p += self.num-1 q += self.num-2 res = self.ide_ele while q-p>1: if p&1 == 0: res = self.segfunc(res, self.seg[p]) if q&1 == 1: res = self.segfunc(res, self.seg[q]) q -= 1 p = p//2 q = (q-1)//2 if p == q: res = self.segfunc(res, self.seg[p]) else: res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q]) return res import sys input = sys.stdin.readline N = int(input()) S = input() L = [-1]*N for i in range(N): L[i] = 2**(ord(S[i]) - ord('a')) def segfunc(a,b): return a | b Seg = SegTree(L,0,segfunc) Q = int(input()) for _ in range(Q): q,a,b = input().split() if q == '1': i = int(a)-1 c = 2**(ord(b) - ord('a')) Seg.update(i,c) elif q=='2': l = int(a)-1 r = int(b)-1 X = Seg.query(l,r+1) tmp = 0 for j in range(30): if X%2==1: tmp += 1 X//=2 print(tmp)
R, C, K = map(int, input().split()) goods = [[0] * C for _ in range(R)] for _ in range(K): r, c, v = map(int, input().split()) goods[r-1][c-1] = v dp = [[[0] * C for _ in range(4)] for _ in range(R)] dp[0][1][0] = goods[0][0] for i in range(R): for j in range(4): for k in range(C): if i < R - 1: dp[i+1][0][k] = max(dp[i+1][0][k], dp[i][j][k]) dp[i+1][1][k] = max(dp[i+1][1][k], dp[i][j][k] + goods[i+1][k]) if k < C - 1: dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k]) if j < 3: dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + goods[i][k+1]) res = 0 for i in range(4): res = max(res, dp[R-1][i][C-1]) print(res)
0
null
33,917,572,270,690
210
94
s = input() n = len(s) t = s[:(n-1)//2] u = s[(n+3)//2-1:] if (s == s[::-1] and t == t[::-1] and u == u[::-1]): print('Yes') else: print('No')
S = input() s = list(S) f = s[:int((len(s)-1)/2)] l = s[int((len(s)+3)/2-1):] if f == l: while len(f) > 1: if f[0] == f[-1]: f.pop(0) f.pop() if len(f) <= 1: while len(l) > 1: if l[0] == l[-1]: l.pop(0) l.pop() if len(l) <= 1: print('Yes') else: print('No') else: print('No') else: print('No')
1
46,286,714,083,730
null
190
190
from collections import Counter N = int(input()) A = list(map(int, input().split())) l =[] r =[] for id,h in enumerate(A,start=1): r.append(id -h) l.append(id +h) r_cou =Counter(r) l_cou =Counter(l) ans =[] for i in l_cou.keys(): ans.append(l_cou[i] *r_cou.get(i,0)) print(sum(ans))
N = int(input()) Alist = list(map(int,input().split())) Aplu = [] Amin = dict() for i in range(N): A = Alist[i] Aplu.append(A+(i+1)) if (i+1)-A not in Amin: Amin[(i+1)-A] = 1 else: Amin[(i+1)-A] += 1 Answer = 0 for k in Aplu: if k in Amin: Answer += Amin[k] print(Answer)
1
25,937,559,700,218
null
157
157
def resolve(): a,b = map(int,input().split()) if 1<=a<=9 and 1<=b<=9: print(a*b) else: print(-1) resolve()
from numpy import cumsum n,k=map(int,input().split()) p=list(map(int,input().split())) p.sort() p=cumsum(p) print((p[k-1]))
0
null
84,480,363,818,518
286
120
n, a, b = map(int, input().split()) mod = 10 ** 9 + 7 #n種類の花を使って、花束を作る組み合わせは2^n-1通り #pow(x,y,mod) : (x**y) % mod ans = pow(2, n, mod)-1 #nCa nCa = 1 #分子:n*(n-1)*...*(n-a+1) for i in range(n-a+1, n+1): nCa *= i nCa %= mod #分母:1/a! = 1/(1*2*...*a) = 1^(p-2)*2^(p-2)*,,,*a^(p-2) for i in range(1, a+1): nCa *= pow(i, mod-2, mod) nCa %= mod #nCb nCb = 1 for i in range(n-b+1, n+1): nCb *= i nCb %= mod for i in range(1, b+1): nCb *= pow(i, mod-2, mod) nCb %= mod #2^n-1通りからnCaとnCbを引く ans -= (nCa + nCb) ans %= mod print(ans)
while 1: s = input() if s == "-": break for _ in range(int(input())): h = int(input()) s = s[h:] + s[:h] print(s)
0
null
34,034,989,969,626
214
66
l = int(input()) x = l/3 print(x**3)
l = int(input()) a = l/3 print(a*a*a)
1
47,013,844,991,840
null
191
191
from bisect import bisect_left, bisect_right n,m = map(int, input().split()) al = list(map(int, input().split())) al.sort() ok, ng = 0, 10**18+1 while abs(ok-ng) > 1: mid = (ok+ng)//2 ok_flag = True cnt = 0 # print('-----') # print(ok,ng,mid) for i,a in enumerate(al): rem = mid-a cnt_a = n-bisect_left(al,rem) # cnt_a = min(n-i-1, cnt_a) cnt += cnt_a # print(i,a,cnt_a) if cnt >= m: ok = mid else: ng = mid min_sum = ok cum_sums = [0] csum = 0 for a in al: csum += a cum_sums.append(csum) # print(min_sum) ans = 0 cnt = 0 for i,a in enumerate(al): rem = min_sum - a ind = bisect_left(al, rem) # ind = ind if 0 <= ind < n else None # ind = max(i+1,ind) csum = cum_sums[n] - cum_sums[ind] # print(i,a,csum) ans += csum ans += a*(n-ind) cnt += (n-ind) ans -= (cnt-m)*min_sum print(ans) # print(min_sum)
n, m = map(int, input().split()) *A, = map(int, input().split()) A.sort() # Aの累積和を求めておく S = [0] x = 0 for a in A: x += a S.append(x) def lower(x): # A[i]<xなるiの個数 left = -1 right = n while right-left > 1: mid = (left+right)//2 if A[mid] < x: left = mid else: right = mid return right def lower_pair(x): # A[i]+A[j]<xなる(i,j)の個数 cnt = 0 for a in A: cnt += lower(x-a) return cnt # A[i]+A[j]のm番目に大きい値を求める # lower_pair(x)<n**2-mなる最大のxを求めればよい left = 2*min(A) right = 2*max(A) while right-left > 1: mid = (left+right)//2 if lower_pair(mid) < n**2-m: left = mid else: right = mid x = left # A[i]+A[j]>=xとなる(i,j)の個数とA[i]+A[j]の総和を求める k = n**2-lower_pair(x) s = 0 for a in A: cnt = lower(x-a) s += (n-cnt)*a+S[n]-S[cnt] print(s-(k-m)*x)
1
108,325,423,768,708
null
252
252
N = int(input()) P = list(map(int, input().split())) pj = P[0] cnt = 1 for pi in P[1:]: if pi < pj: cnt += 1 pj = pi print(cnt)
import math def koch(start,end,n): if n==0: return else: point1=[0,0] point2=[0,0] point3=[0,0] point1[0]=(end[0]-start[0])/3 +start[0] point1[1]=(end[1]-start[1])/3 +start[1] point3[0]=(end[0]-start[0])*2/3+start[0] point3[1]=(end[1]-start[1])*2/3+start[1] rad60 = math.radians(60) point2[0]=(point3[0]-point1[0])* math.cos(rad60) -(point3[1]-point1[1])*math.sin(rad60) +point1[0] point2[1]=(point3[0]-point1[0])* math.sin(rad60) +(point3[1]-point1[1])*math.cos(rad60) +point1[1] koch(start,point1,n-1) print(*point1) koch(point1,point2,n-1) print(*point2) koch(point2,point3,n-1) print(*point3) koch(point3,end,n-1) n=int(input()) start=[0,0] end=[100,0] print(*start) if n>0: koch(start,end,n) print(*end)
0
null
42,839,039,027,360
233
27
import sys input = sys.stdin.readline read = sys.stdin.read n, t = map(int, input().split()) m = map(int, read().split()) AB = sorted(zip(m, m)) A, B = zip(*AB) dp = [[0]*t for _ in range(n+1)] for i, a in enumerate(A[:-1]): for j in range(t): if j < a: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = max(dp[i][j-a]+B[i], dp[i][j]) ans = 0 maxB = [B[-1]]*n for i in range(n-2, 0, -1): maxB[i] = max(B[i], maxB[i+1]) for i in range(n-1): ans = max(ans, dp[i+1][-1] + maxB[i+1]) print(ans)
import os, sys, re, math S = input() dow = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] print(7 - dow.index(S))
0
null
142,446,242,396,068
282
270
print(' ' + ' '.join(str(i) for i in range(1, int(input()) + 1) if not i % 3 or '3' in str(i)))
X,N = map(int,input().split()) P = list(map(int,input().split())) if X not in P: print(X) else: d = 1 while True: if X-d not in P: print(X-d) break if X+d not in P: print(X+d) break d += 1
0
null
7,582,721,261,712
52
128
def main(): X, Y = map(int, input().split()) ans = 0; if X == 1: ans += 300000 elif X == 2: ans += 200000 elif X == 3: ans += 100000 if Y == 1: ans += 300000 elif Y == 2: ans += 200000 elif Y == 3: ans += 100000 if X == 1 and Y == 1: ans += 400000 print(ans) if __name__ == '__main__': main()
h,n=map(int,input().split()) magic=[list(map(int,input().split())) for _ in range(n)] dp=[10**9]*(h+10**5) #dp[i]:敵の体力をi減らすのに必要な魔力の最小値 dp[0]=0 for i in range(h): for damage,cost in magic: dp[i+damage]=min(dp[i+damage],dp[i]+cost) ans=10**9 for i in range(10**5): ans=min(ans,dp[i+h]) print(ans)
0
null
110,961,861,455,592
275
229
import sys def input(): return sys.stdin.readline().rstrip() def main(): n, k =map(int,input().split()) A = list(map(int,input().split())) + [0] while k > 0: B = [0] * (n + 1) for i, a in enumerate(A): B[max(0, i - a)] += 1 B[min(n, i + a + 1)] -= 1 if B[0] == n: flag = True for i in range(1, n+1): B[i] += B[i-1] if B[i] != n and i < n: flag = False A = B[:] if flag: break k -= 1 print(" ".join(map(str, B[:-1]))) if __name__=='__main__': main()
def main(): import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, k = map(int, readline().split()) a = list(map(int, readline().split())) memo = [0] * (n + 1) for _ in range(k): flag = True for i, aa in enumerate(a): bf = (i - aa if i - aa >= 0 else 0) af = (i + aa + 1 if i + aa < n else n) memo[bf] += 1 memo[af] -= 1 for i in range(n): memo[i + 1] += memo[i] a[i] = memo[i] if a[i] != n: flag = False memo[i] = 0 if flag: break print(*a) if __name__ == '__main__': main()
1
15,455,775,324,848
null
132
132
def resolve(): l=float(input()) print(l**3/27) resolve()
x = int(input()) ans = x while True: jud = 0 if(ans <= 2): print(2) break if(ans%2==0): jud += 1 i = 3 while i < ans**(1/2): if(jud>0): break if(ans%i == 0): jud += 1 i += 2 if(jud==0): print(ans) break ans += 1
0
null
76,239,322,019,900
191
250
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W, k = map(int, input().split()) grid = [[0] * W for _ in range(H)] for _ in range(k): r, c, v = map(int, input().split()) grid[r - 1][c - 1] = v # dp[i][h][w]:h行目のアイテムをi個取得した時の、座標(h,w)における価値の最大値 dp = [[[0] * W for _ in range(H)] for _ in range(4)] dp[1][0][0] = grid[0][0] for h in range(H): for w in range(W): for i in range(4): # 下に移動する場合 if h + 1 < H: # アイテムを取らない dp[0][h + 1][w] = max(dp[0][h + 1][w], dp[i][h][w]) # アイテムを取る dp[1][h + 1][w] = max(dp[1][h + 1][w], dp[i][h][w] + grid[h + 1][w]) # 右に移動する場合 if w + 1 < W: # アイテムを取らない dp[i][h][w + 1] = max(dp[i][h][w + 1], dp[i][h][w]) # アイテムを取る(但し、4個以上所持してはいけない) if i + 1 < 4: dp[i + 1][h][w + 1] = max(dp[i + 1][h][w + 1], dp[i][h][w] + grid[h][w + 1]) res = 0 for i in range(4): res = max(res, dp[i][-1][-1]) print(res) if __name__ == '__main__': resolve()
import math def main(): a, b, n = map(int, input().split()) x = n if (b-1) > n else b-1 print(math.floor(a*x/b)-a*math.floor(x/b)) if __name__ == '__main__': main()
0
null
16,767,294,086,110
94
161
import os, sys, re, math N = int(input()) S = input() if S[:N // 2] == S[N // 2:]: print('Yes') else: print('No')
N = int(input()) s = input() if N % 2 == 1: print("No") elif s[0:N//2] != s[N//2:]: print("No") else: print("Yes")
1
147,578,809,743,044
null
279
279
N, M = map(int, input().split()) print('Yes' if N <= M else 'No')
def main(): n, m = map(int, input().split()) if n == m: print('Yes') else: print('No') if __name__ == "__main__": main()
1
82,847,107,249,632
null
231
231
import math import collections def f(a,b,x): return math.floor((a*x)/b) - a*math.floor(x/b) a,b,n=map(int, input().split()) dd = collections.defaultdict(int) print(f(a,b,min(b-1,n)))
S,T = input().split() a = T + S print(a)
0
null
65,270,639,714,268
161
248
# B - Bishop H,W = map(int,input().split()) if H>1 and W>1: print((H*W+1)//2) else: print(1)
import math def resolve(): H, W = [int(i) for i in input().split()] if H==1 or W==1: print(1) else: print(math.ceil(H*W/2)) resolve()
1
50,871,553,447,962
null
196
196
print({"SUN":7, "MON":6,"TUE":5,"WED":4,"THU":3,"FRI":2,"SAT":1}[input()])
import math as m def plot(x,y): print(f'{x:.8f} {y:.8f}') def koch(n,x1,y1,x2,y2): if n==0: plot(x1,y1) return sx=(2*x1+x2)/3 sy=(2*y1+y2)/3 tx=(x1+2*x2)/3 ty=(y1+2*y2)/3 ux=(tx-sx)*m.cos(m.radians(60))-(ty-sy)*m.sin(m.radians(60))+sx uy=(tx-sx)*m.sin(m.radians(60))+(ty-sy)*m.cos(m.radians(60))+sy koch(n-1,x1,y1,sx,sy) koch(n-1,sx,sy,ux,uy) koch(n-1,ux,uy,tx,ty) koch(n-1,tx,ty,x2,y2) n=int(input()) koch(n,0,0,100,0) plot(100,0)
0
null
66,731,517,430,018
270
27
def show(nums): for i in range(len(nums)): if i != len(nums) - 1: print(nums[i],end=' ') else: print(nums[i]) def bubbleSort(A,N): flag = 1 count = 0 while flag: flag = 0 for j in range(N-1,0,-1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag = 1 count += 1 show(A) print(count) N = int(input()) A = list(map(int,input().split())) bubbleSort(A,N)
X,Y,Z=map(int,input().split(" ")) tmp=Y Y=X X=tmp tmp=Z Z=X X=tmp print(X,Y,Z,end=" ")
0
null
19,104,037,785,368
14
178
n = len(input()) print('x' * n)
print("".join('x' for i in range(len(input()))))
1
72,756,858,360,340
null
221
221
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) def celi(a,b): return -(-a//b) sys.setrecursionlimit(5000000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] x=int(input()) def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True ans=x while not is_prime(ans): ans+=1 print(ans)
n=int(input()) for i in range(n,10**6): for j in range(2,int(i**0.5)+1): if i%j==0: break else: print(i) break
1
105,456,623,566,320
null
250
250
s=input() l=[['SSS'],['RSS','SRS','SSR','RSR'],['RRS','SRR'],['RRR']] for i in range(4): if s in l[i]: print(i) exit()
n=int(input()) print(int(n/2)-1 if n%2==0 else int((n-1)/2))
0
null
78,653,252,771,392
90
283
n = int(input()) def gcd(a,b): if b == 0: return a return gcd(b, a%b) print((360 * n // gcd(360, n)) // n)
import sys x = int(input()) ans = 2 while(True): if x*ans % 360 == 0: print(ans) sys.exit() ans +=1
1
13,153,306,936,952
null
125
125
n = int(input()) s = input() if n % 2 == 1: print('No') else: head = s[:n // 2] tail = s[n // 2:] if head == tail: print('Yes') else: print('No')
n = int(input()) print(len([i for i, j in enumerate(input().split()) if int(j)%2 == 1 and i%2 == 0]))
0
null
77,007,797,077,090
279
105
row, col, num = map(int, input().split()) tmp_l = [] board = [] for i in range(row): str = input() for j in range(col): if str[j] == '.': tmp_l.append(0) if str[j] == '#': tmp_l.append(1) board.append(tmp_l) tmp_l = [] onoff = [] bi = [32, 16, 8, 4, 2, 1] for i in range(64): tmp = i for j in bi: tmp_l.insert(0, int(tmp / j)) tmp %= j onoff.append(tmp_l) tmp_l = [] count = 0 ans = 0 for i in range(2**row): for j in range(2**col): for k in range(row): if onoff[i][k] == 1: for l in range(col): if onoff[j][l] == 1: if board[k][l] == 1: count += 1 if count == num: ans += 1 count = 0 print(ans)
N = int(input()) P = list(map(int, input().split())) pj = P[0] cnt = 1 for pi in P[1:]: if pi < pj: cnt += 1 pj = pi print(cnt)
0
null
47,235,385,712,750
110
233
def main(): x,y = list(map(int,input().split())) ans=0 for i in range(0,x+1): if 2*i+4*(x-i)==y: ans=1 if ans==1: print("Yes") else: print("No") main()
N = int(input()) A = [0] * (N + 1) for i in range(1, 102): for j in range(1, 102): for k in range(1, 102): t = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + i * k if t <= N: A[t] += 1 for n in range(1, N + 1): print(A[n])
0
null
10,915,877,479,318
127
106
N = int(input()) string = [0 for i in range(N)] calc_str = lambda :"".join(list(chr(i+ord('a')) for i in string)) chr_a = ord('a') print(calc_str()) now = N-2 while N > 1: if string[now+1]-max(string[:now+1]) > 0: if now == 0: break string[now+1] = 0 now -= 1 else: string[now+1] += 1 now = N-2 print(calc_str())
# -*- coding: utf-8 -*- moji=[] moji.append("eraser") moji.append("erase") moji.append("dreamer") moji.append("dream") user = "erasedream" user = int(input()) result = user count = 1 while result != 0: result += user result %= 360 count += 1 print(count,end="")
0
null
32,851,610,416,820
198
125
D=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split())) for i in range(D)] t=[int(input())-1 for i in range(D)] v=[] S=0 last=[0]*27 for d in range(D): S+=s[d][t[d]] last[t[d]]=d+1 for i in range(26): S-=c[i]*(d+1 - last[i]) print(S)
D = int(input()) c = [0]+list(map(int, input().split())) s = [[0]]+[[0]+list(map(int, input().split())) for _ in range(D)] t = [0]+[int(input()) for _ in range(D)] ans = 0 last = [0]*(27) for d in range(1,D+1): ans += s[d][t[d]] last[t[d]] = d for i in range(1,27): ans -= c[i] * (d-last[i]) print(ans)
1
9,892,228,451,392
null
114
114
x,y=map(int,input().split()) ans=0 if x<=3: ans+=(4-x)*100000 if y<=3: ans+=(4-y)*100000 if ans==600000: ans=1000000 print(ans)
x, y = map(int, input().split()) s = [400000, 300000, 200000, 100000] if x == 1 and y == 1: print(sum(s)) elif x <= 3 and y <= 3: print(s[x] + s[y]) elif x <= 3: print(s[x]) elif y <= 3: print(s[y]) else: print(0)
1
140,910,606,093,532
null
275
275
from random import randint, random from math import exp import sys input = sys.stdin.readline INF = 9223372036854775808 def calc_score(D, C, S, T): """ 開催日程Tを受け取ってそこまでのスコアを返す コンテストi 0-indexed d 0-indexed """ score = 0 last = [0]*26 # コンテストiを前回開催した日 for d, t in enumerate(T): last[t] = d + 1 for i in range(26): score -= (d + 1 - last[i]) * C[i] score += S[d][t] return score def update_score(D, C, S, T, score, ct, ci): """ ct日目のコンテストをコンテストciに変更する スコアを差分更新する ct: change t 変更日 0-indexed ci: change i 変更コンテスト 0-indexed """ new_score = score last = [0]*26 # コンテストiを前回開催した日 prei = T[ct] # 変更前に開催する予定だったコンテストi for d, t in enumerate(T, start=1): last[t] = d new_score += (d - last[prei])*C[prei] new_score += (d - last[ci])*C[ci] last = [0]*26 for d, t in enumerate(T, start=1): if d-1 == ct: last[ci] = d else: last[t] = d new_score -= (d - last[prei])*C[prei] new_score -= (d - last[ci])*C[ci] new_score -= S[ct][prei] new_score += S[ct][ci] return new_score def evaluate(D, C, S, T, k): """ d日目終了時点での満足度を計算し, d + k日目終了時点での満足度の減少も考慮する """ score = 0 last = [0]*26 for d, t in enumerate(T): last[t] = d + 1 for i in range(26): score -= (d + 1 - last[i]) * C[i] score += S[d][t] for d in range(len(T), min(len(T) + k, D)): for i in range(26): score -= (d + 1 - last[i]) * C[i] return score def greedy(D, C, S): Ts = [] for k in range(7, 10): T = [] # 0-indexed max_score = -INF for d in range(D): # d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する max_score = -INF best_i = 0 for i in range(26): T.append(i) score = evaluate(D, C, S, T, k) if max_score < score: max_score = score best_i = i T.pop() T.append(best_i) Ts.append((max_score, T)) return max(Ts, key=lambda pair: pair[0]) def local_search(D, C, S, score, T): T0 = 2e3 T1 = 6e2 Temp = T0 for k in range(500, 95000): if k % 100: t = (k/95000) / 1.9 Temp = pow(T0, 1-t) * pow(T1, t) sel = randint(1, 2) if sel == 1: # ct 日目のコンテストをciに変更 ct = randint(0, D-1) ci = randint(0, 25) new_score = update_score(D, C, S, T, score, ct, ci) lim = random() if score < new_score or \ (new_score > 0 and exp((score - new_score)/Temp) > lim): T[ct] = ci score = new_score else: # ct1 日目と ct2 日目のコンテストをswap ct1 = randint(0, D-1) ct2 = randint(0, D-1) ci1 = T[ct1] ci2 = T[ct2] new_score = update_score(D, C, S, T, score, ct1, ci2) new_score = update_score(D, C, S, T, new_score, ct2, ci1) lim = random() if score < \ (new_score > 0 and exp((score - new_score)/Temp) > lim): score = new_score T[ct1] = ci2 T[ct2] = ci1 return T if __name__ == '__main__': D = int(input()) C = [int(i) for i in input().split()] S = [[int(i) for i in input().split()] for j in range(D)] init_score, T = greedy(D, C, S) T = local_search(D, C, S, init_score, T) for t in T: print(t+1)
import sys input = sys.stdin.readline MOD = 1000000007 N,A,B = map(int,input().split()) if abs(A-B)%2 == 0: print(abs(A-B)//2) else: if (A-1) < (N-B): print((A-1)+1+(B-A-1)//2) else: print((N-B)+1+(B-A-1)//2)
0
null
59,829,352,896,764
113
253
import sys sys.setrecursionlimit(10**9) N, P = list(map(int, input().split())) S = input() if P == 2 or P == 5: ans = 0 for i in range(N): if int(S[i]) % P == 0: ans += i + 1 print(ans) sys.exit() num = [0] * P num[0] = 1 now, ans = 0, 0 _10 = 1 for i in range(N-1, -1, -1): now = (now + int(S[i]) * _10) % P _10 *= 10 _10 %= P ans += num[now] num[now] += 1 print(ans)
def dfs(S): if len(S) == N: ans.append(S) else: for c in range(max(S) + 2): dfs(S + [c]) N = int(input()) ans = [] dfs([0]) for li in ans: print("".join(chr(c + ord("a")) for c in li))
0
null
55,160,213,496,258
205
198
N = int(input()) A = [] B = [] for i in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) A.sort() B.sort() if N % 2 == 1: A_median = A[N // 2] B_median = B[N // 2] print(B_median - A_median + 1) else: A_median2 = A[(N - 1) // 2] + A[N // 2] B_median2 = B[(N - 1) // 2] + B[N // 2] print(B_median2 - A_median2 + 1)
# https://codeforces.com/blog/entry/78195: Geothermal editorial n = int(input()) A, B = [], [] for i in range(n): a, b = map(int, input().split()) A.append(a) B.append(b) A.sort() B.sort() if n%2 == 1: medA, medB = A[n//2], B[n//2] else: medA = A[n//2] + A[n//2 - 1] medB = B[n//2] + B[n//2 - 1] print(medB - medA + 1)
1
17,317,678,087,612
null
137
137
x = input().split() a = int(x[0]) b = int(x[1]) if a == b : print('a == b') elif a > b : print('a > b') else : print('a < b')
z = input() x,y = z.split() a,b = int(x),int(y) if a < b: print("a < b") elif a > b: print("a > b") else: print("a == b")
1
357,231,417,078
null
38
38
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * N = INT() L = LIST() L.sort() ans = 0 for i in range(N-2): a = L[i] for j in range(i+1, N-1): b = L[j] idx = bisect_left(L, a+b) - 1 if j < idx: ans += idx - j print(ans)
n=int(input()) l=list(map(int,input().split())) from bisect import bisect_left l.sort() count=0 for a in range(n-2): for b in range(a+1,n-1): idx=bisect_left(l,l[a]+l[b],lo=b) count+=idx-(b+1) print(count)
1
171,625,880,903,192
null
294
294
n = int(input()) f = 100000 if n == 0: print(int(f)) else: for i in range(n): f *= 1.05 #print(f) #F = f - f%1000 + 1000 if f%1000 != 0: f = (f//1000)*1000 + 1000 #print(i,f) print(int(f))
# coding: utf-8 # Your code here! n = int(input()) sum = 100000 for i in range(n): sum += sum * 0.05 if sum % 1000 > 0: sum -= sum % 1000 sum += 1000 print(int(sum))
1
1,174,858,400
null
6
6
a, b, c = [int(i) for i in raw_input().split()] if a < b< c: print "Yes" else: print "No"
[a,b,c] = map(int,input().split()) print("Yes" if a < b < c else "No")
1
387,923,505,240
null
39
39
M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) if M1 in [1, 3, 5, 7, 8, 10, 12]: if D1 == 31: print(1) else: print(0) elif M1 in [4, 6, 9, 11]: if D1 == 30: print(1) else: print(0) elif M1 == 2: if D1 == 28: print(1) else: print(0)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, K = mapint() v = N//K print(min(N-v*K, K-(N-v*K)))
0
null
81,909,096,423,010
264
180
import sys s = input() def match(a): if a[0:2] == 'hi': return a[2:] else: print('No') sys.exit() if len(s)%2 == 1: print('No') sys.exit() else: while len(s) > 1: s = match(s) print('Yes')
str = input() def hitachi(S): hitachi_str = [True if S[i:i+2] == 'hi' else False for i in range(0,len(S),2)] if all(hitachi_str): result = 'Yes' else: result = 'No' return result print(hitachi(str))
1
53,039,162,410,300
null
199
199
#!/usr/bin/env python3 import sys def solve(S: str): print(S[0:3]) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str solve(S) if __name__ == '__main__': main()
S=str(input()) n=[] for i in range(3): n.append(S[i]) print(''.join(n))
1
14,689,938,891,354
null
130
130
D,T,S = (int(x) for x in input().split()) if D/S <= T: print('Yes') else: print('No')
def digitsum(n): res = 0 for i in n: #print(ni) ni = int(i) res += ni return res s = input() r = digitsum(s) if r % 9 == 0: print("Yes") else: print("No")
0
null
3,943,720,553,568
81
87
# -*- coding: utf-8 -*- input_list = input().split() stack = list() for i in input_list: if i.isdigit(): stack.append(int(i)) else: b = stack.pop() a = stack.pop() if i == '+': stack.append(a + b) elif i == '-': stack.append(a - b) elif i == '*': stack.append(a * b) print(stack.pop())
a = list(input().split()) n = len(a) s = [] for i in a: if i=="+": a = s.pop() b = s.pop() s.append(b + a) elif i=="-": a = s.pop() b = s.pop() s.append(b - a) elif i=="*": a = s.pop() b = s.pop() s.append(b * a) else: s.append(int(i)) print(s[0])
1
36,027,042,798
null
18
18
#!/usr/bin/env python def solve(A: int, B: int, C: int, K: int): if A >= K: return K K -= A if B >= K: return A K -= B return A - K def main(): A, B, C, K = map(int, input().split()) answer = solve(A, B, C, K) print(answer) if __name__ == "__main__": main()
a, b, c, k = map(int, input().split()) if(k <= a): print(k) elif(k <= a+b): print(a) else: if(a <= k-a-b): print(-1*(k-a-b-a)) elif(a > k-a-b): print(a-(k-a-b))
1
21,844,094,501,372
null
148
148
if __name__ == '__main__': from statistics import pstdev while True: # ??????????????\??? data_count = int(input()) if data_count == 0: break scores = [int(x) for x in input().split(' ')] # ?¨??????????????¨???? result = pstdev(scores) # ??????????????? print('{0:.8f}'.format(result))
rate = int(input()) if 400 <= rate < 600: print("8") elif 600 <= rate <800: print("7") elif 800 <= rate <1000: print("6") elif 1000 <= rate <1200: print("5") elif 1200 <= rate <1400: print("4") elif 1400 <= rate <1600: print("3") elif 1600 <= rate <1800: print("2") elif 1800 <= rate <2000: print("1")
0
null
3,439,446,232,710
31
100
import sys import re import queue import collections import math from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left, bisect_right from functools import reduce from decimal import Decimal, getcontext # input = sys.stdin.readline def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 num_list = [] str_list = [] def gcd_list(numbers): return reduce(gcd, numbers) def main(): N = i_input() A = i_list() d = dict() max_A = max(A) count_list = [] MAXN = 10**6+10 sieve = [i for i in range(MAXN+1)] p = 2 while p*p <= MAXN: if sieve[p] == p: for q in range(2*p,MAXN+1,p): if sieve[q] == q: sieve[q] = p p += 1 for i in range(0,max(A)): count_list.append(0) for a in A: tmp = set() while a > 1: tmp.add(sieve[a]) a //= sieve[a] for p in tmp: count_list[p-1] += 1 if (max(count_list)<=1): print("pairwise coprime") elif(gcd_list(A)==1): print("setwise coprime") else: print("not coprime") return if __name__ == '__main__': main()
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) def gcd_list(numbers): return reduce(math.gcd, numbers) def eratosthenes(n): D = [0]*(n+1) for i in range(2, n+1): if D[i] > 0: continue for j in range(i, n+1, i): D[j] = i return D N = int(input()) A = list(map(int, input().split())) D = eratosthenes(10**6+1) # D = eratosthenes(max(A)) dic = {} for i in A: while i != 1: if i in dic: dic[i] += 1 else: dic[i] = 1 i //= D[i] isPairwise = True for i in dic.items(): if i[1] > 1: isPairwise = False break def is_pairwise(): used_primes = [False] * (10**6 + 1) for a in A: while a > 1: prime = D[a] while a % prime == 0: a //= prime if used_primes[prime]: return False used_primes[prime] = 1 return True # if isPairwise: if is_pairwise(): print("pairwise coprime") elif gcd_list(A) == 1: print("setwise coprime") else: print("not coprime")
1
4,120,055,248,360
null
85
85
import math a, b, c = map(float, input().split()) h = b * math.sin(math.radians(c)) c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(c))) L = a + b + c S = 1 / 2 * a * h print(S) print(L) print(h)
import math a, b, C = map(float, input().split()) S = (a * b * math.sin(math.radians(C))) / 2 L = a + b + (math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C)))) h = b * math.sin(math.radians(C)) print("{:.8f}".format(S)) print("{:.8f}".format(L)) print("{:.8f}".format(h))
1
178,580,588,788
null
30
30
# -*- coding: utf-8 -*- # 入力を整数に変換して受け取る def input_int(): return int(input()) # マイナス1した値を返却 def int1(x): return int(x) - 1 # 半角スペース区切り入力をIntに変換してMapで受け取る def input_to_int_map(): return map(int, input().split()) # 半角スペース区切り入力をIntに変換して受け取る def input_to_int_tuple(): return tuple(map(int, input().split())) # 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る def input_to_int_tuple_minus1(): return tuple(map(int1, input().split())) def main(): n = input_int() cnt = [[0] * 10 for i in range(10)] for n in range(1, n + 1): cnt[int(str(n)[0])][int(str(n)[-1])] += 1 ret = 0 for i in range(10): for j in range(10): ret += cnt[i][j] * cnt[j][i] return ret if __name__ == "__main__": print(main())
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) res = 0 numbers = [[0] * 10 for _ in range(10)] for i in range(1, n + 1): ss = str(i) numbers[int(ss[0])][int(ss[-1])] += 1 for j in range(1, 10): for k in range(1, 10): res += numbers[j][k] * numbers[k][j] print(res) if __name__ == '__main__': resolve()
1
86,760,981,031,780
null
234
234
n,m = map(int, input().split()) height_list = list(map(int, input().split())) heightest_list = [0] * n for _ in range(m): a,b = map(int, input().split()) heightest_list[a-1] = max(heightest_list[a-1], height_list[b-1]) heightest_list[b-1] = max(heightest_list[b-1], height_list[a-1]) result = 0 for i in range(n): if height_list[i] > heightest_list[i]: result += 1 print(result)
N,M = map(int,input().split()) H = list(map(int,input().split())) AB = [tuple(map(int,input().split())) for i in range(M)] ans=0 es = [[] for _ in range(N)] for a,b in AB: a,b = a-1,b-1 es[a].append(b) es[b].append(a) for i in range(N): for j in es[i]: if H[j]>=H[i]: break else: ans+=1 print(ans)
1
24,932,396,880,348
null
155
155
print(sum([i for i in range(int(input()) + 1) if (i % 3 != 0 and i % 5 != 0)]))
N = int(input()) dp = [[0]*10 for _ in range(10)] for i in range(1, N+1): if i%10==0: continue strI = str(i) f,l = strI[-1], strI[0] dp[int(f)][int(l)] += 1 res = 0 for i in range(1,10): for j in range(1,10): res += dp[i][j] * dp[j][i] print(res)
0
null
60,803,096,773,188
173
234
X, Y = map(int, input().split()) ans = "No" for i in range(101) : for j in range(101) : if(i + j != X) : continue if(2*i + 4*j != Y) : continue ans = "Yes" break print(ans)
#!/usr/bin/env python3 n, m = map(int, input().split()) d = m r = d + 1 for i in range(m): if d <= 0: break a = i + 1 b = a + d print(a, b) d -= 2 d = m - 1 for i in range(m): if d <= 0: break a = r + i + 1 b = a + d print(a, b) d -= 2
0
null
21,179,703,856,608
127
162
N,K = (int(x) for x in input().split()) Conv = [] while N!=0: Conv.append(N%K) N = N//K Disp = ''.join([str(x) for x in Conv[::-1]]) print(len(Disp))
def top(n): return int(str(n)[0]) def bottom(n): return int(str(n)[-1]) n = int(input()) c = [[0 for _ in range(10)] for _ in range(10)] for i in range(1,n+1): c[top(i)][bottom(i)] += 1 ans = 0 for i in range(10): for j in range(10): ans += c[i][j]*c[j][i] print(ans)
0
null
75,488,167,733,220
212
234
def resolve(): l=float(input()) print(l**3/27) resolve()
def resolve(): N = int(input()) ans = 0 for j in range(1,N+1): Y = int(N // j) ans += Y * (Y+1) * j // 2 print(ans) resolve()
0
null
29,264,848,948,270
191
118
import fractions while True: try: a,b = map(int,input().split()) except: break print(fractions.gcd(a,b),a*b // fractions.gcd(a,b))
import math K = int(input()) ans = 0 for a in range(1, K+1): for b in range(a, K+1): for c in range(b, K+1): s = math.gcd(a, b) t = math.gcd(s, c) if a == c: ans += t elif (a == b or b == c) and a != c: ans += 3*t else: ans += 6*t print(ans)
0
null
17,788,035,244,698
5
174
def resolve(): N = int(input()) s = [] t = [] for i in range(N): S, T = input().split() s.append(S) t.append(int(T)) X = input() print(sum(t[s.index(X)+1:])) resolve()
S = list(map(str, input().split())) count = len(S) stack = [] for i in range(count): if S[i] == "+": b = stack.pop() a = stack.pop() stack.append(a + b) elif S[i] == "-": b = stack.pop() a = stack.pop() stack.append(a - b) elif S[i] == "*": b = stack.pop() a = stack.pop() stack.append(a * b) else: stack.append(int(S[i])) print(stack[0])
0
null
48,676,199,806,572
243
18
s=input() sl=len(s) a=[] count=1 for i in range(sl-1): if s[i+1]==s[i]: count+=1 else: a.append(count) count=1 a.append(count) ans=0 al=len(a) if s[0]=="<": for i in range(0,al-1,2): m,n=max(a[i],a[i+1]),min(a[i],a[i+1]) ans+=(m*(m+1)+n*(n-1))/2 if al%2==1: ans+=a[-1]*(a[-1]+1)/2 elif s[0]==">": ans+=a[0]*(a[0]+1)/2 for i in range(1,al-1,2): m,n=max(a[i],a[i+1]),min(a[i],a[i+1]) ans+=(m*(m+1)+n*(n-1))/2 if al%2==0: ans+=a[-1]*(a[-1]+1)/2 print(int(ans))
import sys from collections import deque def m(): s=sys.stdin.readlines() q=int(s[0].split()[1]) f=lambda x,y:(x,int(y)) d=deque(f(*e.split())for e in s[1:]) t,a=0,[] while d: k,v=d.popleft() if v>q:v-=q;t+=q;d.append([k,v]) else:t+=v;a+=[f'{k} {t}'] print('\n'.join(a)) if'__main__'==__name__:m()
0
null
78,187,706,593,610
285
19
s = input() num = int(input()) for i in range(num): L = input().split() if L[0] == 'print': print(s[int(L[1]):int(L[2])+1]) elif L[0] == 'reverse': ts = s[int(L[1]):int(L[2])+1] s = s[:int(L[1])] + ts[:: -1] + s[int(L[2])+1:] elif L[0] == 'replace': s = s[:int(L[1])] + L[3] + s[int(L[2])+1:]
t = input() for _ in range(int(input())): order = input().split() cmd = order[0] a, b = map(int, order[1:3]) if cmd == 'print': print(t[a:b+1]) elif cmd == 'reverse': t = t[:a] + t[a:b+1][b::-1] + t[b+1:] else: c = order[3] t = t[:a] + c + t[b+1:]
1
2,100,175,062,216
null
68
68
#coding:utf-8 #3????????°??????????????? n = input() print "", for i in xrange(1, n+1): if i % 3 == 0: print i, elif "3" in str(i): print i,
def main(): n, x, y = map(int, input().split()) distances = [0 for _ in range(n)] for i in range(1, n+1): for j in range(i+1, n+1): distances[min(j-i, min(abs(i-x)+abs(j-y), abs(j-x)+abs(i-y))+1)] += 1 for v in distances[1:]: print(v) if __name__ == '__main__': main()
0
null
22,674,812,773,158
52
187
S = input() l = len(S) // 2 ll = l // 2 former = S[:l] latter = S[l+1:] for i in range(l): if S[i] != S[-i-1]: print("No") break else: for i in range(ll): if former[i] != former[-i-1] or latter[i] != latter[-i-1]: print("No") break else: print("Yes")
def main(): S = input() L = len(S) def check(s): return s == s[::-1] cond = check(S) cond = cond and check(S[:L // 2]) cond = cond and check(S[(L + 1) // 2:]) print('Yes' if cond else 'No') if __name__ == '__main__': main()
1
46,251,998,392,378
null
190
190
import collections n=int(input()) S=input() c=collections.Counter(S) ans=c['R']*c['B']*c['G'] hiku=0 for i in range(n): for d in range(n): j=i+d k=j+d if k>n-1: break if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]: hiku+=1 print(ans-hiku)
N = int(input()) S = input() total = 0 for i in range(N-2): if S[i] == "R": num_G = S[i+1:].count('G') num_B = S[i+1:].count('B') total += num_G * num_B elif S[i] == "G": num_B = S[i+1:].count('B') num_R = S[i+1:].count('R') total += num_B * num_R elif S[i] == "B": num_G = S[i+1:].count('G') num_R = S[i+1:].count('R') total += num_G * num_R for i in range(N-2): for j in range(i+1, N-1): if 2*j-i >= N: continue if S[j] != S[i] and S[2*j-i] != S[j] and S[2*j-i] != S[i]: total -= 1 print(total)
1
35,961,264,828,512
null
175
175
# ABC170 # A Five Variables X = list(input().split()) print(X.index('0') + 1)
X = list(map(int, input().split())) sum = X[0] + X[1] + X[2] + X[3] + X[4] print(15 - sum)
1
13,423,564,704,758
null
126
126
def gcd(a, b): while b: a, b = b, a%b return a def lcm(a, b): return a*b//gcd(a, b) X = int(input()) print(lcm(360, X)//X)
x=int(input()) for i in range(1,361): if (x*i)%360==0: print(i) break
1
13,204,774,880,080
null
125
125
N = int(input()) def dfs(s, mx): if len(s) == N: print(s) else: c = 'a' while ord(c) <= ord(mx): if c == mx: dfs(s + c, chr(ord(mx) + 1)) else: dfs(s + c, mx) c = chr(ord(c) + 1) dfs('', 'a')
# D - String Equivalence def dfs(s, mx): if len(s)==n: print(s) return for c in range(ord('a'),ord(mx)+1): dfs(s+chr(c),(chr(ord(mx)+1) if ord(mx)==c else mx)) n=int(input()) dfs('','a')
1
52,419,968,281,422
null
198
198
N = int(input()) S = list(input()) ans = 'No' n = int(N / 2) if S[:n] == S[n:]: ans = 'Yes' print(ans)
n = int(input()) s = input() if n % 2 != 0: print("No") else: t = s[:int((n / 2))] u = t + t print("Yes" if s == u else "No")
1
146,441,788,110,968
null
279
279
n, k = map(int , input().split()) hn = [int(num) for num in input().split()] hn.sort(reverse = True) if len(hn) > k: print(sum(hn[k:])) else : print(0)
n, k = map(int, input().split()) h = list(sorted(map(int, input().split()))) x = 0 if n > k: for i in range(n - k): x += h[i] print(x)
1
79,237,417,639,578
null
227
227
N = input() S = list(N) s = [] for i in range(0, 3): s.append(S[i]) print("".join(s))
s = input() if len(s) > 3: s = list(s) s = s[0] + s[1] + s[2] print(s)
1
14,682,089,161,870
null
130
130
from collections import deque k = int(input()) ans=[] # q = deque([[1],[2],[3],[4],[5],[6],[7],[8],[9]]) q = deque([1,2,3,4,5,6,7,8,9]) while q: a = q.popleft() ans.append(a) if len(ans) > k: break tmp = int(str(a)[-1]) if tmp-1 >= 0: q.append(10*a + tmp-1) q.append(10*a + tmp) if tmp+1 <= 9: q.append(10*a + tmp+1) print(ans[k-1])
K=int(input()) ans=set() for i in range(1,10): ans.add(i) def saiki(A): genzai_saigo=int(A[-1]) ketasu=len(A) if ketasu>0: B="".join(A) ans.add(eval(B)) if ketasu==10: return for i in [genzai_saigo-1,genzai_saigo,genzai_saigo+1]: if i < 0 or i>9: continue A.append(str(i)) saiki(A) A.pop() for i in range(1,10): saiki([str(i)]) kotae=list(ans) kotae.sort() print(kotae[K-1])
1
40,008,200,449,280
null
181
181
a=int(input()) asd=(a)+(a*a)+(a*a*a) print(asd)
def main(): n=int(input()) n=n+n**2+n**3 print(n) if __name__=="__main__": main()
1
10,261,676,981,870
null
115
115
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10 ** 9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) INF=float('inf') N,M=MAP() C=LIST() dp=[INF]*(N+1) dp[0]=0 for i in range(N): for j in range(M): if i+C[j]<=N: dp[i+C[j]]=min(dp[i+C[j]], dp[i]+1) print(dp[N])
class DP: def __init__(self, value, variety, coins): self.value = value self.variety = variety self.coins = coins self.DP = [[0 for _ in range(value + 1)] for _ in range(variety)] self.DPinit() def monitor(self): for (i, row) in enumerate(self.DP): print(coins[i], row) def DPinit(self): for row in self.DP: row[1] = 1 self.DP[0] = [i for i in range(self.value + 1)] def DPcomp(self): for m in range(self.variety): if m == 0: continue for n in range(self.value + 1): self.DP[m][n] = self.numberOfCoin(m, n) def numberOfCoin(self, m, n): if n >= self.coins[m]: return min(self.DP[m - 1][n], self.DP[m][n - self.coins[m]] + 1) else: return self.DP[m - 1][n] def answer(self): self.DPcomp() return self.DP[self.variety - 1][self.value] if __name__ == "__main__": status = list(map(int,input().split())) coins = list(map(int,input().split())) dp = DP(status[0],status[1],coins) print(dp.answer())
1
143,727,718,510
null
28
28
import sys from collections import Counter S = "" for s in sys.stdin: s = s.strip().lower() if not s: break S += s for i in 'abcdefghijklmnopqrstuvwxyz': print(i, ":", S.count(i))
S=input() Q=int(input()) reverse=False front="" rear="" for _ in range(Q): inp=input() if inp[0]=="1": reverse= not reverse elif inp[0]=="2": if (inp[2]=="1" and not reverse) or (inp[2]=="2" and reverse): front=inp[4]+front else: rear=rear+inp[4] ans=front+S+rear if reverse: ans=ans[::-1] print(ans)
0
null
29,474,861,877,410
63
204
s = input() if s=='AAA' or s=='BBB' : print('No') else : print('Yes')
def rvrs(base, start, end): r = base[int(start):int(end) + 1][::-1] return base[:int(start)] + r + base[int(end) + 1:] def rplc(base, start, end, string): return base[:int(start)] + string + base[int(end) + 1:] ans = input() q = int(input()) for _ in range(q): ORD = list(input().split()) if ORD[0] == 'print': print(ans[int(ORD[1]):int(ORD[2])+1]) elif ORD[0] == 'reverse': ans = rvrs(ans, int(ORD[1]), int(ORD[2])) elif ORD[0] == 'replace': ans = rplc(ans, int(ORD[1]), int(ORD[2]), ORD[3])
0
null
28,587,085,314,460
201
68
def Li(): return list(map(int, input().split())) n, a, b = Li() mod = pow(10, 9)+7 bunshi = 1 bunbo = 1 ans = pow(2, n, mod)-1 for i in range(a): bunshi = (bunshi*(n-i)) % mod bunbo = (bunbo*(i+1)) % mod ans = (ans-bunshi*pow(bunbo, -1, mod)) % mod for i in range(a, b): bunshi = (bunshi*(n-i)) % mod bunbo = (bunbo*(i+1)) % mod ans = (ans-bunshi*pow(bunbo, -1, mod)) % mod print(ans)
def main(): import math n,k = map(int,input().split()) a = list(map(int,input().split())) def f(a,l): ans = 0 for i in range(len(a)): ans += math.ceil(a[i]/l)-1 return ans l,r = 1,max(a) while r-l>1: mid = (l+r)//2 g = f(a,mid) if g>k: l = mid+1 else: r = mid if f(a,l)<=k: print(l) else: print(r) if __name__ == "__main__": main()
0
null
36,109,301,666,340
214
99
from collections import defaultdict n,x,y=map(int,input().split()) x-=1 y-=1 dic=defaultdict(int) for i in range(n-1): for j in range(i+1,n): temp=min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i)) dic[temp]+=1 for i in range(1,n): print(dic[i])
from collections import Counter def main(): n,x,y=map(int,input().split()) x,y=x-1,y-1 ans=[] for i in range(n): dp = [n]*n dp[i] = 0 calcstep(i, dp) dp[y] = min(dp[y], dp[x]+1) dp[x] = min(dp[x], dp[y]+1) calcstep(x, dp) calcstep(y, dp) #print(i, dp) ans += dp ans = Counter(ans) for i in range(1,n): print(ans[i]//2) def calcstep(i, dp): for j in range(i, len(dp)-1): if dp[j+1] > dp[j]+1: dp[j+1] = dp[j]+1 else: break for j in range(1,i+1)[::-1]: if dp[j-1] > dp[j]+1: dp[j-1] = dp[j]+1 else: break if __name__ == "__main__": main()
1
44,116,303,300,210
null
187
187