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 bisect import math N, D, A = map(int, input().split()) cusum = [0] * (N+1) X = [] XH =[] for i in range(N): xi, hi = map(int, input().split()) X += [xi] XH += [(xi, hi)] X = sorted(X) XH = sorted(XH) cusumD = 0 ans = 0 for i, (xi, hi) in enumerate(XH): cusumD -= cusum[i] hi = max(0, hi-cusumD) r = bisect.bisect_right(X, xi+2*D) b = int(math.ceil(hi/A)) d = b * A ans += b cusumD += d cusum[r] += d print(ans)
H,A = map(int,input().split()) cnt = 0 while True: if H <= 0: print(cnt) break else: H -= A cnt += 1
0
null
79,668,040,960,380
230
225
# 155 A a, b, c = input().split() if a == b == c or (a != b and b != c and c != a): print("No") else: print("Yes")
S=input()[::-1] ans=0 #支払う枚数 array = list(map(int, S)) L=len(array) for i,n in enumerate(array): if n< 5 : ans+=n elif n > 5: ans+= 10-n if i <L-1: array[i+1] +=1 else: ans +=1 else: ans+=5 if i < L-1: if array[i+1] >=5: array[i+1] +=1 print( ans)
0
null
69,182,068,907,406
216
219
S = input() out = 'ABC' if S == 'ARC' else 'ARC' print(out)
S = input() if S[1:2] == "R": print("ABC") else: print("ARC")
1
23,989,674,467,374
null
153
153
import sys readline = sys.stdin.readline n = int(readline()) s = readline().rstrip() from collections import deque q = deque([]) ss = set(s) for i in ss: q.append(["",0,str(i)]) ans = 0 while q: num, ind, target = q.popleft() #print(num, ind, target) while ind < len(s): if s[ind] == target: #s[ind]が0から9の中のどれかを見てる break ind += 1 else: continue num += target if len(num) == 3: ans += 1 continue sss = set(s[ind+1:]) for i in sss: q.append([num, ind +1, str(i)]) #出現した数字に関するキューを追加(例:一回目は024) print(ans)
#import sys #import numpy as np import math #from fractions import Fraction import itertools from collections import deque from collections import Counter #import heapq #from fractions import gcd #input=sys.stdin.readline import bisect n=int(input()) a=list(map(int,input().split())) b_d=[[0,0] for _ in range(n+1)] b_u=[[0,0] for _ in range(n+1)] b_d[n]=[a[n],a[n]] b_u[0]=[1,1] for i in range(1,n+1): l=(1+b_d[n+1-i][0])//2+a[n-i] r=(b_d[n+1-i][1])+a[n-i] if l>r: print(-1) exit() break b_d[n-i]=[l,r] l=max(0,b_u[i-1][0]-a[i-1]) r=2*(b_u[i-1][1]-a[i-1]) if l>r: print(-1) exit() break b_u[i]=[l,r] ans=0 for i in range(n+1): if b_d[i][0]>b_u[i][1] or b_u[i][0]>b_d[i][1]: print(-1) exit() else: ans+=min(b_u[i][1],b_d[i][1]) print(ans)
0
null
73,978,826,283,878
267
141
n = int(input()) MOD = 10**9+7 a=10 b=9 c=8 for i in range(n-1): a*=10 b*=9 c*=8 if i%10==0: a=a%MOD b=b%MOD c=c%MOD a=a%MOD b=b%MOD c=c%MOD ans = (a-2*b+c)%MOD print(ans)
#!/usr/bin/env python #coding: UTF-8 while True: h,w = map(int,raw_input().split()) if h+w==0: break else: print w*'#'# ??????#### for hight in range(h-2): print '#'+(w-2)*'.'+'#' print w*'#'#????????????#### print
0
null
2,022,982,189,888
78
50
# -*- coding: utf-8 -*- import math a, b, C = map(float, input().split()) c = math.sqrt((a * a) + (b * b) - 2 * a * b * math.cos(math.radians(C))) s = (a * b * math.sin(math.radians(C))) / 2 l = a + b + c h = (2 * s) / a print(s) print(l) print(h)
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() M = 1046527 NIL = -1 H = [None] * M com = [] ch = [] for i in range(n): com_, ch_ = input().split() com.append(com_) ch.append(ch_) table = str.maketrans({ 'A':'1', 'C':'2', 'G':'3', 'T':'4', }) def getChar(ch): return int(ch.translate(table)) def h1(key): return key % M def h2(key): return 1 + (key % (M - 1)) def insert(ch): key = getChar(ch) i = 0 while True: h = (h1(key) + i * h2(key)) % M if H[h] is None: H[h] = ch break else: i += 1 def find(ch): key = getChar(ch) i = 0 while True: h = (h1(key) + i * h2(key)) % M if H[h] == ch: return 1 elif H[h] is None: return 0 else: i += 1 for i in range(n): if com[i][0] == 'i': insert(ch[i]) else: if find(ch[i]): print('yes') else: print('no')
0
null
131,585,765,220
30
23
N,A,B = [int(x) for x in input().split()]; #print(A); #print(B); #print(N); #lm = int(A + (B-A-1)/2); lm = A + (B-A-1)//2; #print(lm); #rm = int(N-B+1 + (B-A-1)/2); rm = N-B+1 + (B-A-1)//2; #print(rm); if (B-A)%2 == 0 : print((B-A)//2); else : print(min(lm,rm));
from collections import deque N,M = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(M)] G = {i:[] for i in range(N+1)} for a,b in AB: G[a].append(b) G[b].append(a) parent = [0]*(N+1) parent[0]==-1 parent[1]==-1 q = deque() q.append(1) while len(q)>0: room = q.popleft() child = G[room] for i in child: if parent[i] == 0: parent[i] = room q.append(i) if min(parent[2:])==0: print('No') else: print('Yes') for i in parent[2:]: print(i)
0
null
64,766,626,511,018
253
145
a,b=map(int,input().split()) c=b*10 for i in range(c,c+10): if int(i*0.08)==a: print(i) exit() print(-1)
N,A,B = map(int,input().split()) d,m = divmod(N,A+B) print(d*A + min(A,m))
0
null
56,078,234,686,880
203
202
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def nPr(n: int, r: int) -> int: return math.factorial(n) // math.factorial(n - r) def nCr(n: int, r: int) -> int: return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def solve(N: int, M: int): return (nCr(N, 2)if N > 1 else 0) + (nCr(M, 2) if M > 1 else 0) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int print(f'{solve(N, M)}') if __name__ == '__main__': main()
N, M = map(int, input().split()) if N < 2: A = 0 else: A = int(N * (N - 1) / 2) if M < 2: B = 0 else: B = int(M * (M - 1) / 2) print(A + B)
1
45,759,396,393,852
null
189
189
x = input() if len(x) < 3: print(0) exit() k = int(x[0:-2]) x = int(x[-2:]) k -= x / 5 if x % 5 == 0 and k >= 0: print(1) elif k > 0: print(1) else: print(0)
X = int(input()) x = X%100 cnt = 0 cnt += x//5 x = x%5 cnt += x//4 x = x%4 cnt += x//3 x = x%3 cnt += x//2 x = x%2 cnt += x X = X-X%100 if X>=100*cnt: print(1) else: print(0)
1
127,410,533,773,978
null
266
266
import sys input = sys.stdin.readline from collections import * def bfs(): q = deque([0]) pre = [-1]*N pre[0] = 0 while q: v = q.popleft() for nv in G[v]: if pre[nv]==-1: pre[nv] = v q.append(nv) return pre N, M = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): A, B = map(int, input().split()) G[A-1].append(B-1) G[B-1].append(A-1) pre = bfs() print('Yes') for pre_i in pre[1:]: print(pre_i+1)
# A - Sum of Two Integers N = int(input()) if N % 2 == 1: N += 1 print(int(N / 2 - 1))
0
null
87,177,067,747,542
145
283
n=int(input()) k=int(input()) def main(N,K): ans=0 if N<=100+10**6: for i in range(1,N+1): a=str(i) if len(a)-list(a).count("0")==K: ans+=1 return ans L=list(map(int,list(str(N)))) ans=0 L=list(map(int,list(str(N)))) if K==1:#おけ return (len(str(N))-1)*9+int(str(N)[0]) elif K==2:#おけ for i in range(len(L)-1): ans+=(9*(int(str(N)[0])-1)) for j in range(i+1,len(L)): if i==0: if j==1: ans+=int(str(N)[1]) else: ans+=9 else: ans+=81 return ans else: le=len(L) for i in range(le-2): for j in range(i+1,le-1): for k in range(j+1,le): if i==0: ans+=81*(int(str(N)[0])-1) if j==1: ans+=9*(int(str(N)[1])-1) if k==2: ans+=int(str(N)[2]) else: ans+=9 else: ans+=81 else: ans+=729 return ans ans2=0 L=list(str(n)) a=len(L) for i in range(a): L=list(str(n)) s=L[:a-i-1] t=L[a-i-1:] t=int("".join(t)) p=s.count("0") p=len(s)-p if p>k: n-=t+1 elif p==k: n-=t+1 ans2+=1 else: ans2+=main(t,k-p) n-=t+1 print(ans2)
import sys from functools import lru_cache N = int(sys.stdin.readline().rstrip()) K = int(sys.stdin.readline().rstrip()) @lru_cache(None) def F(N, K): """(0以上)N以下で、0でないものがちょうどK個""" assert N >= 0 # Nが非負であることを保証する if N < 10: # N が一桁 if K == 0: # 使える 0 以外の数がない場合 return 1 # if K == 1: return N # 1,2,...,N までのどれか return 0 # それ以上 K が余っていたら作れない q, r = divmod(N, 10) # N = 10*q + r と置く ret = 0 if K >= 1: # 1の位(r)が nonzero ret += F(q, K - 1) * r # ret += F(q - 1, K - 1) * (9 - r) # 1の位(r)が zero ret += F(q, K) return ret print(F(N, K))
1
76,239,299,233,060
null
224
224
a=int(input()) b='' for i in range(a): b=b+'ACL' print(b)
def popcount_int(n): return bin(n).count('1') def popcount_bin(s): return s.count('1') def poptimes(n,cnt=1): if n==0: return cnt else: n%=popcount_int(n) cnt+=1 return poptimes(n,cnt) N=int(input()) S=input() S_int=int(S,2) pc=popcount_bin(S) pc_plus=S_int%(pc+1) if pc!=1: pc_minus=S_int%(pc-1) for i in range(N): if S[i]=='1': if pc!=1: tmp=pc_minus-pow(2,N-i-1,pc-1) print(poptimes(tmp%(pc-1))) else: print(0) continue else: tmp=pc_plus+pow(2,N-i-1,pc+1) print(poptimes(tmp%(pc+1)))
0
null
5,131,294,245,646
69
107
# ABC160-B import sys def I(): return int(sys.stdin.readline().rstrip()) X = I() print(1000*(X//500) + 5*((X % 500)//5))
N, M, K = map(int, input().split()) mod = 998244353 inv = [0,1] for i in range(2, N): inv.append((-inv[mod%i]*(mod//i))%mod) if N == 1: print(M) exit() m = [1] s = 1 for _ in range(N-1): s = s*(M-1)%mod m.append(s) ncombi = [1] c = 1 for k in range(K): c = c*(N-1-k)*inv[k+1] c %= mod ncombi.append(c) ans = 0 for k in range(K+1): ans = ans + m[-k -1]*ncombi[k] ans %= mod ans = ans*M%mod print(ans)
0
null
32,893,171,603,200
185
151
while True: (n, x) = [int(i) for i in input().split()] if n == x == 0: break dataset = [] for a in range(1, n + 1): for b in range(a + 1, n + 1): for c in range(b + 1, n + 1): dataset.append([a,b,c]) count = 0 for data in dataset: if sum(data) == x: count += 1 print(count)
from itertools import combinations while True: n, x = map(int, input().split()) if not n: break print(sum(1 for cmb in combinations(range(1, n + 1), 3) if sum(cmb) == x))
1
1,312,249,048,218
null
58
58
from collections import deque H, W = map(int, input().split()) L = [str(input()) for _ in range(H)] ans = 0 for h in range(H): for w in range(W): if L[h][w] == '#': continue else: flag = [[-1] * W for _ in range(H)] depth = [[0] * W for _ in range(H)] flag[h][w] = 0 q = deque([(h, w)]) while q: i, j = q.popleft() d = depth[i][j] if i != H - 1: if L[i+1][j] == '.' and flag[i+1][j] < 0: flag[i+1][j] = 0 depth[i+1][j] = d + 1 q.append((i+1, j)) if i != 0: if L[i-1][j] == '.' and flag[i-1][j] < 0: flag[i-1][j] = 0 depth[i-1][j] = d + 1 q.append((i-1, j)) if j != W - 1: if L[i][j+1] == '.' and flag[i][j+1] < 0: flag[i][j+1] = 0 depth[i][j+1] = d + 1 q.append((i, j+1)) if j != 0: if L[i][j-1] == '.' and flag[i][j-1] < 0: flag[i][j-1] = 0 depth[i][j-1] = d + 1 q.append((i, j-1)) ans = max(ans, d) print(ans)
N = int(input()) R = [int(input()) for _ in range(N)] p_buy = R[0] p_sale = R[1] buy = R[1] sale = None for i in range(2, N): if p_sale < R[i]: p_sale = R[i] if buy > R[i]: if sale is None: sale = R[i] if p_sale - p_buy < sale - buy: p_sale, p_buy = sale, buy sale, buy = None, R[i] else: if sale is None or sale < R[i]: sale = R[i] p_gain = p_sale - p_buy print(p_gain if sale is None else max(p_gain, sale - buy))
0
null
47,005,488,852,790
241
13
from math import gcd from math import factorial as f from math import ceil,floor,sqrt import bisect import re import heapq from copy import deepcopy import itertools from sys import exit ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) yes = "unsafe" no = "safe" def main(): s,w = mi() if w>=s: print(yes) else: print(no) main()
S, W = map(int, input().split(' ')) if S <= W: print('unsafe') else: print('safe')
1
29,141,200,583,052
null
163
163
import math n = int(input()) a = [0, 0] b = [100, 0] root3 = math.sqrt(3) def koch(a, b, n): if n == 1: s = [(a[0] * 2 + b[0]) / 3, (a[1] * 2 + b[1]) / 3] t = [(a[0] + b[0] * 2) / 3, (a[1] + b[1] * 2) / 3] u = [(s[0] + t[0] - root3 * t[1] + root3 * s[1]) / 2, (s[1] + t[1] + root3 * t[0] - root3 * s[0]) / 2] print(*s) print(*u) print(*t) print(*b) elif n > 1: s = [(a[0] * 2 + b[0]) / 3, (a[1] * 2 + b[1]) / 3] t = [(a[0] + b[0] * 2) / 3, (a[1] + b[1] * 2) / 3] u = [(s[0] + t[0] - root3 * t[1] + root3 * s[1]) / 2, (s[1] + t[1] + root3 * t[0] - root3 * s[0]) / 2] koch(a, s, n-1) koch(s, u, n-1) koch(u, t, n-1) koch(t, b, n-1) print(*a) koch(a, b, n) if n == 0: print(*b)
s = [input() for i in range(2)] count=0 for item1, item2 in zip(s[0], s[1]): if (item1 != item2): count +=1 print(count)
0
null
5,349,267,123,524
27
116
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()
a, b = input().split() a, b = int(a), int(b) print('%d %d' % (a * b, 2 * (a + b)))
0
null
31,603,491,112,632
210
36
import sys import math for line in sys.stdin: a = line.split() print int(math.log10(int(a[0]) + int(a[1]))) + 1
import sys, math def run(): N = [] for n in sys.stdin: a,b = map(int, n.split()) N.append((a,b)) for a,b in N: print(math.floor(math.log10(a+b)) + 1) if __name__ == '__main__': run()
1
114,026,088
null
3
3
# 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))
import sys while True: height, width = map(int, raw_input().split()) if height == 0 and width == 0: break for i in range(height): for j in range(width): if j % 2 == 0 and i % 2 == 0: #even n, even n sys.stdout.write("#") elif j % 2 != 0 and i % 2 == 0: #even n, odd n sys.stdout.write(".") elif j % 2 == 0 and i % 2 != 0: #odd n, even n sys.stdout.write(".") elif j % 2 != 0 and i % 2 != 0: #odd n, odd n sys.stdout.write("#") print print
0
null
17,935,021,270,582
173
51
n,m = map(int, input().split()) c=0 if n>1 : c+=n*(n-1) //2 if m>1 : c+=m*(m-1) //2 print(c)
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, M = MI() a = N * (N - 1) // 2 b = M * (M - 1) // 2 print(a + b)
1
45,525,998,500,972
null
189
189
import sys read = sys.stdin.readline import time import math import itertools as it def inp(): return int(input()) def inpl(): return list(map(int, input().split())) start_time = time.perf_counter() # ------------------------------ A = inpl() A.sort() if A[0]!=A[2]: if A[0]==A[1]: print('Yes') sys.exit() if A[1]==A[2]: print('Yes') sys.exit() print('No') # ----------------------------- end_time = time.perf_counter() print('time:', end_time-start_time, file=sys.stderr)
class Combination(): # nCr(mod p) #n<=10**6 def __init__(self, N, MOD): # cmbの前処理 self.mod = MOD self.FACT = [1, 1] # 階乗 self.INV = [0, 1] # 各iの逆元 self.FACTINV = [1, 1] # 階乗の逆元 for i in range(2, N + 1): self.FACT.append((self.FACT[-1] * i) % self.mod) self.INV.append(pow(i, self.mod - 2, self.mod)) self.FACTINV.append((self.FACTINV[-1] * self.INV[-1]) % self.mod) def calculate(self, N, R): # nCr(mod p) #前処理必要 if (R < 0) or (N < R): return 0 R = min(R, N - R) return self.FACT[N] * self.FACTINV[R] * self.FACTINV[N-R] % self.mod n, m, k = map(int, input().split()) mod = 998244353 cmb = Combination(n,mod) cnt = 0 for i in range(k + 1): cnt += (m * pow(m - 1, n - i - 1, mod) * cmb.calculate(n - 1, i)) % mod print(cnt % mod)
0
null
45,375,697,675,462
216
151
N=int(input()) X=input() popcount=X.count('1') bi1=[] bi0=[] Xnum1 = 0 Xnum0 = 0 if popcount != 1: for i in range(N): if i==0: bi1.append(1) else: bi1.append(bi1[i-1]*2%(popcount-1)) Xnum1 = (Xnum1 + int(X[N-i-1])*bi1[i])%(popcount-1) for i in range(N): if i==0: bi0.append(1) else: bi0.append(bi0[i-1]*2%(popcount+1)) Xnum0 = (Xnum0 + int(X[N-i-1])*bi0[i])%(popcount+1) for i in range(N): if popcount==1 and X[i]=='1': print(0) continue if X[i]=='1': Xi = (Xnum1 - bi1[N-i-1])%(popcount-1) else: Xi = (Xnum0 + bi0[N-i-1])%(popcount+1) ans = 1 while Xi!=0: Xi = Xi % bin(Xi).count('1') ans += 1 print(ans)
X=int(input()) x=100 ans=0 while x<X: x=101*x//100 ans+=1 print(ans)
0
null
17,696,757,409,166
107
159
n = int(input()) a = list(map(int, input().split())) cnt = [0] * (10 ** 6 + 1) a.sort() ans = 0 for i in a: cnt[i] += 1 a = set(a) for k in a: for l in range(k * 2, (10 ** 6 + 1), k): cnt[l] += 1 for m in a: if cnt[m] == 1: ans += 1 print(ans)
import sys MOD = 10**9 + 7 def sum_from_to(fr, to): return (to - fr + 1) * (fr + to) // 2 % MOD def main(): input = sys.stdin.buffer.readline n, k = map(int, input().split()) ans = 0 for i in range(k, n + 2): ans += sum_from_to(n - i + 1, n) - sum_from_to(0, i - 1) + 1 ans %= MOD print(ans) if __name__ == '__main__': main()
0
null
23,874,036,832,230
129
170
N=int(input()) A=map(int, input().split()) P=1000000007 ans = 1 cnt = [3 if i == 0 else 0 for i in range(N + 1)] for a in A: ans=ans*cnt[a]%P if ans==0: break cnt[a]-=1 cnt[a+1]+=1 print(ans)
N = int(input()) a_list = list(map(int, input().split())) MOD = 10**9 + 7 cnts = [0,0,0] sames = 0 ind = -1 res = 1 for a in a_list: for i, cnt in enumerate(cnts): if cnt == a: sames += 1 ind = i res *= sames res %= MOD cnts[ind] += 1 sames = 0 print(res)
1
130,303,636,814,410
null
268
268
n,m,l=map(int,input().split()) a=[list(map(int,input().split())) for i in range(n)] b=[list(map(int,input().split())) for i in range(m)] ans=[[0]* l for i in range(n)] for i in range(n): for j in range(l): for k in range(m): ans[i][j]+=b[k][j]*a[i][k] print(*ans[i])
from collections import Counter N = int(input()) S = input() c = Counter(S) ans = c['R'] * c['G'] * c['B'] for s in range(N-2): for d in range(1, (N-1-s)//2+1): t = s + d u = t + d if S[s] != S[t] and S[t] != S[u] and S[u] != S[s]: ans -= 1 print(ans)
0
null
18,685,123,704,522
60
175
# coding: utf-8 # Your code here! while(1): H,W=map(int,input().split(" ")) if H==0 and W==0: break else: for i in range(H): for j in range(W): print("#",end="") print("") print("")
from sys import stdin from collections import deque n = int(stdin.readline()) d = [-1] * (n + 1) def bfs(G): d[1] = 0 queue = [1] dq = deque([1]) while len(dq) > 0: v = dq.popleft() for c in G[v]: if d[c] < 0: d[c] = d[v] + 1 dq.append(c) for i, x in enumerate(d[1:], start=1): print(i, x) G = {} for i in range(n): x = list(map(int, stdin.readline().split())) G[x[0]] = x[2:] bfs(G)
0
null
393,708,702,200
49
9
n = int(input()) S = input() l = len(S) S += 'eeee' cnt = 0 for i in range(10): for j in range(10): for k in range(10): # tmp = str(i)+str(j)+str(k) m = 0 while S[m] != str(i): m += 1 if m >= l: break m += 1 while S[m] != str(j): m += 1 if m >= l: break m += 1 while S[m] != str(k): m += 1 if m >= l: break if m < l: cnt += 1 print(cnt)
import sys, math from functools import lru_cache from collections import deque sys.setrecursionlimit(500000) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def main(): N = ii() S = input() cnt = 0 for i in range(1000): ptn = str(i).zfill(3) j = 0 flg = 0 while j < N: if S[j] == ptn[flg]: flg += 1 if flg == 3: cnt += 1 break j += 1 print(cnt) if __name__ == '__main__': main()
1
128,639,527,456,920
null
267
267
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 wn, wm, l = list(map(int, readline().split())) inf = 10 ** 13 wl = [[inf] * wn for _ in range(wn)] for i in range(wn): wl[i][i] = 0 for i in range(wm): wa, wb, wc = list(map(int, readline().split())) wl[wa - 1][wb - 1] = wc wl[wb - 1][wa - 1] = wc for i in range(wn): for j in range(wn): for k in range(wn): wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k]) inf = 10 ** 13 wwl = [[inf] * wn for _ in range(wn)] for i in range(wn): wwl[i][i] = 0 for i in range(wn): for j in range(wn): if i != j and wl[i][j] <= l: wwl[i][j] = 1 for i in range(wn): for j in range(wn): for k in range(wn): wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k]) q = int(readline()) for i in range(q): s, t = list(map(int, readline().split())) print(wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1) if __name__ == '__main__': solve()
from math import floor from sys import stdin A, B, N = [int(_) for _ in stdin.readline().rstrip().split()] def solve(x): return floor(A*x/B)-A*floor(x/B) print(solve(min(B-1, N)))
0
null
101,306,035,315,690
295
161
def max(a,b,c): if a >= b and a >= c: return a if b >= a and b >= c: return b else: return c def min(a,b,c): if a <= b and a <= c: return a if b <= a and b <= c: return b else: return c def mid(a,b,c): if (b-a)*(c-a) <= 0: return a if (a - b) * (c - b) <= 0: return b else: return c s = input() s = s.split() n = [] for i in s: n.append(int(i)) a = n[0] b = n[1] c = n[2] print(min(a,b,c),mid(a,b,c),max(a,b,c))
n = input().split() a = [] for i in range(len(n)): a.append(int(n[i])) a = sorted(a) print('{0} {1} {2}'.format(a[0],a[1],a[2]))
1
423,854,224,288
null
40
40
n = int(input()) alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] res = '' while (n > 0): n = n - 1 q = n % 26 n = n // 26 res = res + alphabets[q] res = res[::-1] print(res)
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) n = INT() ans = '' while n != 0: x = ( n - 1 ) % 26 n = ( n - x + 1 ) // 26 ans = chr( ord('a') + x ) + ans print(ans)
1
11,923,510,383,110
null
121
121
N = int(input()) arr = list(map(int, input().split())) if N == 0: print(1 if arr[0]==1 else -1) exit() elif arr[0] != 0: print(-1) exit() # 末端の葉の数で初期化 sum_arr = [arr[-1]]*N for i in range(1,N): # 深さi+1での頂点数 + 深さiでの葉の数 sum_arr[i] = sum_arr[i-1]+arr[N-i] # 本来の順番に反転 sum_arr = sum_arr[::-1] # 二分木の根から見ていく ans = [1]*(N+1) for i in range(1,N+1): if ans[i-1]-arr[i-1] < 0: print(-1) exit() tmp = min((ans[i-1]-arr[i-1])*2,sum_arr[i-1]) ans[i] = tmp # for i in range(min(25,N+1)): # if ans[i] > 2**i: # print(-1) # exit() if ans[N] != arr[-1]: print(-1) exit() print(sum(ans))
import sys input = sys.stdin.readline M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) if D2 == 1: print(1) else: print(0)
0
null
71,898,138,440,512
141
264
import math n = int(input()) x = [int(num) for num in input().split()] y = [int(num) for num in input().split()] D1 = 0 D2 = 0 D3 = 0 D4 = [] for i, j in zip(x, y): D1 += abs(i - j) print(D1) for i, j in zip(x, y): D2 += (abs(i - j))**2 print(math.sqrt(D2)) for i, j in zip(x, y): D3 += (abs(i - j))**3 print(math.pow(D3, 1.0/3.0)) for i, j in zip(x, y): D4.append(abs(i - j)) print(max(D4))
n = int(input()) x = [int(x) for x in input().split()] y = [int(x) for x in input().split()] abs_list = [abs(a-b) for a,b in zip(x,y)] p1 = p2 = p3 = p4 = 0 for a in abs_list: p1 += a p2 += a**2 p3 += a**3 p2 = p2 **(1/2) p3 = p3 **(1/3) p4 = max(abs_list) preanswer = [p1,p2,p3,p4] answer = ['{:.6f}'.format(i) for i in preanswer] for a in answer: print(a)
1
215,632,745,682
null
32
32
n = int(input()) a = list(map(int, input().split())) def selectionSort(a, n): count = 0 for i in range(n): mini = i for j in range(i, n): if a[j] < a[mini]: mini = j if i != mini: a[i],a[mini] = a[mini],a[i] count += 1 print(*a) print(count) selectionSort(a,n)
n, m = map(int, input().split()) V = [set() for _ in range(n)] # 隣接リスト for a, b in [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)]: V[a].add(b) V[b].add(a) from collections import deque G = [-1] * n # グループ色分け for s in range(n): # BFS dq = deque([s]) while dq: p = dq.popleft() if G[p] >= 0: continue G[p] = s # 色付け for c in V[p]: dq.append(c) C = dict() # グループメンバ数集計 for g in G: if not g in C: C[g] = 0 C[g] += 1 print(max(C.values())) # 最大メンバ数
0
null
1,966,634,030,240
15
84
n=int(input()) a=list(map(int,input().split())) count=1 chk=False for i in range(1,n+1): if a[i-1]==count: chk=True count+=1 print(n-count+1 if chk else -1)
A, B = map(str, input().split()) N, M = map(int, input().split()) S = input() if A == S: print(N-1,M) elif B == S: print(N,M-1)
0
null
93,192,972,160,718
257
220
h,w,k = map(int, input().split()) s = [] st = 0 zero = [0 for i in range(h)] z = 0 for i in range(h): t = input() st += t.count('#') zero[i] = t.count('#') s.append(t) cake = 0 ans = [[0 for j in range(w)] for i in range(h)] for i in range(h): if zero[i] == 0: continue cake += 1 t = 0 for j in range(w): if s[i][j] == '#': t += 1 if t >= 2: cake += 1 ans[i][j] = cake for i in range(h-1): if zero[i+1] != 0: continue if ans[i][0] == 0: continue for j in range(w): ans[i+1][j] = ans[i][j] for i in range(h-1,0,-1): if zero[i-1] != 0: continue for j in range(w): ans[i-1][j] = ans[i][j] for i in range(h): print (*ans[i])
H,W,K = map(int,input().split()) S = [input() for i in range(H)] ans = [[None]*W for _ in range(H)] v = 0 for i,row in enumerate(S): sp = row.split('#') if len(sp)==1: continue if len(sp)==2: v += 1 for j in range(W): ans[i][j] = v continue j = 0 for k,a in enumerate(sp): if k==len(sp)-1: for _ in range(len(a)): ans[i][j] = v j += 1 else: v += 1 for _ in range(len(a)+1): ans[i][j] = v j += 1 i = 0 while ans[i][0] is None: i += 1 for ii in range(i): for j in range(W): ans[ii][j] = ans[i][j] for i in range(1,H): if ans[i][0] is None: for j in range(W): ans[i][j] = ans[i-1][j] for row in ans: print(*row)
1
143,350,177,551,262
null
277
277
from collections import defaultdict N = int(input()) A = list(map(int, input().split())) dAl = defaultdict(int) dAr = defaultdict(int) for i in range(N): L = (i + 1) + A[i] R = (i + 1) - A[i] dAl[L] += 1 dAr[R] += 1 # dictの中を見る ans = 0 for k, v in dAl.items(): ans += v * dAr[k] print(ans)
import sys #import cython def main(): read = lambda: sys.stdin.readline().rstrip() import collections d = collections.defaultdict(int) N = int(read()) A = list(map(int,read().split())) cnt = 0 for i, x in enumerate(A): d[i + x] += 1 if d[i-x] > 0: cnt += d[i-x] print(cnt) if __name__ == "__main__": main()
1
26,130,517,458,640
null
157
157
#!/usr/bin/env python3 def main(): n = int(input()) xy = [list(map(int, input().split())) for i in range(n)] max_z, max_w, min_z, min_w = -10**20, -10**20, 10**20, 10**20 ans = 0 for p in xy: max_z, max_w = max(max_z, p[0] + p[1]), max(max_w, p[0] - p[1]) min_z, min_w = min(min_z, p[0] + p[1]), min(min_w, p[0] - p[1]) ans = max(max_z - min_z, max_w - min_w) print(ans) if __name__ == "__main__": main()
N=int(input()) L=[] # xでソート #でソート #min, max for i in range(N): x,y=map(int, input().split()) L.append([x+y,x-y]) L=sorted(L) ans=abs(L[0][0]-L[-1][0]) L=sorted(L, key=lambda x: x[1]) ans=max(ans, abs(L[0][1]-L[-1][1])) print(ans)
1
3,430,283,813,460
null
80
80
N,K=map(int,input().split()) A=list(map(lambda x:int(x)%K,input().split())) cum=[0]*(N+1) for i in range(N): cum[i+1]=(cum[i]+A[i]) x=[(cum[i]-i)%K for i in range(N+1)] dic={} ans=0 for i in range(N+1): if i>=K: dic[x[i-K]]-=1 ans+=dic.get(x[i],0) if not x[i] in dic: dic[x[i]]=1 else: dic[x[i]]+=1 print(ans)
n, p = map(int, input().split()) s = list(map(int, input())) ans = 0 if p == 2 or p == 5: for i, x in enumerate(s): if (p == 2 and not x % 2) or (p == 5 and (x == 0 or x == 5)): ans += i+1 print(ans) exit() s.reverse() cum = [0] * (n+1) for i in range(n): cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p t = [0] * p for x in cum: t[x] += 1 for x in t: ans += x * (x-1) // 2 print(ans)
0
null
97,996,196,293,180
273
205
# kurimu_usamaro様のメソッドを拝借しています。 class Combi(): def __init__(self, N, mod): self.power = [1 for _ in range(N+1)] self.rev = [1 for _ in range(N+1)] self.mod = mod for i in range(2, N+1): self.power[i] = (self.power[i-1]*i) % self.mod self.rev[N] = pow(self.power[N], self.mod-2, self.mod) for j in range(N, 0, -1): self.rev[j-1] = (self.rev[j]*j) % self.mod def com(self, K, R): if K < R: return 0 else: return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod def pom(self, K, R): if K < R: return 0 else: return (self.power[K])*(self.rev[K-R]) % self.mod def main(): mod = 10**9+7 N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort() c = Combi(N,mod) ans = 0 if K == 1: print(0) else: for i, a in enumerate(A): ans += c.com(i, K-1)*a ans -= c.com(N-1-i, K-1)*a ans %= mod print(ans%mod) if __name__ == "__main__": main()
s=input() li=list(s) adana_li=[] for i in range(3): adana_li.append(li[i]) adana=li[0]+li[1]+li[2] print(adana)
0
null
55,059,532,002,892
242
130
n = int(input()) d = [[0] * 10 for _ in range(10)] for i in range(1, n + 1): d[int(str(i)[0])][i % 10] += 1 ret = 0 for s in range(10): for e in range(10): ret += d[s][e] * d[e][s] print(ret)
#B - Nice Shopping A,B,M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) X = [] Y = [] C = [] for i in range(M): x,y,c = map(int,input().split()) X.append(x) Y.append(y) C.append(c) #割引券を使う場合 pay_sale = [a[i-1]+b[j-1]-k for i,j,k in zip(X,Y,C)] pay_ticket = min(pay_sale) #使わない場合 pay = min(a) + min(b) print(min(pay,pay_ticket))
0
null
70,319,173,964,608
234
200
def popcount(x): x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555) x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333) x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f) x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff) x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff) x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff) return x n = int(input()) testimonies = [[] * n for _ in range(n)] for i in range(n): a = int(input()) for _ in range(a): x, y = map(int, input().split()) testimonies[i].append((x-1, y)) ans = 0 for bits in range(1, 1<<n): possible = True for i in range(n): if not bits >> i & 1: continue for x, y in testimonies[i]: if bits >> x & 1 != y: possible = False break if not possible: break if possible: ans = max(ans, popcount(bits)) print(ans)
n = int(input()) a = [] x = [] y = [] for i in range(n): ai = int(input()) a.append(ai) xi = [] yi = [] for j in range(ai): xij, yij = map(int, input().split(' ')) xi.append(xij) yi.append(yij) x.append(xi) y.append(yi) ans = 0 for case in range(2**n): truth_t = 0 #正直者の真の数 truth = 0 #正直者の確認した数 for i in range(n): #人ごとに矛盾が生じないか確認 if (case>>i)&1: #正直者であれば証言に矛盾がないか確認 truth_t+=1 proof=0 for j in range(a[i]): if ((case>>(x[i][j]-1))&1)==y[i][j]: proof+=1 if proof==a[i]: truth += 1 if truth==truth_t: if ans<truth: ans = truth print(ans)
1
121,471,066,813,472
null
262
262
w,h,x,y,r=map(int,raw_input().split()) f=0 if x+r>w: f=1 if y+r>h: f=1 if r>x: f=1 if r>y: f=1 if f==0: print "Yes" else: print "No"
n, m, l = [int(_) for _ in input().split()] matrix1 = [] for i in range(n): matrix1.append([int(_) for _ in input().split()]) matrix2 = [] for i in range(m): matrix2.append([int(_) for _ in input().split()]) for i in range(n): for j in range(l): x = 0 for k in range(m): x += matrix1[i][k] * matrix2[k][j] print(x, end=" " if j < l - 1 else "\n")
0
null
951,448,520,448
41
60
n = int(input()) a = list(map(int, input().split())) count = 0 for i in range(n): mini = i + a[i:].index(min(a[i:])) if mini != i: a[i], a[mini] = a[mini], a[i] count += 1 print(' '.join(map(str, a))) print(count)
h, w, k = map(int, input().split()) tizu = [list(input()) for _ in range(h)] ans = [[0 for _ in range(w)] for _ in range(h)] pos = 0 bef = 0 bef_flg = True for i in range(h): pos_tmp = pos f_st = False if "#" in tizu[i]: bef_flg = False pos += 1 for j in range(w): if tizu[i][j] == "#": if f_st: pos += 1 f_st = True ans[i][j] = pos else: if bef_flg: bef += 1 else: for j in range(w): ans[i][j] = ans[i - 1][j] for i in range(bef - 1, -1, -1): for j in range(w): ans[i][j] = ans[i + 1][j] for row in ans: print(*row)
0
null
71,939,274,604,950
15
277
n,x,m = map(int, input().split()) #xに何番目にきたかを記録していく。-1じゃなければ一回以上きている table = [-1] * m extra = [] l = 0 total = 0 #table[x]は周期が始まる点 while table[x] == -1: extra.append(x) table[x] = l l += 1 total += x x = (x*x) % m #周期の長さ c = l - table[x] #周期の和 s = 0 for i in range(table[x], l): s += extra[i] ans = 0 #周期がnより長い場合 if n <= l: for i in range(n): ans += extra[i] else: #最初の一週目を足す ans += total n -= l #残りの周期の周の和を足す ans += s*(n//c) n %= c for i in range(n): ans += extra[table[x]+i] print(ans)
def abc174d(): n = int(input()) s = input() cnt = s.count('R') if cnt == len(s): print(0) return start = 0 while s[start] == 'R': start += 1 cnt -= 1 ans = cnt for i in range(start, start+cnt): if s[i] == 'R': ans -= 1 print(ans) abc174d()
0
null
4,567,697,139,002
75
98
#ライブラリインポート from collections import defaultdict con = 10 ** 9 + 7 #入力受け取り def getlist(): return list(map(int, input().split())) #処理内容 def main(): N, K, C = getlist() S = list(input()) D1 = defaultdict(int) D2 = defaultdict(int) var = - float("inf") cnt = 0 for i in range(N): if S[i] == "o": if i - var >= C + 1: cnt += 1 var = i D1[i] += 1 if cnt >= K + 1: return #詰める var = float("inf") cnt = 0 for i in range(N): if S[N - 1 - i] == "o": if var - (N - 1 - i) >= C + 1: cnt += 1 var = N - 1 - i D2[N - 1 - i] += 1 # print(D1) # print(D2) ans = [] for i in D1: if D2[i] == 1: ans.append(i) ans = sorted(ans) for i in ans: print(i + 1) if __name__ == '__main__': main()
n = int(input()) ans = [0 for _ in range(n+1)] for x in range(1,int(n**0.5)+1): for y in range(1,x+1): for z in range(1,y+1): if x**2+y**2+z**2+x*y+y*z+z*x<=n: if x==y==z: ans[x**2+y**2+z**2+x*y+y*z+z*x] += 1 if (x==y and y != z) or (y==z and z !=x) or (z==x and x != y): ans[x**2+y**2+z**2+x*y+y*z+z*x] += 3 if (x!=y) and (y!=z) and (z!=x): ans[x**2+y**2+z**2+x*y+y*z+z*x] += 6 for a in ans[1:]: print(a)
0
null
24,374,306,620,220
182
106
import math X = int(input()) i = 1 while True: net = (i * X)/360 if math.floor(net) == math.ceil(net): break else: i+=1 print(i)
A,B,M=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) m=[list(map(int,input().split())) for _ in range(M)] min_a=min(a) min_b=min(b) min_cost=min_a+min_b for _m in m: cost=a[_m[0]-1]+b[_m[1]-1]-_m[2] min_cost=min(min_cost,cost) print(min_cost)
0
null
33,556,372,022,220
125
200
# coding: utf-8 # Your code here! # ITP1_3_C while(True): x,y=map(int,input().split()) if x == 0 and y == 0: break if x > y: print(y,x) else: print(x,y)
while True : x, y = map(int, raw_input().split(" ")) if x==0 and y==0 : break if x < y : print "%d %d" % (x, y) else : print "%d %d" % (y, x)
1
523,319,440,800
null
43
43
K, N = map(int, input().split()) A = list(map(int, input().split())) dists = [] for i in range(N): if i==N-1: dists.append(K-A[N-1]+A[0]) else: dists.append(A[i+1]-A[i]) print(K-max(dists))
N,K = map(int,input().split()) S,P,R = map(int,input().split()) point = {'s':S,'p':P,'r':R} T = str(input()) max_point = 0 for i in range(K): while i < N: if i+K < N and T[i] == T[i+K]: max_point += point[T[i]] i = i+2*K else: max_point += point[T[i]] i = i+K print(max_point)
0
null
75,422,584,288,938
186
251
S,H,C,D = set(),set(),set(),set() W = set([1,2,3,4,5,6,7,8,9,10,11,12,13]) n = int(input()) for i in range(n): N = input().split() if N[0] == 'S': S.add(int(N[1])) elif N[0] == 'H': H.add(int(N[1])) elif N[0] == 'C': C.add(int(N[1])) elif N[0] == 'D': D.add(int(N[1])) s,h,c,d = [],[],[],[] st = W - S while st != set(): s.append(st.pop()) s.sort() ht = W - H ct = W - C dt = W - D while ht != set(): h.append(ht.pop()) h.sort() while ct != set(): c.append(ct.pop()) c.sort() while dt != set(): d.append(dt.pop()) d.sort() for i in s: print('S {0}'.format(i)) for i in h: print('H {0}'.format(i)) for i in c: print('C {0}'.format(i)) for i in d: print('D {0}'.format(i))
n=int(input()) a=list(map(int,input().split())) ans=[0]*(n+1) for i in range(n-1): ans[a[i]]+=1 ans.pop(0) for j in ans: print(j)
0
null
16,680,760,998,340
54
169
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) def celi(a,b): return -(-a//b) sys.setrecursionlimit(5000000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] a,b=map(int,input().split()) ans=1 while ans*8//100!=a or ans//10!=b: ans+=1 if ans>2*10**5: print(-1) exit() print(ans)
X, Y = map(int, input().split()) Z = X * 4 - Y if Z % 2 == 0 and X * 2 >= Z >= 0: print('Yes') else: print('No')
0
null
34,929,861,545,532
203
127
s = input() flag = 1 l = len(s) for i in range((l-1)//2): if s[i] == s[(l-1)//2 - 1-i]: continue else: flag = 0 break if s[:(l-1)//2] != s[(l+3)//2-1:]: flag = 0 print("Yes" if flag == 1 else "No")
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) n = ini() ans = n % 1000 print(0 if ans == 0 else 1000 - ans)
0
null
27,547,232,897,282
190
108
import sys # sys.stdin = open('input.txt') k = int(input()) string = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51' s = [i for i in map(int, string.split(', '))] print(s[k-1])
l=[[[0 for i in range(10)] for i in range(3)] for i in range(4)] n=int(input()) for i in range(n): a,b,c,d=list(map(int,input().split())) l[a-1][b-1][c-1]+=d for i in l[:-1]: for j in i: print(" "+" ".join(list(map(str,j)))) print("####################") for j in l[-1]: print(" "+" ".join(list(map(str,j))))
0
null
25,588,112,392,650
195
55
n = int(input()) minv = int(input()) maxv = -1000000000 for r in [int(input()) for i in range(1,n)]: maxv = max(maxv,r-minv) minv = min(r,minv) print(maxv)
def main(): N = int(input()) price = [int(input()) for i in range(N)] minv = float("inf") maxv = -float("inf") for p in price: maxv = max(maxv, p-minv) minv = min(minv, p) print(maxv) if __name__ == "__main__": import os import sys if len(sys.argv) > 1: if sys.argv[1] == "-d": fd = os.open("input.txt", os.O_RDONLY) os.dup2(fd, sys.stdin.fileno()) main() else: main()
1
13,375,983,270
null
13
13
n,m=map(int,input().split()) s=input() ans=[] cursor=n actualfail=0 while cursor!=0: if cursor<=m: ans.append(cursor) break failflag=1 for i in range(m): if s[cursor-m+i]=='0': failflag=0 ans.append(m-i) cursor-=m-i break if failflag==1: actualfail=1 break if actualfail==1: print(-1) else: ans.reverse() for i in ans: print(i)
import collections n=int(input()) box=[] for i in range(n): tmp=str(input()) box.append(tmp) l=len(collections.Counter(box)) print(l)
0
null
84,577,727,752,958
274
165
N = int(input()) V = [0]*10000 for j in range (1, 100): for k in range (1, 100): for l in range (1, 100): if j**2+k**2+l**2+j*k+k*l+j*l < 10001: V[j**2+k**2+l**2+j*k+k*l+j*l-1]+=1 for i in range (0, N): print(V[i])
N = int(input()) ans = [0]*(N+1) for x in range(1,105): for y in range(1,105): for z in range(1,105): tmp = x**2 + y**2 + z**2 +x*y + y*z + z*x if tmp > N: continue ans[tmp]+=1 for i in range(1,N+1): print(ans[i])
1
7,890,871,597,466
null
106
106
a= input() b = input() if b[0:-1] == a: if len(a) + 1 == len(b): print('Yes') exit() print('No')
s = input() t = input() print("Yes" if s == t[:len(t) - 1] else "No")
1
21,517,501,262,840
null
147
147
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) s = [0] * N for i in range(N): s[A[i]-1] += 1 total = 0 for i in range(N): total += s[i]*(s[i]-1) // 2 for k in range(N): ans = total - s[A[k]-1]*(s[A[k]-1]-1)//2 + (s[A[k]-1]-1)*((s[A[k]-1]-1)-1) // 2 print(ans)
# A - Sum of Two Integers N = int(input()) if N % 2 == 1: N += 1 print(int(N / 2 - 1))
0
null
100,768,911,963,564
192
283
# -*- coding: utf-8 -*- #mitsui f import sys import math import collections #sys.setrecursionlimit(100000) #n=int(input()) tmp = input().split() t1,t2 = list(map(lambda a: int(a), tmp)) tmp = input().split() a1,a2 = list(map(lambda a: int(a), tmp)) tmp = input().split() b1,b2 = list(map(lambda a: int(a), tmp)) if(a1*t1+a2*t2==b1*t1+b2*t2): print("infinity") sys.exit() diff=(a1*t1+a2*t2)-(b1*t1+b2*t2) if(diff>0): c1=a1-b1 c2=a2-b2 else: c1=b1-a1 c2=b2-a2 if(c1>0): print("0") sys.exit() diff=c1*t1+c2*t2 pitch=c1*t1*-1 ans=pitch//diff*2+1 if(pitch%diff==0): ans-=1 print(ans)
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) if A1 < B1: A1, A2, B1, B2 = B1, B2, A1, A2 if A1*T1+A2*T2 == B1*T1+B2*T2: print('infinity') exit() if (A1-B1)*T1 > (B2-A2)*T2: print(0) exit() d = abs(A1*T1+A2*T2 - B1*T1-B2*T2) # T1,T2が終わった後に開く距離 L = abs(A1-B1)*T1 # T1の間に開く距離 # print(d, L) if L % d == 0: print(L//d*2) else: ans = L//d*2+1 print(ans) # if d*L//d <= L: # ans += 1
1
131,145,422,608,100
null
269
269
n,m=list(map(int,input().split(' '))) am=[[0 for j in range(m)] for i in range(n)] bm=[0 for l in range(m)] cm=[0 for i in range(n)] for i in range(n): am[i]=list(map(int,input().split(' '))) for j in range(m): bm[j]=int(input()) for i in range(n): for j in range(m): cm[i]=cm[i]+am[i][j]*bm[j] for i in range(n): print(cm[i])
n, m = [int(i) for i in input().split()] vec = [] for i in range(n): vec.append([int(j) for j in input().split()]) c = [] for i in range(m): c.append(int(input())) for i in range(n): sum = 0 for j in range(m): sum += vec[i][j]*c[j] print(sum)
1
1,179,498,095,188
null
56
56
money = int(input()) while money > 1000 : money -= 1000 print(1000 - money)
n = int(input()) for i in range(0,10001,1000): if i - n >= 0: print(i - n) exit() else: continue
1
8,430,302,300,640
null
108
108
def main(istr, ostr): x, y = istr.readline().strip().split() a = int(x) b0, _, b1, b2 = y b0, b1, b2 = list(map(int, [b0, b1, b2])) c = a * (100 * b0 + 10 * b1 + b2) res = c // 100 print(res, file=ostr) if __name__ == "__main__": import sys main(sys.stdin, sys.stdout)
from collections import Counter n = int(input()) c = list(input()) count = Counter(c) ans = float('inf') w = 0 r = 0 if count.get('R'): r = count['R'] ans = max(w, r) for i in range(n): if c[i]=='W': w += 1 else: r -= 1 ans =min(max(w,r), ans) print(ans)
0
null
11,488,091,491,968
135
98
n = int(input()) A = [0]*12000 for i in range(1,101): for j in range(1, 101): for k in range(1, 101): val = i**2 + j**2 + k**2 + i*j + i*k + j*k if val < 12000: A[i**2 + j**2 + k**2 + i*j + i*k + j*k] += 1 for i in A[1:n+1]: print(i)
from collections import defaultdict N = int(input()) D = list(map(int, input().split())) MOD = 998244353 p = defaultdict(int) for d in D: p[d] += 1 if p[0] == 1 and D[0] == 0: ans = 1 for i in range(max(D)): ans *= pow(p[i], p[i + 1], MOD) ans %= MOD if ans == 0: break print(ans) else: print(0)
0
null
81,460,552,259,270
106
284
[S,T] = input().split() print(T+S)
n = int(input()) print(sum(i for i in range(1, n + 1) if i % 3 != 0 and i % 5 != 0))
0
null
68,873,442,493,280
248
173
a=list(input()) ans=0 for i in range(len(a)): ans+=int(a[i]) if ans%9==0: print("Yes") else: print("No")
# 問題文 # 高橋君の夏休みはN日間です。 # 夏休みの宿題が M個出されており、i番目の宿題をやるにはAi日間かかります。 # 複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。 # 夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか? # ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。 # n(夏休みの日数),m(宿題の数):標準入力 # リストの中のA(宿題日):リストを作成し、標準入力 n, m = map(int, input().split()) A = list(map(int, input(). split())) # 最大で n −合計(A1+. . .+AM)日間遊ぶことができる if n < sum(A): # 夏休みの日数より宿題日が多い場合:宿題をやる日数が足りない→終わらせることができない print(-1) else: print(n-sum(A)) # その他→宿題は終わる→夏休みの日数-宿題日 # NameError: name 'N' is not defined
0
null
18,148,663,115,892
87
168
X,N=map(int,input().split()) p=list(map(int,input().split())) i=0 j=0 while X+i in p: i+=1 while X-j in p: j+=1 if i>j: print(X-j) elif i<j: print(X+i) else: print(min([X+i,X-j]))
X, N = list(map(int, input().split())) if N == 0: print(X) exit() P = list(map(int, input().split())) up_min = 0 low_min = 0 arr = [0] * 102 for i in P: arr[i] = 1 lower = arr[:X] lower.reverse() upper = arr[X:] for i, num in enumerate(lower): if num == 0: low_min = len(lower) - 1 - i break for i, num in enumerate(upper): if num == 0: up_min = len(lower) + i break if abs(up_min - X) >= abs(X - low_min): print(low_min) else: print(up_min)
1
14,056,763,661,060
null
128
128
import sys for i in sys.stdin.readlines()[:-1]: h,w = map(int,i.strip().split()) for i in range(h): for j in range(w): if (i+j) % 2 == 0: print('#',end='') else: print('.',end='') print() print()
import sys from collections import deque n = int(sys.stdin.readline()) G = [[] for _ in range(n+1)] G_order = [] for i in range(n-1): a,b = map(lambda x:int(x)-1, sys.stdin.readline().split()) G[a].append(b) G_order.append(b) que = deque([0]) C = [0]*(n+1) while que: nw = que.popleft() c = 1 for nx in G[nw]: if c==C[nw]: c+=1 C[nx] = c c += 1 que.append(nx) print(max(C)) for i in G_order: print(C[i])
0
null
68,736,284,152,570
51
272
import bisect n=int(input()) a=list(map(int,input().split())) suma=[] sumans=0 for i in range(n): sumans += a[i] suma.append(sumans) u=bisect.bisect_right(suma, sumans//2) print(min(abs(2*suma[u-1]-sumans), abs(2*suma[u]-sumans)))
n = int(input()) a = list(map(int,input().split())) l = sum(a) half = 0 tmp=a[0] while tmp<l/2: half+=1 tmp+=a[half] print(int(min(tmp-l/2,abs(tmp-a[half]-l/2))*2))
1
142,358,658,871,678
null
276
276
def resolve(): K = int(input()) N = 7 c = 1 for i in range(10**6): if N % K == 0: print(c) break else: N = N * 10 + 7 N %= K c += 1 else: print(-1) resolve()
K = int(input()) i = 7 % K result = set() for x in range(K): if i == 0: print(x + 1) exit() if i in result: print(-1) exit() else: result.add(i) i = (i * 10 + 7) % K print(-1)
1
6,132,841,116,032
null
97
97
a,b = raw_input().split(" ") x = int(a)*2+int(b)*2 y = int(a)*int(b) print "%d %d"%(y,x)
cond = map(int, raw_input().split()) a = cond[0] b = cond[1] print (a*b), print (a*2 + b*2)
1
304,128,892,550
null
36
36
#ABC 175 C x, k, d = map(int, input().split()) x = abs(x) syou = x // d amari = x % d if k <= syou: ans = x - (d * k) else: if (k - syou) % 2 == 0: #残りの動ける数が偶数 ans = amari else:#残りの動ける数が奇数 ans = abs(amari - d) print(ans)
x, k, d = map(int, input().split()) if abs(x) // d >= k: if x > 0: print(x - k * d) else: print(abs(k * d + x)) exit() div = abs(x) // d k -= div if x > 0: x -= div * d else: x += div * d if k % 2 == 0: print(abs(x)) else: print(abs(abs(x) - d))
1
5,244,726,650,240
null
92
92
N = int(input()) S = input() res = 0 f = S[0] for i in range(N): if S[i] != f: f = S[i] res += 1 print(res+1)
def main(): n = int(input()) s = list(input()) cnt = 1 for i in range(1, n): if s[i] == s[i-1]: continue else: cnt += 1 print(cnt) if __name__ == '__main__': main()
1
170,374,070,110,978
null
293
293
n = int(input()) x = list(map(int, input().split())) sum= 1000000000000000 for p in range(1,101): tmp=0 # print("p",p) for i in range(len(x)): tmp += (x[i] - p)**2 # print("tmp",tmp) sum = min(sum,tmp) # print("su",sum) print(sum)
import math N = int(input()) X = list(map(int, input().split())) def average(a): return sum(a) / len(a) avg = average(X) res = 0 if avg - int(avg) >= 0.5: for i in X: res += (i - math.ceil(avg)) **2 else: for i in X: res += (i - math.floor(avg)) ** 2 print(res)
1
65,285,108,992,476
null
213
213
n = int(input()) a = list(map(int, input().split())) x = 0 b = [0] * n for i in range(n): b[a[i] - 1] += 1 x = 0 for j in range(n): x += ((b[j] - 1) * b[j] / 2) for k in range(n): print(int(x - b[a[k] - 1] + 1))
s = input() if len(s)%2!=0: print("No") else: if s.count("hi") == len(s)//2: print("Yes") else: print("No")
0
null
50,578,597,938,678
192
199
n = list(map(int, list(input()))) k = int(input()) dp = [[0,0,0] for _ in range(len(n))] counter = 0 for i in range(len(n)): dp[i][0] += dp[i-1][0] + 9*(counter > 0) dp[i][1] += dp[i-1][0]*9 + dp[i-1][1] dp[i][2] += dp[i-1][1]*9 + dp[i-1][2] if n[i] > 0: if counter >= 1 and counter <= 3: dp[i][counter-1] += 1 counter += 1 if counter <= 3: dp[i][counter-1] += n[i]-1 print(dp[len(n)-1][k-1]+(counter==k))
t,h=0,0 for _ in range(int(input())): a,b=input().split() if a>b:t+=3 if a<b:h+=3 if a==b:t+=1;h+=1 print(t,h)
0
null
39,186,616,325,600
224
67
n, m = map(int, input().split()) mat = [] for i in range(n): mat.append(list(map(int, input().split()))) vec = [] for i in range(m): vec.append(int(input())) for i in range(n): e = 0 for j in range(m): e += mat[i][j] * vec[j] print(e)
from collections import defaultdict as d n=int(input()) a=list(map(int,input().split())) p=d(int) l=0 for i in a: p[i]+=1 l+=i for i in range(int(input())): b,c=map(int,input().split()) l+=p[b]*(c-b) p[c]+=p[b] p[b]=0 print(l)
0
null
6,703,701,970,340
56
122
class Info: def __init__(self,arg_start,arg_end,arg_S): self.start = arg_start self.end = arg_end self.S = arg_S LOC = [] POOL = [] line = input() loc = 0 sum_S = 0 for ch in line: if ch == '\\': LOC.append(loc) elif ch == '/': if len(LOC) == 0: continue tmp_start = int(LOC.pop()) tmp_end = loc tmp_S = tmp_end-tmp_start; sum_S += tmp_S; #既に突っ込まれている池の断片が、今回の断片の部分区間になるなら統合する while len(POOL) > 0: if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end: tmp_S += POOL[-1].S POOL.pop() else: break POOL.append(Info(tmp_start,tmp_end,tmp_S)) else: pass loc += 1 print("%d"%(sum_S)) print("%d"%(len(POOL)),end = "") while len(POOL) > 0: print(" %d"%(POOL[0].S),end = "") #先頭から POOL.pop(0) print()
d,t,s=list(map(int,input().split())) time=d/s if(time<t or time==t): print("Yes") else: print("No")
0
null
1,808,894,852,818
21
81
a=int(input()) c=a+a**2+a**3 print(c)
#import numpy as np import math import collections import bisect def main(): a = int(input()) print(a + a**2 + a**3) if __name__ == '__main__': main()
1
10,098,111,171,468
null
115
115
import sys nums = [] for line in sys.stdin: nums.append(line) for i in range(len(nums)): input_line = nums[i].split(" ") a = int(input_line[0]) b = int(input_line[1]) if a > b: num_bigger = a num_smaller = b else: num_bigger = b num_smaller = a r = 1 #????????? while r > 0: r = num_bigger % num_smaller num_bigger = num_smaller num_smaller = r max_common_div = num_bigger min_common_mpl = int((a * b)/max_common_div) print(str(max_common_div) + " " + str(min_common_mpl))
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) a, b, n = MAP() x = min(b-1, n) ans = (a*x)//b - a*(x//b) print(ans)
0
null
14,148,302,437,152
5
161
n = int(input()) print(n//2+1 if n%2!=0 else n//2)
from sys import stdin, setrecursionlimit def main(): n = int(stdin.readline()) print(n // 2) if n % 2 == 0 else print((n + 1) // 2) if __name__ == "__main__": setrecursionlimit(10000) main()
1
59,368,919,282,628
null
206
206
from collections import deque def bfs(start): Q = deque() Q.append(start) dist[start] = 0 while Q: v = Q.popleft() for nv in G[v]: if dist[nv] != -1: continue # print(Q) dist[nv] = dist[v] + 1 Q.append(nv) N = int(input()) G = [[]] + [list(map(int, input().split())) for _ in range(N)] for a in range(1, N + 1): b = G[a][2:] G[a] = b # print(G) dist = [-1 for _ in range(N + 1)] start = 1 bfs(start) # print(dist[1:]) for i in range(1, N + 1): print(i, dist[i])
X,Y=map(int, input().split()) v = [300000, 200000, 100000] x = 0 y = 0 if X <= 3: x = int(v[X-1]) if Y <= 3: y = int(v[Y-1]) print(int(x + y + ((X==1) & (Y==1)) * 400000))
0
null
70,120,040,883,854
9
275
x = int(input()) money = 100 count = 0 while money < x: money = (money * 101) // 100 count += 1 print(count)
class stack(): def __init__(self): self.S = [] def push(self, x): self.S.append(x) def pop(self): return self.S.pop() def isEmpty(self): if len(self.S) == 0: return True else: return False areas = input() S1 = stack() S2 = stack() for i, info in enumerate(areas): if info == '/': if S1.isEmpty(): continue left = S1.pop() menseki = i - left while True: if S2.isEmpty(): S2.push([menseki, left]) break if S2.S[-1][1] < left: S2.push([menseki, left]) break menseki += S2.pop()[0] elif info == '\\': S1.push(i) ans = [m[0] for m in S2.S] print(sum(ans)) if len(ans) == 0: print(len(ans)) else: print(len(ans), ' '.join(list(map(str, ans))))
0
null
13,558,540,821,956
159
21
N,P=map(int,input().split()) S=input() list=[0 for _ in range(P)] list[0]=1 now=0 a=0 if P==2 or P==5: M=len(S) S=reversed(S) l=0 for s in S: if int(s)%P==0: a+=M-l l+=1 else: l+=1 print(a) else: b=1 h=0 for s in reversed(S): h=h+b*int(s) list[h%P]+=1 b=b*10%P c=0 for i in range(len(list)): c+=list[i]*(list[i]-1)/2 print(int(c))
X = int(input()) yen_500 = X // 500 yen_5 = (X % 500) // 5 print(yen_500 * 1000 + yen_5 * 5)
0
null
50,310,655,951,768
205
185
n, m, l = [int(i) for i in input().split()] A = [] B = [] C = [] for ni in range(n): A.append([int(i) for i in input().split()]) for mi in range(m): B.append([int(i) for i in input().split()]) for i in range(n): C.append([]) for j in range(l): C[i].append(0) for k in range(m): C[i][j] += A[i][k] * B[k][j] for li in range(n): print(" ".join([str(s) for s in C[li]]))
x=input() if x=='0': print('1') if x=='1': print('0')
0
null
2,158,380,615,030
60
76
import math def main(): n=int(input()) print(math.ceil(n/2)/n) if __name__ == '__main__': main()
n = int(input()) S = list(map(int, input().split())) S.append(0) q = int(input()) T = list(map(int, input().split())) N = 0 for t in T: i = 0 S[n] = t while S[i] != t: i += 1 if i != n: N += 1 print(N)
0
null
88,212,130,360,952
297
22
n = int(input()) str = "" while 1: n, mod = divmod(n, 26) if mod == 0: str = 'z' + str n -=1 else: str = chr(96+mod) + str if n == 0: break print(str)
str = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" input_field = [int(i) for i in str.split(", ")] print(input_field[int(input()) - 1])
0
null
31,016,183,798,522
121
195
N, K = list(map(lambda n: int(n), input().split(" "))) h = list(map(lambda x: int(x), input().split(" "))) print(len(list(filter(lambda height: height >= K, h))))
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, X, mod = mapint() first = set() second = set() in_loop = [] ans = 0 for i in range(min(10**5*2, N)): if X in first: if X in second: break in_loop.append(X) second.add(X) first.add(X) ans += X X = pow(X, 2, mod) else: print(ans) exit() loop_len = len(in_loop) rest = N-len(first)-len(in_loop) ans += (rest//loop_len)*sum(in_loop) amari = rest%loop_len for i in range(amari): ans += in_loop[i] print(ans)
0
null
91,234,931,333,220
298
75
n = int(input()) rem = n%1000 if rem!=0:rem = 1000 - rem print(rem)
T=int(input()) a=T//1000 T=T-1000*a if T==0: print(0) else: print(1000-T)
1
8,488,914,001,974
null
108
108
H,W=map(int,input().split()) ans=0 if H==1 or W==1: ans=1 else: if H%2==0: ans=H*W//2 else: if W%2!=0: ans = H*(W-1)//2+(H//2+1) else: ans=H*W//2 print(ans)
# C - Traveling Salesman around Lake K,N = map(int,input().split()) A = list(map(int,input().split())) tmp = 0 for i in range(N): tmp = max(tmp, (A[i]-A[i-1])%K) print(K-tmp)
0
null
47,303,879,268,280
196
186
import sys def main(): n, m = map(int, input().split()) r = n * (n - 1) / 2 r += m * (m - 1) / 2 print(int(r)) if __name__ == '__main__': main()
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) M=10**6+10 n=int(input()) a=Counter(lmp()).most_common() a=sorted(a, key=lambda x: x[0]) c=[0]*M for j,x in a: if c[j]==0: k=2 while j*k<M: c[j*k]=1 k+=1 ans=0 for x,y in a: if c[x]==0 and y==1: ans+=1 print(ans)
0
null
29,990,669,076,020
189
129
x, y = map(int, input().split()) lst = [] ans = 'No' for i in range(x): lst.append(2) for i in range(x): if sum(lst) == y: ans = 'Yes' break lst[i] = 4 if sum(lst) == y: ans = 'Yes' print(ans)
X, Y = map(int, input().split()) for k in range(X+1): t = X - k if k*4 + t*2 == Y: print("Yes") exit() print("No")
1
13,658,552,200,430
null
127
127
a,b,m=map(int,input().split()) ali= list(map(int,input().split())) bli= list(map(int,input().split())) min=min(ali)+min(bli) for i in range(0,m): x,y,c=map(int,input().split()) mon=ali[x-1]+bli[y-1]-c if mon<min: min=mon print(min)
N, K, C = map(int, input().split()) S = list(input()) l = [0] * N r = [0] * N cnt = 1 yutori = 10 ** 10 for i, s in enumerate(S): if s == "o" and yutori > C: l[i] = cnt yutori = 0 cnt += 1 yutori += 1 S.reverse() yutori = 10 ** 10 cnt = K for i, s in enumerate(S): if s == "o" and yutori > C: r[i] = cnt yutori = 0 cnt -= 1 yutori += 1 ans = set() r.reverse() for i in range(N): if l[i] == r[i] and l[i] > 0: ans.add(i+1) print(*ans, sep="\n")
0
null
47,333,175,125,282
200
182
a, b, c = map(int, input().split()) k = int(input()) for i in range(k): if a >= b: b *= 2 elif b >= c: c *= 2 else: c *= 2 if a < b < c: print("Yes") else: print("No")
a,b,c = map(int,input().split()) k = int(input()) for i in range(k): if(a >= b): b*=2 continue if(b >= c): c*=2 continue if(a<b and b<c): print("Yes") exit() else: print("No")
1
6,855,953,120,268
null
101
101
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) A = list(map(int,readline().split())) A = [(A[i], i) for i in range(N)] A_sort = sorted(A,reverse = True) dp = [-float('inf')]*(N+1) dp[0] = 0 for i in range(N): dp_new = [-float('inf')]*(N+1) pi = A_sort[i][1] #もともといた場所 for l in range(i+1): r = i - l #右を選んだ回数 dp_new[l+1] = max(dp_new[l+1],dp[l] + A_sort[i][0] * (pi-l)) dp_new[l] = max(dp_new[l],dp[l] + A_sort[i][0] * ((N-r-1)-pi)) dp = dp_new print(max(dp))
S = input() Sr = S[ : : -1] hug = 0 for i in range(len(S)): if S[i] != Sr[i]: hug += 1 print((hug + 1) // 2)
0
null
76,772,222,565,628
171
261
X = int(input()) print(X + X**2 + X**3)
i = int(input()) print(i + i**2 + i**3)
1
10,172,466,534,480
null
115
115
from collections import defaultdict n=int(input()) a=[int(i) for i in input().split()] INF=float('inf') dp0=defaultdict(lambda: -INF) dp1=defaultdict(lambda: -INF) dp0[(0,0)]=0 for i in range(1,n+1): for j in range(i//2-1,(i+1)//2+1): dp0[(i,j)]=max(dp0[(i-1,j)],dp1[(i-1,j)]) dp1[(i,j)]=dp0[(i-1,j-1)]+a[i-1] print(max(dp0[(n,n//2)],dp1[(n,n//2)]))
n,m = map(int, input().split()) h = list(map(int, input().split())) ab = [map(int, input().split()) for _ in range(m)] a,b = [list(i) for i in zip(*ab)] Max = [] for i in range(n): Max.append(0) # print(Max) ans = 0 for i in range(m): Max[a[i]-1] = max(Max[a[i]-1],h[b[i]-1]) Max[b[i]-1] = max(Max[b[i]-1],h[a[i]-1]) for i in range(n): if h[i] > Max[i]: ans += 1 print(ans)
0
null
31,312,466,623,008
177
155
# -*- coding: utf-8 -*- import sys from collections import deque N,u,v=map(int, sys.stdin.readline().split()) al=[ [] for i in range(N+1) ] #隣接リスト for _ in range(N-1): a,b=map(int, sys.stdin.readline().split()) al[a].append(b) al[b].append(a) dist_t=[ 0 for _ in range(N+1) ] #高橋君のスタート地点からの各頂点までの距離 dist_a=[ 0 for _ in range(N+1) ] #青木君のスタート地点からの各頂点までの距離 #print "al :: ",al #高橋君のスタート地点からの各頂点までの距離 Visit=[ 0 for _ in range(N+1) ] q=deque() q.append(u) Visit[u]=1 while q: fro=q.popleft() for to in al[fro]: if Visit[to]==0: Visit[to]=1 #訪問済みに1をセット dist_t[to]=dist_t[fro]+1 #距離を計算 q.append(to) #print "dist_t :: ",dist_t #青木君のスタート地点からの各頂点までの距離 Visit=[ 0 for _ in range(N+1) ] q=deque() q.append(v) Visit[v]=1 while q: fro=q.popleft() for to in al[fro]: if Visit[to]==0: Visit[to]=1 #訪問済みに1をセット dist_a[to]=dist_a[fro]+1 #距離を計算 q.append(to) #print "dist_a :: ",dist_a ans=0 max_a=0 for t,a in zip(dist_t,dist_a): if t<a: ans=max(ans,a) print ans-1
import sys sys.setrecursionlimit(2*10**5) n, u, v = map(int, input().split()) edge = [tuple(map(int, input().split())) for _ in range(n-1)] u -= 1 v -= 1 connect = [set() for _ in range(n)] for a, b in edge: connect[a-1].add(b-1) connect[b-1].add(a-1) du = [0] * n dv = [0] * n def dfs(v, dis, ng, d): d[v] = dis ng.add(v) for w in connect[v]: if w not in ng: dfs(w, dis+1, ng, d) dfs(u, 0, set(), du) dfs(v, 0, set(), dv) ans = 0 for i in range(n): if du[i] < dv[i]: ans = max(ans, dv[i]-1) print(ans)
1
117,691,817,077,120
null
259
259
n = int(input()) #a, b = map(int, input().split()) #l = list(map(int, input().split())) s = input() ans = 1 last = s[0] for i in range(1,n): if last != s[i]: last = s[i] ans = ans + 1 print(ans)
n = int(input()) s = input() b = s[0] ans = 0 for i in range(1, n): if b == s[i]: next else: ans += 1 b = s[i] ans += 1 print(ans)
1
169,712,800,098,790
null
293
293
def main(): stop = list(input()) a, b = 0, 0 for i in stop: if 'A' == i: a+=1 else: b+=1 if a > 0 and b > 0: print('Yes') else: print('No') main()
n = input() print("No" if n.count("A") == 3 or n.count("B") == 3 else "Yes")
1
54,520,061,431,968
null
201
201