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
n = int(input()) m=list(map(int,input().split())) A=[0]*n for i in range(n-1): A[m[i]-1]+=1 print(*A, sep = "\n")
N = int(input()) ls = list(map(int,input().split())) cnt = [0] * (N+1) for i in range(N-1): cnt[ls[i]] += 1 for i in range(1,N+1): print(cnt[i])
1
32,452,048,183,390
null
169
169
import sys #fin = open("test.txt", "r") fin = sys.stdin n = int(fin.readline()) d = {} for i in range(n): op, str = fin.readline().split() if op == "insert": d[str] = 0 else: if str in d: print("yes") else: print("no")
# ALDS1_4_C.py N = int(input()) dict = {} for i in range(N): query, s = input().split() if query == "insert": dict[s] = True else: print('yes' if s in dict else 'no')
1
73,790,061,386
null
23
23
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import copy import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] def solve(): X = Scanner.int() X -= 400 print(8 - X // 200) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") solve() if __name__ == "__main__": main()
from sys import stdin input = stdin.readline def solve(): X = int(input()) check = (X - 400)//200 print(8 - check) if __name__ == '__main__': solve()
1
6,631,924,615,808
null
100
100
# -*- coding: utf-8 -*- def selection_sort(A, N): change = 0 for i in xrange(N): minj = i for j in xrange(i, N, 1): if A[j] < A[minj]: minj = j if minj != i: temp = A[minj] A[minj] = A[i] A[i] = temp change += 1 return (A, change) if __name__ == "__main__": N = input() A = map(int, raw_input().split()) result, change = selection_sort(A, N) print ' '.join(map(str, result)) print change
n = int(input()) k = [int(i) for i in input().split()] m = 0 for i in range(n): minj = i for j in range(i,n): if k[j] < k[minj]: minj = j x = k[i] k[i] = k[minj] k[minj]=x if k[i] != k[minj]: m += 1 print(' '.join(map(str, k))) print(m)
1
21,636,758,702
null
15
15
from collections import Counter N = int(input()) S = input() D = Counter(S) ans = 1 for d in D.values(): ans *= d if len(D.values()) < 3: ans = 0 for i in range(N): for x in range(1, (N-i+1)//2): if S[i] != S[i+x] and S[i+x] != S[i+2*x] and S[i+2*x] != S[i]: ans -= 1 print(ans)
from collections import deque k = int(input()) num_deq = deque([i for i in range(1, 10)]) for i in range(k-1): x = num_deq.popleft() if x % 10 != 0: num_deq.append(10 * x + x % 10 - 1) num_deq.append(10 * x + x % 10) if x % 10 != 9: num_deq.append(10 * x + x % 10 + 1) x = num_deq.popleft() print(x)
0
null
38,216,387,199,052
175
181
k, n = map(int, input().split()) A = list(map(int, input().split())) D = [] for i in range(n-1): D.append(A[i+1]-A[i]) else: D.append(k-(A[n-1]-A[0])) D.sort(reverse=True) print(k-D[0])
X, Y, A, B, C = map(int, input().split()) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) cand = p[0:X] + q[0:Y] + r cand.sort(reverse=True) ans = sum(cand[0:X+Y]) print(ans)
0
null
44,308,405,231,730
186
188
def insert(S, string): S.add(string) def find(S, string): if string in S: print 'yes' else: print 'no' n = input() S = set() for i in range(n): tmp1, tmp2 = map(str, raw_input().split()) if tmp1 == 'insert': insert(S, tmp2) elif tmp1 == 'find': find(S, tmp2) else: print 'error!'
command_num = int(input()) dict = set([]) for i in range(command_num): in_command, in_str = input().rstrip().split(" ") if in_command == "insert": dict.add(in_str) elif in_command == "find": if in_str in dict: print("yes") else: print("no")
1
73,818,863,902
null
23
23
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() num = 0 for i in range(N): a, b = MI() if a == b: num += 1 if num == 3: print("Yes") return else: num = 0 print("No") main()
N = int(input()) flag = 0 ans = "No" for i in range(N): A,B = input().split() if A == B: flag += 1 else: flag = 0 if flag == 3: ans = "Yes" break print(ans)
1
2,443,574,366,628
null
72
72
# Union-Find class UnionFind(): def __init__(self, n): self.n = n self.parents = [i for i in range(n + 1)] def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return 0 elif x < y: self.parents[y] = x else: self.parents[x] = y return 1 from collections import Counter n, m = map(int, input().split()) uf = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) uf.unite(a, b) roots = [] for num in uf.parents: roots.append(uf.find(num)) count_roots = Counter(roots) print(len(count_roots)-2)
n,k=map(int,input().split()) lst_1=list(map(int,input().split())) # print(lst_1) lst_2=[] for i in range(n-k): temp=1 temp=lst_1[i+k]/lst_1[i] lst_2.append(temp) for i in lst_2: if i>1: print("Yes") else:print("No")
0
null
4,658,851,681,832
70
102
import sys sys.setrecursionlimit(10**5) N,u,v=map(int,input().split()) du,dv=[0]*-~N,[0]*-~N T=[list() for i in range(-~N)] def dfs(p,t,v,d): d[v]=t for i in T[v]: if i!=p: dfs(v,t+1,i,d) for i in range(N-1): a,b=map(int,input().split()) T[a].append(b) T[b].append(a) dfs(0,0,u,du) dfs(0,0,v,dv) c=0 for i in range(1,-~N): if len(T[i])==1 and i!=v: if du[i]<dv[i]: c=max(c,~-dv[i]) print(c)
n,a,b=map(int,input().split()) p=a+b c=n%p d=n//p if c<a: print(d*a+c) else: print((d+1)*a)
0
null
86,723,706,097,676
259
202
#coding:utf-8 #1_1_C 2015.3.6 a,b = input().split() area = int(a) * int(b) circumference = (int(a) + int(b)) * 2 print(area,circumference)
st = input().split() S = st[0] T = st[1] ab = input().split() A = int(ab[0]) B = int(ab[1]) U = input() new_a = A - 1 if S == U else A new_b = B-1 if T == U else B print("{} {}".format(new_a, new_b))
0
null
35,976,662,099,080
36
220
import networkx as nx n, m = map(int, input().split()) nodes = [0 for i in range(n)] L = [] for i in range(m): a, b = map(int, input().split()) L.append((a,b)) nodes[a-1] += 1 nodes[b-1] += 1 num = 0 for node in nodes: if node == 0: num += 1 graph = nx.from_edgelist(L) num += len(list(nx.connected_components(graph))) print(num-1)
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N, M = MI() routes = [] cities = [[] for i in range(N)] for i in range(M): a, b = MI() cities[a-1].append(b-1) cities[b-1].append(a-1) groups = [-1] * N group = 0 for i in range(N): if groups[i] != -1: continue deque = cl.deque([i]) groups[i] = group while len(deque) > 0: city = deque.popleft() next_cities = cities[city] for next_city in next_cities: if groups[next_city] != -1: continue groups[next_city] = group deque.append(next_city) group += 1 print(group - 1) main()
1
2,303,704,516,610
null
70
70
from bisect import bisect_right as br from itertools import accumulate as ac n,m,k=map(int,input().split()) a=list(ac([0]+list(map(int,input().split())))) b=list(ac([0]+list(map(int,input().split())))) l=0 for i in range(n+1): if k<a[i]: break else: l=max(l,i+br(b,k-a[i])-1) print(l)
# 解説 import sys pin = sys.stdin.readline pout = sys.stdout.write perr = sys.stderr.write N, M, K = map(int, pin().split()) A = list(map(int, pin().split())) B = list(map(int, pin().split())) a = [0] b = [0] for i in range(N): a.append(a[i] + A[i]) for i in range(M): b.append(b[i] + B[i]) ans = 0 for i in range(N + 1): #Aの合計がKを超えるまで比較する if a[i] > K: break # 超えていた場合に本の個数を減らす while b[M] > K - a[i]: M -= 1 ans = max(ans, M + i) print(ans)
1
10,784,253,870,818
null
117
117
a, b=map(int,input().split()) print(str(a)*b if a<b else str(b)*a)
a , b = (int(a) for a in input().split()) x = min(a,b) t = max(a,b) ans = [str(x)]*t print("".join(ans))
1
84,179,638,013,130
null
232
232
num_freebies = int(input()) freebies = [] for _ in range(num_freebies): freebies.append(input()) print(len(set(freebies)))
n=int(input()) l =[] for i in range(n): s =input() l.append(s) l = set(l) print(len(l))
1
30,310,821,386,652
null
165
165
N = int(input()) #https://img.atcoder.jp/abc178/editorial-E-phcdiydzyqa.pdf z_list = list() w_list = list() for i in range(N): x,y = map(int, input().split()) z_list.append(x + y) w_list.append(x - y) print(max(max(z_list)-min(z_list),max(w_list)-min(w_list)))
a,b=[],[] for _ in range(int(input())): x,y=map(int,input().split()) a+=[x-y] b+=[x+y] print(max(max(a)-min(a),max(b)-min(b)))
1
3,441,764,066,364
null
80
80
X,N=map(int,input().split()) P=set(map(int,input().split())) l=[0]+[(1+i//2)*(-1 if i%2==0 else 1) for i in range(101)] for i in l: if X+i not in P: print(X+i) break
X, N = map(int, input().split()) P = list(map(int, input().split())) occupied = set(P) for i in range(200): if X - i not in occupied: print(X - i) break if X + i not in occupied: print(X + i) break
1
14,106,531,906,420
null
128
128
a, b, c = map(int, input().split(" ")) print("Yes" if len(set({a,b,c})) == 2 else "No")
A,B,C=map(int,input().split()) result=0 if A == B: if A != C and B != C: result+=1 elif A == C: if A != B and B != C: result+=1 elif B == A: if B != A and C != B: result+=1 elif B ==C: if B != A and A != C: result+=1 elif C == A: if C != B and A == B: result+=1 elif C == B: if C != A and A == B: result+=1 if result==1: print('Yes') else: print('No')
1
67,735,130,313,536
null
216
216
m=[0]*50 f=[0]*50 r=[0]*50 result=[""]*50 num=0 while True: a,b,c=map(int,input().split()) if a == b == c ==-1: break else: m[num],f[num],r[num]=a,b,c num+=1 for i in range(num): if m[i] == -1 or f[i]==-1: result[i]="F" elif m[i]+f[i]>=80: result[i]="A" elif m[i]+f[i]>=65: result[i]="B" elif m[i]+f[i]>=50: result[i]="C" elif m[i]+f[i]>=30: if r[i] >=50: result[i]="C" else: result[i]="D" else: result[i]="F" for i in range(num): print(result[i])
date=[[],[],[]] a,b,c=0,0,0 while True: if a < 0 and b < 0 and c < 0: break else: a,b,c =[int(i) for i in input().split()] date[0].append(a) date[1].append(b) date[2].append(c) for h in range(0,len(date[0])-1): if date[0][h] == -1 or date[1][h] == -1: print("F") elif date[0][h] == date[1][h] == date[2][h]: break else: if date[0][h] + date[1][h] >= 80: print("A") else: if date[0][h] + date[1][h] >= 65: print("B") else: if date[0][h] + date[1][h] >= 50: print("C") else: if date[0][h] + date[1][h] >=30: if date[2][h] >= 50: print("C") else: print("D") else: print("F")
1
1,210,138,973,248
null
57
57
n = int(input()) d1 = [0] * n d2 = [0] * n for i in range(n): d1[i], d2[i] = map(int,input().split()) for i in range(n-2): if d1[i] == d2[i] and d1[i+1] == d2[i+1] and d1[i+2] == d2[i+2]: print('Yes') break else: print('No')
import sys n = int(input()) d = [list(map(int, input().split())) for _ in range(n)] cnt = 0 for z in d: x, y = z if x == y: cnt += 1 if cnt >= 3: print("Yes") sys.exit() else: cnt = 0 print("No")
1
2,486,675,057,722
null
72
72
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def battle(enemy, r, s, p): if enemy == "r": return p if enemy == "s": return r if enemy == "p": return s def main(): N, K = MI() r, s, p = MI() t = input() splited_t = [[] for i in range(K)] for i in range(N): amari = i % K splited_t[amari].append(t[i]) ans = 0 for i in range(K): targets = splited_t[i] score = battle(targets[0], r, s, p) ans += score won = True for j in range(1, len(targets)): if targets[j] == targets[j - 1] and won: won = False continue score = battle(targets[j], r, s, p) won = True ans += score print(ans) main()
n,k = map(int,input().split()) r,s,p = map(int,input().split()) t = input() point = {"r":(p,"p"), "s":(r,"r"), "p":(s,"s")} ans = 0 hand = "" for i in range(n): if i < k: ans += point[t[i]][0] hand += point[t[i]][1] else: if (t[i-k] != t[i]): ans += point[t[i]][0] hand += point[t[i]][1] else: if hand[i-k] != point[t[i]][1]: ans += point[t[i]][0] hand += point[t[i]][1] else: if (i+k) < n: hand += "rsp".replace(point[t[i+k]][1],"").replace(hand[i-k],"")[0] else: hand += "rsp".replace(hand[i-k],"")[0] print(ans)
1
107,331,672,963,242
null
251
251
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): n = int(input()) now = 0 for _ in range(n): x, y = map(int, input().split()) if x == y: now += 1 else: now = 0 if now == 3: print("Yes") return print("No") resolve()
n = int(input()) s = 0 b = False for _ in range(n): w = input().split() if w[0] == w[1]: s += 1 if s == 3: b = True break else: s = 0 print('Yes' if b else 'No')
1
2,493,111,854,932
null
72
72
import math p_max = 1000000 * 1000000 n, k = map(int, input().split()) w = [int(input()) for i in range(n)] def check(p): i = 0 for j in range(k): s = 0 while (s + w[i] <= p): s += w[i] i += 1 if i == n: return n return i if __name__ == "__main__": right = p_max left = 0 mid = 0 while (right - left > 1): mid = math.floor((right + left) / 2) v = check(mid) if v >= n: right = mid else: left = mid print (right)
s = int(input()) print((1000-s%1000)%1000)
0
null
4,286,783,341,632
24
108
N = int(input()) for i in range(1, 10): for k in range(1, 10): if(i*k == N): print('Yes') exit(0) print('No')
N = int(input()) for i in range(1,10): for j in range(1,10): temp = i*j if N == temp: print("Yes") exit() print("No")
1
160,154,314,975,830
null
287
287
N, A, B = map(int, input().split()) ans = 0 roop = int(N / (A + B)) # print(roop) padding = N % (A + B) if padding >= A: ans += roop * A + A else: ans += roop * A + padding print(ans)
n, a, b = map(int, input().split()) set_num = n // (a + b) remain_num = n - (a + b) * set_num print(set_num * a + min(remain_num, a))
1
55,583,940,472,210
null
202
202
import sys input = sys.stdin.readline n, s, c = int(input()), [[0 for i in range(10)] for j in range(10)], 0 for i in range(1, n+1): s[int(str(i)[0])][int(str(i)[-1])] += 1 print(sum([s[i][j] * s[j][i] for i in range(1, 10) for j in range(1, 10)]))
from collections import defaultdict n = int(input()) d = defaultdict(int) for i in range(1, n+1): s = str(i) f = int(s[0]) b = int(s[-1]) d[(f, b)] += 1 ans = 0 for a in range(1, 10): for b in range(1, 10): ans += d[(a, b)] * d[(b, a)] print(ans)
1
86,746,454,109,860
null
234
234
while True: a, b = map(int, input().split()) if a == b == 0: break for i in range(a): if i == 0 or i == a - 1: print('#' * b) continue print('#', '.' * (b - 2), '#', sep = '') print()
def solve(): h, a = map(int, input().split()) print(-(-h//a)) if __name__ == '__main__': solve()
0
null
38,883,561,930,330
50
225
from networkx import * n,m = map(int, input().split()) G = Graph() for i in range(m): a,b = map(int, input().split()) G.add_edges_from([(a, b)]) m3 = list(connected_components(G)) count = 0 if len(max(connected_components(G), key=len)) == n: print(0) exit() else: for i in m3: count += len(i) sub = n - count if sub != 0: print((len(m3)-1)+sub) else: print(len(m3)+sub-1)
# 再帰呼び出しのとき付ける 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)
1
2,304,029,007,940
null
70
70
r,cr,c = map(int,input().split()) matrix_a = [list(map(int,input().split())) for i in range(r)] matrix_b = [list(map(int,input().split())) for i in range(cr)] matrix_c = [ [0 for a in range(c)] for b in range(r)] for j in range(r): for k in range(c): for l in range(cr): matrix_c[j][k] += matrix_a[j][l]*matrix_b[l][k] for x in matrix_c: print(" ".join(list(map(str,x))))
#!/usr/bin/env python # -*- coding: utf-8 -*- N, M, K = map(int, input().split()) result = 0 # max a_time = list(map(int, input().split())) b_time = list(map(int, input().split())) sum = 0 a_num = 0 for i in range(N): sum += a_time[i] a_num += 1 if sum > K: sum -= a_time[i] a_num -= 1 break i = a_num j = 0 while i >= 0: while sum < K and j < M: sum += b_time[j] j += 1 if sum > K: j -= 1 sum -= b_time[j] if result < i + j: result = i + j i -= 1 sum -= a_time[i] print(result)
0
null
6,024,020,581,172
60
117
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print('\n'.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) from math import ceil h,w = readints() s = [readstr() for i in range(h)] dp = [[0]*w for i in range(h)] if s[0][0] == '.': dp[0][0] = 0 else: dp[0][0] = 1 for i in range(1,h): if s[i][0] != s[i-1][0]: dp[i][0] = dp[i-1][0] + 1 else: dp[i][0] = dp[i-1][0] for i in range(1,w): if s[0][i] != s[0][i-1]: dp[0][i] = dp[0][i-1] + 1 else: dp[0][i] = dp[0][i-1] for i in range(1,h): for j in range(1,w): if s[i][j] != s[i-1][j]: dp[i][j] = dp[i-1][j] + 1 else: dp[i][j] = dp[i-1][j] if s[i][j] != s[i][j-1]: dp[i][j] = min(dp[i][j-1] + 1,dp[i][j]) else: dp[i][j] = min(dp[i][j-1],dp[i][j]) print(ceil(dp[-1][-1]/2))
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 def I(): return int(input()) def F(): return float(input()) def S(): 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 LS(): return input().split() def resolve(): N = I() fact = [] for i in range(1, int(N ** 0.5) + 1): if N % i == 0: fact.append((i, N // i)) print(sum(fact[-1]) - 2) if __name__ == '__main__': resolve()
0
null
105,238,534,835,710
194
288
n = int(input()) ans = [] def dfs(A): if len(A) == n: ans.append(''.join(A)) return for i in range(len(set(A))+1): v = chr(i+ord('a')) A.append(v) dfs(A) A.pop() dfs([]) ans.sort() for i in range(len(ans)): print(ans[i])
def dfs(s, ub, n): if len(s) == n: print(s) else: ch = "a" while ord(ch) < ord(ub): dfs(s + ch, ub, n) ch = chr(ord(ch) + 1) ub = chr(ord(ub) + 1) dfs(s + ch, ub, n) def solve(n): dfs("", "a", n) n = int(input()) solve(n)
1
52,600,196,698,060
null
198
198
ichi = input().split() n = int(ichi[0]) m = int(ichi[1]) a = [[0 for j in range(m)] for i in range(n)] for i in range(n): input_a = input().split() for j in range(m): a[i][j] = int(input_a[j]) b = [] for i in range(m): b.append(int(input())) for i in range(n): c=0 for j in range(m): c += a[i][j] * b[j] print(c)
import math import collections import fractions import itertools import functools import operator def solve(): n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(k, n): if a[i] > a[i-k]: print("Yes") else: print("No") return 0 if __name__ == "__main__": solve()
0
null
4,172,955,673,182
56
102
# 解説AC import sys input = sys.stdin.buffer.readline n = int(input()) A = list(map(int, input().split())) B = [] for i, e in enumerate(A): B.append((e, i + 1)) B.sort(reverse=True) # dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値 dp = [[-1] * (n + 1) for _ in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(i + 1): # 左の個数 k = i - j # 右の個数 ni = i + 1 val, idx = B[i] dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val) dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val) ans = 0 for i in range(n + 1): ans = max(ans, dp[n][i]) print(ans)
#!/usr/bin/env python3 import sys from itertools import chain from collections import Counter # form bisect import bisect_left, bisect_right, insort_left, insort_right # import numpy as np def solve(N: int, S: "List[str]"): d = Counter(S) for key in ("AC", "WA", "TLE", "RE"): print(f"{key} x {d.get(key, 0)}") def main(): tokens = chain(*(line.split() for line in sys.stdin)) # N, S = map(int, line.split()) N = int(next(tokens)) # type: int S = [next(tokens) for _ in range(N)] # type: "List[str]" solve(N, S) if __name__ == "__main__": main()
0
null
21,202,855,977,448
171
109
import sys h, w = map(int, input().split()) s = [list(x.rstrip()) for x in sys.stdin.readlines()] dp = [[10**6]*w for _ in range(h)] if s[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 for j in range(h): for i in range(w): for k in range(2): nx, ny = i + (k + 1)%2, j + k%2 if nx >= w or ny >= h: continue else: add = 0 if s[ny][nx] == "#" and s[j][i] == ".": add = 1 dp[ny][nx] = min(dp[ny][nx], dp[j][i] + add) print(dp[h-1][w-1])
H, W = map(int, input().split()) S = [list(input()) for h in range(H)] table = [[0 for w in range(W)] for h in range(H)] table[0][0] = int(S[0][0]=='#') for i in range(1, H): table[i][0] = table[i-1][0] + int(S[i-1][0]=='.' and S[i][0]=='#') for j in range(1, W): table[0][j] = table[0][j-1] + int(S[0][j-1]=='.' and S[0][j]=='#') for i in range(1, H): for j in range(1, W): table[i][j] = min(table[i-1][j] + int(S[i-1][j]=='.' and S[i][j]=='#'), table[i][j-1] + int(S[i][j-1]=='.' and S[i][j]=='#')) print(table[-1][-1])
1
48,947,241,674,338
null
194
194
from collections import deque n, m = map(int ,input().split()) graph = [[] for _ in range(n)] for i in range(m): a,b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) v = [0]*n ans = 0 for i in range(n): if v[i] == 0: ans += 1 q = deque() q.append(i) v[i] = 1 while q: node = q.popleft() for j in graph[node]: if v[j] == 0: q.append(j) v[j] = 1 print(ans-1)
s = input().rstrip() p = input().rstrip() line = s + s print("Yes") if p in line else print("No")
0
null
1,981,653,889,480
70
64
import sys input = sys.stdin.readline H,W,K=map(int,input().split()) CO=[[0 for i in [0]*W] for j in [0]*H] DO=[[0 for i in [0]*W] for j in [0]*H] for i in range(H): C=input() for j in range(W): DO[i][j]=int(C[j]) CO[H-1]=DO[H-1] F=1000000 for s in range(2**(H-1)): D=0 E=0 Sui=[0]*(H-1) for t in range(H-1): if ((s >> t) & 1): Sui[t]+=1 for m in range(H-1): E+=Sui[m] for k in range(H-1): if Sui[k]==0: for i in range(W): CO[H-k-2][i]=DO[H-k-2][i]+CO[H-k-1][i] else: for i in range(W): CO[H-k-2][i]=DO[H-k-2][i] lst=[0]*H for h in range(W): c=max(CO[x][h] for x in range(H)) d=max(lst[y]+CO[y][h] for y in range(H)) if c>K: E=1000000 break elif d>K: D+=1 lst=[0]*H for z in range(H): lst[z]+=CO[z][h] F=min(F,D+E) print(F)
ini = lambda : int(input()) inm = lambda : map(int,input().split()) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors #maincode------------------------------------------------- k = ini() a,b = inm() ans = 'NG' for i in range(1000): if a <= i * k <= b: ans = 'OK' print(ans)
0
null
37,400,586,616,080
193
158
n = input() a = map(int, raw_input().split()) for i in range(n): key = a[i] j = i - 1 while j >= 0 and a[j] > key: a[j + 1] = a[j] j -= 1 a[j + 1] = key print(" ".join(map(str, a)))
# ?????\?????????????????°?????? import sys def print_data(data): last_index = len(data) - 1 for idx, item in enumerate(data): print(item, end='') if idx != last_index: print(' ', end='') print('') def main(): n = int(sys.stdin.readline().strip()) data = [int(i) for i in sys.stdin.readline().strip().split(' ')] print_data(data) for i in range(1, n): v = data[i] j = i - 1 while j >= 0 and data[j] > v: data[j+1] = data[j] j -= 1 data[j+1] = v print_data(data) if __name__ == '__main__': main()
1
5,868,903,782
null
10
10
N = int(input()) k, l = divmod(N, 2) if l == 1: print(0) else: cnt = 0 while k > 1: cnt += k // 5 k //= 5 print(cnt)
N = int(input()) if N % 2 == 1: print(0) else: i = 1 ans = 0 while 2*(5**i) <= N: div = 2 * (5 ** i) ans += int(N//div) i += 1 print(ans)
1
116,101,259,669,120
null
258
258
N = int(input()) A = list(map(int, input().split())) ct = 0 for n in range(N + 1): if n % 2: if A[n - 1] % 2: ct +=1 print(ct)
while True: H, W = map(int, input().split()) if H == 0 and W == 0 : break for j in range(H): for i in range(W): print('#',end='') print() print() if H == 0 and W == 0 : break
0
null
4,276,419,646,742
105
49
s=input() s=s[::-1] l=[0]*2019 l[0]=1 prev=0 ans=0 mul=1 for i in range(len(s)): now=(int(s[i])*mul)%2019 ans+=l[(prev+now)%2019] l[(prev+now)%2019]+=1 prev=(prev+now)%2019 mul=(mul*10)%2019 print(ans)
import collections S=input() l=len(S) T,d=0,1 A=[0]*2019 A[0]=1 for i in range(l): T+=int(S[l-i-1])*d d*=10 T%=2019 d%=2019 A[T]+=1 B=map(lambda x: x*(x-1)//2,A) print(sum(B))
1
30,882,101,821,116
null
166
166
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 5 3 1 3 4 3 output: 3 """ import sys def solve(): # write your code here max_profit = -1 * float('inf') min_stock = prices[0] for price in prices[1:]: max_profit = max(max_profit, price - min_stock) min_stock = min(min_stock, price) return max_profit if __name__ == '__main__': _input = sys.stdin.readlines() p_num = int(_input[0]) prices = list(map(int, _input[1:])) print(solve())
from sys import stdin n = int(input()) r=[int(input()) for i in range(n)] rv = r[::-1][:-1] m = None p_r_j = None for j,r_j in enumerate(rv): if p_r_j == None or p_r_j < r_j: p_r_j = r_j if p_r_j > r_j: continue r_i = min(r[:-(j+1)]) t = r_j - r_i if m == None or t > m: m = t print(m)
1
13,448,535,780
null
13
13
#!usr/bin/env pypy3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect 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) def main(): N, K = LI() x = N % K y = abs(x - K) print(min(x, y)) main()
n, k = [int(i) for i in input().split()] ans = min((n % k), (k - n % k)) print(ans)
1
39,291,725,289,190
null
180
180
N, K = map(int, input().split()) A = list(map(int, input().split())) visited = [-1 for _ in range(N)] visited[0] = 0 k = 0 k = A[k] - 1 count = 0 while visited[k] == -1: count += 1 visited[k] = count k = A[k]-1 roop = count - visited[k] + 1 beforeroop = visited[k] if K < beforeroop: k = 0 for _ in range(K): k = A[k] - 1 print(k+1) else: K = K - beforeroop K = K % roop for _ in range(K): k = A[k]-1 print(k+1)
N, K = map(int, input().split()) A = list(map(int, input().split())) A = [-1] + A loop_pos = None loop_start_time = None loop_end_time = None visited = [-1]*(N+1) pos = 1 i = 0 while visited[pos] == -1: visited[pos] = i pos = A[pos] i += 1 if visited[pos] != -1: loop_pos = pos loop_start_time = visited[pos] loop_end_time = i # print(loop_start_time, loop_end_time) w = loop_end_time - loop_start_time K = min(K, loop_start_time) + max(0, K-loop_start_time)%w # print(f"K: {K}") pos = 1 for i in range(K): # print(pos) pos = A[pos] print(pos)
1
22,811,833,573,660
null
150
150
X , Y = map(int,input().split()) a = 0 ans = "No" for a in range(0,X+1): if (a * 2)+((X-a) * 4)==Y: ans = "Yes" print(ans)
# coding: utf-8 def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) rem = sum(A) cur = 1 ret = 0 for a in A: cur = min(rem, cur) rem -= a ret += cur cur = 2*(cur-a) if cur < 0: ret = -1 break return str(ret) if __name__ == "__main__": print(solve(*(open(0).read().splitlines())))
0
null
16,245,225,599,890
127
141
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) h, w = map(int, input().split()) if h == 1 or w == 1: print(1) sys.exit(0) # a/bの切り上げ: (a + b - 1)//b print(((h * w) + 2 - 1) // 2)
import sys import math input=sys.stdin.buffer.readline h,w=map(int,input().split()) ans=math.ceil(h*w/2) print(1 if min(h,w)==1 else ans)
1
50,583,707,361,198
null
196
196
h, w, k = map(int, input().split()) # 横に分けてから縦に切る s = [list(input()) for _ in range(h)] ans = 1 a = [[0]*w for _ in range(h)] a_0 = [0]*w # 行にイチゴがないときよう for i in range(h): s_count = s[i].count("#") if s_count == 1: for j in range(w): a[i][j] = ans a_0[j] = ans elif s_count != 0: count = 0 # これは#の今現在数えた数 for j in range(w): a[i][j] = ans a_0[j] = ans if s[i][j] == "#" and j+1 != w and s_count != count + 1: # 最後のイチゴと端のイチゴの条件 ans += 1 count += 1 else: for j in range(w): a[i][j] = a_0[j] ans -= 1 ans += 1 for i in range(h): if max(a[i]) == 0: for j in range(h): if max(a[j]) != 0: a[i] = a[j] break for i in a: print(*i)
N,M = map(int,(input().split())) s = list(input()) s.reverse() now = 0 me = [] flag = 0 while now != N: for i in range(1,M+1,)[::-1]: if now + i <= N and s[now+i] == "0": now += i me.append(i) break else: print(-1) flag = 1 break if flag == 0: me.reverse() print(*me)
0
null
141,514,861,394,720
277
274
s = len(input()) print("x" * s)
N,K = map(int,input().split()) i = 0 while True: if N >= K ** i: i += 1 else: break print(i)
0
null
68,613,805,631,030
221
212
n = int(input()) robot = [0]*n for i in range(n): x,l = map(int,input().split()) robot[i] = (x+l, x-l) robot.sort() #print(robot) ans = 1 right = robot[0][0] for i in range(1,n): if right <= robot[i][1]: right = robot[i][0] ans += 1 print(ans)
# -*- coding: utf-8 -*- import math N, M = map(int, input().split()) A = list(map(int, input().split())) for i in range(M): N -= A[i] if N >= 0: print(N) else: print(-1)
0
null
61,079,615,303,730
237
168
def main(): S = input() print(S[0:3]) if __name__ == "__main__": main()
import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int, input().split())) 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 S(): return input() def LS(): return input().split() INF = float('inf') s = S() print(s[:3])
1
14,726,186,183,488
null
130
130
from collections import deque n = int(input()) ki = [[] for i in range(n)] lis = [] for i in range(n-1): a,b = map(int, input().split()) a -= 1 b -= 1 ki[a].append(b) ki[b].append(a) lis.append([a,b,i]) mx = 0 for i in range(n): ki[i].sort() mx = max(mx,len(ki[i])) lis = sorted(lis, key=lambda x:x[0]) lis = sorted(lis, key=lambda x:x[1]) lis2 = [[] for i in range(n)] cnt = 0 for i in range(n-1): lis2[lis[i][0]].append(lis[i]) #print(lis2) #print(ki) def bfs(ki,lis2): d = [True] * n que = deque([(0,-1)]) d[0] = False while len(que) != 0: val = que.popleft() cnt = 1 cnt2 = 0 for i in range(len(ki[val[0]])): if d[ki[val[0]][i]] == True: d[ki[val[0]][i]] = False #print(cnt,cnt2,val,i) if val[1] == cnt: cnt += 1 lis2[val[0]][cnt2].append(cnt) que.append([ki[val[0]][i],cnt]) cnt += 1 cnt2 += 1 return lis2 lis2 = bfs(ki,lis2) #print(lis2) val = 0 for i in range(n): val = max(len(ki[i]),val) print(val) lis = [] for i in range(n): for j in range(len(lis2[i])): lis.append(lis2[i][j]) lis = sorted(lis,key=lambda x:x[2]) for i in range(n-1): print(lis[i][3])
print(["win","bust"][sum(map(int,input().split()))>21])
0
null
127,495,153,698,500
272
260
A, B, C, K = map( int, input().split()) ret = min( A, K ) if A < K: ret -= max( 0, K - A - B ) print( ret )
h,w,k=map(int,input().split()) s=[] ans=[[0 for k in range(w)] for _ in range(h)] for _ in range(h): s.append(input()) temp=0 for i in range(h): flag=0 for j in range(w): if flag: if s[i][j]=="#": temp+=1 ans[i][j]=temp else: if s[i][j]=="#": temp+=1 flag=1 ans[i][j]=temp temp=[ans[i].count(0) for i in range(h)] for i,val in enumerate(temp): if 0<val<w: j=w-1 while ans[i][j]!=0: j-=1 while j>=0: ans[i][j]=ans[i][j+1] j-=1 for i in range(h): if i>0 and ans[i][0]==0: ans[i]=ans[i-1] for i in range(h-1,-1,-1): if i<h-1 and ans[i][0]==0: ans[i]=ans[i+1] for i in range(h): for j in range(w): print(ans[i][j],end=" ") print()
0
null
82,726,385,019,042
148
277
def main(): for N in range(1,10): for M in range(1,10): print(str(N)+"x"+str(M)+"="+str(N*M)) if __name__ == '__main__': main()
from heapq import heappop, heappush X, Y, A, B, C = map(int, input().split()) h = [] for p in map(int, input().split()): heappush(h, (-p, 1)) for q in map(int, input().split()): heappush(h, (-q, 2)) for r in map(int, input().split()): heappush(h, (-r, 3)) ans = 0 cnt = 0 total = X + Y while cnt < total: point, color = heappop(h) if color == 1: if X > 0: ans += -point X -= 1 cnt += 1 elif color == 2: if Y > 0: ans += -point Y -= 1 cnt += 1 elif color == 3: ans += -point cnt += 1 print(ans)
0
null
22,301,940,206,040
1
188
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools from collections import Counter def main(): n = int(input()) a = list(map(int, input().split())) c = Counter(a) p = [True] * (10**6 + 1) s = list(set(a)) for x in s: t = x * 2 while t <= 10**6: p[t] = False t += x ans = 0 for x in a: if c[x] == 1 and p[x] == True: ans += 1 print(ans) if __name__=="__main__": main()
if int(input()) == 0: print('1') else: print('0')
0
null
8,778,124,098,432
129
76
N = int(input()) ans = [0 for _ in range(10050)] for i in range(1, 105): for j in range(1, 105): for k in range(1, 105): v = i**2 + j**2 + k**2 + i*j + j*k + k*i if v<10050: ans[v] += 1 for i in range(N): print(ans[i+1])
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline x, y, a, b, c = map(int, input().split()) pqr = [] p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) for i in range(a): pqr.append([p[i], 1]) for i in range(b): pqr.append([q[i], 2]) for i in range(c): pqr.append([r[i], 0]) pqr.sort(reverse=True) ans = 0 c_a = 0 c_b = 0 c_c = 0 for v, k in pqr: if k == 1 and c_a < x: ans += v c_a += 1 elif k == 2 and c_b < y: ans += v c_b += 1 elif k == 0 and c_a + c_b + c_c < x + y: ans += v c_c += 1 if c_a + c_b + c_c == x + y: print(ans) exit() if __name__ == "__main__": setrecursionlimit(10000) main()
0
null
26,454,919,747,932
106
188
n = list(map(int, input().split())) print('Yes' if sum(n) % 9 == 0 else 'No')
import sys,math input = sys.stdin.readline n,k = map(int,input().split()) a = [int(i) for i in input().split()] f = [int(i) for i in input().split()] a.sort() f.sort(reverse=True) c = [(i*j,j) for i,j in zip(a,f)] m = max(c) def is_ok(arg): # 条件を満たすかどうか?問題ごとに定義 chk = 0 for i,j in c: chk += math.ceil(max(0,(i-arg))/j) return chk <= k def bisect_ok(ng, ok): ''' 初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す まずis_okを定義 ng = 最小の値-1 ok = 最大の値+1 で最小 最大最小が逆の場合はng ok をひっくり返す ''' while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok print(bisect_ok(-1,m[0]+1))
0
null
84,837,585,958,192
87
290
a,b = input().split() a = int(a) b = int(b) S = a*b C = 2 * (a+b) print(str(S) + " " + str(C))
# B - Bishop H,W = map(int,input().split()) if H>1 and W>1: print((H*W+1)//2) else: print(1)
0
null
25,450,275,992,462
36
196
currAndRot2FBLR = { 'N':{'N':'F','E':'R','S':'B','W':'L'}, 'E':{'E':'F','S':'R','W':'B','N':'L'}, 'S':{'S':'F','W':'R','N':'B','E':'L'}, 'W':{'W':'F','N':'R','E':'B','S':'L'} } dice = { '1': {'F':'2F', 'R':'4R', 'B':'5B', 'L':'3L'}, '2': {'F':'6F', 'R':'4F', 'B':'1F', 'L':'3F'}, '3': {'F':'6L', 'R':'2F', 'B':'1R', 'L':'5F'}, '4': {'F':'6R', 'R':'5F', 'B':'1L', 'L':'2F'}, '5': {'F':'6B', 'R':'3F', 'B':'1B', 'L':'4F'}, '6': {'F':'5B', 'R':'4L', 'B':'2F', 'L':'3R'} } faces = list(map(int, input().split())) cmd = input() ## initial state currNum = '1' currDir = 'N' for c in cmd: numDir = dice[currNum][currAndRot2FBLR[currDir][c]] currNum = numDir[0] currFBLR = numDir[1] currDir = {v:k for k,v in currAndRot2FBLR[currDir].items()}[currFBLR] print(faces[int(currNum) - 1])
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 } dice = [ int( i ) for i in raw_input( ).split( " " ) ] roll = raw_input( ) for i in range( len( roll ) ): if "E" == roll[i]: t = dice[ diceface["TOP"] ] dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ] dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ] dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ] dice[ diceface["RIGHT"] ] = t elif "N" == roll[i]: t = dice[ diceface["TOP"] ] dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ] dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ] dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ] dice[ diceface["BACK"] ] = t elif "S" == roll[i]: t = dice[ diceface["TOP"] ] dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ] dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ] dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ] dice[ diceface["FRONT"] ] = t elif "W" == roll[i]: t = dice[ diceface["TOP"] ] dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ] dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ] dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ] dice[ diceface["LEFT"] ] = t print( dice[ diceface["TOP"] ] )
1
233,580,118,720
null
33
33
A,B = map(int,input().split()) if A - 2*B > 0 : print(A-2*B) else : print("0")
#!/usr/bin/env python3 A, B = [int(s) for s in input().split()] print(A - 2 * B if A - 2 * B > 0 else 0)
1
166,380,606,545,920
null
291
291
n, m = list(map(int, input().split())) A = [] V = [] B = [] for i in range(n): A.append(list(map(int, input().split()))) for j in range(m): V.append([int(input())]) for i in range(n): B.append([0]) for j in range(m): B[i][0] += A[i][j] * V[j][0] for i in range(n): print(B[i][0])
h1, m1, h2, m2, k = map(int, input().split()) s = h1*60+m1 t = h2*60+m2 ans = t-s-k print (max(ans,0))
0
null
9,554,195,330,862
56
139
a,b,c = map(int,(input().split())) d = (a//(b+c))*b + min((a%(b+c)),b) print(d)
#! /usr/bin/env python3 import sys sys.setrecursionlimit(10**9) YES = "Yes" # type: str NO = "No" # type: str INF=10**20 def solve(A: int, B: int, C: int, D: int): while True: C-=B if C <= 0: print(YES) break A-=D if A <= 0: print(NO) break return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int D = int(next(tokens)) # type: int solve(A, B, C, D) if __name__ == "__main__": main()
0
null
42,847,498,008,760
202
164
n = int(input()) ans = '' while n: n -= 1 ans += chr(ord('a') + n % 26) n //= 26 print(ans[::-1])
import sys array = list(map(int,input().split())) if not ( 1 <= min(array) and max(array) <= 100 ): sys.exit() check = lambda x: isinstance(x,int) print(array[2],array[0],array[1])
0
null
25,027,911,711,430
121
178
A, B = map(int, input().split()) ans = A*B if max(A,B)<=9 else -1 print(ans)
a,b=map(int,input().split()) if max(a,b)<10:print(a*b) else:print(-1)
1
157,636,972,946,608
null
286
286
def main(): S = input() T = input() l_s = len(S) l_t = len(T) cnt_list = [] for i in range(l_s - l_t + 1): cnt = 0 S_ = S[i: i+l_t] for j in range(l_t): if S_[j] != T[j]: cnt += 1 cnt_list.append(cnt) ans = min(cnt_list) print(ans) return if __name__ == '__main__': main()
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * from heapq import heapify, heappop, heappush import math import random import string from copy import deepcopy from itertools import combinations, permutations, product from operator import mul, itemgetter from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# N, M = getNM() W = [] V = [] for i in range(M): a, b = getNM() W.append(b) V.append(a) # magicを重複ありで適当に組み合わせて合計Nを目指す def knapsack_4(N, limit, weight, value): dp = [float('inf')] * (limit + 1) dp[0] = 0 for i in range(1, limit + 1): for j in range(N): if i < value[j]: dp[i] = min(dp[i], weight[j]) else: dp[i] = min(dp[i], dp[i - value[j]] + weight[j]) return dp[-1] print(knapsack_4(M, N, W, V))
0
null
42,291,947,418,240
82
229
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)
def main(): # import sys # readline = sys.stdin.readline # readlines = sys.stdin.readlines N = int(input()) A = [(a, i) for i, a in enumerate(map(int, input().split()))] A.sort(reverse=True) dp = [[-float('inf')] * (N + 1) for _ in range(N + 1)] dp[0][0] = 0 for k in range(N): for i in range(k + 1): j = k - i here = dp[i][j] a, idx = A[k] dp[i + 1][j] = max(dp[i + 1][j], here + a * ((N - 1 - i) - idx)) dp[i][j + 1] = max(dp[i][j + 1], here + a * (idx - j)) # print(k, i) ans = 0 for i in range(N + 1): j = N - i ans = max(ans, dp[i][j]) print(ans) if __name__ == "__main__": main()
0
null
70,809,136,986,368
252
171
n = int(input()) a = list(map(int, input().split())) x = 0 for a_i in a: x ^= a_i for a_i in a: print(x ^ a_i)
N = int(input()) a = list(map(int, input().split())) Xsum = 0 for i in a: Xsum = Xsum ^ i ans = list() for i in a: s = Xsum ^ i # print(s) ans.append(str(s)) print(' '.join(ans))
1
12,546,569,768,798
null
123
123
import sys def input(): return sys.stdin.readline().strip() def resolve(): a=int(input()) print(a+a**2+a**3) resolve()
def main(): height, width = map(int, input().split()) grid = [list(input()) for _ in range(height)] dp = [[float("inf") for _ in range(width)] for _ in range(height)] if grid[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 delta = [[0, 1], [1, 0]] for i in range(height): for j in range(width): for dx, dy in delta: if i + dy >= height or j + dx >= width: continue else: add = 0 if grid[i][j] == "." and grid[i + dy][j + dx] == "#": add = 1 dp[i + dy][j + dx] = min(dp[i + dy][j + dx], dp[i][j] + add) print(dp[-1][-1]) if __name__ == '__main__': main()
0
null
29,840,289,075,210
115
194
N = int(input()) lst = list(map(int, input().split())) c = True for i in lst: if i%2 ==0: if i%3 != 0 and i%5 != 0: c = False break if c: print('APPROVED') else: print('DENIED')
n=int(input()) a=list(map(int,input().split())) for i in a: if i%2==0 and i%3!=0 and i%5!=0: print("DENIED") exit() print("APPROVED")
1
68,611,897,899,132
null
217
217
k = int(input()) print('ACL' * k)
n = int(input()); print(n*"ACL");
1
2,176,080,326,530
null
69
69
a = input() if a == "RSR": print(1) else : print(a.count("R"))
s = input() p = input() ring = s * 2 if p in ring: print("Yes") else: print("No")
0
null
3,292,872,913,656
90
64
r = input() print(r[0:3])
a=map(int,raw_input().split()) if 0<=a[2]-a[4] and a[2]+a[4]<=a[0] and 0<=a[3]-a[4] and a[3]+a[4]<=a[1]: print "Yes" else: print "No"
0
null
7,627,088,104,678
130
41
N=int(input()) S,T=map(str,input().split()) l=[] a,b=0,0 for i in range(N*2): if (i+1)%2!=0: l.append(S[a]) a+=1 else: l.append(T[b]) b+=1 print(''.join(l))
n = int(input()) s,t = input().split() for i in range(n): print(s[i]+t[i],end="")
1
111,985,921,158,628
null
255
255
n, k = map(int, input().split()) mod = 10**9 + 7 res = 0 z = n*(n+1)//2 for x in range(k, n+2): min_ = (x-1)*x//2 max_ = z - (n-x)*(n+1-x)//2 res += max_ - min_ + 1 res %= mod print(res)
n,k = map(int,input().split()) ans = 1 y = sum(list(range(n-k+2,n+1))) j = n - k + 1 for i in range(k,n+1): x = (1+(i-1))*(i-1)//2 y += j j -= 1 ans += y - x + 1 ans %= 10 ** 9 + 7 print(ans)
1
33,186,284,539,668
null
170
170
def resolve(): ''' code here ''' import collections import numpy as np H, W = [int(item) for item in input().split()] grid = [[item for item in input()] for _ in range(H)] dp = [[300 for _ in range(W+1)] for _ in range(H+1)] for i in range(H): for j in range(W): if i == 0 and j == 0: if grid[0][0] == '#': dp[i+1][j+1] = 1 else: dp[i+1][j+1] = 0 else: add_v = 0 add_h = 0 if grid[i][j] != grid[i][j-1]: add_h = 1 if grid[i][j] != grid[i-1][j]: add_v = 1 dp[i+1][j+1] = min(dp[i+1][j]+add_h, dp[i][j+1]+add_v) # print(dp) if grid[H-1][W-1] == '#': print(dp[H][W]//2+1) else: print(dp[H][W]//2) if __name__ == "__main__": resolve()
import math def main(): n = int(input()) ans = 0 for i in range(n): x = int(input()) if x == 2: ans += 1 elif x % 2 == 0: pass else: flag = True j = 3 while j <= math.sqrt(x): if x % j == 0: flag = False break j += 2 if flag: ans += 1 print(ans) if __name__ == '__main__': main()
0
null
24,736,210,842,350
194
12
from math import gcd # X * K = 360 * n lcm = lambda x, y: (x * y) // gcd(x, y) X = int(input()) print(lcm(X, 360) // X)
import math n=int(input()) a=360/n b=a-360//n print(int(n*360/math.gcd(n,360)/n))
1
12,997,808,649,540
null
125
125
H,W,K = map(int,input().split()) S = [input() for i in range(H)] ans = H+W+9999 for b in range(1<<(H-1)): mp = [0] k = 0 for i in range(H-1): if b&(1<<i): k += 1 mp.append(k) tmp = bin(b).count('1') ws = [0] * H muri = False for col in zip(*S): for i,c in enumerate(col): if c == '1': ws[mp[i]] += 1 if any(w > K for w in ws): ws = [0] * len(mp) for i,c in enumerate(col): if c == '1': ws[mp[i]] += 1 if any(w > K for w in ws): muri = True break tmp += 1 if muri: break if not muri: ans = min(ans, tmp) print(ans)
## coding: UTF-8 N, P = map(int,input().split()) S = input()[::-1] remainder = [0] * P tmp = 0 rad = 1 #10**(i) % P ''' if(P == 2 or P == 5): for i in range(N): r = int(S[i]) tmp += r * rad tmp %= P remainder[tmp] += 1 rad *= 10 ''' if(P == 2): ans = 0 for i in range(N): r = int(S[i]) if(r % 2 == 0): ans += N-i print(ans) elif(P == 5): ans = 0 for i in range(N): r = int(S[i]) if(r % 5 == 0): ans += N-i print(ans) else: for i in range(N): r = int(S[i]) tmp += r * rad tmp %= P remainder[tmp] += 1 rad *= 10 rad %= P remainder[0] += 1 #print(remainder) ans = 0 for i in range(P): e = remainder[i] ans += e*(e-1)/2 print(int(ans))
0
null
53,346,274,088,590
193
205
a,b,c,d=input().split() a = int(a) b = int(b) c = int(c) d = int(d) z1 = a*c z2 = a*d z3 = b*c z4 = b*d l = [z1, z2, z3, z4] max_value = max(l) print(max_value)
a, b, c, d = map(int, input().split()) h = a * c i = a * d j = b * c k = b * d print(max(h, i, j, k))
1
3,032,693,882,388
null
77
77
N = input() sum = 0 for i in range(10): sum += N.count(str(i)) * i print('Yes' if sum%9 == 0 else 'No')
n,k=map(int,input().split()) a=n//k print(min(abs(n-a*k),abs(n-(a+1)*k)))
0
null
21,940,964,757,088
87
180
# cook your dish here a,b,c = map(int, input().split()) k = int(input()) c1, c2 = 0, 0 while b<=a: b=b*2 c1 = c1 + 1 while c <= b: c=c*2 c2 = c2 +1 if c1 + c2 <= k: print('Yes') else: print('No')
red, green, blue = map(int, input().split()) k = int(input()) success = 0 for cnt in range(k+1): if red >= green: green *= 2 elif red >= blue: blue *= 2 elif green >= blue: blue *= 2 else: success = 1 break if success == 1: print('Yes') else: print('No')
1
6,906,047,450,552
null
101
101
import math n = int(input()) towns = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n-1): x1, y1 = towns[i] for j in range(i+1, n): x2, y2 = towns[j] ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)*(n-1)*2 print(ans/((n-1)*n))
S=input() count=[0] s=0 for i in range(3): if S[i]=='R': if i==2 or S[i+1]=='S': s=s+1 count.append(s) s=0 else: s=s+1 print(max(count))
0
null
76,399,204,479,510
280
90
N = int(input()) def solve(N): fib = [1]*(N+1) for i in range(2,N+1): fib[i] = fib[i-1] + fib[i-2] ans = fib[N] return ans print(solve(N))
#coding:utf-8 import sys,os sys.setrecursionlimit(10**6) write = sys.stdout.write dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0 def main(given=sys.stdin.readline): input = lambda: given().rstrip() LMIIS = lambda: list(map(int,input().split())) II = lambda: int(input()) XLMIIS = lambda x: [LMIIS() for _ in range(x)] YN = lambda c : print('Yes') if c else print('No') MOD = 10**9+7 n,a,b = LMIIS() def cmb(n,r): if r == 0: return 0 res = 1 r = min(r,n-r) for i in range(n-r+1,n+1): res *= i res %= MOD for i in range(1,r+1): res *= pow(i,(MOD-2),MOD) res %= MOD return res print((pow(2,n,MOD)-cmb(n,a)-cmb(n,b)-1)%MOD) if __name__ == '__main__': main()
0
null
33,107,902,989,902
7
214
# ????????? n ?¬?????????????????????????p ??????????????? 1???2???3????????? ?????????????????????????????¢????±???????????????°?????? import math # ?¬??????°n????¨??????\??????????????? n = int(input()) # ????????????x????¨??????\??????????????? x = list(input()) x = "".join(x).split() # ????????????y????¨??????\??????????????? y = list(input()) y = "".join(y).split() # p=1,2,????????§???????????????????????????????????¢???????´????????????? # ????????????????????? dxy = [0 for i in range(4)] # p=1???????????????????????????????????¢????¨???? for i in range(0, n): dxy[0] += math.fabs(int(x[i]) - int(y[i])) # p=2 for i in range(0, n): dxy[1] += (math.fabs(int(x[i]) - int(y[i]))) ** 2 dxy[1] = math.sqrt(dxy[1]) # p=3 for i in range(0, n): dxy[2] += (math.fabs(int(x[i]) - int(y[i]))) ** 3 dxy[2] = math.pow(dxy[2], 1.0 / 3.0) # p=????????§ dxy[3] = math.fabs(int(x[0]) - int(y[0])) for i in range(1, n): if dxy[3] < math.fabs(int(x[i]) - int(y[i])): dxy[3] = math.fabs(int(x[i]) - int(y[i])) # ?????? for i in range(0, 4): print("{0}".format(dxy[i]))
from bisect import bisect_left N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() def doesOver(k): cnt = 0 for a in A: cnt += N - bisect_left(A, k - a) return cnt >= M overEq = 0 less = A[-1] * 2 + 100 while less - overEq > 1: mid = (less + overEq) // 2 if doesOver(mid): overEq = mid else: less = mid accA = [0] * (N + 1) for i in range(1, N + 1): accA[i] = accA[i - 1] + A[i - 1] ans = 0 cnt = 0 for a in A: left = bisect_left(A, overEq - a) ans += accA[N] - accA[left] ans += (N - left) * a cnt += N - left ans -= (cnt - M) * overEq print(ans)
0
null
54,184,837,810,308
32
252
from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall def solve(): N, M, L = map(int, input().split()) dist = [[0 for _ in range(N)] for _ in range(N)] for i in range(M): a, b, c = map(int, input().split()) dist[a-1][b-1] = c dist[b-1][a-1] = c fw = floyd_warshall(csr_matrix(dist)) ok = [[0 for _ in range(N)] for _ in range(N)] for i in range(N): for j in range(N): if fw[i][j] <= L: ok[i][j] = 1 ans = floyd_warshall(csr_matrix(ok)) Q = int(input()) for i in range(Q): s, t = map(lambda x: int(x)-1, input().split()) if ans[s][t] < N: print(int(ans[s][t])-1) else: print(-1) if __name__ == '__main__': solve()
import sys input = sys.stdin.readline class WarshallFloyd: def __init__(self,n): self.v = n self.d = [[1e100]*n for _ in range(n)] for i in range(n): self.d[i][i] = 0 def path(self,x,y,c): if x == y: return False self.d[x][y] = c self.d[y][x] = c return True def build(self): for k in range(self.v): for i in range(self.v): for j in range(self.v): self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j]) n,m,l = map(int,input().split()) wf = WarshallFloyd(n) for i in range(m): a,b,c = map(int,input().split()) wf.path(a-1,b-1,c) wf.build() d = [[1e100]*n for _ in range(n)] for i in range(n): for j in range(n): if i == j: d[i][j] = 0 elif wf.d[i][j] <= l: d[i][j] = 1 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) q = int(input()) for i in range(q): s,t = map(int,input().split()) ans = d[s-1][t-1] if ans == 1e100: print(-1) else: print(ans - 1)
1
173,629,746,866,822
null
295
295
pen = int(input()[-1]) if pen in [2, 4, 5, 7, 9]: print('hon') elif pen in [0, 1, 6, 8]: print('pon') elif pen in [3]: print('bon')
kazu = int(input()) kazu2 = (kazu % 100) % 10 if kazu2 == 3: print("bon") elif kazu2 == 0 or kazu2 == 1 or kazu2 == 6 or kazu2 == 8: print("pon") else: print("hon")
1
19,218,534,352,160
null
142
142
N = int(input()) b=[] c=[] for j in range(N): a = input() b.append(a) c = set(b) print(len(c))
S = input() ans = 'Yes' while S: if S.startswith('hi'): S = S[2:] else: ans = 'No' break print(ans)
0
null
41,736,076,259,940
165
199
s = list(input()) if s[-1] == 's': s.append('es') else: s.append('s') print(''.join(s))
s = input().strip() if s[-1]=='s': s += 'es' else: s += 's' print(s)
1
2,350,822,181,368
null
71
71
s = input() t = input() ls = len(s) lt = len(t) ret = lt for i in range(ls+1 - lt): diff = 0 for j in range(lt): diff += (t[j] != s[i+j]) if diff == 0: ret = diff break if diff < ret: ret = diff print(ret)
S = input() T = input() # S = "cabacc" # T = "abc" lt = len(T) def diff(s1, s2): d = len(s1) d -= len([i for i,j in zip(s1, s2) if i == j]) return d dlen = 1000000000 for i in range(len(S)): if i + lt <= len(S): dlen = min(dlen, diff(T, S[i:i+lt])) print(dlen)
1
3,675,773,257,380
null
82
82
j = [] for i in range(10) : j.append(int(input())) j.sort(reverse = True) for k in range(3) : print(j[k])
h=[] for i in range(10): h.append((int)(input())) h.sort() h.reverse() for i in range(3): print(h[i])
1
24,152,828
null
2
2
abcd = list(map(int, input().split())) max_pro = -float("inf") for i in range(2): for j in range(1,3): product = abcd[i] * abcd[-j] if max_pro < product: max_pro = product print(max_pro)
(X1,X2,Y1,Y2)=list(map(int,input().split())) ans=max(X2*Y2,X1*Y1,X1*Y2,X2*Y1) print (ans)
1
3,051,714,527,400
null
77
77
#!/usr/bin python3 # -*- coding: utf-8 -*- def main(): A, B = map(int, input().split()) print(max(0,A-2*B)) if __name__ == '__main__': main()
a,b=map(int,input().split()) result=a-b*2 if result > 0: print(result) else: print(0)
1
167,302,587,126,428
null
291
291
A, B, N = map(int, input().split()) if (B-1) >= N: Max = ((A*N) // B) - A*(N // B) elif (B-1) < N: Max = ((A*(B-1)) // B) - A*((B-1) // B) print(Max)
print("".join('x' for i in range(len(input()))))
0
null
50,485,407,438,840
161
221
def main(): x = int(input()) print((2000-x)//200 + 1 if x %200 != 0 else (2000-x)//200) if __name__ == '__main__': main()
C = input() n = chr(ord(C)+1) print(n)
0
null
49,376,570,740,448
100
239
S=str(input()) if S.count('R')==0: print(0) if S.count('R')==1 : print(1) if S.count('R')==2 and not S.count('RR') ==1: print(1) if S.count('RR')==1 and not S.count('RRR')==1: print(2) if S.count('RRR')==1: print(3)
import sys from sys import stdin input = stdin.readline n,k = (int(x) for x in input().split()) w = [int(input()) for i in range(n)] # 最大積載Pのトラックで何個の荷物を積めるか def check(P): i = 0 for j in range(k): s = 0 while s + w[i] <= P: s += w[i] i += 1 if i == n: return n return i def solve(): left = 0 right = 100000 * 10000 #荷物の個数 * 1個当たりの最大重量 while right - left > 1 : mid = (right + left)//2 v = check(mid) if v >= n: right = mid else: left = mid return right print(solve())
0
null
2,460,116,504,480
90
24
n, x, m = map(int,input().split()) amari = [0]*m v = [x] cnt = 0 while True: xn_1 = x**2%m cnt += 1 if x == 0: break amari[x] = xn_1 if amari[xn_1]: break v.append(xn_1) x = xn_1 #print(v) if 0 in v: ans = sum(v) else: ind = v.index(xn_1) rooplen = len(v) - ind ans = sum(v[0:ind]) l = n-ind if rooplen: ans += (l//rooplen)*sum(v[ind:]) nokori = l - rooplen*(l//rooplen) ans += sum(v[ind:ind+nokori]) #print(v) print(ans)
N, X, M = [int(x) for x in input().split()] A = [0] * (M + 1) firstApearAt = {i:0 for i in range(M)} A[1] = X firstApearAt[X] = 1 l, r = 1, 2 for i in range(2, M + 1): A[i] = (A[i - 1] * A[i - 1]) % M if firstApearAt[A[i]] > 0: r = i l = firstApearAt[A[i]] break firstApearAt[A[i]] = i ans = 0 if N <= l - 1: ans = sum(A[1:N + 1]) else: q, p = (N - l + 1) // (r - l), (N - l + 1) % (r - l) ans = sum(A[1:l]) + q * sum(A[l:r]) + sum(A[l:l + p]) print(ans)
1
2,811,700,386,912
null
75
75
def main(): s = input() dp = [0, 1] for c in s: x = int(c) a = dp[0] + x if a > dp[1] + 10 - x: a = dp[1] + 10 - x b = dp[0] + x + 1 if b > dp[1] + 10 - x - 1: b = dp[1] + 10 - x - 1 dp[0] = a dp[1] = b dp[1] += 1 print(min(dp)) if __name__ == "__main__": main()
s = "0"+input() ans = 0 n = len(s) f = 0 p = 0 for i in range(1,n+1): n = int(s[-i]) # n += f if p+(n>4) > 5: f = 1 else: # ans += f f = 0 n += f ans += min(n,10-n) p = n # ans += f print(ans)
1
71,186,973,502,732
null
219
219
def resolve(): N, M = list(map(int, input().split())) AB = {} for _ in range(M): a, b = list(map(int, input().split())) a, b = a-1, b-1 if a not in AB: AB[a] = [] if b not in AB: AB[b] = [] AB[a].append(b) AB[b].append(a) import collections q = collections.deque([0]) passed = [-1 for i in range(N)] passed[0] = 0 while q: node = q.pop() for nxt in AB[node]: if passed[nxt] == -1: passed[nxt] = node q.appendleft(nxt) #print(metrics) for m in passed: if m == -1: print("No") return print("Yes") for i in range(1, N): print(passed[i]+1) if '__main__' == __name__: resolve()
r=input();p=3.1415926535897;print "%.9f"%(p*r*r),r*2*p
0
null
10,629,834,340,582
145
46
import sys import math import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): K = int(input()) S = input().strip() MOD = 10 ** 9 + 7 fact = [1, 1] factinv = [1, 1] inv = [0, 1] def cmb(n, k, p): if (k < 0) or (n < k): return 0 r = min(k, n - k) return fact[n] * factinv[k] * factinv[n - k] % p N = 10 ** 6 * 2 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) ans = 0 a = 1 b = pow(26, K, MOD) for i in range(K + 1): ans += a * cmb(i + len(S) - 1, len(S) - 1, MOD) * b a = a * 25 % MOD b = b * pow(26, MOD - 2, MOD) % MOD print(ans % MOD) if __name__ == '__main__': main()
def main(): nums = list(map(int,input().split())) for i,n in enumerate(nums): if n == 0: return i + 1 if __name__ == '__main__': print(main())
0
null
13,113,516,063,800
124
126
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines S = read().rstrip().decode() x = ['ABC', 'ARC'] x.remove(S) print(x[0])
# A - Sum of Two Integers N = int(input()) if N % 2 == 1: N += 1 print(int(N / 2 - 1))
0
null
89,118,787,788,842
153
283
N=int(input());S,T=map(str,input().split()) for i in range(N):print(S[i],end='');print(T[i],end='')
from math import gcd s = int(input()) print(360//gcd(360,s))
0
null
62,702,680,979,560
255
125
table = [[[ 0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) i = 0 while i < n: b,f,r,v = (int(x) for x in input().split()) table[b-1][f-1][r-1] += v i += 1 for i,elem_i in enumerate(table): # building for j,elem_j in enumerate(elem_i): # floor for k, elem_k in enumerate(elem_j): # room print (" " + str(elem_k), end='') print ("") if i != 3: print ("####################")
import itertools import bisect n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a_acc = [0] + list(itertools.accumulate(a)) b_acc = [0] + list(itertools.accumulate(b)) ans = 0 for i in range(n+1): if k - a_acc[i] >= 0: ans = max(ans, i + bisect.bisect(b_acc, k - a_acc[i])-1) print(ans)
0
null
5,975,918,500,200
55
117
string = input() hon = ["2", "4", "5", "7", "9"] pon = ["0", "1", "6", "8"] if string[-1] in hon: print("hon") elif string[-1] in pon: print("pon") else: print("bon")
# -*- coding: utf-8 -*- """ コッホ曲線 参考:https://www.mynote-jp.com/entry/2016/04/30/201249    https://atarimae.biz/archives/23930 ・回転行列を使うと、向きの変わった座標が出せる。 ・そのために行列の計算方法も確認。  →m行n列成分は、「左の行列のm行目」と「右の行列のn列目」の内積 """ from math import sin, cos, radians N = int(input()) def dfs(p1x, p1y, p2x, p2y, depth): if depth == N: return sx = p1x + (p2x-p1x)/3 tx = p1x + (p2x-p1x)/3*2 sy = p1y + (p2y-p1y)/3 ty = p1y + (p2y-p1y)/3*2 # s,tを基準の位置として左回りに60度回転させる ux = sx + (tx-sx) * cos(radians(60)) - (ty-sy) * sin(radians(60)) uy = sy + (tx-sx) * sin(radians(60)) + (ty-sy) * cos(radians(60)) # 再帰が終了した場所から出力していけば、線分上の各頂点の順番になる dfs(p1x, p1y, sx, sy, depth+1) print(sx, sy) dfs(sx, sy, ux, uy, depth+1) print(ux, uy) dfs(ux, uy, tx, ty, depth+1) print(tx, ty) dfs(tx, ty, p2x, p2y, depth+1) print(0, 0) dfs(0, 0, 100, 0, 0) print(100, 0)
0
null
9,596,221,569,632
142
27