code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
import numpy as np from numba import njit @njit def solve(stdin): n, k = stdin[:2] A = stdin[2: 2 + n] A = np.sort(A)[::-1] F = np.sort(stdin[2 + n:]) def is_ok(x): tmp = 0 for a, f in zip(A, F): y = a * f if y > x: tmp += a - x // f return tmp <= k ok = 10 ** 16 ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok print(solve(np.fromstring(open(0).read(), dtype=np.int64, sep=' ')))
import math n = int(input()) List = [] n_sqrt = int(math.sqrt(n)) for i in range(1,n_sqrt+1): if n % i == 0: number = i + (n // i) -2 List.append(number) print(min(List))
0
null
163,068,128,628,768
290
288
N = int(input()) L = list("abcdefghijklmnopqrstuvwxyz") a = 1 while N > 26**a: N = N - 26**a a += 1 pre = [] for i in reversed(range(1,a)): r = (N-1) // 26**i pre.append(r) N = int(N%(26**i)) ans = '' for i in pre: ans += L[i] print(ans+L[N-1])
H, N = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) S = sum(A[:N]) if S >= H: print('Yes') else: print('No')
0
null
45,114,081,441,758
121
226
#単位元を設定 ide = 0 class SegmentTree: def __init__(self,n): #セグ木の頂点はindex == 1から。index == 0は無視すること。 #つまり、STtable[0]は無視。頂点はSTtable[1]。 self.n = n tmp = 0 while True: if 2 ** tmp >= self.n: break tmp += 1 self.STtable = [ide] * (2*2**tmp) self.STtable_size = len(self.STtable) def update(self,i,a): #更新のためのインデックスの指定は0_indexedで。 a_bit = 1 << ord(a)-97 i += self.STtable_size//2 self.STtable[i] = a_bit while i > 0: i //= 2 self.STtable[i] = self.STtable[i*2] | self.STtable[i*2+1] def find(self,a,b,k=1,l=0,r=None): #kは頂点番号。初期値は1にすること。 #[a,b)の最小を返す。 #[l,r)からです。 #初期値のrは、self.STtable_size//2にすると、ちょうど要素数と同じ値になって[l,r)のrになる。 #問題に適するように範囲を指定するように注意。大体[l,r]で指定されている。 if r == None: r = self.STtable_size//2 if a >= r or b <= l: return ide elif a <= l and b >= r: return self.STtable[k] else: mid = (l+r)//2 if b <= mid: return self.find(a,b,2*k,l,mid) elif a >= mid: return self.find(a,b,2*k+1,mid,r) else: v1 = self.find(a,mid,2*k,l,mid) v2 = self.find(mid,b,2*k+1,mid,r) return v1 | v2 N = int(input()) solve = SegmentTree(N) S = input() for i in range(N): solve.update(i,S[i]) Q = int(input()) ans = [] for _ in range(Q): a,b,c = map(str, input().split()) if a == '1': solve.update(int(b)-1,c) else: tmp = solve.find(int(b)-1,int(c)) cnt = 0 for i in range(26): if tmp >> i & 1 == 1: cnt += 1 ans.append(cnt) for a in ans: print(a)
n = int(input()) s = input() table = {x: 2**i for i, x in enumerate(map(chr, range(97, 123)))} SEG_LEN = n SEG = [0]*(SEG_LEN*2) def update(i, x): i += SEG_LEN SEG[i] = table[x] while i > 0: i //= 2 SEG[i] = SEG[i*2] | SEG[i*2+1] def find(left, right): left += SEG_LEN right += SEG_LEN ans = 0 while left < right: if left % 2 == 1: ans = SEG[left] | ans left += 1 left //= 2 if right % 2 == 1: ans = SEG[right-1] | ans right -= 1 right //= 2 return format(ans, 'b').count('1') for i, c in enumerate(s): update(i, c) q = int(input()) for _ in range(q): com, *query = input().split() if com == '1': idx, x = query update(int(idx)-1, x) else: L, R = map(int, query) print(find(L-1, R))
1
62,589,277,530,682
null
210
210
from collections import deque def print_list(que): for i, q in enumerate(que): if i != len(que)-1: print(q, end=' ') else: print(q) def main(): List = deque() n = int(input()) for i in range(n): order = input().split() if order[0] == "insert": List.appendleft(order[1]) elif order[0] == "delete": try: List.remove(order[1]) except ValueError: pass elif order[0] == "deleteFirst": List.popleft() elif order[0] == "deleteLast": List.pop() print_list(List) if __name__ == "__main__": main()
a, b = map(int, input().split()) def gcd(a, b): if a == b: return a big = max(a, b) small = min(a, b) while not big % small == 0: big, small = small, big%small return small print(gcd(a, b))
0
null
31,410,421,120
20
11
(lambda *_: None)( *map(print, map('Case {0[0]}: {0[1]}'.format, enumerate(iter(input, '0'), 1))))
i = 0 while 1: x = raw_input() i += 1 if x == '0': break print 'Case %s: %s' % (i,x)
1
495,378,005,440
null
42
42
print((int(input())+1)//2-1)
N = int(input()) if N % 2 == 0: ans = (N // 2) - 1 ans = (N // 2) - 1 else: ans = (N - 1) // 2 print(ans)
1
153,504,597,076,630
null
283
283
# coding:utf-8 while True: array = map(int, list(raw_input())) if array[0] == 0: break print sum(array)
while 1: num = input() if num == "0": break a = [] for i in range(len(num)): a.append(int(num[i:i+1])) print(sum(a))
1
1,557,887,446,788
null
62
62
import sys #da[i][j]:(0,0)~(i,j)の長方形の和 def da_generate(h, w, a): da = [[0] * w for j in range(h)] da[0][0] = a[0][0] for i in range(1, w): da[0][i] = da[0][i - 1] + a[0][i] for i in range(1, h): cnt_w = 0 for j in range(w): cnt_w += a[i][j] da[i][j] = da[i - 1][j] + cnt_w return da #da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和 def da_calc(p, q, x, y): if p > x or q > y: return 0 if p == 0 and q == 0: return da[x][y] if p == 0: return da[x][y] - da[x][q - 1] if q == 0: return da[x][y] - da[p - 1][y] return da[x][y] - da[p - 1][y] - da[x][q - 1] + da[p - 1][q - 1] H, W, K = map(int, sys.stdin.readline().rstrip().split()) grid = [list(map(int, list(sys.stdin.readline().rstrip()))) for _ in range(H)] da = da_generate(H, W, grid) ans = 10 ** 18 for i in range(2**(H - 1)): res = 0 s = [k for k, j in enumerate(range(H), 1) if i >> j & 1] # s行は含まない res += len(s) s.append(H) y = 0 for w in range(1, W + 1): # w行は含まない x = 0 flag = False for s_i in s: if da_calc(x, y, s_i - 1, w - 1) > K: if y + 1 < w: res += 1 y = w - 1 else: flag = True break x = s_i else: pass if flag: break else: ans = min(ans, res) print(ans)
import sys def I(): return int(sys.stdin.readline().rstrip()) N = I() for i in range(50000): if i*27//25 == N: print(i) break else: print(':(')
0
null
86,775,954,360,800
193
265
s = input() def addAll(end): return (end * (end + 1)) // 2 total = 0 index = 0 while len(s) > index: leftCount = 0 rightCount = 0 while len(s) > index and s[index] == "<": leftCount += 1 index += 1 while len(s) > index and s[index] == ">": rightCount += 1 index += 1 maxCount = max(leftCount, rightCount) minCount = min(leftCount, rightCount) total += addAll(maxCount) + addAll(max(minCount - 1, 0)) print(total)
import math def main(): s = str(input()) first = s[0] cnt_l = [] tmp_cnt = 1 prev_s = first for curr_s in s[1:]: if prev_s != curr_s: cnt_l.append(tmp_cnt) tmp_cnt = 1 else: tmp_cnt+=1 prev_s = curr_s cnt_l.append(tmp_cnt) ans_l = [] last_num = 0 if first == '>': down_cnt = cnt_l[0] for d in range(down_cnt): ans_l.append(down_cnt-d) cnt_l = cnt_l[1:] # if first == '<': # print(cnt_l) ans_l.append(0) last_num = 0 for i in range(math.ceil(len(cnt_l)/2)): # print('i',i) up_cnt = cnt_l[i*2] if i*2+1 >= len(cnt_l): down_cnt = 0 else: down_cnt = cnt_l[i*2+1] # print(up_cnt,down_cnt) # print() for u in range(up_cnt): if u != up_cnt-1: last_num+=1 ans_l.append(last_num) else: last_num = max(last_num+1, down_cnt) ans_l.append(last_num) for d in range(down_cnt): if d==0: if last_num > down_cnt: last_num = down_cnt-1 else: last_num-=1 ans_l.append(last_num) else: last_num-=1 ans_l.append(last_num) # print(ans_l) print(sum(ans_l)) if __name__ == "__main__": main()
1
156,448,927,312,660
null
285
285
import math N = int(input()) min = math.floor(N / 1.08) max = math.ceil(N/ 1.08) flag = False for i in range(min,max+1): ans = math.floor(i*1.08) if N == ans: X = i flag = True break if(flag): print(X) else: print(':(')
import math num1 = int(input()) num2 = math.floor(num1 / 1.08) num3 = math.ceil(num1 / 1.08) end = False if math.floor(math.floor(num1 / 1.08) * 1.08) == num1: print(math.floor(num1 / 1.08)) end = True elif math.floor(math.ceil(num1 / 1.08) * 1.08) == num1 and end == False: print(math.ceil(num1 / 1.08)) else: print(':(')
1
125,482,490,827,840
null
265
265
marks=[] while True: s=input().split() marks.append(s) if ["-1","-1","-1"] in marks: break marks=marks[:-1] for i in marks: if int(i[0])==-1 or int(i[1])==-1: print("F") elif int(i[0])+int(i[1])>=80: print("A") elif 65<=int(i[0])+int(i[1])<80: print("B") elif 50<=int(i[0])+int(i[1])<65: print("C") elif 30<=int(i[0])+int(i[1])<50: if int(i[2])>=50: print("C") else: print("D") elif int(i[0])+int(i[1])<30: print("F")
while 1: m,f,r=map(int, raw_input().split()) if m==f==r==-1: break s=m+f if m==-1 or f==-1 or s<30: R="F" elif s>=80: R="A" elif s>=65: R="B" elif s>=50: R="C" elif r>=50: R="C" else: R="D" print R
1
1,224,148,784,640
null
57
57
def main(): from sys import stdin n,a,b = map(int,stdin.readline().rstrip().split()) k = b-a-1 if k%2==1: print(k//2+1) else: print(k//2+1+min(n-b,a-1)) main()
N, A, B = map(int, input().split()) if (A + B) % 2 == 0: print(B - (A + B) // 2) exit() to1 = A - 1 toN = N - B if to1 < toN: B -= to1 + 1 print(to1 + 1 + B - (1 + B) // 2) else: A += toN + 1 print(toN + 1 + N - (A + N) // 2)
1
109,099,968,792,820
null
253
253
(h,n),*t=[map(int,o.split())for o in open(0)] d=[0]+[9e9]*h for a,b in t: for j in range(h+1):d[j]=min(d[j],d[max(0,j-a)]+b) print(d[h])
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") H, N = il() magic = [il() for _ in range(N)] dp = [0] * (H + 1) dp[0] = 0 for h in range(1, H + 1): for n in range(N): if n == 0: if magic[n][0] <= h: dp[h] = dp[h - magic[n][0]] + magic[n][1] else: dp[h] = magic[n][1] else: if magic[n][0] <= h: dp[h] = min(dp[h], dp[h - magic[n][0]] + magic[n][1]) else: dp[h] = min(dp[h], magic[n][1]) print(dp[-1]) if __name__ == '__main__': main()
1
81,287,550,874,892
null
229
229
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) N = I() A = LI() c = collections.Counter(A) cnt = 0 for _ in c: cnt += c[_] * (c[_] - 1) // 2 for i in range(N): a = c[A[i]] print(cnt - (a - 1))
s = input() if s.replace('hi', '') == '': print('Yes') else: print('No')
0
null
50,784,661,508,188
192
199
n = int(input()) s = input() if n == 1 or n % 2 == 1: print('No') exit() mid = n // 2 if s[:mid] == s[mid:]: print('Yes') else: print('No')
n=int(input()) s=str(input()) if(n%2!=0): print('No') else: if(s[0:len(s)//2]==s[len(s)//2:]): print('Yes') else: print('No')
1
146,536,369,454,858
null
279
279
S = input() N = len(S) one = S[:(N-1) // 2] two = S[(N+3) // 2 - 1:] if S == S[::-1]: if one == one[::-1]: if two == two[::-1]: print('Yes') exit() print('No')
def is_p(s): return s == s[::-1] s = input() n = len(s) l = (n - 1)//2 r = l + 1 print('Yes' if is_p(s) and is_p(s[:l]) and is_p(s[r:]) else 'No')
1
46,130,344,443,960
null
190
190
while True: first_string=input() if first_string=="-": break lst=list(first_string) m=int(input()) for i in range(m): h=int(input()) for l in range(1,h+1): letter=lst.pop(0) lst.insert(len(lst),letter) answer_string='' for m in lst: answer_string+=m print(answer_string)
while True: deck = input() if deck == "-": break m = int(input()) for i in range(m): h = int(input()) deck += deck[:h] deck = deck[h:] print(deck)
1
1,915,065,526,528
null
66
66
from collections import deque h, w = map(int, input().split()) chiz = [[] for _ in range(w)] for _ in range(h): tmp_list = input() for i in range(w): chiz[i].append(tmp_list[i]) def bfs(i,j): ds = [[-1]*h for _ in range(w)] dq = deque([(i,j)]) ds[i][j] = 0 res = -1 while dq: i,j = dq.popleft() for move in [(1,0),(-1,0),(0,-1),(0,1)]: if i+move[0] >= 0 and i+move[0] < w and j+move[1] >= 0 and j+move[1] < h: if chiz[i+move[0]][j+move[1]]=='.' and ds[i+move[0]][j+move[1]] == -1: ds[i + move[0]][j + move[1]] = ds[i][j] + 1 res = max(res,ds[i + move[0]][j + move[1]]) dq.append((i + move[0],j + move[1])) return res res = -1 for j in range(h): for i in range(w): if chiz[i][j]=='.': res = max(res, bfs(i,j)) print(res)
import sys n = int(input()) dic =set() t = sys.stdin.readlines() for i in t: i,op = i.split() if i == 'insert': dic.add(op) else: if op in dic: print('yes') else: print('no')
0
null
47,437,377,425,678
241
23
X, Y = map(int, input().split()) temp = [0, 300000, 200000, 100000] ans = 0 if X == Y == 1: ans += 400000 if X <= 3: ans += temp[X] if Y <= 3: ans += temp[Y] print(ans)
n,m = map(int,input().split()) lis = [0]*205 lis[0] = 300000 lis[1] = 200000 lis[2] = 100000 if n == m and n == 1: print(1000000) else: print(lis[n-1]+lis[m-1])
1
140,818,868,954,050
null
275
275
N = input() if len(N) == 1: if N == '3': print('bon') elif N == '0' or N == '1' or N == '6' or N == '8': print('pon') else: print('hon') elif len(N) == 2: 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') elif len(N) == 3: if N[2] == '3': print('bon') elif N[2] == '0' or N[2] == '1' or N[2] == '6' or N[2] == '8': print('pon') else: print('hon')
def resolve(): import itertools N = int(input()) A = [] X = [] ans = [0] for _ in range(N): a = int(input()) xx = [] for __ in range(a): x = list(map(int, input().split())) xx.append(x) X.append(xx) A.append(a) for i in itertools.product([0, 1], repeat=N): flag = 0 for p in range(N): for q in range(A[p]): if i[p] == 1 and X[p][q][1] != i[X[p][q][0]-1]: flag = 1 if flag == 0: ans.append(i.count(1)) print(max(ans)) resolve()
0
null
70,176,649,020,282
142
262
#(40)フィボナッチ数列 n=int(input()) def fib(n): a=1 b=1 for _ in range(n): a,b=b,a+b return a print(fib(n))
def main(): N = int(input()) if N <= 1: print(1) return fib = [0]*(N+1) fib[0], fib[1] = 1, 1 for i in range(2, N+1): fib[i] = fib[i-1] + fib[i-2] print(fib[N]) if __name__ == "__main__": main()
1
1,908,534,602
null
7
7
#coding:utf-8 H,W=map(int,input().split()) while not(H==0 and W==0): for i in range(0,H): for j in range(0,W): if (i+j)%2==0: print("#",end="") else: print(".",end="") print("") print("") H,W=map(int,input().split())
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 flush = sys.stdin.flush() def solve(): x,y = LI() ans = 0 f = [300000,200000,100000,0] if x == 1 and y == 1: print(1000000) else: ans = f[min(3,x-1)]+f[min(3,y-1)] print(ans) return #Solve if __name__ == "__main__": solve()
0
null
71,007,263,713,012
51
275
s = input() n = len(s) + 1 t = [0]*n for i in range(n-1): if s[i] == '<': t[i+1] = t[i] + 1 for i in range(n-2,-1,-1): if s[i] == '>': t[i] = max(t[i],t[i+1]+1) print(sum(t))
import math A,B,C,D = list(map(int,input().split())) if (math.ceil(C/B)-math.ceil(A/D))<1: print("Yes") else: print("No")
0
null
93,560,806,191,940
285
164
import copy def count(w,h): Dtemp = copy.deepcopy(Data) for i in range(W): if ((1 << i) & w) != 0: for hh in range(H): Dtemp[hh][i] = 'R' for i in range(H): if ((1 << i) & h) != 0: for ww in range(W): Dtemp[i][ww] = 'R' c = 0 for hh in range(H): for ww in range(W): if Dtemp[hh][ww] == '#': c += 1 return c H,W,K = map(int,input().split()) Data = [] for _ in range(H): s = input() l = [] for c in s: l.append(c) Data.append(l) ans = 0 for w in range(0,2**W): for h in range(0,2**H): if count(w,h) == K: ans += 1 print(ans)
import copy H, W, K = map(int, input().split()) tiles = [list(input()) for _ in range(H)] count = 0 for num in range(2**(H+W)): copied_tiles = copy.deepcopy(tiles) for i in range(H+W): if num>>i&1: if i < H: for j in range(W): copied_tiles[i][j] = 'R' else: for j in range(H): copied_tiles[j][i-H] = 'R' black_c = 0 for i in range(H): for j in range(W): if copied_tiles[i][j] == '#': black_c += 1 if black_c == K: count += 1 print(count)
1
8,941,117,784,858
null
110
110
# -*- coding: utf-8 -*- # 1つの文字列 s = str(input()) ans = '' for i in range(3): ans = ans + s[i] print(ans)
import sys import bisect input = sys.stdin.readline class Bisect(object): def bisect_max(self, reva, func,M): ok = 0 # exist ng = 4*(10**5) # not exist while abs(ok-ng) > 1: cnt = (ok + ng) // 2 if func(cnt,reva,M): ok = cnt else: ng = cnt return ok def solve1(tgt,reva,M): res=0 n = len(reva) for i in range(n): tmp = bisect.bisect_left(reva,tgt-reva[i]) tmp = n - tmp res += tmp if M <= res: return True else: return False N,M = map(int,input().split()) a = list(map(int,input().split())) a.sort(reverse=True) reva = a[::-1] bs = Bisect() Kmax = (bs.bisect_max(reva,solve1,M)) r=[0] for i in range(N): r.append(r[i]+a[i]) res = 0 cnt = 0 t = 0 for i in range(N): tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1]) tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1]) if tmp!=tmp2: t = 1 tmp = N - tmp cnt += tmp res += tmp*a[i]+r[tmp] if t==1: res -= (cnt-M)*Kmax print(res)
0
null
61,446,464,755,552
130
252
import sys import math from collections import deque n,m = map(int, input().split()) q = [0]*(n+1) graph = [[] for _ in range(n+1)] for i in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) dist = [-1] * (n+1) dist[0] = 0 dist[1] = 0 # if m == 0: # print(1) # exit() d = deque() a = 0 for l,j in enumerate(q): b = set() if j == 0: d.append(l) while d: v = d.popleft() b.add(v) q[v] = -1 for i in graph[v]: b.add(i) q[i] = -1 if dist[i] != -1: continue dist[i] = dist[v] + 1 d.append(i) a = max(a,len(b)) print(a)
n,k=map(int,input().split()) a=list(map(int,input().split())) b=[0]*n c=[0]*n cnt=0 while cnt<min(k,101): cnt+=1 for i in range(n): b[max(0,i-a[i])]+=1 if i+a[i]<n-1: b[i+a[i]+1]-=1 c[0]=b[0] for j in range(n-1): c[j+1]=c[j]+b[j+1] a=c b=[0]*n c=[0]*n print(*a)
0
null
9,721,617,122,010
84
132
K = int(input()) A, B = map(int,input().split()) C = A % K if B - A >= K - 1: print('OK') elif C == 0: print('OK') elif C + B - A >= K: print('OK') else: print('NG')
import decimal a, b = input().split() x, y = decimal.Decimal(a), decimal.Decimal(b) print(int(x * y))
0
null
21,610,734,795,240
158
135
a = [] b = [] a = input().split() b = input().split() if a[0] == b[0]: print("0") else: print("1")
W,H,x,y,r = (int(i) for i in input().split()) if W-(x+r) >=0 and H-(y+r) >= 0: if x-r >= 0 and y-r >= 0: print("Yes") else: print("No") else: print("No")
0
null
62,587,050,631,370
264
41
class UnionFind: def __init__(self, num): self.parent = [-1] * num def find(self, node): if self.parent[node] < 0: return node self.parent[node] = self.find(self.parent[node]) return self.parent[node] def union(self, node1, node2): node1 = self.find(node1) node2 = self.find(node2) if node1 == node2: return if self.parent[node1] > self.parent[node2]: node1, node2 = node2, node1 self.parent[node1] += self.parent[node2] self.parent[node2] = node1 return def same(self, node1, node2): return self.find(node1) == self.find(node2) def size(self, x): return -self.parent[self.find(x)] def roots(self): return [i for i, x in enumerate(self.parent) if x < 0] def group_count(self): return len(self.roots()) n, m = map(int, input().split()) uf = UnionFind(n) for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 uf.union(a, b) print(uf.group_count() - 1)
s = input() t = input() print(['No','Yes'][s == t[:-1]])
0
null
11,926,204,589,490
70
147
N,K=list(map(int,input().split())) A=sorted(list(map(int,input().split()))) mod=10**9+7 def modinv(x): return pow(x,mod-2,mod) comb=1 ans=0 for i in range(N-K+1): ans+=comb*A[K-1+i] ans-=comb*A[N-K-i] ans%=mod comb*=(K+i)*modinv(i+1) comb%=mod print(ans)
# -*- coding: utf-8 -*- import math def g(nx, ny, nz): return nx ** 2 + ny ** 2 + nz ** 2 + nx * ny + ny * nz + nz * nx def solve(n): # min_z = max(1, int(math.sqrt(n) / 3)) max_z = max(1, int(math.sqrt(n - 2) - 1) if n > 2 else 1) # max_x = max(1, int(math.sqrt(n / 3) + 1)) counter = [0 for _ in range(n + 1)] for z in range(1, max_z + 1): for y in range(1, max_z + 1): for x in range(1, max_z + 1): gn = g(x, y, z) if gn <= n: counter[gn] += 1 for i in range(1, n + 1): print(counter[i]) N = int(input()) solve(N)
0
null
52,017,878,394,692
242
106
from itertools import groupby n=int(input()) print(len(list(groupby(input()))))
n = int(input()) s = input() c_curr = "" ans = 0 for c in s: if c != c_curr: ans += 1 c_curr = c print(ans)
1
170,003,524,617,620
null
293
293
def fib(n): a = 1 b = 1 if n == 0: print(a) elif n == 1: print(b) else: for i in range(n-1): c = a + b a , b = b , c print(c) n = int(input()) fib(n)
import collections n = int(input()) d = list(map(int,input().split())) ma = max(d) mod = 998244353 if d[0] != 0: print(0) exit() p = [0 for i in range(ma+1)] for i in range(n): p[d[i]] += 1 if p[0] != 1: print(0) exit() else: ans = 1 for i in range(1,ma+1): ans *= (p[i-1]**p[i])%mod ans %= mod print(ans)
0
null
77,135,566,385,450
7
284
h0, w0, k0 = [ int(x) for x in input().split() ] found, buf = 0, {} for i in range(h0): buf[1 << i] = { 1 << j for j,x in enumerate(input()) if x == '#' } for i in range(1, 1 << h0): idx = {} for k,vs in buf.items(): if k & i == 0: continue for v in vs: idx[v] = idx.get(v, 0) + 1 for j in range(1, 1 << w0): n = sum([ v for k,v in idx.items() if k & j ]) if n == k0: found += 1 print(found)
import copy H, W, K = map(int, input().split()) tiles = [list(input()) for _ in range(H)] answer = 0 for h in range(2**H): for w in range(2**W): b_cnt = 0 for i in range(H): for j in range(W): if not (h>>i&1 or w>>j&1) and tiles[i][j] == '#': b_cnt += 1 if b_cnt == K: answer += 1 print(answer)
1
8,815,434,665,440
null
110
110
a, b,c ,d = list(map(int,input().split())) ll = [a*c,a*d,b*c,b*d] print(max(ll))
k = int(input()) s = input() n = len(s) mod = 10 ** 9 + 7 f = [1, 1] f_inv = [1, 1] inv = [0, 1] for i in range(2, n+k+1): f.append((f[-1] * i ) % mod) inv.append((-inv[mod % i] * (mod // i) ) % mod) f_inv.append((f_inv[-1] * inv[-1]) % mod) def comb(n, k): return f[n] * f_inv[k] * f_inv[n-k] % mod ans = 0 for i in range(k+1): x = pow(25, i, mod) * pow(26, k-i, mod) * comb(n-1+i, n-1) ans += x ans %= mod print(ans)
0
null
7,993,638,156,162
77
124
N = int(input()) ans = 'No' for i in range(1,10): if N%i == 0: tmp = str(int(N/i)) if len(tmp) >= 2: continue else: ans = 'Yes' break else: continue print(ans)
n = int(input()) graph = [[-1 for _ in range(n)] for _ in range(n)] for i in range(n): a = int(input()) for _ in range(a): x, y = map(int, input().split()) graph[i][x-1] = y ans = 0 for p in range(2**n): q = p c = 0 t = [] l = 0 while q: if q&1: t.append(graph[c]) l += 1 q >>= 1 c += 1 flag = True for c in range(n): if p&1: for s in t: if s[c] == 0: flag = False else: for s in t: if s[c] == 1: flag = False p >>= 1 if flag: ans = max(ans, l) print(ans)
0
null
141,203,471,616,764
287
262
a,b = map(int,input().split()) ans = "" k = min(a,b) l = max(a,b) for i in range(l): ans += str(k) print(ans)
f = list(map(int, input().split())) print(str(min(f)) * max(f))
1
84,186,697,837,600
null
232
232
import sys if sys.platform =='ios': sys.stdin=open('Untitled.txt') input = sys.stdin.readline def MAP(): return [int(s) for s in input().split()] n,m=MAP() a=MAP() #dp[price]=num of coins? dp=[float('inf') for _ in range(n+1)] dp[0]=0 for i in range(n+1): for j in a: if i+j <= n: dp[i+j]=min(dp[i]+1,dp[i+j]) print(dp[-1])
n , m = list(map(int, input().split())) par=[i for i in range(n)] rank=[0 for _ in range(n)] def find(x): if x==par[x]: return x else: par[x]=find(par[x]) return par[x] def unit(x,y): x=find(x) ; y=find(y) if find(x)==find(y): return if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x]==rank[y]: rank[x]+=1 for _ in range(m): x , y=list(map(int, input().split())) x -= 1 ; y-=1 unit(x,y) count=[0 for _ in range(n)] for i in range(n): count[find(i)]+=1 print(max(count))
0
null
2,082,414,300,660
28
84
a=0 b=0 n=int(input()) for i in range(n): x=input().split() y=x[0] z=x[1] if y>z:a+=3 elif y<z:b+=3 else: a+=1 b+=1 print(a,b)
def main(): TaroScore = HanaScore = 0 n = int(input()) for _ in range(n): [Taro, Hana] = list(input().lower().split()) lenT = len(Taro) lenH = len(Hana) lenMin = min(lenT, lenH) if Taro == Hana: TaroScore += 1 HanaScore += 1 else: for i in range(lenMin+1): if Taro == '': HanaScore += 3 break elif Hana == '': TaroScore += 3 break elif ord(Taro[0]) > ord(Hana[0]): TaroScore += 3 break elif ord(Taro[0]) < ord(Hana[0]): HanaScore += 3 break else: Taro = Taro[1:] Hana = Hana[1:] print(TaroScore, HanaScore) if __name__ == '__main__': main()
1
1,994,510,573,198
null
67
67
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b n = int(input()) nums = [int(i) for i in input().split()] for i in range(n - 1): nums[i + 1] += nums[i] ans = float('inf') for i in range(n - 1): d = abs(nums[-1] - nums[i] * 2) ans = min(ans, d) print(ans)
while True: a,b = map(int,input().split()) if(a==0 and b==0): break; for i in range(a): for j in range(b): type='#' if(i%2 == 0): if(j%2 == 0): print('#',end='') else: print('.',end='') elif(i%2 == 1): if(j%2 == 0): print('.',end='') else: print('#',end='') print() print()
0
null
71,193,442,879,450
276
51
#!/usr/bin/env python3 import sys def cube(x): if not isinstance(x,int): x = int(x) return x*x*x if __name__ == '__main__': i = sys.stdin.readline() print('{}'.format( cube( int(i) ) ))
cube = input() print(cube**3)
1
282,109,907,012
null
35
35
#import re N = input() stones = input() #pattern = 'W.*R' #stoneslist =list(stones) #result = re.search(pattern,stones) #if result: # print (result.start()) #print (result.end()) #print(stones[result.start()]) #stoneslist[result.start()]='R' #stoneslist[result.end()-1]='W' count =0 #while 'WR' in stones: # if stones.count('WR')>1: # stoneslist =list(stones) # result = re.search(pattern,stones) #stoneslist[result.start()]='R' #stoneslist[result.end()-1]='W' #stones =str(stoneslist) #stones = "".join(stoneslist) #else: # stones = stones.replace('WR','RR',1) #count+=1 #print(stones) #print (stones) red = 0 white = 0 for i in range(len(stones)): if stones[i] == "R": red +=1 for i in range(red): if stones[i] =='W': white+=1 print (white) #print (count)
A,B,H,M=map(int, input().split()) import math angle = abs(30*H-5.5*M) angle = min(angle, 360-angle)*math.pi/180 c=A**2 + B**2 -2*A*B* math.cos(angle) c=c**0.5 print(c)
0
null
13,128,320,509,840
98
144
from collections import Counter def prime_fact(n): P = [] for i in range(2, int(n**0.5)+1): while n % i == 0: P.append(i) n //= i if n != 1: P.append(n) return P n = int(input()) cnt = Counter(prime_fact(n)) #print(cnt) ans = 0 for c in cnt.values(): tmp = 1 while c >= tmp: c -= tmp ans += 1 tmp += 1 print(ans)
def solve(): N=n=int(input()) q=int(n**0.5) ans=0 for d in range(2,q+1) : a=0 while n % d == 0 : a+=1 n//=d if a>0 : ans+=int(((a*8+1)**0.5-1)/2) if n > 1 : ans+=1 return ans print(solve())
1
16,960,707,107,790
null
136
136
a,b,c,d,e=map(int,input().split()) l=(60*c+d)-(60*a+b) ans=l-e print(ans)
def Int(): return int(input()) def Ints(): return map(int,input().split()) def IntList(): return list(Ints()) def IntMat(N): return [IntList() for i in range(N)] import sys sys.setrecursionlimit(4100000) rl = sys.stdin.readline H1,M1,H2,M2,K = Ints() S = (H2-H1)*60+(M2-M1) print(S-K)
1
18,135,890,676,162
null
139
139
h, m = map(int, input().split()) if h == 1 or m == 1: count = 1 else: count = ((h //2) * m) + ((h %2) *((m //2) + (m %2))) print(count)
from itertools import * N = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) dic = dict() i = 0 for a in permutations(range(1,N+1),N): dic[a] = i i += 1 print(abs(dic[P]-dic[Q]))
0
null
75,680,328,872,450
196
246
s,w=map(int,input().split());print('unsafe' if s<=w else 'safe')
# Connect Cities # Union Findデータ構造(素集合データ構造) #入力:N,M(int:整数) def input2(): return map(int,input().split()) #入力:[n1,n2,...nk](int:整数配列) def input_array(): return list(map(int,input().split())) class UnionFind(): """docstring for UnionFind""" 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 if self.parents[x] > self.parents[y]: x,y=y,x self.parents[y]=x n,m=input2() AB=[input_array() for _ in range(m)] uf = UnionFind(n) for ab in AB: a=ab[0] b=ab[1] uf.union(a-1,b-1) ans=0 for i in uf.parents: if i < 0: ans+=1 print(ans-1)
0
null
15,629,942,019,838
163
70
from collections import Counter N = int(input()) S = list(input()) cnt = Counter(S) Red, Green, Blue = (cnt['R'], cnt['G'], cnt['B']) patn = Red*Green*Blue cnt = 0 for i in range(N): for j in range(i+1, N): if (2*j - i) >= N: break elif S[i] != S[j] and S[j] != S[2*j-i] and S[i] != S[2*j-i]: cnt += 1 print(patn-cnt)
from itertools import permutations n = int(input()) s = input() out = 0 ans = s.count("R")*s.count("G")*s.count("B") combi = list(permutations(["R","G","B"],3)) for i in range(1,n): for j in range(n-i*2): if (s[j], s[j+i], s[j+i*2]) in combi: ans -= 1 print(ans)
1
36,093,519,389,980
null
175
175
import math print([ ( int(x) * 360 // math.gcd(int(x),360) ) // int(x) for x in input().split(' ') ][0])
n=int(input()) s=input() A=[] for i in range(n): A.append(s[i]) W=0 R=A.count('R') ans=float('inf') for i in range(n+1): if i!=0: if A[i-1]=='W': W+=1 else: R-=1 ans=min(max(W,R),ans) print(ans)
0
null
9,684,053,795,472
125
98
while True: x, y = [int(n) for n in input().split()] if x == 0 and y == 0: break if x < y: print("{} {}".format(x, y)) else: print("{} {}".format(y, x))
while True: (x, y) = [int(i) for i in input().split()] if x == y == 0: break if x < y: print(x, y) else: print(y, x)
1
533,823,040,088
null
43
43
N = int(input()) X = list(map(int, input().split())) small = 10000000 temp = 0 p_max = max(X) for p in range(1, p_max + 1): for i in range(N): temp += (X[i] - p)**2 if temp < small: small = temp temp = 0 print(small)
while 1: x,y = map( int , raw_input().split() ) if x == 0 and y == 0: break elif x <= y: print "%d %d" %(x,y) elif y < x : print "%d %d" %(y,x)
0
null
33,073,224,493,462
213
43
import sys while True: a,b = map(int, raw_input().split()) if a ==0 and b == 0: break for i in range(a): for j in range(b): if i == 0 or i == a-1 or j == 0 or j == b-1: sys.stdout.write("#") else: sys.stdout.write(".") print print
s=input() t=input() a=0 for i in range(len(s)): if s[i]==t[i]: a+=1 if a==len(s): print('Yes') else: print('No')
0
null
10,992,097,887,484
50
147
import math def merge(S, left, mid, right) -> int: # n1 = mid - left # n2 = right - mid L = S[left: mid] R = S[mid: right] # for i in range(n1): # L.append(S[left + i]) L.append(math.inf) # for i in range(n2): # R.append(S[mid + i]) R.append(math.inf) i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: S[k] = L[i] i += 1 else: S[k] = R[j] j += 1 return right - left def merge_sort(S, left, right): count = 0 if left + 1 < right: mid = int((left + right) / 2) count += merge_sort(S, left, mid) count += merge_sort(S, mid, right) count += merge(S, left, mid, right) return count def main(): n = int(input()) S = list(map(int, input().split())) count = 0 count = merge_sort(S, 0, n) print(*S) print(count) if __name__ == "__main__": main()
n = int(input()) arr = list(map(int,input().split())) cur=1000 for i in range(n-1): p=0 if arr[i] < arr[i+1]: p=cur // arr[i] cur += (arr[i+1] - arr[i])*p print(cur)
0
null
3,684,502,620,810
26
103
n=int(input()) s=[str(input()) for _ in range(n)] print(len(set(s)))
def solve(): N = int(input()) items = set([]) for i in range(N): S = input() items.add(S) print(len(items)) if __name__ == "__main__": solve()
1
30,454,374,981,888
null
165
165
while True: (H, W) = [int(x) for x in input().split()] if H == W == 0: break for row in range(H): if row % 2 == 0: for w in range(W): if w % 2 == 0: print("#", end="") else: print(".", end="") else: print() else: for w in range(W): if w % 2 == 0: print(".",end="") else: print("#",end="") print() print()
h = [[[0]*10 for i in range(3)] for j in range(4)] n = int(input()) for i in range(n): b,f,r,v = map(int,input().split()) h[b-1][f-1][r-1] += v s = "" for i in range(4): for j in range(3): for k in range(10): s += " " + str(h[i][j][k]) s += "\n" if i < 3: s += "####################\n" print(s,end="")
0
null
1,005,642,670,430
51
55
import math x = int(input()) initial = 100 count = 0 while initial < x: initial += initial//100 count += 1 print(count)
x = int(input()) a = 100 i = 0 while a < x: i += 1 a += a // 100 print(i)
1
27,182,351,843,020
null
159
159
def main(): n,m,k = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) import itertools sum_a = list(itertools.accumulate(a)) sum_b = list(itertools.accumulate(b)) if sum_a[-1] + sum_b[-1] <= k: print(n+m) return if a[0] > k and b[0] > k: print(0) return for i in range(n): if sum_a[i] > k: break s_a = i - 1 if sum_a[-1] <= k: s_a = n-1 now_sum = 0 if s_a >= 0: now_sum = sum_a[s_a] for i in range(m): if now_sum + sum_b[i] > k: break s_b = i - 1 ans = s_a + 1 + s_b + 1 now_sum = 0 for a_i in range(s_a-1, -2, -1): for b_i in range(s_b+1,m): if a_i < 0: now_sumtime = sum_b[b_i] else: now_sumtime = sum_a[a_i] + sum_b[b_i] if b_i == m-1 and now_sumtime <= k: now_sum = a_i + m + 1 break if now_sumtime > k: now_sum = a_i + b_i + 1 break s_b = b_i-1 ans = max(ans, now_sum) print(ans) if __name__=='__main__': main()
# Tsundoku import numpy as np N, M, K = map(int,input().split()) A = np.array([0] + list(map(int, input().split()))) B = np.array([0] + list(map(int, input().split()))) a = np.cumsum(A) b = np.cumsum(B) ans = 0 j = M for i in range(N+1): if a[i] > K: break while b[j] > K - a[i]: j -= 1 ans = max(ans, i+j) print(ans)
1
10,759,712,006,708
null
117
117
#!/usr/bin/env python3 l, r, d = map(int, input().split()) n = (l-1) // d + 1 m = r // d print(m-n+1)
n = int(input()) c0 = 0 c1 = 0 c2 = 0 c3 = 0 for i in range(n): s = input() if s == "AC": c0 += 1 elif s == "WA": c1 += 1 elif s == "TLE": c2 += 1 elif s == "RE": c3 += 1 else: exit() print(f"AC x {c0}") print(f"WA x {c1}") print(f"TLE x {c2}") print(f"RE x {c3}")
0
null
8,146,048,040,670
104
109
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ コンテスト後に解説記事を見てAC Python 3だとTLE """ import array from bisect import * from collections import * import fractions import heapq from itertools import * import math import random import re import string import sys def solve(N_str): """ https://betrue12.hateblo.jp/ の通り実装 上の桁から順番に見ていく dp[i][j] = 上から i 桁目までの硬貨の支払いとお釣りを処理し終わって、 N の i 桁目までの金額よりも j 枚分多く支払っているときの、 これまでの支払い・お釣り硬貨の最小合計枚数 """ N_str = '0' + N_str dp = [[0] * 2 for _ in range(len(N_str))] # 0376円のとき # dp[1][0] = 0 0円払う(0) # dp[1][1] = 1 1000円払う(1) # # dp[2][0] = 3 0円の状態から300円払う(3) vs 1000円の状態から700円お釣りをもらう(8) # dp[2][1] = 4 0円の状態から400円払う(4) vs 1000円の状態から600円お釣りをもらう(7) # # dp[3][0] = 7 300円の状態から追加で70円払う(3+7) vs 400円の状態から30円もらう(4+3) # dp[3][1] = 6 300円の状態から追加で80円払う(3+8) vs 400円の状態から20円もらう(4+2) # # dp[4][0] = 10 370円の状態から追加で6円払う(7+6) vs 380円の状態から4円もらう(6+4) # dp[4][1] = 9 370円の状態から追加で7円払う(7+7) vs 380円の状態から3円もらう(6+3) for i, ch in enumerate(N_str): if i == 0: dp[0][0] = 0 dp[0][1] = 1 else: dp[i][0] = min(dp[i - 1][0] + int(ch), dp[i - 1][1] + 10 - int(ch)) dp[i][1] = min(dp[i - 1][0] + int(ch) + 1, dp[i - 1][1] + 9 - int(ch)) return dp[len(N_str) - 1][0] def wrong(N_str): """最初に間違って書いた貪欲 1の位から見ていき、0~4なら支払い、5~9なら10払ってお釣りをもらう N = 65のとき、 この関数だと70払って5お釣りをもらうことになるが 実際は100払って35お釣りをもらうべきなので誤り """ N_str = N_str[::-1] ans = 0 prev = 0 for ch in N_str: n = int(ch) n += prev if n <= 5: ans += n prev = 0 else: ans += 10 - n prev = 1 ans += prev return ans # for n in range(1, 101): # print() # n_str = str(n) # w = wrong(n_str) # gt = solve(n_str) # if w != gt: # print("n, gt, wrong = ", n, gt, w) N_str = input() print(solve(N_str))
N=[int(c) for c in input()][::-1] dp=[[0]*2 for _ in range(len(N)+1)] dp[0][1]=1 for i in range(len(N)): dp[i+1][1]=min(dp[i][0]+N[i]+1,dp[i][1]+10-N[i]-1) dp[i+1][0]=min(dp[i][0]+N[i],dp[i][1]+10-N[i]) print(dp[len(N)][0])
1
70,620,306,075,812
null
219
219
import math def prime_array(n=1000): List = [2] i = 3 while i <= n: judge = True for k in List : if math.sqrt(i) < k : break if i%k == 0: judge = False break if judge : List.append(i) i += 2 return List def main(): cnt=0 prime_List=prime_array(10**4) n=input() for i in range(n): a=input() if a<=10**4: for j in prime_List: if a==j: cnt+=1 break else: judge=True for j in prime_List: if a%j==0: judge=False break if judge: cnt+=1 print('%d' % cnt) if __name__=='__main__': main()
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 11 7 8 9 10 11 12 13 14 15 16 17 output: 4 """ import sys def is_prime(x): if x == 2: return True elif x < 2 or not x % 2: return False return pow(2, x - 1, x) == 1 def solve(_c_list): cnt = 0 for ele in _c_list: if is_prime(ele): cnt += 1 return cnt if __name__ == '__main__': _input = sys.stdin.readlines() c_num = int(_input[0]) c_list = list(map(int, _input[1:])) ans = solve(c_list) print(ans)
1
10,477,874,296
null
12
12
H, W, K = map(int, input().split()) C = [list(input()) for _ in range(H)] ans = 0 # ビット探索 for i in range(2**H): for j in range(2**W): cnt = 0 for h in range(H): for w in range(W): if((i >> h) & 1) == 0 and ((j >> w) & 1) == 0: if C[h][w] == "#": cnt += 1 if cnt == K: ans += 1 print(ans)
import itertools a,b,c=map(int, input().split()) l = [input() for i in range(a)] ans = 0 Ans = 0 for i in itertools.product((1,-1),repeat=a): for j in itertools.product((1,-1),repeat=b): for k in range(a): for m in range(b): if i[k] == j[m] == 1 and l[k][m] == '#': ans += 1 if ans == c: Ans += 1 ans = 0 print(Ans)
1
8,970,378,000,386
null
110
110
import sys input = sys.stdin.readline def main(): n, k = map(int, input().split()) products = [int(input()) for _ in range(n)] left = 1 right = 10000 * 100000 # 最大重量 × 最大貨物数 while left < right: mid = (left + right) // 2 # print("left:{}".format(left)) # print("right:{}".format(right)) # print("mid:{}".format(mid)) v = allocate(mid, k, products) # print("count:{}".format(v)) if n <= v: right = mid else: left = mid + 1 print(right) def allocate(capacity, truckNum, products): # print("===== start allocation capacity:{}======".format(capacity)) v = 0 tmp = 0 truckNum -= 1 while len(products) > v: product = products[v] # print("tmp weight:{}".format(tmp)) # print("product weight:{}".format(product)) if product > capacity: # print("capacity over") # そもそも1個も乗らない時避け return 0 if tmp + product <= capacity: # 同じトラックに積み続ける tmp += product else: # 新しいトラックがまだあればつむ if truckNum > 0: # print("new truck") truckNum -= 1 tmp = product else: return v v += 1 return v if __name__ == '__main__': main()
A, B = [s for s in input().split()] A = int(A) B = int(float(B) * 100 + .5) C = A * B ans = int(C // 100) print(ans)
0
null
8,326,133,488,948
24
135
import sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = LI() A = LI() ans = [] for i in range(K,N): if A[i-K] < A[i]: print('Yes') else: print('No')
#!/usr/bin/env python3 import sys from itertools import chain from bisect import bisect_right # from collections import Counter # import numpy as np def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"): A = [0] + A for i in range(1, N + 1): A[i] = A[i] + A[i - 1] B = [0] + B for i in range(1, M + 1): B[i] = B[i] + B[i - 1] answer = 0 for n in range(N+1): ka = A[n] if ka > K: break kb = K - ka # ak > K だから kb >= 0 bisect_right > 0 m = bisect_right(B, kb) - 1 if n + m > answer: answer = n + m return answer def main(): tokens = chain(*(line.split() for line in sys.stdin)) # N, M, K, A, B = map(int, line.split()) N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" B = [int(next(tokens)) for _ in range(M)] # type: "List[int]" answer = solve(N, M, K, A, B) print(answer) if __name__ == "__main__": main()
0
null
8,900,126,170,078
102
117
raw_input() a = raw_input().split(" ") a.reverse() print " ".join(a)
N = int(input()) A = list(map(int, input().split())) if A[0] == 1: if len(A) > 1: print(-1) exit() else: print(1) exit() elif A[0] > 1: print(-1) exit() S = [0] * (N + 2) for i in range(N, -1, -1): S[i] = S[i + 1] + A[i] sec = [0] * (N + 1) sec[0] = 1 for i in range(1, N + 1): a = A[i] v = sec[i - 1] * 2 if v < a: print(-1) exit() sec[i] = min(v - a, S[i + 1]) print(sum(A) + sum(sec[:-1])) # print(sec) # print(A)
0
null
9,823,130,840,740
53
141
from math import sqrt N = int(input()) # Cが固定されAxBを入れ替えるときは省略したい def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] ans = 0 """ for C in range(1,N): ans += len(make_divisors(N-C)) """ for A in range(1,N): ans += (N-1)//A print(ans)
import sys input = sys.stdin.buffer.readline N = int(input()) ans = 0 for a in range(1, N+1): maxb = (N-1)//a ans += maxb print(ans)
1
2,599,353,021,188
null
73
73
n,k=map(int,input().split()) i=0 ans=0 while k**i <= n: ans+=1 i+=1 print(ans)
#coding: utf-8 #ALDS1_2A def pnt(s): for i in xrange(len(s)): print s[i], print n=int(raw_input()) a=map(int,raw_input().split()) sw=0 flag=True while flag: flag=False for j in xrange(n-1,0,-1): if a[j]<a[j-1]: a[j],a[j-1]=a[j-1],a[j] flag=True sw+=1 pnt(a) print sw
0
null
32,282,006,769,090
212
14
N = int(input()) A = list(map(int,input().split())) sum_A = sum(A) mod = 10**9+7 ans = 0 for i in range(N-1): a = A[i] sum_A-=a ans+=a*sum_A print(ans%mod)
x,y = map(int,raw_input().split()) if x==y: print x else: if y>x: tmp = x x = y y = tmp i=2 ans = 1 al = [] while i*i<=x: if x % i ==0: if y % i==0: al.append(i) x = x/i y = y/i continue i+=1 if len(al)==0: pass else: for j in al: ans *= j print ans
0
null
1,913,423,469,180
83
11
def resolve(): INF = 1<<60 H, N = map(int, input().split()) A, B = [], [] for i in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) dp = [INF]*(H+1) dp[0] = 0 for h in range(H): for i in range(N): to = min(H, A[i]+h) dp[to] = min(dp[to], dp[h]+B[i]) print(dp[H]) if __name__ == "__main__": resolve()
import math as ma r=int(input()) print(2*r*ma.pi)
0
null
56,459,097,617,148
229
167
A = list(map(int,input().split())) a=A[0] b=A[1] if a<b: a,b=b,a while b: a,b=b,a%b print(a)
a,b=map(int,input().split()) while b: a,b=b,a%b print(a)
1
8,071,018,512
null
11
11
def resolve(): a = int(input()) print(sum([a, a*a, a*a*a])) if __name__ == "__main__": resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): S = input() if S[-1] == 's': S += 'es' else: S += 's' print(S) resolve()
0
null
6,275,608,064,542
115
71
import itertools n = int(input()) a = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)] for _ in range(n): b, f, r, v = map(int, input().split()) a[b-1][f-1][r-1] += v for b in range(4): for f in range(3): for r in range(10): print('', a[b][f][r], end="") print() if b < 3: print("#"*20)
dic = {} for b in range(1,5): for f in range(1,4): for r in range(1,11): dic[(b,f,r)] = 0 n = int(raw_input()) for k in range(n): b,f,r,v = map(int,raw_input().split()) dic[(b,f,r)] += v j = 0 for b in range(1,5): for f in range(1,4): ls = [] for r in range(1,11): ls.append(dic[(b,f,r)]) print ' ' + ' '.join(map(str,ls)) else: if j < 3: print '#'*20 j +=1
1
1,105,616,132,438
null
55
55
from math import * PI = 3.1415926535898 while True: try: a, b = map(float, raw_input().strip().split(' ')) print "%d %d" % (a*b, 2*(a+b)) except EOFError: break
N, K = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(K)] mod = 998244353 dp = [0] * N dp[0] = 1 now = 0 for i in range(1, N): for l, r in LR: if i - l >= 0: now += dp[i - l] now %= mod if i - r - 1 >= 0: now -= dp[i - r - 1] now %= mod dp[i] = now #print(dp) print(dp[-1])
0
null
1,494,297,825,302
36
74
n = int(input()) #n, m = map(int, input().split()) al = list(map(int, input().split())) #al=[list(input()) for i in range(n)] mod = 10**9+7 add = 0 ans = 0 for i in range(n-1, 0, -1): add = (add+al[i]) % mod ans = (ans+add*al[i-1]) % mod print(ans)
n=int(input()) a=list(map(int,input().split())) score=0 mod=10**9+7 b=sum(a) for i in range(0,n-1): b-=a[i] score+=a[i]*b print(score%mod)
1
3,829,887,237,568
null
83
83
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): x = input() if (x == "AC"): ac = ac + 1 elif (x == "WA"): wa = wa + 1 elif (x == "TLE"): tle = tle + 1 else: re = re + 1 print("AC", "x", ac) print("WA", "x", wa) print("TLE", "x", tle) print("RE", "x", re)
n = int(input()) l = {'AC':0,'WA':0,'TLE':0,'RE':0} for i in range(n): l[input()] += 1 print('AC x',l['AC']) print('WA x',l['WA']) print('TLE x',l['TLE']) print('RE x',l['RE'])
1
8,783,239,597,040
null
109
109
S = input() if S == 'AAA' or S== 'BBB': print("No") else: print("Yes")
from sys import stdin, setrecursionlimit WEEK = { 'SUN': 0, 'MON': 1, 'TUE': 2, 'WED': 3, 'THU': 4, 'FRI': 5, 'SAT': 6 } def main(): input = stdin.buffer.readline s = input()[:-1].decode() print(7 - WEEK[s]) if __name__ == "__main__": setrecursionlimit(10000) main()
0
null
94,438,417,155,148
201
270
h, w, n = map(int, [input() for _ in range(3)]) print((n-1)//max(h, w)+1)
a=int(input()) b=int(input()) c=int(input()) if a<b: a,b=b,a if c%a==0: print(c//a) else: print(c//a+1)
1
89,081,381,561,260
null
236
236
S = input() if 'RRR' in S: ANS = 3 elif 'RR' in S: ANS = 2 elif 'RS' in S: ANS = 1 elif 'SR' in S: ANS = 1 elif 'SSS' in S: ANS = 0 print(ANS)
S = input() rain_d = 0 max_rain_d = 0 for s in S: if s == 'R': rain_d += 1 max_rain_d = rain_d elif s == 'S': rain_d = 0 print(max_rain_d)
1
4,930,056,486,430
null
90
90
import math from decimal import * import random mod = int(1e9)+7 s = str(input()) n =len(s) if(n%2==0): s1, s2 = s[:n//2], s[n//2:][::-1] ans =0 for i in range(len(s1)): if(s1[i]!= s2[i]): ans+=1 print(ans) else: s1, s2 = s[:(n-1)//2], s[(n-1)//2:][::-1] ans = 0 for i in range(len(s1)): if(s1[i]!= s2[i]): ans+=1 print(ans)
from collections import defaultdict as dd from itertools import accumulate N, K = map(int, input().split()) As = [0] + list(map(int, input().split())) S = list(accumulate(As)) ans = 0 counts = dd(int) counts[0] = 1 for j in range(1, N+1): if j >= K: counts[(S[j-K] - (j-K)) % K] -= 1 t = (S[j] - j) % K ans += counts[t] counts[t] += 1 print(ans)
0
null
129,121,874,392,452
261
273
def main(): import sys b=sys.stdin.buffer input=b.readline n=int(input()) d=[set()for _ in range(n)]+[{c}for c in input()] for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i] r=[] add=r.append input() for q,a,b in zip(*[iter(b.read().split())]*3): i=int(a)+n-1 if q<b'2': d[i]={b[0]} while i: i>>=1 d[i]=d[i+i]|d[i-~i] continue j=int(b)+n s=set() while i<j: if i&1: s|=d[i] i+=1 if j&1: j-=1 s|=d[j] i>>=1 j>>=1 add(len(s)) print(' '.join(map(str,r))) main()
import sys def input(): return sys.stdin.readline().rstrip() def ctoi(c): return ord(c)-97 class BIT: def __init__(self, n): self.unit_sum=0 # to be set self.n=n self.dat=[0]*(n+1)#[1,n] def add(self,a,x): #a(1-) i=a while i<=self.n: self.dat[i]+=x i+=i&-i def sum(self,a,b=None): if b!=None: return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-) res=self.unit_sum i=a while i>0: res+=self.dat[i] i-=i&-i return res #Σ[1,a] a(1-) def __str__(self): self.ans=[] for i in range(1,self.n): self.ans.append(self.sum(i,i+1)) return ' '.join(map(str,self.ans)) def main(): n=int(input()) S=list(input()) q=int(input()) BIT_tree=[] for i in range(26): obj=BIT(n+1) BIT_tree.append(obj) for i in range(n): BIT_tree[ctoi(S[i])].add(i+1,1) for _ in range(q): query=input().split() if query[0]=="1": index,x=int(query[1])-1,query[2] BIT_tree[ctoi(S[index])].add(index+1,-1) BIT_tree[ctoi(x)].add(index+1,1) S[index]=x else: l,r=int(query[1])-1,int(query[2])-1 ans=0 for c in range(26): if BIT_tree[c].sum(l+1,r+2): ans+=1 print(ans) if __name__=='__main__': main()
1
62,741,383,178,404
null
210
210
#!/usr/bin/env python3 # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): N = int(input()) C = list(input()) Rc = len(list(filter(lambda x:x=="R",C))) Wc = len(C) - Rc c = 0 for i in range(Rc): if C[i] == "W": c+=1 # print(Rc) # print(Wc) print(c) pass if __name__ == '__main__': main()
from sys import stdin N = int(stdin.readline().rstrip()) C = stdin.readline().rstrip() rc = C.count('R') ans = 0 for i in range(rc): if C[i] == 'W': ans += 1 print(ans)
1
6,300,681,773,982
null
98
98
a,b=map(int,input().split()) for i in range(2000): if int(i*0.08)==a and int(i*0.1)==b: print(i) exit() print("-1")
#coding:UTF-8 n = map(int,raw_input().split()) n.sort() print n[0],n[1],n[2]
0
null
28,303,836,990,010
203
40
MOD = 10**9 + 7 N = 2 * 10**6 + 10 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod MOD) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod MOD) inv = [0, 1] def nCr(n, r, mod): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % mod for i in range(2, N + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) k = int(input()) s = len(input()) ans = 0 for i in range(k+1): ansp = pow(26,i,MOD) * pow(25,k-i,MOD) * nCr(s+k-1-i,s-1,MOD) % MOD ans = (ans + ansp) % MOD print(ans)
k = int(input()) s = input() n = len(s) MOD = 10 ** 9 + 7 ans = 0 comb = 1 for i in range(k+1): if i > 0: comb = comb * (n+i-1) * pow(i, MOD-2, MOD) % MOD ans = (ans + comb * pow(25, i, MOD) * pow(26, k-i, MOD)) % MOD print(ans)
1
12,896,737,670,908
null
124
124
N = int(input()) A = input().split() num_even = 0 num_approved = 0 for i in range(N): if int(A[i]) % 2 == 0: num_even += 1 if int(A[i]) % 3 == 0 or int(A[i]) % 5 == 0: num_approved += 1 if num_even == num_approved: print("APPROVED") else: print("DENIED")
#D N=int(input()) X=str(input()) CNT=0 for i in range(N): if X[i]=="1": CNT+=1 NUM=int(X,2) to0_cnt=[0 for i in range(N)] for i in range(1,N): ans=0 num=i while True: cnt=0 for j in bin(num)[2:]: if j=="1": cnt+=1 if cnt==0: break r=num%cnt ans+=1 if r==0: break num=r to0_cnt[i]=ans R=[NUM%(CNT+1),NUM%(CNT-1) if CNT!=1 else 0] for i in range(N): if X[i]=="0": cnt=CNT+1 r=(R[0]+pow(2,N-i-1,cnt))%cnt else: cnt=CNT-1 if NUM-pow(2,N-i-1)==0: print(0) continue r=(R[1]-pow(2,N-i-1,cnt))%cnt ans=1+to0_cnt[r] print(ans)
0
null
38,450,523,337,760
217
107
n = int(input()) dict = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j"} dict2 = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10} #ans = [["a", 1]] #for i in range(n-1): # newans = [] # for lis in ans: # now = lis[0] # count = lis[1] # for j in range(1, count + 2): # newans.append([now + dict[j], max(j, count)]) # ans = newans #for lis in ans: # print(lis[0]) def dfs(s): if len(s) == n: print(s) return m = max(s) count = dict2[m] for i in range(1, count+2): dfs(s+dict[i]) dfs("a")
S=input() B=0 B=S[0]+S[1]+S[2] print(B)
0
null
33,527,327,707,812
198
130
N = int(input()) Suji_check = False for s in range(1,10): for t in range(1,10): if s*t == N: Suji_check = True break if Suji_check: print('Yes') else: print('No')
def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) s=input() from collections import Counter c=Counter(s) if len(c.keys())>=2: print("Yes") else: print("No")
0
null
107,181,667,653,632
287
201
# Template 1.0 import sys, re from collections import deque, defaultdict, Counter, OrderedDict from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from heapq import heappush, heappop, heapify, nlargest, nsmallest def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx])) def sortDictWithVal(passedDic): temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0])) toret = {} for tup in temp: toret[tup[0]] = tup[1] return toret def sortDictWithKey(passedDic): return dict(OrderedDict(sorted(passedDic.items()))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 n = INT() a = LIST() first = a[:] dd = defaultdict(int) for i in range(n): first[i] = first[i]+(i+1) dd[first[i]]+=1 ans = 0 for i in range(n): ans+=dd[(i+1)-a[i]] print(ans)
S=100000 n=int(input()) for i in range(n): S*=1.05 S=int(S) if S%1000==0: S=S else: S=S+1000 S=S//1000 S=S*1000 print(S)
0
null
13,103,075,602,200
157
6
import re def main(): S , T =map(str, input().split()) print (T+S) if __name__ == '__main__': main()
def solve(): S,T = input().split() print(T+S) if __name__ == "__main__": solve()
1
102,995,125,047,942
null
248
248
N = int(input()) As = list(map(int,input().split())) dic = {} array = [] x = As[0] init = 1 - x for i in range(1,N): v = init + i - 1 - As[i] array.append(v) if v not in dic: dic[v] = 1 else: dic[v] += 1 if 0 in dic: ans = dic[0] else: ans = 0 for i in range(1,N): y = As[i] + i - x z = array[i-1] dic[z] -= 1 if y in dic: ans += dic[y] print(ans)
import bisect n = int(input()) a = list(map(int,input().split())) # ni - nj = ai + aj (i>j) # ai - ni = - aj - nj a1 = sorted([a[i] - (i+1) for i in range(n)]) a2 = sorted([- a[i] - (i+1) for i in range(n)]) ans = 0 for i in range(n): left = bisect.bisect_left(a2, a1[i]) right = bisect.bisect_right(a2, a1[i]) ans += (right - left) print(ans)
1
25,955,894,431,000
null
157
157
N = int(input()) az = [chr(i) for i in range(97, 97+26)] N = N - 1 tmp1 = 0 for i in range(1, 1000): tmp1 += 26 ** i if tmp1 > N: num = i tmp1 -= 26 ** i N -= tmp1 break tmp = [0 for _ in range(num)] for i in range(num): tmp[i] = N%26 N = N // 26 ans = "" for i in range(len(tmp)): ans = az[tmp[i]] + ans print(ans)
N = int(input()) ans = "" while N > 0: N -= 1 q, r = N//26, N%26 ans += chr(ord("a") + r) N = q print(ans[::-1])
1
11,935,566,582,704
null
121
121
s = input() p = input() s += s if s.count(p): print("Yes") else: print("No")
a = list(map(int, input().split())) b = (a[2] * 60 + a[3]) - (a[0] * 60 + a[1]) print(b - a[4])
0
null
10,015,724,947,522
64
139
a=100000 for _ in range(int(input())): a=((a*1.05)//1000+1)*1000 if (a*1.05)%1000 else a*1.05 print(int(a))
from collections import deque n = int(input()) dq = deque() for _ in range(n): query = input() if query == "deleteFirst": dq.popleft() elif query == "deleteLast": dq.pop() else: op, arg = query.split() if op == "insert": dq.appendleft(arg) else: tmp = deque() while dq: item = dq.popleft() if item == arg: break else: tmp.append(item) while tmp: dq.appendleft(tmp.pop()) print(*dq)
0
null
26,774,609,850
6
20
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline a,b,c = map(int, input().split()) if a == b and a != c and b != c: print("Yes") elif a == c and a != b and c != b: print("Yes") elif b == c and a != b and a != c: print("Yes") else: print("No")
l = list(map(int,input().split())) l.sort() if (l[0]==l[1] and l[1] != l[2]) or (l[0] != l[1] and l[1]==l[2]): print('Yes') else: print('No')
1
68,002,407,867,250
null
216
216
n=int(input()) ans = 0 ans += n*(n+1)//2 ans += 15*(n//15)*(n//15+1)//2 ans -= 3*(n//3)*(n//3+1)//2 ans -= 5*(n//5)*(n//5+1)//2 print(ans)
# 1 <= N <= 1000000 N = int(input()) total = [] # N項目までに含まれる->N項目は含まない。だからN項目は+1で外す。 for x in range(1, N+1): if x % 15 == 0: "FizzBuzz" elif x % 5 == 0: "Buzz" elif x % 3 == 0: "Fizz" else: total.append(x) #リストに加える print(sum(total))
1
34,893,144,138,400
null
173
173
def main(): def inputs(): li = [] count = 0 try: while count < 200: li.append(input()) count += 1 except EOFError: return li return li li = inputs() for x in li: a = x.split(" ") result = len(str(int(a[0]) + int(a[1]))) print(result) return None if __name__ == '__main__': main()
import sys from collections import deque def read(): return sys.stdin.readline().rstrip() def main(): n, m, k = map(int, read().split()) friend = [[] for _ in range(n)] block = [set() for _ in range(n)] potential = [set() for _ in range(n)] for _ in range(m): a, b = [int(i) - 1 for i in read().split()] friend[a].append(b) friend[b].append(a) for _ in range(k): c, d = [int(i) - 1 for i in read().split()] block[c].add(d) block[d].add(c) sd = set() for u in range(n): if u in sd: continue sn = deque([u]) pf = set() while sn: p = sn.pop() if p in sd: continue sd.add(p) pf.add(p) for f in friend[p]: sn.append(f) for pfi in pf: potential[pfi] = pf print(*[len(potential[i]) - len(block[i] & potential[i]) - len(friend[i]) - 1 for i in range(n)]) if __name__ == '__main__': main()
0
null
30,773,252,404,260
3
209
x = int(input()) idx = 0 tmp = 0 while 1: tmp += x idx += 1 if tmp % 360 == 0: break print(idx)
a = int(input()) n = 1 while True: if a*n % 360 == 0: break else: n += 1 print(n)
1
13,147,774,108,612
null
125
125
N, P = map(int, input().split()) S = list(map(int, input())) ans = 0 if P == 2: for i in range(N): if S[i]%2 == 0: ans +=i+1 print(ans) elif P ==5: for i in range(N): if S[i]%5 == 0: ans +=i+1 print(ans) else: data =[0]*P tens = 1 k = 0 for i in range(N-1,-1,-1): k += S[i] *tens %P k = k%P data[k] += 1 tens *=10 tens %=P for i in data: ans += i*(i-1)/2 ans +=data[0] print(int(ans))
N = int(input()) S, T = map(list, input().split(' ')) result = '' for s, t in zip(S, T): result = result + s + t print(result)
0
null
85,054,431,998,218
205
255
import itertools h, w, k = map(int, input().split()) c = [[x for x in input()] for i in range(h)] ans = 0 for hi in range(2**h): for wi in range(2**w): c_cp = [[n for n in i] for i in c] for hj in range(h): if (hi & (1<<hj)) != 0: c_cp[hj] = ['R' for n in c_cp[hj]] for wj in range(w): if (wi & (1<<wj)) != 0: for hk in range(h): c_cp[hk][wj] = 'R' cnt = list(itertools.chain.from_iterable(c_cp)).count('#') if cnt == k: ans += 1 print(ans)
H,W,K=map(int,input().split()) c_map=[] for _ in range(H): c=input() c_map.append(c) ans=0 for i in range(2**H): for j in range(2**W): cnt=0 for k in range(H): for l in range(W): if c_map[k][l]=='#' and (i>>k)&1==0 and (j>>l)&1==0: cnt+=1 if cnt==K: ans+=1 print(ans)
1
9,009,626,989,808
null
110
110
s = input() t = input() ans = 1e+9 for si in range(len(s)): if si + len(t) > len(s): continue cnt = 0 for ti in range(len(t)): if s[si+ti] != t[ti]: cnt += 1 ans = min(ans, cnt) print(ans)
S = input() T = input() U = [0] * (len(S)-len(T)+1) for j in range(len(S)-len(T)+1): for i in range(len(T)): if(S[i+j] != T[i]): U[j] += 1 print(min(U))
1
3,700,918,886,908
null
82
82
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] for num in numbers: for num2 in numbers: print('{0}x{1}={2}'.format(num, num2, num * num2))
N = int(input()) S, T = input().split() charac = [] for i in range(N): charac += S[i] charac += T[i] print(''.join(charac))
0
null
55,738,592,386,048
1
255
rig=[int(i) for i in input().split(" ")] while True: ke=rig[0]+rig[1] ans=1 count=10 while True: if ke<count: print(ans) break else: ans+=1 count=count*10 try:rig=[int(i) for i in input().split(" ")] except:break
h, w, k = map(int, input().split()) S = [] for i in range(h): s = str(input()) S.append(s) Ans = [[False for _ in range(w)] for _ in range(h)] now = 1 for i in range(h): for j in range(w): if S[i][j] == '#': Ans[i][j] = now now += 1 for i in range(h): now = False for j in range(w): if now == False and Ans[i][j] == False: continue elif now != False and Ans[i][j] == False: Ans[i][j] = now elif Ans[i][j] != False: now = Ans[i][j] for i in range(h): now = False for j in range(w-1, -1, -1): if now == False and Ans[i][j] == False: continue elif now != False and Ans[i][j] == False: Ans[i][j] = now elif Ans[i][j] != False: now = Ans[i][j] now = False for i in range(h): if now == False and Ans[i].count(False) == w: continue elif now != False and Ans[i].count(False) == w: Ans[i] = now elif Ans[i].count(False) != w: now = Ans[i] now = False for i in range(h-1, -1, -1): if now == False and Ans[i].count(False) == w: continue elif now != False and Ans[i].count(False) == w: Ans[i] = now elif Ans[i].count(False) != w: now = Ans[i] for i in range(h): print(' '.join(map(str, Ans[i])))
0
null
71,571,622,255,426
3
277
n, m, k = [int(i) for i in input().split()] subsets = [] splits = [i for i in range(1, n)] n -= 1 for i in range(2**n): x = [] for j in range(n): if i&(1<<j): x.append(j) subsets.append(x) n+=1 A = [] for i in range(n): A.append([int(j) for j in input()]) ans = n*m for subset in subsets: cur_ans = len(subset) tmp = [] col = 0 subset.append(100000) running_sum = [0 for i in range(len(subset))] while col<m: row_ptr = 0 for row in range(n): if row > subset[row_ptr]: row_ptr += 1 running_sum[row_ptr] += A[row][col] if running_sum[row_ptr] > k: col -= 1 running_sum = [0 for i in range(len(subset))] cur_ans += 1 break col += 1 if cur_ans >= ans: break ans = min(ans, cur_ans) print(ans)
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def s(): return input() def cuts(H): for i in range(1<<H): yield bin(i)[2:].zfill(H) def main(): H, W, K = LI() S = [] for _ in range(H): S.append(s()) ans = inf for cut in cuts(H-1): p = sum([1 for x in cut if x == '1']) cnt = p lines = [[0 for _ in range(W)] for __ in range(p+1)] cumr = 0 for c in range(W): n_line = 0 for r in range(H): if S[r][c] == '1': cumr += 1 if r >= H-1: continue if cut[r] == '1': lines[n_line][c] += cumr n_line += 1 cumr = 0 lines[-1][c] = cumr cumr = 0 ng = False cumsum = [[0 for _ in range(W+1)] for __ in range(p+1)] for i in range(p+1): line = lines[i] for j in range(W): cumsum[i][j+1] = line[j] + cumsum[i][j] before = 0 for j in range(1, W+1): # import pdb # pdb.set_trace() for i in range(p+1): if ng: break if cumsum[i][j] - cumsum[i][before] > K: if j - before == 1: ng = True cnt += 1 before = j - 1 break if ng: continue ans = min(ans, cnt) print(ans) main()
1
48,496,095,971,712
null
193
193
S = list(map(str, input())) N = len(S)+1 List = [0]*N rightcount = 0 leftcount = 0 if S[0] == "<": leftcount+=1 else: rightcount+=1 for i in range(1, N-1): if S[i] == "<": leftcount+=1 if S[i-1] == "<": List[i] = List[i-1]+1 elif S[i-1] == ">": for j in range(rightcount): List[i-j] = j if List[i-rightcount]<=List[i-rightcount+1]: List[i-rightcount] = List[i-rightcount+1] + 1 rightcount = 0 if S[i] == ">": rightcount+=1 if S[i-1] =="<": for j in range(leftcount+1): List[i-j] = leftcount - j leftcount = 0 if S[N-2] == "<": List[N-1] = List[N-2] + 1 else: for j in range(rightcount): List[N-1-j] = j if List[N-1-rightcount]<=List[N-1-rightcount+1]: List[N-1-rightcount] = List[N-1-rightcount+1] + 1 print(sum(List))
s = input() inc = 0 dec = 0 increasing = True ans = 0 for c in s: if increasing: if c == '<': inc += 1 else: increasing = False dec += 1 else: if c == '>': dec += 1 else: if inc > dec: inc, dec = dec, inc ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2 increasing = True inc = 1 dec = 0 else: if increasing: ans += inc * (inc + 1) // 2 else: if inc > dec: inc, dec = dec, inc ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2 print(ans)
1
156,553,739,428,842
null
285
285