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 math import sys import os from operator import mul import bisect sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") N = I() S = list(_S()) ans = 0 r = [] g = [] b = [] for i,s in enumerate(S): if s == 'R': r.append(i) if s == 'G': g.append(i) if s == 'B': b.append(i) # j = bisect.bisect_right(<list>,<value>) # print(r) # print(g) # print(b) # for i in r: # for j in g: # for k in b: # tmp = sorted([i,j,k]) # if not tmp[1]-tmp[0]==tmp[2]-tmp[1]: # ans += 1 ans = len(r)*len(g)*len(b) for i in range(N): for j in range(i,N): k = j + (j-i) if k > N-1: break if S[i]==S[j]: continue if S[i]==S[k] or S[j]==S[k]: continue ans -= 1 print(ans) # R G B # R B G # G B R # G R B # B G R # B R G # i j k # - != - # RBRBGRBGGB # 1122233333 # 0000111233 # 0112223334 # B*3 # G*4 # GB系: (2,4), (4,5) # RB系: (1,3),
n = int(input()) x = list(map(int,input().split())) ans = 100**2 * n for i in range(1,101): energy = 0 for j in x: energy += (i-j)**2 ans = min(ans, energy) print(ans)
0
null
50,642,094,756,180
175
213
from sys import stdin test = list(stdin.readline().rstrip()) result=0 for i in test: result = result + int(i) if (result % 9) == 0: print('Yes') else: print('No')
x = input() s = 0 for i in range(len(x)): s = s + int(x[i]) if s % 9 == 0: print("Yes") else: print("No")
1
4,399,583,775,200
null
87
87
n = int(input()) a = list(map(int, input().split())) le, lo, re, ro = [0], [0], [0], [0] for i in range(n): if i % 2 == 0: le.append(le[-1] + a[i]) else: lo.append(lo[-1] + a[i]) for i in range(n-1, -1, -1): if i % 2 == 0: re.append(re[-1] + a[i]) else: ro.append(ro[-1] + a[i]) le_o = [0] for i in range(len(lo)-1): le_o.append(max(0, le_o[-1] + a[2*i+1] - a[2*i])) if n % 2 == 0: n //= 2 ans = lo[n] for i in range(0, n + 1): ans = max(ans, le[i] + ro[n-i]) print(ans) else: n //= 2 ans = le[n] for i in range(0, n+1): ans = max(ans, le[i] + ro[n-i]) ans = max(ans, lo[i] + re[n-i]) ans = max(ans, le[i] + re[n-i] + le_o[i]) print(ans)
n = int(input()) maximum_profit = -10**9 r0 = int(input()) r_min = r0 for i in range(1, n): r1 = int(input()) if r0 < r_min: r_min = r0 profit = r1 - r_min if profit > maximum_profit: maximum_profit = profit r0 = r1 print(maximum_profit)
0
null
18,833,663,869,920
177
13
import collections N = int(input()) hList = list(map(int, input().split())) count = 0 n_p = collections.Counter([ i + hList[i] for i in range(len(hList))]) for i in range(N): if i - hList[i] > 0: count += n_p.get(i - hList[i], 0) print(count)
import math def fact(n): ans = 1 for i in range(2, n+1): ans*= i return ans def comb(n, c): return fact(n)//(fact(n-c)*c) n = int(input()) nums = list(map(int, input().split())) ans = 0 l = {} r = [] for i in range(1,n+1): if(i + nums[i-1] not in l): l[i+nums[i-1]] =0 l[i+nums[i-1]]+=1 if((-1*nums[i-1])+i in l): ans+=l[(-1*nums[i-1])+i] print(ans)
1
26,218,500,648,782
null
157
157
k = int(input()) a,b = map(int,input().split()) for i in range(a,b+1): if i % k == 0: print("OK") exit() if a % k == 0: print("OK") else: print("NG")
k = int(input()) a, b = map(int, input().split()) x = 0 while True: x += k if a <= x <= b: print('OK') break if x > b: print('NG') break
1
26,437,566,524,952
null
158
158
num = input() lst = [] for x in num: lst.append(int(x)) total = sum(lst) if total % 9 == 0: print('Yes') else: print('No')
n = list(input()) for i in range(len(n)) : n[i] = int(n[i]) if sum(n)%9==0 : print("Yes") else : print("No")
1
4,399,371,923,580
null
87
87
H, W, K = map(int, input().split()) s = [list(input()) for _ in range(H)] c = [[0 for _ in range(W)] for _ in range(H)] # 1×wの一次元の配列で考える。分割したマスをそれぞれホワイトチョコをカウントする # データを加工してから貪欲法を行う # bit全探索: 横線で割るパターン全てについて、縦線での折り方を考える ans = (H-1) * (W-1) for div in range(1<<(H-1)): g = 0 # g: 横線で分割するグループ番号(0、1、2...) id = [0] * H #何行目であるかを識別するid: i=1なら グループiになる for i in range(H): id[i] = g if div>>i&1: # 2進法でdivのi桁目が1の時、そこで分割する g += 1 #分割線がきたらgを増やす g += 1 # グループ数は分割線+1になる # 集計に使うc配列を初期化 for i in range(g): for j in range(W): c[i][j] = 0 # グループごとを各列ごとのホワイトチョコを集計する for i in range(H): for j in range(W): c[id[i]][j] += int(s[i][j]) num = g - 1 #すでに横線で折った回数(グループ数-1) now = [0] * g #現状で何個のホワイトチョコがあるか # 各グループの縦割りの確認 def add(j): for i in range(g): now[i] += c[i][j] #j列目のホワイトチョコを足していく for i in range(g): if now[i] > K: return False return True for j in range(W): if not (add(j)): # ホワイトチョコがKを超えていれば、縦で織る。 num += 1 now = [0] * g if not (add(j)): num = (H-1) * (W-1) break #print(g, c, num) # 横割りの回数、各グループの集計、最終的に折った回数 ans = min(ans, num) # 割った回数値の最小を更新 print(ans)
N, K = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): A[i] -= 1 judge = N*[0] pos = 0 freq = 0 while judge[pos]==0 and K > 0: judge[pos] = 1 pos = A[pos] K -= 1 freq+=1 tmp = pos pos = 0 while pos!=tmp: pos = A[pos] freq -= 1 #print(freq) if K==0: print(pos+1) else: K %= freq pos = tmp for i in range(K): pos = A[pos] print(pos+1)
0
null
35,722,029,543,072
193
150
import sys import functools # sys.setrecursionlimit(100000000) n = input() # import random # n = ''.join(str(random.randint(1,9)) for _ in range(10**6)) # # @functools.lru_cache(None) # def doit(index: int, carry: int) -> int: # if index >= len(n): # return 0 if carry == 0 else 2 # d = int(n[index]) # if carry > 0: # return min(10 - d + doit(index + 1, 0), 9 - d + doit(index + 1, 1)) # else: # return min(d + doit(index + 1, 0), d + 1 + doit(index + 1, 1)) # # # print(min(doit(0, 0), 1 + doit(0, 1))) dp = [0, 2] for d in reversed(n): d = int(d) dp = [min(d + dp[0], d + 1 + dp[1]), min(10 - d + dp[0], 9 - d + dp[1])] print(min(dp[0], 1 + dp[1]))
def sell(rate, kabu): return rate * kabu def buy(rate, money): kabu = money//rate otsuri = money % rate return kabu, otsuri N,*A = map(int, open(0).read().split()) money = 1000 have_kabu = 0 for i in range(N): #売る money += sell(A[i], have_kabu) have_kabu = 0 #買う if i != N-1 and A[i] < A[i+1]: have_kabu, money = buy(A[i], money) print(money)
0
null
38,976,222,602,078
219
103
from collections import Counter N = int(input()) c = input() cntr = Counter(c) ans = 0 for c, r in zip(c, "R" * cntr["R"]): if c != r: ans += 1 print(ans)
n = int(input()) wr = input() R_cnt = wr.count('R') ans = wr.count('W',0,R_cnt) print(ans)
1
6,377,729,452,900
null
98
98
a,b,c,d = map(int,input().split()) result=(a*c),(b*c),(a*d),(b*d) print(max(result))
n = int(input()) a = list(map(int, input().split())) m = 65 # a<2**m mod = 10**9+7 xor_num = [0]*m for i in range(n): for j in range(m): if ((a[i] >> j) & 1): xor_num[j] += 1 b = 1 ans = 0 for i in range(m): ans += b*xor_num[i]*(n-xor_num[i]) b *= 2 b %= mod print(ans%mod)
0
null
62,793,546,291,784
77
263
s = input() days_of_the_week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] n = days_of_the_week.index(s) print(7 - days_of_the_week.index(s))
S = input() day = ["SAT","FRI","THU","WED","TUE","MON","SUN"] print(day.index(S) + 1)
1
133,274,027,962,560
null
270
270
S = input() print('Yes' if S != 'AAA' and S != 'BBB' else 'No')
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)
0
null
60,002,314,327,798
201
213
K = int(input()) S = input() M = int(10 ** 9 + 7) fact = [1] for i in range(1, K + len(S) + 10): fact.append(fact[-1] * i % M) finv = [pow(fact[-1], M - 2, M)] for i in range(K + len(S) + 9, 0, -1): finv.append(finv[-1] * i % M) finv.reverse() def comb(a, b, m): return fact[a] * finv[b] % m * finv[a - b] % m def hcomb(a, b, m): return comb(a + b - 1, a - 1, m) ans = 0 for l in range(0, K + 1): ans += pow(26, l, M) * pow(25, K - l, M) % M * hcomb(len(S), K - l, M) % M ans %= M print(ans)
h, w, k = map(int, input().split()) s = [list(map(int, input())) for _ in range(h)] ans = float("inf") for sep in range(1 << (h-1)): g_id = [0] * h cur = 0 for i in range(h-1): g_id[i] = cur if sep >> i & 1: cur += 1 g_id[h-1] = cur g_num = cur+1 ng = False for i in range(w): tmp = [0] * g_num for j in range(h): tmp[g_id[j]] += s[j][i] if any([x > k for x in tmp]): ng = True; break if ng: continue res = g_num-1 gs = [0] * g_num for i in range(h): gs[g_id[i]] += s[i][0] for i in range(1, w): tmp = gs[::] for j in range(h): tmp[g_id[j]] += s[j][i] if any([x > k for x in tmp]): res += 1 gs = [0] * g_num for j in range(h): gs[g_id[j]] += s[j][i] ans = min(ans, res) print(ans)
0
null
30,629,066,492,962
124
193
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) n, m, k = map(int, input().split()) friends = UnionFind(n) direct_friends = [0] * n enemies = [[] for _ in range(n)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 direct_friends[a] += 1 direct_friends[b] += 1 friends.union(a, b) for i in range(k): c, d = map(int, input().split()) c -= 1 d -= 1 enemies[c].append(d) enemies[d].append(c) ans = [] for i in range(n): num = friends.size(i) - 1 - direct_friends[i] for enm in enemies[i]: if friends.same(i, enm): num -= 1 ans.append(num) print(*ans)
from collections import deque N, M, K = map(int,input().split()) friendlist = [[] for _ in range(N+1)] for n in range(M): A, B = map(int,input().split()) friendlist[A].append(B) friendlist[B].append(A) blocklist = [[] for _ in range(N+1)] for n in range(K): C, D = map(int, input().split()) blocklist[C].append(D) blocklist[D].append(C) whatgroup = [-1 for _ in range(N+1)] visited = [-1] * (N+1) d = deque() leaderdic = {} for person in range(1,N+1): d.append(person) leader = person cnt = 0 while len(d)>0: nowwho = d.popleft() if whatgroup[nowwho] != -1: continue d.extend(friendlist[nowwho]) whatgroup[nowwho] = leader cnt += 1 if cnt != 0: leaderdic[leader] = cnt for person in range(1,N+1): ans = leaderdic[whatgroup[person]] ans -= 1 ans -= len(friendlist[person]) for block in blocklist[person]: if whatgroup[person]==whatgroup[block]: ans -= 1 print(ans)
1
61,434,598,426,432
null
209
209
str = input() nums = str.split() if nums[0] == "0" or nums[1] == "0": print("error") else: turn = float(nums[0]) / float(nums[1]) + 0.9 if turn < 1: turn = 1 print(int(turn))
h, a = map(int,input().split()) print(h//a + min(h%a,1))
1
76,753,547,803,482
null
225
225
import numpy as np from numba import njit N,K = map(int, input().split()) A = np.array(list(map(int, input().split()))) @njit def main(N, K, A): for _ in range(min(K, 42)): A_ = np.zeros_like(A) for n in range(N): A_[max(0, n - A[n])] += 1 if n + A[n] + 1 < N: A_[n + A[n] + 1] -= 1 A = A_.cumsum() return A print(*main(N, K, A))
import sys import numpy as np input = sys.stdin.buffer.readline N = int(input()) A = np.array(list(map(int, input().split()))) MOD = 10**9 + 7 answer = 0 for n in range(63): B = (A >> n) & 1 x = np.count_nonzero(B) y = N - x x *= y for _ in range(n): x = x * 2 % MOD answer += x answer %= MOD print(answer)
0
null
69,584,527,536,218
132
263
import sys input = sys.stdin.readline n,m=map(int,input().split()) d={i+1:[] for i in range(n)} for i in range(m): x,y=map(int,input().split()) d[x].append(y) d[y].append(x) visit=set() ans= 0 for i in range(1,n+1): if i not in visit: ans+=1 stack = [i] while stack: c=stack.pop() visit.add(c) for i in d[c]: if i not in visit: stack.append(i) print(ans-1)
n = int(input()) #a, b, h, m = map(int, input().split()) #al = list(map(int, input().split())) #al=[list(input()) for i in range(h)] l = 1 total = 26 while n > total: l += 1 total += 26**l last = total-26**l v = n-last-1 ans = '' # 26進数だと見立てて計算 for i in range(l): c = v % 26 ans += chr(ord('a')+c) v = v//26 print("".join(ans[::-1]))
0
null
7,033,951,958,008
70
121
s = input() n = len(s) s_re =s[::-1] s_first = s[:(n-1)//2] s_first_re = s_first[::-1] s_second = s[(n+3)//2-1:] s_second_re = s_second[::-1] print(['No','Yes'][s == s_re and s_first==s_first_re and s_second == s_second_re])
S = input() s = list(S) f = s[:int((len(s)-1)/2)] l = s[int((len(s)+3)/2-1):] if f == l: while len(f) > 1: if f[0] == f[-1]: f.pop(0) f.pop() if len(f) <= 1: while len(l) > 1: if l[0] == l[-1]: l.pop(0) l.pop() if len(l) <= 1: print('Yes') else: print('No') else: print('No') else: print('No')
1
46,310,980,798,420
null
190
190
from collections import defaultdict n = int(input()) a = [0] a.extend(map(int, input().split())) mp = defaultdict(int) ans = 0 for i in range(1, n+1): ans += mp[i-a[i]] mp[i+a[i]] += 1 print(ans)
from collections import Counter N = int(input()) A = list(map(int, input().split())) L = [-1 for _ in range(N)] R = [-1 for _ in range(N)] for i in range(N): L[i] = A[i] - i-1 R[i] = A[i] + i+1 # L = -R となる物のうち、i>jになりゃいいんだけど、最後にいくつかで破れば良い気がす # i > 0 なので、自分自身を2回選んでL=Rみたいにはならない・・・? LC = Counter(L) RC = Counter(R) ans = 0 for k,v in LC.items(): if (-1) * k in RC: ans += v * RC[(-1)*k] #print(k,v,(-1)*k,RC[(-1)*k], ans) print(ans)
1
26,131,889,100,060
null
157
157
from collections import * n=int(input()) l=[] for i in range(n): l.append(input()) c=Counter(l) m=max(c.values()) d=[] for i in c: if(c[i]==m): d.append(i) d.sort() for i in d: print(i)
n = int(input()) d = dict(zip([i for i in range(1, n + 1)], [0] * n)) l = map(int, input().split()) for i in l: d[i] += 1 for i in d.values(): print(i)
0
null
50,987,752,545,482
218
169
x=int(input()) if x>=400 and x<=599: print(8) exit() if x>=600 and x<=799: print(7) exit() if x>=800 and x<=999: print(6) exit() if x>=1000 and x<=1199: print(5) exit() if x>=1200 and x<=1399: print(4) exit() if x>=1400 and x<=1599: print(3) exit() if x>=1600 and x<=1799: print(2) exit() if x>=1800 and x<=1999: print(1) exit()
import sys def gcd(inta, intb): large = max(inta, intb) small = min(inta,intb) mod = large % small if mod ==0: return small else: return gcd(small, mod) def lcm(inta, intb, intgcd): return (inta * intb // intgcd) sets = sys.stdin.readlines() for line in sets: a, b = map(int, line.split()) c = gcd(a, b) print(c, lcm(a, b, c))
0
null
3,365,967,351,472
100
5
A, B, C, K = [int(_) for _ in input().split()] print(K if K <= A else A if K <= A + B else A - (K - A - B))
A, B, C, K = map(int, input().split()) if (K - A) <= 0: print(K) else: if (K - A - B) <= 0: print(A) else: c = (K - A - B) print(A - c)
1
21,868,797,688,068
null
148
148
def input_int(): return map(int, input().split()) def one_int(): return int(input()) def one_str(): return input() def many_int(): return list(map(int, input().split())) A, B = input_int() print(A*B)
a,b=input().split(' ') if int(a)<=100 and int(b)<=100: print(int(a)*int(b)) else: pass
1
15,808,797,612,960
null
133
133
str = input() n = int(len(str) / 2) cnt = 0 for i in range(n): if str[i] != str[-1-i]: cnt += 1 print(cnt)
a,b = input().split() #print(a,b) A = int(a) x,y = b.split('.') B = int(x)*100+int(y) print(int(A*B)//100)
0
null
68,610,523,110,272
261
135
from math import sin,cos,pi,sqrt a,b,d=map(float,input().split()) S=a*b*sin(d*pi/180)/2 c=sqrt(a**2+b**2-2*a*b*cos(d*pi/180)) h=2*S/a print(S) print(a+b+c) print(h)
def flg(s): le = len(s) // 2 return s[:le] == s[::-1][:le] s = input() le1 = len(s) // 2 t = s[:le1] print(["No", "Yes"][flg(s) and flg(t)])
0
null
23,164,914,472,688
30
190
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9+7 def lcm(x,y): return x*y//gcd(x,y) def lgcd(l): return reduce(gcd,l) def llcm(l): return reduce(lcm,l) def powmod(n,i,mod): return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod) def div2(x): return x.bit_length() def div10(x): return len(str(x))-(x==0) def intput(): return int(input()) def mint(): return map(int,input().split()) def lint(): return list(map(int,input().split())) def ilint(): return int(input()), list(map(int,input().split())) def judge(x, l=['Yes', 'No']): print(l[0] if x else l[1]) def lprint(l, sep='\n'): for x in l: print(x, end=sep) def ston(c, c0='a'): return ord(c)-ord(c0) def ntos(x, c0='a'): return chr(x+ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self,x,d=1): self.setdefault(x,0) self[x] += d def list(self): l = [] for k in self: l.extend([k]*self[k]) return l class comb(): def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self,k): l,n,mod = self.l, self.n, self.mod k = n-k if k>n//2 else k while len(l)<=k: i = len(l) l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod) return l[k] def pf(x): C = counter() p = 2 while x>1: k = 0 while x%p==0: x //= p k += 1 if k>0: C.add(p,k) p = p+2-(p==2) if p*p<x else x return C H,W,K=mint() s=[input() for _ in range(H)] res=[[0]*W for _ in range(H)] ans=1 index=[] for k in range(H): index.append(k) if s[k].count('#')==0: continue tmp=True for j in range(W): if s[k][j]=='#': K-=1 if tmp: tmp=False else: ans+=1 for i in index: res[i][j]=ans ans+=1 index=[] if K==0: for i in range(k+1,H): for j in range(W): res[i][j]=res[k][j] break for r in res: lprint(r,' ') print('')
H, W, K = map(int, input().split()) s = ['' for i in range(H)] for i in range(H): s[i] = input() now = 1 ans = [[] for i in range(H)] count = 0 flag = False for i in range(H): gokei = s[i].count('#') shap = 0 if gokei >= 1: flag = True for j in range(W): ans[i].append(now) if j == W-1: now += 1 elif s[i][j] == '#' and shap < gokei-1: now += 1 shap += 1 elif s[i][j] == '#' and shap == gokei-1: shap += 1 elif gokei == 0 and flag: ans[i] = ans[i-1] elif gokei == 0 and flag == False: count += 1 for i in range(count): ans[i] = ans[count] for i in range(H): print(*ans[i])
1
143,138,090,324,190
null
277
277
while True: c = input().split() x, y = int(c[0]), int(c[1]) if x == y == 0: break if y < x: x, y = y, x print("%d %d" % (x, y))
while True: (x, y) = [int(i) for i in input().split()] if x < y: print(x, y) elif x > y: print(y, x) elif x == y: if x == 0 and 0 == y: break print(x, y)
1
507,876,302,710
null
43
43
n, k = map(int, input().split()) data = list(map(int, input().split())) ans = 0 for d in data: if d >= k: ans += 1 print(ans)
import math import sys from collections import deque import heapq import copy import itertools from itertools import permutations from itertools import combinations import bisect def mi() : return map(int,sys.stdin.readline().split()) def ii() : return int(sys.stdin.readline().rstrip()) def i() : return sys.stdin.readline().rstrip() a,b=mi() l=list(mi()) l=sorted(l) ind=bisect.bisect_left(l,b) print(a-ind)
1
178,851,238,641,248
null
298
298
n = int(input()) s = [] for _ in range(n): s.append(str(input())) print('AC x ' + str(s.count('AC'))) print('WA x ' + str(s.count('WA'))) print('TLE x ' + str(s.count('TLE'))) print('RE x ' + str(s.count('RE')))
N = int(input()) n = 0 if not N%2: s = 5 N = N//2 while N>=s: n += N//s s *= 5 print(n)
0
null
62,021,225,074,672
109
258
import collections a=int(input()) b=list(map(int,input().split())) c=collections.Counter(b) n,m=zip(*c.most_common()) n,m=list(n),list(m) result=0 for i in range(len(m)): result+=(m[i]*(m[i]-1))//2 for i in b: print(result-c[i]+1)
N = int(input()) Alst = list(map(int, input().split())) Blst = [0]*(N+1) num = 0 for i in Alst: num = num + Blst[i] Blst[i] += 1 for i in Alst: k = Blst[i] -1 print(num - k)
1
47,748,583,400,378
null
192
192
n = int(input()) a = 0 b = 0 for _ in range(n): word_a, word_b = input().split() words = [word_a, word_b] words.sort() if word_a == word_b: a += 1 b += 1 elif words.index(word_a) == 1: a += 3 else: b += 3 print(a, b)
n = int(input()) t = 0 h = 0 for i in range(n): taro,hana = input().split() if taro == hana: t += 1 h += 1 else: m = list((taro,hana)) m.sort() if m == list((taro,hana)): h += 3 else: t += 3 print("{} {}".format(t,h))
1
2,009,639,426,624
null
67
67
H,W = map(int,input().split()) P = H*W if H == 1 or W ==1: print(1) elif P%2 == 0: print(int(P/2)) else: print(int(P/2)+1)
a=int(input()) print(2*3.1416*a)
0
null
41,244,277,399,272
196
167
n, m = map(int, input().split()) *C, = map(int, input().split()) # n, m = 15, 6 # C = [1, 2, 7, 8, 12, 50] # DP[i][j]=i種類以内でj円払う最小枚数 inf = 10**10 DP = [[inf for j in range(n+1)] for i in range(m+1)] DP[0][0] = 0 for i in range(m): for j in range(n+1): if j < C[i]: DP[i+1][j] = DP[i][j] else: DP[i+1][j] = min(DP[i][j], DP[i+1][j-C[i]]+1) print(DP[m][n])
from collections import deque def min_coin_select(C, m, n): DP = [float('inf')] * (n+1) DP[0] = 0 # Cのindexが合わないので左をゼロ埋め。Cはdequeとする。 C.appendleft(0) for i in range(1, m+1): for j in range(1, n+1): if j >= C[i]: DP[j] = min(DP[j-C[i]] + 1, DP[j]) return DP[n] def read_and_print_results(): n, m = [int(i) for i in input().split()] C = deque([int(i) for i in input().split()]) print(min_coin_select(C, m, n)) read_and_print_results()
1
143,886,876,772
null
28
28
N = int(input()) if N %2 == 0: K = N//2 else: K = N//2+1 print(K/N)
#!/usr/bin/env python3 #!/usr/bin/env python3 N = int(input()) print(0.5 if N % 2 == 0 else ((N//2)+1) / N)
1
177,331,926,860,686
null
297
297
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from bisect import bisect_left def comb(n, k): if n < 0 or n < k or k < 0: return 0 return fac[n] * ifac[k] * ifac[n - k] % mod n, k, *a = map(int, read().split()) a.sort() mod = 10 ** 9 + 7 max_n = 2 * 10 ** 5 + 1 ans = 0 fac = [1] * max_n inv = [1] * max_n ifac = [1] * max_n for i in range(2, max_n): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod ifac[i] = ifac[i - 1] * inv[i] % mod for i, aa in enumerate(a): ans += aa * (comb(i, k - 1) - comb(n - 1 - i, k - 1)) ans %= mod print(ans)
import itertools from collections import deque,defaultdict,Counter from itertools import accumulate import bisect from heapq import heappop,heappush,heapify import math from copy import deepcopy import queue import numpy as np # sympy as syp(素因数分解とか) Mod = 1000000007 fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, 10**5 + 1): fact.append((fact[-1] * i) % Mod) inv.append((-inv[Mod % i] * (Mod // i)) % Mod) factinv.append((factinv[-1] * inv[-1]) % Mod) def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n - r] % p def sieve_of_eratosthenes(n): if not isinstance(n,int): raise TypeError("n is not int") if n<2: raise ValueError("n is not effective") prime = [1]*(n+1) for i in range(2,int(math.sqrt(n))+1): if prime[i] == 1: for j in range(2*i,n+1): if j%i == 0: prime[j] = 0 res = [] for i in range(2,n+1): if prime[i] == 1: res.append(i) return res class UnionFind: def __init__(self,n): self.parent = [i for i in range(n+1)] self.rank = [0 for i in range(n+1)] def findroot(self,x): if x == self.parent[x]: return x else: y = self.parent[x] y = self.findroot(self.parent[x]) return y def union(self,x,y): px = self.findroot(x) py = self.findroot(y) if px < py: self.parent[y] = px else: self.parent[px] = py def same_group_or_no(self,x,y): return self.findroot(x) == self.findroot(y) def main(): #startline------------------------------------------- n, k = map(int, input().split()) a=list(map(int, input().split())) a.sort() ans = 0 for i in range(n - k + 1): t = cmb(n - i - 1, k - 1, Mod) ans += (a[n - i - 1] * t % Mod - (a[i] * t % Mod)) % Mod print(ans%Mod) if __name__ == "__main__": main() #endline===============================================
1
95,443,288,732,640
null
242
242
H = int(input()) c=1 h=H while 1: h = h//2 if h==0 : break c+=(1+c) print(c)
def solve(n): if n is 0: return 0 return 1 + 2 * solve(n // 2) print(solve(int(input())))
1
80,270,468,733,548
null
228
228
n,k=map(int,input().split()) sunu=[0]*n for i in range(k): d=int(input()) a=list(map(int,input().split())) for j in range(d): sunu[a[j]-1]+=1 ans=0 for i in range(len(sunu)): if sunu[i]==0: ans+=1 print(ans)
n = input() k = int(input()) dp0 = [[0]*(k+1) for _ in range(len(n)+1)] dp1 = [[0]*(k+1) for _ in range(len(n)+1)] dp0[0][0] = 1 for i in range(len(n)): for j in range(k+1): if int(n[i]) == 0: dp0[i+1][j] += dp0[i][j] if int(n[i]) > 0: dp1[i+1][j] += dp0[i][j] if j < k: dp0[i+1][j+1] += dp0[i][j] dp1[i+1][j+1] += dp0[i][j]*(int(n[i])-1) if j < k: dp1[i+1][j+1] += dp1[i][j]*9 dp1[i+1][j] += dp1[i][j] print(dp0[len(n)][k]+dp1[len(n)][k])
0
null
50,454,822,200,608
154
224
n=int(input());print(str(n//3600)+":"+str((n//60)%60)+":"+str(n%60))
import math def main(): n=int(input()) print(math.ceil(n/2)/n) if __name__ == '__main__': main()
0
null
88,346,648,799,480
37
297
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) h, w, k = map(int, readline().split()) a = [readline().rstrip().decode() for _ in range(h)] cnt = 0 memo = 0 for aa in a: memo += 1 low, high = -1, aa.find('#') if high == -1: continue ans = [] while high != -1: cnt += 1 ans += [cnt] * (high - low) low, high = high, aa.find('#', high + 1) ans += [cnt] * (w - low - 1) for i in range(memo): print(*ans) memo = 0 for i in range(memo): print(*ans)
def main(): n = int(input()) s = list(map(int,input().strip().split())) e = [] for ss in s: if ss % 2 == 0: e.append(ss) for ee in e: if ee % 3 == 0 or ee % 5 == 0: continue else: print("DENIED") return print("APPROVED") return main()
0
null
106,324,585,848,940
277
217
while True: n = input() if n == 0: break print sum(map(int, list(str(n))))
#! /usr/bin/python3 m=[int(input()) for i in range(10)] m.sort() m.reverse() print("{0}\n{1}\n{2}".format(m[0], m[1], m[2]))
0
null
802,805,213,316
62
2
num = int(input()) a = "" for _ in range(num): a += "ACL" print(a)
a,b,c,d = map(int, input().split()) x1=a*c x2=a*d x3=b*c x4=b*d print(max(x1,x2,x3,x4))
0
null
2,587,586,619,658
69
77
from collections import defaultdict def combination(a, b): if b > a - b: return combination(a, a - b) return fact[a] * ifact[b] * ifact[a-b] MOD = 10**9+7 n, k = map(int, input().split()) k = min(k, n-1) # 階乗を前処理 fact = defaultdict(int) fact[0] = 1 for i in range(1, n+1): fact[i] = fact[i-1] * i fact[i] %= MOD # 階乗の逆元を前処理 ifact = defaultdict(int) ifact[n] = pow(fact[n], MOD-2, MOD) for i in reversed(range(1, n + 1)): ifact[i-1] = ifact[i] * i ifact[i-1] %= MOD ans = 0 for i in range(k+1): ans += combination(n, i) * combination((n-i-1)+i, i) ans %= MOD print(ans % MOD)
import sys import numpy as np sys.setrecursionlimit(10 ** 7) N, K = map(int, input().split()) MOD = 10 ** 9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(N * 2 + 10, MOD) fact, fact_inv = fact.tolist(), fact_inv.tolist() def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD)) a %= MOD ans += a ans %= MOD ''' a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1]) a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \ int(fact_inv[N-i-1]) % MOD ans = (a + ans) % MOD ''' print(ans)
1
67,143,590,208,422
null
215
215
import fractions lst = [] for i in range(200): try: lst.append(input()) except EOFError: break nums = [list(map(int, elem.split(' '))) for elem in lst] # gcd res_gcd = [fractions.gcd(num[0], num[1]) for num in nums] # lcm res_lcm = [nums[i][0] * nums[i][1] // res_gcd[i] for i in range(len(nums))] for (a, b) in zip(res_gcd, res_lcm): print('{} {}'.format(a, b))
def GCD(a, b): if b == 0: return a return GCD(b, a % b) def LCM(a, b): return a * b // GCD(a, b) import sys s = sys.stdin.readlines() n = len(s) for i in range(n): x, y = map(int, s[i].split()) print(GCD(x, y), LCM(x, y))
1
732,829,410
null
5
5
#coding: utf-8 x=input() y=x*x*x print y
x = input() print(int(x)*int(x)*int(x))
1
269,622,450,020
null
35
35
import itertools from typing import List def main(): h, w, k = map(int, input().split()) c = [] for _ in range(h): c.append(list(input())) print(hv(c, h, w, k)) def hv(c: List[List[str]], h: int, w: int, k: int) -> int: ret = 0 for comb_h in itertools.product((False, True), repeat=h): for comb_w in itertools.product((False, True), repeat=w): cnt = 0 for i in range(h): for j in range(w): if comb_h[i] and comb_w[j] and c[i][j] == '#': cnt += 1 if cnt == k: ret += 1 return ret if __name__ == '__main__': main()
import sys import itertools input = sys.stdin.readline def SI(): return str(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): H, W, K = MI() grid = [SI().rstrip('\n') for _ in range(H)] n = H + W ans = 0 for i in itertools.product(range(2),repeat = H): for j in itertools.product(range(2),repeat = W): count = 0 for k in range(H): if i[k] == 1: continue for l in range(W): if j[l] == 1: continue if grid[k][l] == "#": count += 1 if count == K: ans +=1 print(ans) main()
1
8,919,169,435,160
null
110
110
N, M = map(int, input().split()) assert 2*M+1 <= N if M % 2 == 1: step_m1 = M step_m2 = M - 1 else: step_m1 = M - 1 step_m2 = M assert step_m1 + 1 + step_m2 + 1 <= N ans = [] a = 0 for step in range(step_m1, -1, -2): # print(step) # print(a, a+step) ans.append([a+1, a+step+1]) a += 1 a = step_m1 + 1 for step in range(step_m2, 0, -2): # print(step) # print(a, a+step) ans.append([a+1, a+step+1]) a += 1 print('\n'.join(map(lambda L: ' '.join(map(str, L)), ans)))
# import math # import statistics a=input() b=input() #b,c=int(input()),int(input()) c,d=[],[] for i in a: c.append(i) for i in b: d.append(i) #e1,e2 = map(int,input().split()) # f = list(map(int,input().split())) #g = [input() for _ in range(a)] # h = [] # for i in range(e1): # h.append(list(map(int,input().split()))) ma=[] if b in a: print(0) else: for i in range(len(c)-len(d)+1): count=0 for k in range(len(d)): if c[i:len(d)+i][k]!=d[k]: count+=1 ma.append(count) print(min(ma))
0
null
16,122,140,867,820
162
82
import math from functools import reduce n, m = input().split() a = list(map(int, input().split())) b =[0]*int(n) for i in range(len(a)): b[i] = a[i]//2 def lcm_base(x, y): return (x * y) // math.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) c = 0 x = lcm_list(b) for i in range(int(n)): if (x // b[i]) % 2 == 0: c = -1 break else: continue if c == -1: print(0) else: print(math.floor(((int(m)/x)+1)/2))
n=int(input()) for x in range(n+1): if int(x*1.08)==n: print(x) exit() print(":(")
0
null
114,139,995,140,708
247
265
a,b = map(int,input().split()) if(a-(2*b)<0): print(0) else: print(a-(2*b))
A,B = map(int,input().split()) if A <= 2*B: x = 0 else: x = A - 2*B print(x)
1
166,690,088,877,994
null
291
291
n = int(input()) a = list(map(int, input().split())) a.sort() m = a[-1] c = [0] * (m + 1) for ai in a: for i in range(ai, m + 1, ai): c[i] += 1 ans = 0 for ai in a: if c[ai] == 1: ans += c[ai] print(ans)
#!/usr/bin/env python3 import sys def solve(N: int, A: int, B: int): c = A + B d = N // c ans = d * A e = N % c if e >= A: ans += A else: ans += e print(ans) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int solve(N, A, B) if __name__ == '__main__': main()
0
null
34,864,627,441,560
129
202
import sys from decimal import Decimal as D, ROUND_FLOOR def resolve(in_): x = D(next(in_)) year = 0 deposit = D('100') rate = D('1.01') a = D('1.') while deposit < x: year += 1 deposit *= rate deposit = deposit.quantize(a, rounding=ROUND_FLOOR) return year def main(): answer = resolve(sys.stdin) print(answer) if __name__ == '__main__': main()
X=int(input()) ans=100 count=0 while ans<X: ans=ans+(ans//100) count+=1 print(count)
1
26,853,935,012,672
null
159
159
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)
s = input() s1 = s[:len(s) // 2] s2 = s[:len(s) // 2:-1] s3 = s[len(s) // 2 + 1:] if s1 == s2 == s3: print('Yes') else: print('No')
0
null
33,415,973,765,210
145
190
def ans(n,k): if n==0: return k else: return ans(n//2,k)*2+1 N=int(input()) print(ans(N,0))
n=int(input()) ans=0 m=1 while n>1: n=n//2 ans+=m m*=2 print(ans+m)
1
80,147,472,229,048
null
228
228
import itertools n, x, y = map(int, input().split()) k = [0] * n for v in itertools.combinations(list(range(1,n+1)), 2): k[min(abs(v[1]-v[0]),abs(x-min(v))+1+abs(y-max(v)))] += 1 for item in k[1:]: print(item)
from collections import deque, defaultdict def main(): N, X, Y = map(int, input().split()) g = [[] for _ in range(N)] for i in range(N-1): g[i].append(i+1) g[i+1].append(i) g[X-1].append(Y-1) g[Y-1].append(X-1) ans = defaultdict(int) for i in range(N): q = deque() q.append(i) visit_time = [0 for _ in range(N)] while len(q): v = q.popleft() time = visit_time[v] for j in g[v]: if visit_time[j] == 0 and j != i: q.append(j) visit_time[j] = time + 1 else: visit_time[j] = min(time + 1, visit_time[j]) for v in visit_time: ans[v] += 1 for i in range(1, N): print(ans[i] // 2) if __name__ == '__main__': main()
1
44,352,441,124,860
null
187
187
N = int(input()) D = list(map(int, input().split())) if D[0] != 0: print(0) else: tmp = [0 for _ in range(10 ** 5)] for i in range(N): tmp[D[i]] += 1 if tmp[0] != 1: print(0) else: ans = 1 flag = False flag2 = False for i in range(1, 10 ** 5 - 1): if flag2 and tmp[i+1] != 0: ans = 0 break if tmp[i+1] == 0: flag2 = True ans = (ans * (tmp[i] ** tmp[i+1])) % 998244353 print(ans)
n=int(input()) d=list(map(int,input().split())) if d[0]!=0: print(0) exit() del d[0] for i in range(n-1): if d[i]==0: print(0) exit() dcnt=[0]*(n) for i in range(n-1): dcnt[d[i]]+=1 for j in range(n-1,-1,-1): if dcnt[j]==0: del dcnt[j] else: break if len(dcnt)==0: print(0) exit() dcnt[0]=1 sum=1 for i in range(1,len(dcnt)): sum*=pow(dcnt[i-1],dcnt[i]) sum%=998244353 print(sum)
1
155,021,639,408,188
null
284
284
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() n = len(s) ans = 0 cnt = 0 before_cnt = 0 now = s[0] for x in s: if now == x: # 同じ不等号が連続しているとき cnt += 1 else: # 不等号が変わるとき ans += cnt * (cnt + 1) // 2 if now == '>': # > から < に変わるとき if before_cnt < cnt: ans -= before_cnt else: ans -= cnt before_cnt = cnt cnt = 1 now = x ans += cnt * (cnt + 1) // 2 if now == '>': if before_cnt < cnt: ans -= before_cnt else: ans -= cnt print(ans)
N = int(input()) N += 1 print(N // 2)
0
null
108,058,604,049,042
285
206
#!/usr/bin/env python # coding: utf-8 # In[86]: # ans = [0]*(len(S)+1) # for i in range(len(S)): # count_left = 0 # count_right = 0 # for j in range(i): # if S[i-j-1] == "<": # count_left += 1 # else: # j -= 1 # break # for k in range(i,len(S)): # if S[k] == ">": # count_right += 1 # else: # k -= 1 # break # ans[i] = max(count_left, count_right) # # print(count_left, count_right) # # print(S[i-j-1:i], S[i:k+1]) # # print(ans) # print(sum(ans)) # In[87]: from collections import deque S = input() left = deque([0]) right = deque([0]) cnt = 0 for s in S: if s == '<': cnt += 1 else: cnt = 0 left.append(cnt) cnt = 0 for s in S[::-1]: if s == '>': cnt += 1 else: cnt = 0 right.appendleft(cnt) ans = 0 for l, r in zip(left, right): ans += max(l, r) print(ans) # In[ ]:
S = input() N = len(S) ans = 0 i = 0 while i < N and S[i]=='>': i += 1 ans += i*(i+1)//2 arr = [i] while i < N: while i < N and S[i]=='<': i += 1 arr.append(i) if i==N: break while i < N and S[i]=='>': i += 1 arr.append(i) arr = [b-a for a,b in zip(arr,arr[1:])] for a,b in zip(arr[::2],arr[1::2]): if a<b: a,b = b,a ans += a*(a+1)//2 ans += b*(b-1)//2 if len(arr)%2: ans += arr[-1]*(arr[-1]+1)//2 print(ans)
1
156,794,616,019,996
null
285
285
N,K=map(int,input().split()) A=0 for a in range(100000000000000): if N>K: kot=N%K if abs(K-kot)>kot: print(kot) break else: print(abs(K-kot)) break if N%K==0: print(0) break if N<K: if abs(N-K)<N: print(abs(N-K)) break else: print(N) break tugi=abs(N-K) N=tugi A=tugi tugi=abs(N-K) B=tugi N=tugi tugi=abs(N-K) if A==tugi: if B<A: print(B) break else: print(A) break
n,k=map(int,input().split()) ans=n%k print(min(ans,abs(ans-k)))
1
39,370,376,808,100
null
180
180
A,B,C,K = map(int,input().split()) if A>=K: print(K) else: K-=A if B>=K: print(A) else: K-=B print(A-K)
import collections n = int(input()) A = list(map(int, input().split())) A.sort() cnt = collections.Counter(A) #print(cnt) for a in A: if cnt[a] >= 2: del cnt[a] for j in range(2*a, A[-1]+1, a): del cnt[j] #print(cnt) print(len(cnt))
0
null
18,099,280,719,442
148
129
minute = int(input()) print('{}:{}:{}'.format(minute // 3600, (minute % 3600) // 60, (minute % 3600) % 60))
a,b = input().split() print(a*int(b)) if a < b else print(b*int(a))
0
null
42,421,612,718,660
37
232
n = int(input()) p = [] for i in range(n): x,y = map(int,input().split()) p.append([x,y]) q = [] r = [] for i in range(n): q.append(p[i][0]+p[i][1]) r.append(p[i][0]-p[i][1]) q.sort() r.sort() ans = max(abs(q[-1]-q[0]),abs(r[-1]-r[0])) print(ans)
H,W,N=[int(input()) for i in range(3)] print(min((N+H-1)//H,(N+W-1)//W))
0
null
46,018,164,195,728
80
236
A, B = map(int, input().split()) a = [i for i in range(int((A-1)*100/8 ), int((A+1)*100/8 ))] b = [i for i in range(int((B-1)*100/10), int((B+1)*100/10))] a = [i for i in a if int(i*0.08) == A] b = [i for i in b if int(i*0.10) == B] ans = list(set(a) & set(b)) if ans and min(ans) > 0: print(min(ans)) else: print(-1)
from heapq import * import sys from collections import * from itertools import * from decimal import * import copy from bisect import * import math import random sys.setrecursionlimit(4100000) def gcd(a,b): if(a%b==0):return(b) return (gcd(b,a%b)) input=lambda :sys.stdin.readline().rstrip() N=int(input()) mod=10**9+7 dp=[[8,1,1,0] for i in range(N)]#1,2~8,9,both for i in range(1,N): dp[i][0]=dp[i-1][0]*8 dp[i][1]=dp[i-1][0]+dp[i-1][1]*9 dp[i][2]=dp[i-1][0]+dp[i-1][2]*9 dp[i][3]=dp[i-1][1]+dp[i-1][2]+dp[i-1][3]*10 for n in range(4): dp[i][n]%=mod print(dp[-1][3]%mod)
0
null
29,913,536,646,840
203
78
n,k=[int(x) for x in input().split()] ans=0 l=[0]*(k+1) i=k mod=1000000007 while i>0: l[i]=pow(k//i,n,mod) j=2*i while j<=k: l[i]=(l[i]-l[j]+mod)%mod j+=i i-=1 for i in range(1,k+1): ans+=(l[i]*i)%mod print(ans%mod)
from collections import defaultdict N, u, v = map(int, input().split()) d = defaultdict(list) for _ in range(N-1): A, B = map(int, input().split()) d[A].append(B) d[B].append(A) def get_dist(s): dist = [-1]*(N+1) dist[s] = 0 q = [s] while q: a = q.pop() for b in d[a]: if dist[b]!=-1: continue dist[b] = dist[a] + 1 q.append(b) return dist du, dv = get_dist(u), get_dist(v) ds = [(i,j[0], j[1]) for i,j in enumerate(zip(du, dv)) if j[0]<j[1]] ds.sort(key=lambda x:-x[2]) a, b, c = ds[0] print(c-1)
0
null
76,885,278,752,168
176
259
s = list(input()) n = len(s) + 1 left = [0]*n right = [0]*n for i in range(n-1): if s[i] == '<': left[i+1] = left[i] + 1 for i in range(n-2, -1, -1): if s[i] == '>': right[i] = right[i+1] + 1 a = [0]*n for i in range(n): a[i] = max(left[i], right[i]) ans = sum(a) print(ans)
import heapq s = [] h, w = map(int, input().split()) for _ in range(h): s.append(list(input().strip())) ans = 0 for i in range(h): for j in range(w): if s[i][j] == '#': continue q = [(0, (i, j))] mins = [[h * w for _ in range(w)] for _ in range(h)] visited = [[0 for _ in range(w)] for _ in range(h)] while len(q) > 0: c, (x, y) = heapq.heappop(q) ans = max(ans, c) if visited[x][y]: continue visited[x][y] = True for nx, ny in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]: if nx < 0 or nx >= h or ny < 0 or ny >= w or s[nx][ny] == '#': continue if visited[nx][ny]: continue if mins[nx][ny] > c + 1: mins[nx][ny] = c + 1 heapq.heappush(q, (c + 1, (nx, ny))) print(ans)
0
null
125,362,989,216,868
285
241
R = int(input()) print(2 * R * 3.14159265359)
a=int(input()) print(a*6.283185307178)
1
31,477,823,330,778
null
167
167
m1, d1 = map(int, input().split()) m2, d2 = map(int, input().split()) if m1 + 1 == m2 and d2 == 1: print(1) else: print(0)
poi = [0,0] for mak in range(int(input())) : tem = input().split() if tem[0] == tem[1] : poi[0] += 1 poi[1] += 1 else : che = sorted(tem) if tem[0] != che[0] : poi[0] += 3 else : poi[1] += 3 print(poi[0],poi[1])
0
null
63,244,268,814,948
264
67
#!/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, M = MI() print(int(N*(N-1)/2 + M*(M-1)/2)) main()
import itertools import functools import math from collections import Counter from itertools import combinations N,M=map(int,input().split()) ans = 0 if N >= 2: ans += len(list(itertools.combinations(range(N), 2))) if M >= 2: ans += len(list(itertools.combinations(range(M), 2))) print(ans)
1
45,715,944,171,480
null
189
189
def main(): N, K = map(int, input().split()) R, S, P = map(int, input().split()) d = {'r': R, 's': S, 'p': P} T = input() scores = [] for t in T: if t == 'r': scores.append('p') elif t == 's': scores.append('r') else: scores.append('s') for i in range(N-K): if scores[i] == scores[i+K]: scores[i+K] = 0 print(sum([d[v] for v in scores if v in ['p', 'r', 's']])) if __name__ == '__main__': main()
n = int(input()) taro = 0 hanako = 0 for i in range(n): columns = input().rstrip().split() tcard = columns[0] hcard = columns[1] if tcard > hcard: taro += 3 elif hcard > tcard: hanako += 3 else: taro += 1 hanako += 1 print(taro,hanako)
0
null
54,506,769,014,852
251
67
N = int(input()) myans = [ 0 for n in range(N+1)] upper = int(N**(2/3)) #print(upper) for x in range(1, 105): for y in range(1, 105): for z in range(1, 105): v = x**2 + y**2 + z**2 + x*y + y*z + z*x if v < N+1: myans[v] += 1 #print(myans) for a,b in enumerate(myans): if a != 0: print(b)
h1, m1, h2, m2, k = list(map(int, input().split())) s = (h1*60)+m1 e = (h2*60)+m2 print(e-s-k)
0
null
13,026,622,818,248
106
139
a = int(input()) b = int(input()) ans = [1,2,3] ans.remove(a) ans.remove(b) print(ans[0])
A =int(input()) B =int(input()) res = 6- A -B print(res)
1
111,018,374,939,682
null
254
254
S = input() N = len(S) S1 = S[0:(N-1)//2] S2 = S[(N+3)//2-1:] print('Yes' if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1] else 'No')
import sys import numpy as np input = sys.stdin.readline def main(): H, W, K = map(int, input().split()) s = np.zeros(shape=(H, W), dtype=np.bool) for i in range(H): s[i] = tuple(map(lambda x: True if x == "#" else False, input().rstrip())) ans = np.zeros(shape=(H, W), dtype=np.int64) h_keep = 0 k = 1 for h in range(H): if s[h].sum() > 0: indices = np.where(s[h])[0] ans[h_keep:h + 1] = k k += 1 for idx in reversed(indices[:-1]): ans[h_keep:h + 1, :idx + 1] = k k += 1 h_keep = h + 1 else: h_keep = min(h_keep, h) if h_keep < H: h_base = h_keep - 1 for h in range(h_keep, H): ans[h] = ans[h_base] for h in range(H): print(" ".join(map(str, ans[h]))) if __name__ == "__main__": main()
0
null
95,105,089,684,598
190
277
def resolve(): N, M = list(map(int, input().split())) H = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] good = [True for i in range(N)] for a, b in AB: a, b = a-1, b-1 if H[a] < H[b]: good[a] = False elif H[a] == H[b]: good[a] = False good[b] = False else: good[b] = False cnt = 0 for g in good: if g: cnt += 1 print(cnt) if '__main__' == __name__: resolve()
S = input() print('No' if S == 'AAA' or S == 'BBB' else 'Yes')
0
null
39,917,903,744,388
155
201
H, W = list(map(int, input().split())) while H != 0 or W != 0 : print('#' * W) for i in range(H-2) : print('#', end = '') print('.' * (W - 2), end = '') print('#') print('#' * W) print() H, W = list(map(int, input().split()))
while (1): h, w = map(int, input().split()) if (h == 0) and (w == 0): break print("#" * w) for i in range(h - 2): print("#" + "." * (w - 2) + "#") print("#" * w) print()
1
823,609,368,748
null
50
50
import sys def solve(h): if h == 1: return 1 else: return 1 + 2 * solve(h // 2) def main(): input = sys.stdin.buffer.readline h = int(input()) print(solve(h)) if __name__ == "__main__": main()
#!/usr/bin/env python3 H = int(input()) i = 1 while H >= 2**i: i += 1 ans = 0 for x in range(i): ans += 2 ** x print(ans)
1
79,800,105,247,150
null
228
228
from math import factorial def combination(n, r): return factorial(n)//(factorial(n-r) * factorial(r)) def answer(n,k): ans = 0 if k>1: if n=='': return 0 # 先頭が0の時 if n[0]=='0': ans += answer(n[1:],k) else: # 先頭以外で3つ使う if len(n)>k: ans += combination(len(n)-1,k)*9**k # 先頭で一つ使うが、先頭はNの先頭より小さい if len(n)>k-1: ans += (int(n[0])-1)*combination(len(n)-1,k-1)*9**(k-1) # 先頭で、Nの先頭と同じ数を使う ans += answer(n[1:],k-1) else: if n=='': return 0 if n[0]=='0': ans += answer(n[1:],k) else: if len(n)>1: ans += combination(len(n)-1,1)*9 ans += int(n[0]) return ans n = input() k = int(input()) print(answer(n,k) if len(n)>=k else 0)
S = input() L = len(S) K = int(input()) dp = [[[0,0] for _ in range(K+1)] for _ in range(L+1)] dp[0][0][0] = 1 for i,c in enumerate(S): c = int(c) for k in reversed(range(K+1)): for d in range(10): nk = k + (d>0) if nk > K: continue dp[i+1][nk][1] += dp[i][k][1] if d > c: continue less = int(d < c) dp[i+1][nk][less] += dp[i][k][0] print(sum(dp[-1][-1]))
1
76,222,308,639,540
null
224
224
from enum import Enum from queue import Queue import collections import sys import math 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()
n = input() taro = 0 hanako = 0 for i in xrange(n): t_card, h_card = raw_input().split(" ") if t_card < h_card: hanako += 3 elif t_card > h_card: taro += 3 elif t_card == h_card: taro += 1 hanako += 1 print taro, hanako
0
null
1,044,025,237,542
21
67
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce from pprint import pprint sys.setrecursionlimit(2147483647) INF = 10 ** 13 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n, t = LI() ab = sorted(LIR(n)) dp = [0] * t ans = 0 for a, b in ab: ans = max(ans, dp[-1] + b) for i in range(a, t)[::-1]: dp[i] = max(dp[i], dp[i - a] + b) print(ans)
def solve(): import numpy as np from sys import stdin f_i = stdin N, T = map(int, f_i.readline().split()) AB = [tuple(map(int, f_i.readline().split())) for i in range(N)] AB.sort() max_Ai = AB[-1][0] dp = [[0] * T for i in range(N + 1)] dp = np.zeros(max_Ai + T, dtype=int) for A_i, B_i in AB: dp[A_i:A_i+T] = np.maximum(dp[A_i:A_i+T], dp[:T] + B_i) print(max(dp)) solve()
1
152,121,381,609,362
null
282
282
n = input() debt = 100000 for i in range(n): debt *= 1.05 if(debt % 1000): debt -= debt % 1000 debt += 1000 print(int(debt))
nS = int(input()) S = list(map(int,input().split())) nQ = int(input()) Q = list(map(int,input().split())) cnt = 0 for i in range(nQ): copy_S = S.copy() copy_S.append(Q[i]) j = 0 while copy_S[j] != Q[i]: j += 1 if j < len(copy_S)-1 : cnt += 1 print(cnt)
0
null
36,632,510,642
6
22
x = input() if x == "ABC": print("ARC") else: print("ABC")
print('aA'[input()<'a'])
0
null
17,640,666,445,600
153
119
n = int(input()) lis = list(map(int, input().split())) cnt = 0 a = 1 for i in range(n): if lis[i] == a: cnt += 1 a += 1 if cnt == 0: print(-1) else: print(n-cnt)
#D - Brick Break N = int(input()) a = list(map(int,input().split())) num = 1 count = 0 for i in range(N): if a[i] == num: num += 1 else: count += 1 result = count if result == N: result = '-1' print(result)
1
114,485,470,456,548
null
257
257
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)
n=int(input()) a=list(map(int,input().split())) a.sort() # 小さい側から処理する。a[i]について、10**6 以下のすべての倍数をset()として持つ。 # ただし、set内に存在しない==初出の約数のみ倍数計算をしてカウントする。 # 例えば、2,6,... となった場合、(6の倍数セットは2の倍数セットの下位集合となるため計算不要) s=set() cnt=0 for i,aa in enumerate(a): if aa not in s: # 同値が複数ある場合、カウントしない。sortしているため、同値は並ぶ if i+1 == len(a) or aa != a[i+1]: cnt+=1 for i in range(1,10**6+1): ma=aa*i if ma > 10**6: break s.add(ma) print(cnt)
1
14,393,769,969,758
null
129
129
import bisect import copy import heapq import math import sys from collections import * from itertools import accumulate, combinations, permutations, product from math import gcd def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n=int(input()) s=[input() for i in range(n)] # lst=[[0]*2 for i in range(n)] sei=[] hu=[] for i in range(n): l,r=0,0 for j in range(len(s[i])): if s[i][j]==")": if r==0: l+=1 else: r-=1 if s[i][j]=="(": r+=1 if r-l>0: sei.append([l,r-l]) else: hu.append([r,l-r]) sei.sort(key=lambda x: x[0]) hu.sort(key=lambda x: x[0]) tmp=0 for i in range(len(sei)): if tmp-sei[i][0]<0: print("No") quit() tmp+=sei[i][1] tmp2=0 for i in range(len(hu)): if tmp2-hu[i][0]<0: print("No") quit() tmp2+=hu[i][1] if tmp==tmp2: print("Yes") else: print("No")
N = int(input()) l = [0] * 10 ** 5 for x in range(1,100): for y in range(1,100): for z in range(1,100): n = (pow(x + y,2) + pow(y + z,2) + pow(z + x,2)) // 2 l[n] += 1 for n in range(1,N + 1): print(l[n])
0
null
15,733,016,467,740
152
106
S = input() arr = ["x" for i in range(len(S))] print("".join(arr))
# forしながらif、ifでないときはforしないので、計算量減 # 初期入力  2020-0727 21:50 from collections import Counter import sys input = sys.stdin.readline #文字列では使わない N = int(input()) *S, =input().strip() """ c =Counter(S) ans =combinations_count(N, 3) -len(c) """ count =0 x100=0 x10=0 x1=0 for i in range(10): if str(i) not in S: continue else: x100 =S.index(str(i)) +1 for j in range(10): if str(j) not in S[x100:]: continue else: x10 =S[x100:].index(str(j)) +1 for k in range(10): if str(k) in S[x100 +x10:]: x1 =S[x100+x10:].index(str(k)) +1 count +=1 #print("aa",i,j,k,"bb",x100,x100+x10,x100+x10+x1) print(count)
0
null
100,591,384,959,240
221
267
def minkovsky(A,B,n = 0): C = [abs(a - b) for a , b in zip(A,B)] if n == 0: return max(C) else: d = 0 for c in C: d += c ** n d = d ** (1 / n) return d N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) print(minkovsky(A,B,1)) print(minkovsky(A,B,2)) print(minkovsky(A,B,3)) print(minkovsky(A,B))
import sys h,w,m = map(int,input().split()) h_lst = [[0,i] for i in range(h)] w_lst = [[0,i] for i in range(w)] memo = [] for i in range(m): x,y = map(int,input().split()) h_lst[x-1][0] += 1 w_lst[y-1][0] += 1 memo.append((x-1,y-1)) h_lst.sort(reverse = True) w_lst.sort(reverse = True) Max_h = h_lst[0][0] Max_w = w_lst[0][0] h_ans = [h_lst[0][1]] w_ans = [w_lst[0][1]] if h != 1: s = 1 while s < h and h_lst[s][0] == Max_h: h_ans.append(h_lst[s][1]) s+= 1 if w!= 1: t=1 while t < w and w_lst[t][0] == Max_w: w_ans.append(w_lst[t][1]) t += 1 memo = set(memo) #探索するリストは、最大を取るものの集合でなければ計算量はO(m)にはならない! for j in h_ans: for k in w_ans: if (j,k) not in memo: print(Max_h+Max_w) sys.exit() print((Max_h+Max_w)-1)
0
null
2,456,338,881,128
32
89
n = int(input()) for i in range(11): ans = i*1000 judge = ans-n if judge>=0: break print(judge)
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop from functools import lru_cache import math #setrecursionlimit(10**6) rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: map(int, stdin.readline().split()) rlf = lambda: map(float, stdin.readline().split()) INF, NINF = float('inf'), float('-inf') MOD = 10**9 + 7 def main(): n = int(rl()) x = pow(10, n, MOD) - 2*pow(9, n, MOD) + pow(8, n, MOD) print(x % MOD) stdout.close() if __name__ == "__main__": main()
0
null
5,853,487,129,984
108
78
def main(): A = list(input()) N = len(A) K = int(input()) DP0 = [[0] * (K+1) for _ in range(N+1)] DP1 = [[0] * (K+1) for _ in range(N+1)] DP0[0][0] = 1 #print(A) for i in range(1, N+1): for k in range(0, K+1): if k >= 1: DP0[i][k] = (int(A[i-1]) == 0) * DP0[i-1][k] + (int(A[i-1]) >= 1) * DP0[i-1][k-1] DP1[i][k] = DP0[i-1][k-1]*max(int(A[i-1])-1, 0) + DP0[i-1][k]*(int(A[i-1]) >= 1) + DP1[i-1][k-1]*9 + DP1[i-1][k] else: DP0[i][k] = (int(A[i-1]) == 0) * DP0[i-1][k] DP1[i][k] = DP0[i-1][k]*(int(A[i-1]) >= 1) + DP1[i-1][k] #print("#===#") #print(DP0) #print(DP1) print(DP0[N][K] + DP1[N][K]) if __name__ == "__main__": main()
#!/usr/bin/env python3 def main(): n = input() l = len(n) k = int(input()) dp0 = [0 for j in range(4)] dp1 = [0 for j in range(4)] dp1[0] = 1 for i in range(l): d = int(n[i]) if d == 0: for j in [3, 2, 1]: dp0[j] += dp0[j - 1] * 9 else: for j in [3, 2, 1]: dp0[j] += dp0[j - 1] * 9 dp0[j] += dp1[j - 1] * max(0, d - 1) dp0[j] += dp1[j] dp0[0] += dp1[0] dp1 = [0] + dp1[0:3] print(dp0[k] + dp1[k]) if __name__ == "__main__": main()
1
76,066,124,830,960
null
224
224
from collections import defaultdict def main(): height, width, target_count = [int(x) for x in input().split()] count_by_height = defaultdict(int) count_by_width = defaultdict(int) bomb_locations = set() for _ in range(target_count): h, w = [int(x) - 1 for x in input().split()] count_by_height[h] += 1 count_by_width[w] += 1 bomb_locations.add((h, w)) max_h = max(v for v in count_by_height.values()) max_w = max(v for v in count_by_width.values()) max_h_rows = [i for i, x in count_by_height.items() if x == max_h] max_w_columns = [i for i, x in count_by_width.items() if x == max_w] all_crossing_bomb = all((h, w) in bomb_locations for h in max_h_rows for w in max_w_columns) return max_h + max_w - all_crossing_bomb if __name__ == '__main__': print(main())
import sys from collections import Counter def main(): input = sys.stdin.buffer.readline n, x, y = map(int, input().split()) k_cnt = Counter() for i in range(1, n): for j in range(i + 1, n + 1): if i <= x: if j < y: dist = min(j - i, (x - i) + 1 + (y - j)) elif y <= j: dist = (x - i) + 1 + (j - y) elif x < i < y: dist = min(j - i, (i - x) + 1 + abs(j - y)) else: dist = j - i k_cnt[dist] += 1 for i in range(1, n): print(k_cnt[i]) if __name__ == "__main__": main()
0
null
24,559,901,757,260
89
187
n=int(input()) s=input().split() a=s[0] b=s[1] ans='' for i in range(len(a)): ans+=a[i] ans+=b[i] print (ans)
A,B,M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) oldp = min(a)+min(b) for _ in range(M): x, y, cp = map(int,input().split()) p = a[x-1]+b[y-1]-cp if oldp > p: oldp = p print(oldp)
0
null
82,899,510,492,942
255
200
[a,b]=map(int,input().split()) print(a*b,(a+b)*2)
lines = input().split(' ') x = int(lines[0]) y = int(lines[1]) print(x * y, (x + y) * 2)
1
302,196,728,704
null
36
36
N,K = map(int,input().split()) number = N+1-K+1 W = 0 for i in range(number): min = (K+i)*(K+i-1)/2 max = (K+i)*(2*N-K-i+1)/2 W += (max-min+1) w = W % (1000000007) print(int(w))
def f(m): return (((N+1)*((m*(m+1))//2))%p-((m*(m+1)*(2*m+1))//6)%p+m%p)%p p = 10**9+7 N,K = map(int,input().split()) cnt = (f(N+1)-f(K-1))%p print(cnt)
1
33,277,991,324,878
null
170
170
a, b, c, d = map(int, input().split()) if a % d == 0: mons_a = a // d else: mons_a = a // d + 1 if c % b == 0: mons_b = c // b else: mons_b = c // b + 1 if mons_a >= mons_b: print("Yes") else: print("No")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * X = INT() lim = 10**5+1 dp = [0]*lim t = [100 + i for i in range(6)] for i in range(6): dp[100+i] = 100+i for j in range(106, lim): dp[j] += sum([dp[j-k] for k in t]) if dp[X] == 0: print("0") else: print("1")
0
null
78,223,244,855,480
164
266
h = int(input()) w = int(input()) n = int(input()) x = max(h, w) ans = (n + x - 1) // x print(ans)
N, K = map(int, input().split()) A = list(map(int, input().split())) def check(lst): for i in range(N): if lst[i] != N: return False return True def move(lst): tmp = [0] * (N + 1) for i in range(N): a = lst[i] left = max(0, i - a) right = min(N, i + a + 1) tmp[left] += 1 tmp[right] -= 1 for i in range(N): tmp[i + 1] += tmp[i] return tmp for i in range(K): A = move(A) if check(A): # print (i) break print (*A[:-1])
0
null
52,026,647,334,090
236
132
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)
from collections import deque def bfs(x): for v in graph[x]: if dist[v] != -1: continue dist[v] = dist[x] + 1 queue.append(v) if len(queue) == 0: return bfs(queue.popleft()) N = int(input()) graph = [] for _ in range(N): graph.append(list(map(lambda x: int(x)-1, input().split()))[2:]) dist = [-1] * N queue = deque() dist[0] = 0 bfs(0) for i in range(N): print("{} {}".format(i+1, dist[i]))
1
4,240,073,420
null
9
9
s=input() for i in range(1,6): if s=='hi'*i: print('Yes') quit() print('No')
import re s = input() if s == "hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s== "hihihihihi": print("Yes") else: print("No")
1
53,327,866,730,500
null
199
199
import math r = float(input()) S = math.pi * (r**2) l = 2 * math.pi * r print("{} {}".format(S, l))
import fractions, sys input = sys.stdin.buffer.readline def lcm(x, y): return (x * y) // fractions.gcd(x, y) def calc(n, m): for i in range(cycle//m+1): X = m * (i + 0.5) if X > M: print(0) exit() return flag = True for x in n: if (X - x // 2) % x != 0: flag = False break if flag: return int(X) print(0) exit() return N, M = map(int, input().split()) A = list(map(int, input().split())) cycle = 1 ma = 0 for a in A: cycle = lcm(cycle, a) ma = max(ma, a) start = calc(A, ma) print((M - start) // cycle + 1)
0
null
51,260,023,139,368
46
247
res = {1:300000, 2:200000, 3:100000} a, b = map(int, input().split()) if a == b == 1: c = 400000 else: c = 0 try: a = res[a] except: a = 0 try: b = res[b] except: b = 0 print(c+a+b)
x,y = map(int,input().split()) s = max(0,(4-x)*100000)+max(0,(4-y)*100000) print(s if s!=600000 else s+400000)
1
141,207,515,416,644
null
275
275
import sys n = int(input()) pmax = 10 ** 9 + 7 if n == 1 or n== 0 : print('0') sys.exit() elif n == 2: print('2') sys.exit() x = 10 ** n % pmax y = 9 ** n % pmax z = 9 ** n % pmax yz = 8 ** n % pmax ans = (x - y - z + yz) % pmax print(ans)
n=int(input()) p=10**9+7 total=(10**n)%p except_0=(9**n)%p except_9=except_0 except_both=(8**n)%p # double reduced from [1,8] # so add that print((total-except_0-except_9+except_both)%p)
1
3,182,736,647,300
null
78
78
a = int(input()) print((a)+(a ** 2)+(a ** 3))
x=input() X=int(x) y=X+X**2+X**3 print(y)
1
10,197,322,671,482
null
115
115
n,x,mod = map(int,input().split()) num = [] ans = cnt = 0 ch = x while True: if ch not in num: num.append(ch) else: st = ch break ch *= ch ch %= mod index = num.index(st) if (len(num)-index) != 0: rest = (n-index)%(len(num)-index) qu = (n-index)//(len(num)-index) else: rest = n qu = 0 if n <= index + 1: ans = sum(num[:n]) else: ans = sum(num[:index]) + sum(num[index:index+rest]) + sum(num[index:])*qu print(ans)
def solve(): N, X, M = map(int,input().split()) past_a = {X} A = [X] ans = prev = X for i in range(1, min(M,N)): next_a = prev ** 2 % M if next_a in past_a: loop_start = A.index(next_a) loop_end = i loop_size = loop_end - loop_start loop_elem = A[loop_start:loop_end] rest_n = N-i ans += rest_n // loop_size * sum(loop_elem) ans += sum(loop_elem[:rest_n%loop_size]) break ans += next_a past_a.add(next_a) A.append(next_a) prev = next_a print(ans) if __name__ == '__main__': solve()
1
2,797,985,584,992
null
75
75
import sys import itertools def resolve(in_): return len(set(s.strip() for s in itertools.islice(in_, 1, None))) def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
import sys S = input() if not S.islower():sys.exit() if not ( 3 <= len(S) <= 99 and len(S) % 2 == 1 ): sys.exit() # whole check first = int((len(S)-1)/2) F = S[0:first] last = int((len(S)+3)/2) L = S[last-1:] condition = 0 if S == S[::-1]: condition += 1 if F == F[::-1]: condition += 1 if L == L[::-1]: condition += 1 print('Yes') if condition == 3 else print('No')
0
null
38,229,327,431,712
165
190
s = input() INF = float('inf') dp = [[INF,INF] for _ in range(len(s)+1)] dp[0][0]=0 dp[0][1]=1 for i in range(len(s)): dp[i+1][0] = min(dp[i][0]+int(s[i]), dp[i][1]+10-int(s[i]), dp[i][1]+int(s[i])+1) dp[i+1][1] = min(dp[i][0]+int(s[i])+1,dp[i][1]+10-int(s[i])-1) print(dp[-1][0])
s = input() s = "".join([ i for i in reversed(s)]) + "0" INF = 10 ** 32 n = len(s) dp = [ [INF]*2 for _ in range(n)] dp[0][0] = 0 for i in range(n-1): x = int(s[i]) dp[i+1][0] = min( dp[i][0]+x, dp[i][1]+x ) dp[i+1][1] = min( dp[i][0]+1+(10-x), dp[i][1]+(9-x) ) print(min(dp[n-1][0], dp[n-1][1]))
1
71,372,062,206,148
null
219
219