code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
k = int(input()) a,b = map(int,input().split()) flag = False for i in range(a,b + 1): if i % k == 0: flag = True break if flag: print('OK') else: print('NG')
a,b = map(str, input().split()) a2 = a*int(b) b2 = b*int(a) print(a2) if a2 < b2 else print(b2)
0
null
55,722,019,695,708
158
232
n=int(input()) a=[int(i) for i in input().split()] s=a[0] for i in a[1:]: s^=i print(*[s^i for i in a])
I=input r=range a=[[[0 for i in r(10)]for j in r(3)]for k in r(4)] for i in r(int(I())):b,f,r,v=map(int,I().split());a[b-1][f-1][r-1]+=v f=0 for i in a: if f:print('#'*20) else:f=1 for j in i:print('',*j)
0
null
6,747,030,290,220
123
55
k=int(input()) line="ACL"*k print(line)
def bubbleSort(c, n): flag = 1 while(flag) : flag = 0 for i in reversed(range(1,n)): if(c[i][1] < c[i-1][1]): c[i], c[i-1] = c[i-1], c[i] flag = 1 return c def selectionSort(c,n): for i in range(n): minj = i for j in range(i, n): if(c[j][1] < c[minj][1]): minj = j c[i], c[minj] = c[minj], c[i] return c def isStable(c1, c2, n): for i in range(n): if(c1[i] != c2[i]): return False return True n = int(input()) c = input().split(' ') trump = [list(i) for i in c] bubble = ["".join(s) for s in bubbleSort(trump, n)] trump = [list(i) for i in c] selection = ["".join(s) for s in selectionSort(trump, n)] str_bubble = " ".join(bubble) str_selection = " ".join(selection) print(str_bubble) print('Stable') print(str_selection) if isStable(bubble, selection, n): print('Stable') else: print('Not stable')
0
null
1,102,921,158,262
69
16
def gcd(x, y): if x < y: x, y = y, x while y > 0: x, y = y, x % y return x if __name__ == '__main__': x, y = map(int, input().split()) result = gcd(x, y) print(result)
import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 T1,T2 = map(int,readline().split()) A1,A2 = map(int,readline().split()) B1,B2 = map(int,readline().split()) P = (A1 - B1) * T1 Q = (A2 - B2) * T2 if P > 0: P *= -1 Q *= -1 if P + Q < 0: print(0) elif P + Q == 0: print("infinity") else: S = (-P) // (P + Q) T = (-P) % (P + Q) if T != 0: print(S * 2 + 1) else: print(S * 2)
0
null
66,133,881,551,216
11
269
N=int(input()) w =0 x =0 y =0 z =0 for i in range(N): s =input() if s =='AC': w +=1 elif s == 'WA': x +=1 elif s == 'TLE': y +=1 elif s == 'RE': z +=1 print ('AC x '+str(w)) print ('WA x '+str(x)) print ('TLE x '+str(y)) print ('RE x '+str(z))
def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) n=int(input()) ar=[] for _ in range(n): ar.append(input()) from collections import Counter c=Counter(ar) print("AC x",c["AC"]) print("WA x",c["WA"]) print("TLE x",c["TLE"]) print("RE x",c["RE"])
1
8,693,117,542,102
null
109
109
def getResult(a,b): if a<b: a,b=b,a while b!=0: r = a%b a = b b = r return a a,b = map(int,input().strip().split()) print(getResult(a,b))
x,y = map(int,input().split(" ")) def gdp(x,y): if x > y: big = x small = y else: big = y small = x if big%small == 0: print(small) return else: gdp(small,big%small) gdp(x,y)
1
7,755,728,510
null
11
11
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) class modint():#add:和,mul:積,pow:累乗,div:商(modと互いに素であること) def __init__(self,x,mod=1000000007): self.x, self.mod=x, mod def add(self,a): self.x=(self.x+a%self.mod)%self.mod def mul(self,c): self.x=(self.x*(c%self.mod))%self.mod def pow(self,p): self.x=pow(self.x,p,self.mod) def div(self,d): u,v,a,b=1,0,d,self.mod while b: t=a//b a-=t*b a,b,u,v=b,a,v,u-t*v if a!=1: print("not 素") self.x=(self.x*(u%self.mod))%self.mod def main(): mod = 1000000007 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え N = int(input()) #N, K = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル #L = tuple(int(input()) for i in range(N)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 d=dict() m=10**18+100 for i in range(N): A, B = map(int, input().split()) if A==0 and B==0: d[-m]=d.get(-m,0)+1 elif B==0: d[m]=d.get(m,0)+1 elif A==0: d[0]=d.get(0,0)+1 else: sa=sb=1 if A<0: sa=-1 A*=-1 if B<0: sb=-1 B*=-1 g=math.gcd(A,B) A=A//g B=B//g if sa==-1 and sb==-1: t=(A,B) elif sb==-1: t=(-A,B) else: t=(sa*A,sb*B) d[t]=d.get(t,0)+1 #print(d) ks=set(d.keys()) alis=[] tot=modint(1) for i, k in enumerate(ks): if d[k]==-1.0: continue if k==-m: continue if k==m: ik=0 elif k==0: ik=m elif k[0]<0: ik=(k[1],-k[0]) else: ik=(-k[1],k[0]) #print(ik) if ik in ks: d1,d2=d[k],d[ik] tot.mul((pow(2,d1,mod)-1)+(pow(2,d2,mod)-1)+1) d[ik]=-1 else: tot.mul(pow(2,d[k],mod)) tot.add(-1) tot.add(d.get(-m,0)) print(tot.x) 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
17,836,365,863,692
146
130
h,w,n=[int(input()) for _ in range(3)] m=max(h,w) print(0--n//m)
import math h = int(input()) w = int(input()) n = int(input()) if h < w: h = w print(math.ceil(n / h))
1
88,528,490,935,072
null
236
236
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) count = 0 flag = 0 for i in range(N): if N == 1: break minj = i for j in range(i, N): if A[j] < A[minj]: minj = j flag = 1 if flag == 1: A[i], A[minj] = A[minj], A[i] count += 1 flag = 0 for i in range(N): if i == N - 1: print("{0}".format(A[i])) else: print("{0} ".format(A[i]), end="") print(count)
N=int(input()) A=list(map(int,input().split())) A.sort() sum=1 for i in range(N): sum=sum*A[i] if sum>10**18: sum=-1 break print(sum)
0
null
8,132,548,470,424
15
134
D = int(input()) C = [int(x) for x in input().split()] S = [[int(i) for i in input().split()] for D in range(D)] T = [0]*D for i in range(D): T[i] = int(input()) score = [0]*26 last = [-1]*26 for i in range(D): score[T[i]-1] += S[i][T[i]-1] last[T[i]-1] = i for j in range(26): score[j] -= C[j]*(i-last[j]) print(sum(score))
# coding: utf-8 # Your code here! import numpy as np import copy D = int(input()) C = list(map(int,input().split())) contest = [list(map(int,input().split())) for i in range(D)] inputs = [int(input()) for i in range(D)] # print(contest) # print(inputs) lists = np.array([0 for i in range(26)]) Y = 0 for i,j in zip(contest,inputs): lists += 1 lists[j-1] = 0 X = C * lists.T # print(X) # print(sum(X)) # x = sum(C[:j-1])+sum(C[j:]) # y = i[j-1]-x+solve Y = i[j-1]-sum(X)+Y print(Y) Y = copy.deepcopy(Y)
1
9,950,061,681,814
null
114
114
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def error(): print(-1) quit() n = inp() a = inpl() if n == 0 and sum(a) == 1: print(1) quit() can = [0] * (n+1); can[0] = 1 b = [0] * (n+1) res = [0] * (n+1) if a[0] != 0: error() for i in range(n): can[i+1] = can[i]*2 - a[i+1] if can[i+1] < 0: error() can[-1] = 0 b[-1] = 0 res[-1] = a[-1] for i in range(n)[::-1]: b[i] = min(res[i+1], can[i]) res[i] = a[i] + b[i] print(sum(res))
n=int(input()) A=list(map(int,input().split())) s=0 cap=[] flag=False for i,a in enumerate(A): s*=2 s+=a cap.append(min(2**i-s,(n+1-i)*10**8)) if s>2**i: flag=True break if flag: print(-1) else: remain=2**n-s ans=0 node=0 for i in range(n,-1,-1): a=A[i] c=cap[i] node=min(c,node)+a ans+=node print(ans)
1
18,763,832,094,238
null
141
141
a,b,n= map(int, input().split()) if a<n: if (n-a)>b: print(0,0) else: print(0,b-(n-a)) else: print(a-n,b)
#!/usr/bin/env python3 import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() A = LI() A.sort() MAX = 10**6+1 All = [0] * MAX setA = set(A) for i in A: k = i All[k] += 1 k += i if All[i] >= 2: continue while k < MAX: All[k] += 1 k += i ans = 0 for i in range(1, MAX): if All[i] == 1 and i in setA: ans += 1 print(ans) # oj t -c "pypy3 main.py" # acc s main.py -- --guess-python-interpreter pypy main()
0
null
59,408,083,119,360
249
129
n=int(input()) l=list(map(int,input().split())) summ=0 for i in l: summ+=i ans=0 for i in l: summ-=i ans+=i*summ print(ans%1000000007)
A, B, C, D=map(int,input().split()) while C or A >= 0: C -= B A -= D if C <= 0: print("Yes") break if A <= 0: print("No") break
0
null
16,721,186,345,150
83
164
a, b = list(map(int, input().split())) ret = (str(a) * b) if a > b: ret = (str(b) * a) print("{}".format(ret))
A,B=map(int,input().split()) if B < A: A,B=B,A for i in range(B): print(A, end="") print()
1
84,816,286,044,620
null
232
232
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) # あるbit列に対するコストの計算 def count(zerone): one = 0 cnt = 0 for i in range(N): flag = True if zerone[i] == 1: one += 1 for j in range(len(A[i])): if A[i][j][1] != zerone[A[i][j][0]-1]: flag = False break if flag: cnt += 1 if cnt == N: return one else: return 0 # bit列の列挙 def dfs(bits): if len(bits) == N: return count(bits) res = 0 for i in range(2): bits.append(i) res = max(res, dfs(bits)) bits.pop() return res # main N = int(input()) A = [[] for _ in range(N)] for i in range(N): a = int(input()) for _ in range(a): A[i].append([int(x) for x in input().split()]) ans = dfs([]) print(ans)
import re i = str(input()) j = i.islower() if j == 1: o = 'a' else: o = 'A' print(o)
0
null
66,749,821,568,910
262
119
# 高橋くんのモンスターは体力Aで攻撃力B # 青木くんのモンスターは体力Cで攻撃力D # 高橋くんが勝つならYes、負けるならNoを出力する A, B, C, D = map(int, input().split()) while A > 0 and C > 0: C -= B A -= D if C <= 0: print('Yes') elif A <= 0: print('No')
t_hp, t_atk, a_hp, a_atk = map(int, input().split()) t_count = 0 a_count = 0 while a_hp > 0: a_hp -= t_atk t_count += 1 while t_hp > 0: t_hp -= a_atk a_count += 1 if t_count <= a_count: print('Yes') else: print('No')
1
29,687,310,041,088
null
164
164
n = int(input()) n_l = list(map(int, input().split())) VORDER = 10 ** 18 ans = 1 if 0 in n_l: ans = 0 else: for i in n_l: ans = i * ans if ans > VORDER: ans = -1 break print(ans)
n = int(input()) ans = 1 l = list(map(int,input().split())) if l.count(0) != 0 : print(0) exit() for i in range(n) : ans *= l[i] if ans > 10**18 : print('-1') exit() print(ans)
1
16,323,760,659,712
null
134
134
a, b, c = map(int, input().split()) k = int(input()) if a >= b: x = a // b x_ = len(bin(x)) - 2 else: x_ = 0 b *= 2 ** x_ if b >= c: y = b // c y_ = len(bin(y)) -2 else: y_ = 0 if (x_ + y_) <= k: print('Yes') else: print('No')
import itertools N = int(input()) l = list(itertools.permutations(range(1,N+1))) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) print(abs(l.index(A) - l.index(B)))
0
null
53,821,974,791,492
101
246
n,k = map(int,input().split()) a = list(map(int,input().split())) tt = [0] * n tt[0] = 1 ans_l = [1] i = 1 c = 0 while True: if c == k: #ループに達することができないk回を入力として与えられるとこの条件式がない場合 break #ループに達した上で計算されてしまう。これがあるとkが下の式で0として計算される。 c += 1 i = a[i-1] if tt[i-1] == False: tt[i-1] = 1 ans_l.append(i) else: break #print(c,k) d = ans_l.index(i) k -= d ans = k % (len(ans_l)-d) print(ans_l[ans+d])
def f(): n,k=map(int,input().split()) l=list(map(int,input().split())) now=1 for i in range(k.bit_length()): if k%2:now=l[now-1] l=[l[l[i]-1]for i in range(n)] k//=2 print(now) if __name__ == "__main__": f()
1
22,694,892,866,826
null
150
150
k = int(input()) sum = 0 def gcd(x, y): # ユークリッドの互除法 if y > x: y,x = x,y while y > 0: r = x%y x = y y = r return x import math for i in range(1,k+1): for m in range(1,k+1): sub = gcd(i,m) for l in range(1,k+1): sum += gcd(sub,l) print(sum)
#coding:UTF-8 def IS(N,A): for i in range(int(N)): v=A[i] j=i-1 while j>=0 and A[j]>v: A[j+1]=A[j] j=j-1 A[j+1]=v ans="" for k in range(len(A)): ans+=str(A[k])+" " print(ans[:-1]) if __name__=="__main__": N=input() a=input() A=a.split(" ") for i in range(len(A)): A[i]=int(A[i]) IS(N,A)
0
null
17,617,109,088,140
174
10
n, m = map(int, input().split()) c = list(map(int, input().split())) dp = [float("inf")]*(n+1) dp[0] = 0 for i in range(m): for j in range(c[i], n+1): dp[j] = dp[j - c[i]]+1 if dp[j - c[i]] < dp[j] else dp[j] print(dp[n])
import sys from collections import deque import bisect import copy import heapq import itertools import math import random input = sys.stdin.readline sys.setrecursionlimit(1000000) mod = 10 ** 9 + 7 def read_values(): return map(int, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_list(): return list(read_values()) def read_lists(N): return [read_list() for n in range(N)] def main(): K = int(input()) print("ACL" * K) if __name__ == "__main__": main()
0
null
1,161,311,920,122
28
69
a = int(input()) b, c = map(int, input().split()) ans = int(c/a) * a if b<=ans<=c: print('OK') else: print('NG')
a,b,c,d=map(int,input().split()) for i in range(1001): if i%2==0: c-=b if c<=0: print("Yes") exit(0) else: a-=d if a<=0: print("No") exit(0)
0
null
27,934,300,643,128
158
164
h,w,m=map(int,input().split()) st=set() h_b=[0 for i in range(h)] w_b=[0 for i in range(w)] for i in range(m): th,tw=map(int,input().split()) th-=1 tw-=1 st.add((th,tw)) h_b[th]+=1 w_b[tw]+=1 h_max=max(h_b) w_max=max(w_b) h_cand=[i for i in range(h) if h_b[i]==h_max] w_cand=[i for i in range(w) if w_b[i]==w_max] for i in h_cand: for j in w_cand: if (i,j) not in st: print(h_max+w_max) exit() print(h_max+w_max-1)
import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(10 ** 9) def main(): N, K, S = map(int, input().split()) A = [S for _ in range(K)] if S != 10 ** 9: B = [S + 1 for _ in range(N - K)] else: B = [S - 1 for _ in range(N - K)] C = A + B print(*C, sep=" ") if __name__ == "__main__": main()
0
null
47,939,512,225,528
89
238
import sys input = sys.stdin.readline def main(): N = int( input()) U = [] V = [] for _ in range(N): x, y = map( int, input().split()) u, v = x+y, x-y U.append(u) V.append(v) U.sort() V.sort() print( max(U[-1]-U[0], V[-1]-V[0])) if __name__ == '__main__': main()
def main(): n = int(input()) z = [[], []] for i in range(n): x, y = map(int, input().split()) z[0].append(x + y) z[1].append(x - y) z[0] = sorted(z[0]) z[1] = sorted(z[1]) print(max(z[0][-1] - z[0][0], z[1][-1] - z[1][0])) if __name__ == '__main__': main()
1
3,384,790,038,460
null
80
80
N = int(input()) if N % 2 == 1: print(0) exit() ans = 0 N //= 2 i = 1 while N >= 5 ** i: ans += (N // 5 ** i) i += 1 print(ans)
import math n = int(input()) cnt = 0 mod = 10 if n%2 == 1: print(0) exit() while mod<=n: cnt += n//mod mod*=5 print(cnt)
1
116,308,039,826,758
null
258
258
import collections n,m = list(map(int,input().split())) coriddorList = [set() for i in range(n+1)] deepList = [-1 for i in range(n+1)] for i in range(m): a,b = list(map(int,input().split())) coriddorList[a].add(b) coriddorList[b].add(a) checkList = [0] * (n + 1) ansList = [0] * (n + 1) checkList[1] = 1 q = collections.deque() q.appendleft(1) while len(q) > 0: value = q.pop() for k in coriddorList[value]: if checkList[k] == 0: checkList[k] = 1 ansList[k] = value q.appendleft(k) print("Yes") for i in range(2,n+1): print(ansList[i])
# -*- coding: utf-8 -*- """ Created on Mon Apr 30 11:23:30 2018 ALDS1-4a most simple implementation using the features of the python @author: maezawa """ n = int(input()) s = map(int, input().split()) q = int(input()) t = map(int, input().split()) s_set = set(s) t_set = set(t) sandt = s_set & t_set print(len(sandt))
0
null
10,261,501,169,512
145
22
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, 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 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 N = INT() A = LIST() ans = INF sum_A = sum(A) tmp = 0 for a in A: tmp += a ans = min(ans, abs(tmp-(sum_A-tmp))) print(ans)
# import string import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N = int(input()) A = list(map(int, input().split())) from itertools import accumulate B = [0] + A B = list(accumulate(B)) # 累積和を格納したリスト作成 # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り S=B[-1] minans = 10 ** 20 for i in range(1,N): val=abs(B[i]-(S-B[i])) minans=min(minans,val) print(minans) resolve()
1
141,993,768,199,920
null
276
276
N = int(input()) X = input() def f(x): ret = 0 c = bin(x).count("1") while c > 0: x %= c c = bin(x).count("1") ret += 1 return ret MOD = 10 ** 9 + 7 origin_pop = X.count("1") one_pop = origin_pop - 1 zero_pop = origin_pop + 1 one_mod = 0 zero_mod = 0 for i in X: if one_pop > 0: one_mod = one_mod * 2 + int(i) one_mod %= one_pop zero_mod = zero_mod * 2 + int(i) zero_mod %= zero_pop for i, x in enumerate(X): if x == "0": tmp = zero_mod + pow(2, N-1-i, zero_pop) tmp %= zero_pop print(f(tmp)+1) else: if one_pop == 0: print(0) else: tmp = one_mod - pow(2, N-1-i, one_pop) tmp = (tmp + one_pop) % one_pop print(f(tmp)+1)
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 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 = 10 ** 9 + 7 n = I() x = input() cnt = x.count("1") if cnt == 1: for i in range(n): if x[i] == "1": print(0) elif i == n - 1: print(2) else: print(1) exit() def f(x): if x==0: return 0 return 1+f(x%bin(x).count('1')) xx = int(x, 2) Y = xx % (cnt + 1) Z = xx % (cnt - 1) for i in range(n): if x[i] == '1': print(1 + f((Z - pow(2, n - i - 1, cnt - 1)) % (cnt - 1))) else: print(1 + f((Y + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)))
1
8,192,290,432,000
null
107
107
word = input() print(word + "es" if word[-1] == "s" else word + "s" )
s = input() if s[-1] == 's': s += 'es' else: s += 's' print(s)
1
2,413,559,718,802
null
71
71
input() d=[abs(s-t)for s,t in zip(*[list(map(int,input().split()))for _ in'12'])] f=lambda n:sum(s**n for s in d)**(1/n) print(f(1),f(2),f(3),max(d),sep='\n')
n, x, y = int(input()), list(map(int, input().split())), list(map(int, input().split())) def dist(p): return pow(sum(pow(abs(a - b), p) for a, b in zip(x, y)), 1.0 / p) for i in [1, 2, 3]: print(dist(i)) print(max(abs(a - b) for a, b in zip(x, y)))
1
208,774,701,660
null
32
32
while True: n = int(input()) if n == 0: break x = tuple(map(float, input().strip().split())) y = (sum(x)/n)**2 z = sum(map(pow, x, (2 for i in range(n))))/n print((z-y)**0.5)
n = int(input()) s = str(input()) w = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" t = "" for i in range(len(s)): for h in range(26): if s[i] == w[h]: t += w[h+n] break print(t)
0
null
67,202,336,177,822
31
271
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**7) import bisect import heapq import itertools import math from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from math import gcd from operator import add, itemgetter, mul, xor def cmb(n,r,mod): bunshi=1 bunbo=1 for i in range(r): bunbo = bunbo*(i+1)%mod bunshi = bunshi*(n-i)%mod return (bunshi*pow(bunbo,mod-2,mod))%mod mod = 10**9+7 def I(): return int(input()) def LI(): return list(map(int,input().split())) def MI(): return map(int,input().split()) def LLI(n): return [list(map(int, input().split())) for _ in range(n)] #bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す #つまりlist[i] < x となる i の個数 #bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す #つまりlist[i] <= x となる i の個数 #これを応用することで #len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す #len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す #これらを使うときはあらかじめlistをソートしておくこと! def maze_solve(S_1,S_2,maze_list): d = deque() d.append([S_1,S_2]) dx = [0,0,1,-1] dy = [1,-1,0,0] while d: v = d.popleft() x = v[0] y = v[1] for i in range(4): nx = x + dx[i] ny = y + dy[i] if nx < 0 or nx >= h or ny < 0 or ny >= w: continue if dist[nx][ny] == -1: dist[nx][ny] = dist[x][y] + 1 d.append([nx,ny]) return max(list(map(lambda x: max(x), dist))) h,w = MI() if h==1 and w == 2: print(1) elif h == 2 and w == 1: print(1) else: ans = 0 maze = [list(input()) for _ in range(h)] dist = [[-1]*w for _ in range(h)] start_list = [] for i in range(h): for j in range(w): if maze[i][j] == "#": dist[i][j] = 0 else: start_list.append([i,j]) dist_copy = deepcopy(dist) for k in start_list: dist = deepcopy(dist_copy) ans = max(ans,maze_solve(k[0],k[1],maze)) print(ans+1)
import sys read = sys.stdin.buffer.read input = sys.stdin.readline input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode('utf-8') #2325 #import numpy as np import math def main(): a,b,x=MI() k=0 if b/2<=x/a**2: k=2/a*(b-x/a**2) else: k=a*b**2/(2*x) print(math.degrees(math.atan(k))) if __name__ == "__main__": main()
0
null
129,538,570,432,922
241
289
n = int(input()) a = list(map(int,input().split())) number = len(a) count = 0 for i in range(0,number,2): if a[i]%2 == 1: count += 1 print(count)
n = int(input()) A = list(map(int, input().split())) for i in range(n - 1): A[i + 1] += A[i] minv = float('inf') for a in A[:-1]: minv = min(minv, abs(A[-1]/2 - a)) print(int(minv * 2))
0
null
75,270,957,956,442
105
276
n = int(input()) a = list(map(int,input().split())) m = 1 for i in range(n): if a[i] == m: m += 1 print(-1) if m == 1 else print(n-m+1)
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, gcd 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 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 TUPLE(): return tuple(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 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N = INT() A = LIST() C = Counter(A) tmp = 0 for x in C.values(): tmp += x*(x-1)//2 for x in A: print(tmp - (C[x]-1))
0
null
80,903,347,595,070
257
192
n= int(input()) A = list(map(int, input().split())) q = int(input()) Mi = map(int, input().split()) PS={} def solve(i,m): if m == 0: return True if (i,m) in PS: return PS[(i,m)] if i >= n: return False res = solve(i+1, m) or solve(i + 1, m - A[i]) PS[(i,m)] = res return res for m in Mi: if solve(0, m): print("yes") else: print("no")
def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) from collections import deque def main(): mod=10**9+7 S=input() from collections import deque dq=deque() for c in S: dq.appendleft(c) rev=0 Q=I() for _ in range(Q): q=input().split() if q[0]=="1": rev=(rev+1)%2 else: f=int(q[1]) c=q[2] if (rev+f)%2==1: dq.append(c) else: dq.appendleft(c) ans=[] if rev: while dq: ans.append(dq.popleft()) else: while dq: ans.append(dq.pop()) print(''.join(map(str, ans))) main()
0
null
28,797,258,810,398
25
204
S = input() ans = 0 for i in range(0,len(S)//2): if S[i] != S[len(S)-1-i]: ans += 1 print(ans)
s=list(input());print(sum([1 for i,j in list(zip(s[:(len(s)//2)],s[len(s)//2:][::-1])) if i!=j]))
1
120,550,971,652,200
null
261
261
N = int(input()) S = input() #print(ord("A")) #print(ord("B")) #print(ord("Z")) for i in range(len(S)): ascii = ord(S[i]) + N #Sのi文字目のアスキーコードを計算してしれにNを足してづらす if ascii > ord("Z"): #アスキーコードがよりも大きくなった時はA初まりにづらす ascii = ascii - (ord("Z") - ord("A") + 1) print(chr(ascii),end = "") #,end = "" は1行ごとに改行しないでプリントする仕組み
n,m = map(int,input().split()) A=[-1]*n ans=0 for i in range(m): s,c = map(int,input().split()) if A[s-1]!=-1 and A[s-1]!=c : ans=-1 break else: A[s-1]=c if A[0]==0 and n!=1 : ans=-1 if ans==-1 : print(ans) exit() if A[0]==-1 and n!=1 : A[0]=1 for i in range(n): ans*=10 if A[i]==-1 : A[i] = 0 ans += A[i] print(ans)
0
null
98,122,343,911,622
271
208
import sys from collections import deque input = sys.stdin.readline def main(): n = int( input() ) input_a = list ( map( int, input().split() ) ) a = deque( input_a ) while( len(a) != 1 ): x = a.popleft() y = a.popleft() z = x ^ y a.append(z) sum = a.popleft() ans = [] for i in input_a: x = i ^ sum ans.append(x) for i in ans: print( i , end = ' ' ) main()
n,m=map(int,input().split()) c=list(map(int,input().split())) dp=[[10001]*m for i in range(n)] #dp[value][i_coin] dp.insert(0,[0]*m) for i in range(m): for v in range(1,n+1): if i==0: dp[v][i]=v//c[i] if v%c[i]==0 else 10001 continue if v<c[i]: dp[v][i]=dp[v][i-1] else: dp[v][i]=min(dp[v][i-1],dp[v-c[i]][i]+1) print(dp[n][m-1])
0
null
6,288,528,112,640
123
28
while True: h, w = map(int, input().split()) if h==w==0: break for y in range(h): for x in range(w): print('#.'[(x+y)%2], end='') print() print()
import math def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): N = read_int() P = read_ints() min_so_far = math.inf count = 0 for p in P: min_so_far = min(min_so_far, p) if min_so_far >= p: count += 1 return count if __name__ == '__main__': print(solve())
0
null
43,234,824,587,810
51
233
from math import ceil H, K = list(map(int, input().split())) print(ceil(H/K))
N = int(input()) A = [int(x) for x in input().split()] money = 1000 s = 0 for i in range(N - 1): # begginig of i-th day # sell all of stocks money += s * A[i] s = 0 if A[i] < A[i + 1]: s = money // A[i] money %= A[i] # print('end of {0}-th day, money: {1}, stock: {2}'.format(i, money, s)) money += s * A[-1] print(money)
0
null
42,095,719,268,580
225
103
a,b = map (int,input().split()) print(a*b,a+a+b+b)
a,b = map(int, open(0).read().split()) i = int(a/0.08-1e-8) while 1: if int(i*0.08)==a and int(i*0.1)==b: print(i) break if int(i*0.08)>a: print(-1) break i += 1
0
null
28,214,166,111,000
36
203
K = int(input()) A,B = map(int,input().split()) if (A-1)//K == B//K: print("NG") else: print("OK")
n = int(input()) p = 10 a = 0 if n % 2 == 0: while p <= n: a += n // p p *= 5 print(a)
0
null
71,420,013,175,808
158
258
import itertools n,m,x=[int(x) for x in input().split()] book=[] for i in range(n): b=[int(x) for x in input().split()] book.append(b) l=[] a=itertools.product(range(2),repeat=n) for i in a: l.append(i) price=[] for i in range(2**n): check_list=[0]*(m+1) for j in range(n): if l[i][j]==1: for k in range(m+1): check_list[k]+=book[j][k] check=[] for p in range(1,m+1): if check_list[p]<x: check.append(False) if check==[]: price.append(check_list[0]) if price==[]: print("-1") else: print(min(price))
n = input() p = input() s = len(n) count = 0 for i in range(s): if n[i] != p[i]: count += 1 print(count)
0
null
16,506,911,769,792
149
116
A,B,C,D=map(int,input().split()) while A>0 and C>0: C-=B A-=D # print(A,C) if C<=0:print('Yes') else:print('No')
a,b,c=map(int,input().split()) if a>b: n=a a=b b=n else: pass if b>c: n=b b=c c=n else: pass if a>b: n=a a=b b=n else: pass print(a,b,c)
0
null
15,204,799,639,300
164
40
n=int(input()) while n>0: n-=1000 print(abs(n))
n = int(input()) div = n // 1000 if (n % 1000 == 0): ans = 0 else: ans = (div + 1) * 1000 - n print(ans)
1
8,438,067,719,288
null
108
108
A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) if(A<B): A1=A+V*T B1=B+W*T if(A1>=B1): print('YES') else: print('NO') else: A1=A-V*T B1=B-W*T if(A1<=B1): print('YES') else: print('NO')
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) D = abs(A - B) if (V > W) and \ (D / (V - W) <= T): print("YES") else: print("NO")
1
15,168,826,754,660
null
131
131
c = input() print(chr(ord(c) + 1))
#!/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 solve(C: str): return chr(ord(C)+1) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() C = next(tokens) # type: str print(f'{solve(C)}') if __name__ == '__main__': main()
1
92,598,483,214,240
null
239
239
A, B = map(int, input().split()) ans = 0 for i in range(10,1001): if int(i*0.08) == A and int(i*0.1) == B: ans = i break if ans == 0: print(-1) else: print(i)
n,k = map(int, input().split()) sunuke = [] for i in range(n): sunuke.append(1) for i in range(k): d = int(input()) a = list(map(int, input().split())) for j in range(d): sunuke[a[j]-1] = 0 print(sum(sunuke))
0
null
40,337,616,849,088
203
154
S, T = map(str, input().split()) A, B = map(int, input().split()) U = input() if U == S: A -= 1 A = str(A) B = str(B) print(A+' '+B) else : B -= 1 A = str(A) B = str(B) print(A+' '+B)
import itertools h, w, k = map(int, input().split()) c = [] ans = 0 for i in range(h): c.append(list(input())) for i in range(2 ** h - 1): c2 = [] x = str(bin(i))[2:].zfill(h) for a in range(h): if x[a] == '0': c2.append(c[a]) elif x[a] == '1': c2.append(['*'] * w) black = list(itertools.chain.from_iterable(c2)).count('#') for j in range(2 ** w - 1): black2 = black y = str(bin(j))[2:].zfill(w) for b in range(w): if y[b] == '1': for a in range(h): if c2[a][b] == '#': black2 -= 1 if black2 == k: ans += 1 print(ans)
0
null
40,656,608,210,212
220
110
# -*- coding: utf-8 -*- # F import sys from collections import defaultdict, deque from heapq import heappush, heappop import math import bisect from itertools import accumulate, combinations input = sys.stdin.readline mod = 998244353 N, S = map(int, input().split()) A = list(map(int, input().split())) dp = [[0] * (S+1) for _ in range(N+1)] dp[0][0] = 1 for i in range(1, N+1): for j in range(S+1): dp[i][j] += dp[i-1][j] * 2 if j + A[i-1] <= S: dp[i][j+A[i-1]] += dp[i-1][j] dp[i][j] %= mod # print(dp) print(dp[-1][S] % mod)
#!/usr/bin/env python3 import sys input = sys.stdin.readline MOD = 998244353 n, s = map(int, input().split()) a = [int(item) for item in input().split()] dp = [[0] * (s + 1) for _ in range(n+1)] dp[0][0] = 1 for i, item in enumerate(a): for j in range(s, -1, -1): if dp[i][j] == 0: continue if j + item <= s: dp[i+1][j+item] += dp[i][j] dp[i+1][j] += dp[i][j] * 2 dp[i+1][j] %= MOD print(dp[-1][-1] % MOD)
1
17,575,588,915,808
null
138
138
import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int, input().split()) lin=lambda : list(tin()) mod=1000000007 #+++++ def modinv(a,m): b=m u=1 v=0 while b > 0: t = a //b a = a - (t * b) a,b = b,a u = u - (t * v) u,v=v,u u = u % m if u < 0: u+=m return u size_l=(10**5)+5 kaijoy=[1]*(size_l) inv = [0]*(size_l) pre=1 for i,v in enumerate(kaijoy[1:], 1): pre *= i pre %= mod kaijoy[i]=pre inv[-1] = modinv(kaijoy[-1], mod) pre = inv[-1] #print(pre*24) for i, v in enumerate(inv[1:],1): pre *= (size_l-i) pre %= mod inv[-i-1]=pre #print(kaijoy) #print(inv) #print([(v*s)%mod for v, s in zip(kaijoy, inv)]) def conv(n, k): if n < k: return 0 global kaijoy global inv ret = kaijoy[n] ret *= inv[n-k] ret *= inv[k] return ret def main(): # = int(input()) n, k = tin() #s = input() al = lin() al.sort() ret = 0 for i in range(n-k+1): d= (al[-i-1] - al[i])*conv(n-i-1, k-1) #pa((d,kaijoy[max(0,n-i-1)],inv[k-1])) ret += d ret %= mod return ret #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
#!/usr/bin/env python3 import sys MOD = 1000000007 # type: int class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] # 階乗を求めるためのキャッシュ self.invModulos = [0, 1] # n^-1のキャッシュ self.invFactorial_ = [1, 1] # (n^-1)!のキャッシュ def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0]*(n+1-len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n+1): prev = nextArr[i-initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0]*(n+1-len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n+1)): next = -self.invModulos[p % i]*(p//i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0]*(n+1-len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n+1): prev = nextArr[i-initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def choose_k_from_n(self, n, k): if k < 0 or n < k: return 0 k = min(k, n-k) f = self.factorial return f.calc(n)*f.invFactorial(max(n-k, k))*f.invFactorial(min(k, n-k)) % self.MOD def solve(N: int, K: int, A: "List[int]"): c = Combination(MOD) A.sort() minSum = 0 for i in range(N-K+1): remain = N-i-1 minSum = (minSum + A[i]*c.choose_k_from_n(remain, K-1)) % MOD maxSum = 0 A.reverse() for i in range(N-K+1): remain = N-i-1 maxSum = (maxSum + A[i]*c.choose_k_from_n(remain, K-1)) % MOD print((maxSum - minSum + MOD) % MOD) return # Generated by 1.1.6 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 K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, K, A) if __name__ == '__main__': main()
1
95,996,792,121,372
null
242
242
def main(): N = int(input()) A = list(map(int, input().split())) for i in range(N): if A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0): return "DENIED" return "APPROVED" if __name__ == '__main__': print(main())
N=int(input()) S=[int(s) for s in input().split()] for i in range(N): if S[i]%2==0 and S[i]%5!=0 and S[i]%3!=0: print("DENIED") break elif i==N-1: print("APPROVED")
1
69,081,914,383,460
null
217
217
N = int(input()) abc_list = ['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'] abc = '' while(N>26): n = N%26 N = N//26 if n==0: abc+=abc_list[25] N = N-1 else: abc+=abc_list[n-1] abc+=abc_list[N-1] print(abc[::-1])
t1, t2 = map(int,input().split()) a1, a2 = map(int,input().split()) b1, b2 = map(int,input().split()) a1 = t1*a1 a2 = t2*a2 b1 = t1*b1 b2 = t2*b2 if (a1 + a2) == (b1 + b2): print('infinity') exit(0) elif (a1 + a2) > (b1 + b2): a1, b1 = b1, a1 a2, b2 = b2, a2 if b1 > a1: print(0) exit(0) tmp00 = a1 - b1 tmp01 = b1 + b2 - a1 - a2 ans = tmp00 // tmp01 * 2 + 1 if tmp00 % tmp01 == 0: ans -= 1 print(ans)
0
null
71,514,928,479,450
121
269
while 1: a = list(map(int, input().split())) if a[0] or a[1]: print(min(a), max(a)) else: break
num_list = input().split() i = 0 while True: if int(num_list[i]) == 0: print(i + 1) break i += 1
0
null
6,956,692,931,528
43
126
digitsArr = list(map(int, input().split())) multipleConter = 0 for i in range(digitsArr[0], digitsArr[1]+1): if i % digitsArr[-1] == 0: multipleConter += 1 print(multipleConter)
n = int(input()) p = list(map(int,input().split())) ans = 1 dotira = False s = 10**18 if 0 in p : print(0) else: for x in p: ans = ans * x if ans > s: dotira = True break if dotira: print(-1) else: print(ans)
0
null
11,773,415,734,970
104
134
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys n = int(sys.stdin.readline()) s = list(map(int, sys.stdin.readline().split())) q = int(sys.stdin.readline()) t = list(map(int, sys.stdin.readline().split())) s_set = set(s) total = 0 for x in t: if x in s_set: total += 1 print(total)
def linearSearch(A, n, key): i = 0 A.append(key) while (A[i] != key): i += 1 del A[n] return i != n if __name__ == '__main__': n = int(input()) L = list(map(int, input().split())) q = int(input()) Key = list(map(int, input().split())) cnt = 0 for i in range(q): if (linearSearch(L, n, Key[i])): cnt += 1 print(cnt)
1
67,466,308,460
null
22
22
numbers = [int(x) for x in input().split(" ")] a, b = numbers[0], numbers[1] print("{} {} {:.5f}".format((a//b), (a%b), (a/b)))
string = input() numbers = string.split() a, b = int(numbers[0]), int(numbers[1]) d = a//b r = a%b f = a/b print(d, r, "{:.12f}".format(f))
1
600,995,179,560
null
45
45
n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) flag = [False] * 2000 for i in range(2 ** n): total = 0 for j in range(n): if((i >> j) & 1): total += A[j] flag[total] = True for m in M: print('yes' if flag[m] else 'no')
N = int(input()) A = list(map(int, input().split())) se = set() for i in range(1<<N): tot = 0 for j in range(N): if i&(1<<j): tot += A[j] se.add(tot) _ = int(input()) Q = list(map(int, input().split())) for q in Q: if q in se: print("yes") else: print("no")
1
99,517,617,408
null
25
25
import math N = int(input()) K = int(input()) l = len(str(N)) dp = [[[0 for _ in range(2)] for _ in range(4)] for _ in range(102)] dp[0][0][0] = 1 for i in range(l): for j in range(4): for k in range(2): for d in range(10): nd = int(str(N)[i]) ni = i + 1 nj = j nk = k if d > 0: nj += 1 if nj > K: continue if k == 0: if d > nd: continue if d < nd: nk = 1 dp[ni][nj][nk] += dp[i][j][k] print(dp[l][K][0] + dp[l][K][1])
s = input() print('No' if s.count('A') > 2 or s.count('B') > 2 else 'Yes')
0
null
65,316,043,390,042
224
201
from math import sqrt N = int(input()) def f(x): n = N while n % x == 0: n //= x return n % x == 1 ans = 1 for k in range(2, int(sqrt(N)) + 1): res = N % k if res == 0: k1, k2 = k, N // k ans += 1 if f(k1) else 0 ans += 1 if k1 != k2 and f(k2) else 0 elif res == 1: ans += 1 if k == (N - 1) // k else 2 if N >= 3: ans += 1 print(ans)
import math def resolve(): import sys input = sys.stdin.readline # row = [int(x) for x in input().rstrip().split(" ")] # n = int(input().rstrip()) x = int(input().rstrip()) def get_sieve_of_eratosthenes(n: int): candidate = [i for i in range(2, n + 1)] primes = [] while len(candidate) > 0: prime = candidate[0] candidate = [num for num in candidate if num % prime != 0] primes.append(prime) return primes # xまでの素数 primes = get_sieve_of_eratosthenes(x) ans = x if not x in primes: while True: if any([ans % prime == 0 for prime in primes]): ans += 1 continue break print(ans) if __name__ == "__main__": resolve()
0
null
73,560,548,744,920
183
250
N,K = map(int,input().split()) i = N%K j = -i+K print(min(i,j))
N, K = map(int, input().split()) def f(x): return( N-x*K ) def test(x): return( f(x) >= 0 ) left = - 1 # return = right = (取り得る値の最小値) の可能性を排除しないために、-1 が必要 right = 10**18 while right - left > 1: # 最終的に (right, left, mid) = (最小値, 最小値 - 1, 最小値 - 1) に収束するため、差が 1 になったときに終了すればよい mid = (left+right)//2 if test(mid): left = mid else: right = mid print(min(abs(N-left*K), abs(N-right*K)))
1
39,342,079,511,852
null
180
180
from collections import deque def main(): s = list(input()) q = int(input()) query = [] que = deque(s) f = False for i in range(q): query.append(input().split(" ")) for i in range(q): if query[i][0] == '1': f = not f else: if f: if query[i][1] == '2': que.appendleft(query[i][2]) else: que.append(query[i][2]) else: if query[i][1] == '1': que.appendleft(query[i][2]) else: que.append(query[i][2]) if f: que.reverse() print("".join(que)) if __name__ == "__main__": main()
print(input().replace(*'?D'))
0
null
37,819,652,817,100
204
140
import math n = int(input()) x = list(map(int,input().split())) y = list(map(int,input().split())) p1 = p2 = p3 = p = 0 for x,y in zip(x,y): d = abs(x-y) p1 += d p2 += d**2 p3 += d**3 if d>p: p = d print('{0:.5f}\n{1:.5f}\n{2:.5f}\n{3:.5f}'.format(p1,math.sqrt(p2),math.pow(p3,1/3),p))
N=int(input()) A=list(map(int,input().split())) mul=1 if 0 in A:print("0") else: for i in range(N): mul*=A[i] if mul>pow(10,18): print("-1") break elif i==N-1:print(mul)
0
null
8,126,241,186,660
32
134
n, k = map(int, input().split()) h = sorted(map(int, input().split())) print([0, sum(h[: n - k])][n > k])
import sys import heapq n, k = map(int, input().split()) h = [] heapq.heapify(h) for x in map(int, input().split()): heapq.heappush(h, x) if n <= k: print(0) sys.exit() ans = 0 for x in range(n - k): ans += heapq.heappop(h) print(ans)
1
78,976,417,593,468
null
227
227
N=int(input()) A = list(map(int, input().split())) money=1000 stock=0 if A[0]<A[1]: stock=int(money/A[0]) money=money-A[0]*stock for i in range(1,N-1): if A[i-1]<A[i]: money=money+A[i]*stock stock=0 if A[i]<A[i+1]: stock=int(money/A[i]) money=money-A[i]*stock money=money+A[N-1]*stock print(money)
import time N = int(input()) A = list(map(int, input().split())) left = 0 right = left + 1 money = 1000 while left < N - 1: if A[left] >= A[left+1]: left += 1 right = left continue if right <= N-2: if A[right] <= A[right+1]: right += 1 continue money += (money//A[left]) * (A[right]-A[left]) left = right print(money)
1
7,288,895,881,916
null
103
103
class Combination: def __init__(self, n_max, mod=10**9+7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n+1): fac.append(fac[i-1] * i % self.mod) facinv.append(facinv[i-1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n+1) modinv[1] = 1 for i in range(2, n+1): modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod return modinv N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort() MOD = 10**9+7 comb = Combination(10**5+1) ans = 0 for i in range(N-K+1): ans -= A[i] * comb(N - i - 1, K - 1) % MOD ans %= MOD A = A[::-1] for i in range(N-K+1): ans += A[i] * comb(N - i - 1, K - 1) % MOD ans %= MOD print(ans % MOD)
N,D = map(int,input().split()) ans = 0 for i in range(N): X1,Y1 = map(int,input().split()) if X1*X1+Y1*Y1 <= D*D: ans += 1 print(ans)
0
null
51,060,390,398,258
242
96
l,r,d = map(int,input().split()) count = 0 for i in range(l,r + 1): if i % d == 0: count += 1 else: pass print(count)
""" pppppppppppppppppppp ppppp ppppppppppppppppppp ppppppp ppppppppppppppppppppp pppppppp pppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppp pppppppp ppppppppppppppppppppp ppppppp ppppppppppppppppppp ppppp pppppppppppppppppppp """ import sys from functools import lru_cache, cmp_to_key from collections import defaultdict as dd, deque, Counter as C from bisect import bisect_left as bl, bisect_right as br, bisect mod = pow(10, 9) + 7 mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(var, end="\n"): sys.stdout.write(str(var)+end) def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end) def L(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] l, r, d = sp() answer = 0 for i in range(l, r + 1): if i % d == 0: answer += 1 out(answer)
1
7,519,335,219,158
null
104
104
def A(): S = input() if(S[-1] == 's'): S += 'es' else: S += 's' print(S) A()
a = [[0] * 3 for x in range(3)] s = [[0] * 3 for x in range(3)] for i in range(3): a[i] = [int(x) for x in input().split()] n = int(input()) b = [] for i in range(n): b.append(int(input())) for i in range(n): for j in range(3): for k in range(3): if b[i] == a[j][k]: s[j][k] = 1 res = "No" if s[0][0] == 1 and s[0][1] == 1 and s[0][2] == 1: res = "Yes" if s[1][0] == 1 and s[1][1] == 1 and s[1][2] == 1: res = "Yes" if s[2][0] == 1 and s[2][1] == 1 and s[2][2] == 1: res = "Yes" if s[0][0] == 1 and s[1][0] == 1 and s[2][0] == 1: res = "Yes" if s[0][1] == 1 and s[1][1] == 1 and s[2][1] == 1: res = "Yes" if s[0][2] == 1 and s[1][2] == 1 and s[2][2] == 1: res = "Yes" if s[0][0] == 1 and s[1][1] == 1 and s[2][2] == 1: res = "Yes" if s[2][0] == 1 and s[1][1] == 1 and s[0][2] == 1: res = "Yes" print(res)
0
null
31,187,225,927,302
71
207
while True: a,b = map(int,raw_input().split()) if a == 0: if b==0: break elif b>0: print a,b else: print b,a elif a>=b: print b,a else: print a,b
while True: line = list(map(int, input().split())) if line==[0,0]: break print(' '.join(map(str,sorted(line))))
1
528,854,746,530
null
43
43
# row = [int(x) for x in input().rstrip().split(" ")] # n = int(input().rstrip()) # s = input().rstrip() def resolve(): import sys input = sys.stdin.readline x = int(input().rstrip()) if x // 100 * 5 >= x % 100: print(1) else: print(0) if __name__ == "__main__": resolve()
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())) x=int(input()) a,b=divmod(x,100) if a*5>=b: print(1) else: print(0)
1
127,870,443,875,032
null
266
266
# Not Divisible N = int(input()) A = [int(n) for n in input().split()] check = [0] * 1000001 A.sort() ok = [-1] p = 0 for a in A: if a == p: if ok[-1] == p: ok = ok[:-1] continue p = a if check[a] == 1: continue for i in range(a, 1000001, a): check[i] = 1 ok.append(a) print(len(ok) - 1)
r = input() r = int(r) ans = r ** 2 print(ans)
0
null
79,573,784,413,980
129
278
def calc_change(price: int) -> int: return 1000 - price % 1000 if price % 1000 != 0 else 0 if __name__ == '__main__': print(calc_change(int(input())))
import sys import bisect as bi import math from collections import defaultdict as dd import heapq input=sys.stdin.readline ##import numpy as np #sys.setrecursionlimit(10**7) mo=10**9+7 def cin(): return map(int,sin().split()) def ain(): return list(map(int,sin().split())) def sin(): return input() def inin(): return int(input()) ##def power(x, y): ## if(y == 0):return 1 ## temp = power(x, int(y / 2))%mo ## if (y % 2 == 0):return (temp * temp)%mo ## else: ## if(y > 0):return (x * temp * temp)%mo ## else:return ((temp * temp)//x )%mo ## ##for _ in range(inin()): n=inin() if(n%1000==0): print(0) else: print(1000-n%1000) ## ##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power ##def pref(a,n,f): ## pre=[0]*n ## if(f==0): ##from beginning ## pre[0]=a[0] ## for i in range(1,n): ## pre[i]=a[i]+pre[i-1] ## else: ##from end ## pre[-1]=a[-1] ## for i in range(n-2,-1,-1): ## pre[i]=pre[i+1]+a[i] ## return pre ##maxint=10**24 ##def kadane(a,size): ## max_so_far = -maxint - 1 ## max_ending_here = 0 ## ## for i in range(0, size): ## max_ending_here = max_ending_here + a[i] ## if (max_so_far < max_ending_here): ## max_so_far = max_ending_here ## ## if max_ending_here < 0: ## max_ending_here = 0 ## return max_so_far
1
8,382,422,833,180
null
108
108
n=int(input());a=list(map(int,input().split()));dict={i+1:a[i] for i in range(n)} print(*[i[0] for i in sorted(dict.items(),key=lambda x:x[1])],sep=' ')
n,*a=map(int,open(0).read().split()) b=[0]*n for i in range(n): b[a[i]-1]=str(i+1) print(' '.join(b))
1
181,273,822,554,782
null
299
299
n, a = int(input()), input().split() ta = list((int(c[1]), i, c) for i, c in enumerate(a)) ca = sorted(ta) ba = ta[:] for i in range(n): for j in range(n - 1, i, -1): if ba[j][0] < ba[j - 1][0]: ba[j], ba[j - 1] = ba[j - 1], ba[j] print(*[t[2] for t in ba]) print(('Not s' if ba != ca else 'S') + 'table') sa = ta[:] for i in range(n): minj = i for j in range(i, n): if sa[j][0] < sa[minj][0]: minj = j if minj != i: sa[i], sa[minj] = sa[minj], sa[i] print(*[t[2] for t in sa]) print(('Not s' if sa != ca else 'S') + 'table')
length = int(input()) targ = [n for n in input().split(' ')] selecttarg = targ[:] #bubbleflag = 0 for l in range(length): for init in range(l): if targ[l - init][1] < targ[l - init - 1][1]: disp = targ[l-init] targ[l-init] = targ[l-init-1] targ[l-init-1] = disp print(' '.join([str(n) for n in targ])) print("Stable") selectflag = 0 for l in range(length): value = l samevalue = l for init in range(l+1,length): if selecttarg[value][1] > selecttarg[init][1]: value = init elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]: samevalue = init if samevalue != l and value != l and value > samevalue: selectflag = 1 disp = selecttarg[l] selecttarg[l] = selecttarg[value] selecttarg[value] = disp print(' '.join([str(n) for n in selecttarg])) if selectflag == 0: print("Stable") else: print("Not stable")
1
25,291,347,368
null
16
16
x1, y1, x2, y2 = map(float,input().split()) a=((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 print(a)
# -*- coding: utf-8 -*- import sys import os import math x1, y1, x2, y2 = list(map(float, input().split())) x_diff = x1 - x2 y_diff = y1 - y2 d = math.sqrt(x_diff ** 2 + y_diff ** 2) print(d)
1
160,461,524,828
null
29
29
# -*- coding: utf-8 -*- while True: n = int(input()) if n == 0: break l = [int(x) for x in list(str(n))] print(sum(l))
n=int(input()) a=list(map(int,input().split(' '))) sw=0 flag=False for i in range(n): flag=False for j in range(i+1,n)[::-1]: if a[j]<a[j-1]: a[j],a[j-1]=a[j-1],a[j] flag=True sw=sw+1 if not flag: break print(" ".join(map(str,a))) print(str(sw))
0
null
793,208,437,308
62
14
# Belongs to : midandfeed aka asilentvoice w = str(input()).lower() ans = 0 while(1): s = str(input()) if s == "END_OF_TEXT": break else: ans += sum([1 for x in s.split() if x.lower() == w]) print(ans)
#coding:utf-8 #1_9_A 2015.4.12 w = input().lower() c = 0 while True: t = input() if 'END_OF_TEXT' in t: break c += t.lower().split().count(w) print(c)
1
1,837,795,022,852
null
65
65
def row(): c=0 for y in range(HEIGHT): for x in range(WIDTH): if A[y][x]!=-1: break else: c+=1 return c def col(): c=0 for x in range(WIDTH): for y in range(HEIGHT): if A[y][x]!=-1: break else: c+=1 return c def obl(): c=0 for z in range(HEIGHT): if A[z][z]!=-1: break else: c+=1 y=0 for x in range(WIDTH-1,-1,-1): if A[y][x]!=-1: break y+=1 else: c+=1 return c def main(): for b in B: for y in range(HEIGHT): for x in range(WIDTH): if A[y][x]==b: A[y][x]=-1 cnt=row()+col()+obl() print('Yes' if cnt else 'No') if __name__=='__main__': HEIGHT=3 WIDTH=3 A=[[int(a) for a in input().split()] for y in range(HEIGHT)] N=int(input()) B=[int(input()) for n in range(N)] main()
N = int(input()) S = list(str(input())) t = 0 for i in range(len(S)): if S[i] == 'C' and S[i-1] == 'B' and S[i-2] == 'A': t += 1 print(t)
0
null
79,531,409,144,650
207
245
def resolve(): X = list(map(int, input().split())) print(X.index(0)+1) if '__main__' == __name__: resolve()
#!/usr/bin/env python k = int(input()) s = 'ACL' ans = '' for i in range(k): ans += s print(ans)
0
null
7,836,742,133,660
126
69
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy def prime_factorize(n): prime_fact = [] while n%2 == 0: prime_fact.append(2) n//=2 f = 3 while f * f <= n: if n % f == 0: prime_fact.append(f) n //= f else: f += 2 if n != 1: prime_fact.append(n) return prime_fact if __name__ == "__main__": n = int(input()) a = list(map(int,input().split())) prefix_gcd = a[0] dp = [0]*(max(a)+1) for i in range(n): prefix_gcd = math.gcd(prefix_gcd,a[i]) for i in range(n): d = prime_factorize(a[i]) d = set(d) for j in d: dp[j]+=1 pair = True for i in range(len(dp)): if dp[i] > 1: pair = False if pair == True and prefix_gcd == 1: print("pairwise coprime") elif pair == False and prefix_gcd == 1: print("setwise coprime") else: print("not coprime")
n = int(input()) a = list(map(int,input().split())) M = max(a)+1 if M == 2: print("pairwise coprime") exit() count = [0]*(M) prime = [2,3,5,7,11,13] for i in range(14,int(M**0.5)+2): check = True for j in prime: if i%j == 0: check = False break if check: prime.append(i) for i in a: for j in prime: if i < j: break if i%j==0: while i%j == 0: i //= j count[j] += 1 if i > 1: count[i] += 1 ans = max(count) if ans == 1: print("pairwise coprime") elif ans == n: print("not coprime") else: print("setwise coprime")
1
4,080,347,415,452
null
85
85
n=int(input()) s=input() c=0 for i in range(n-2): if s[i]=="A": if s[i+1]=="B": if s[i+2]=="C": c+=1 else: pass else: pass else: pass print(c)
import sys input = sys.stdin.readline n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) js = [None for _ in range(n)] # 周期とスコア増分 for s in range(n): if js[s]: continue m = s tmp = 0 memo = [[] for _ in range(n)] i = 0 while True: m = p[m] - 1 tmp += c[m] memo[m].append((i, tmp)) if len(memo[m]) > 1: js[m] = (memo[m][1][0] - memo[m][0][0], memo[m][1][1] - memo[m][0][1]) if len(memo[m]) > 2: break i += 1 ans = -100000000000 for s in range(n): m = s tmp = 0 visited = [0] * n for i in range(k): m = p[m] - 1 if visited[m]: break visited[m] = 1 tmp += c[m] if js[m] and js[m][1] > 0: ans = max(ans, tmp + js[m][1] * ((k - i - 1) // js[m][0])) else: ans = max(ans, tmp) print(ans)
0
null
52,158,960,343,464
245
93
u, s, e, w, n, b = map(int, input().split()) roll = input() for i in roll: if i == "E": e,u,w,b = u,w,b,e elif i == "S": s,u,n,b = u,n,b,s elif i == "W": w,u,e,b = u,e,b,w elif i == "N": n,u,s,b = u,s,b,n print(u)
dice = list(map(int, input().split())) command = str(input()) for c in command: if (c == 'S'): ##2651 --> 1265 dice[1],dice[5],dice[4],dice[0] = dice[0],dice[1],dice[5],dice[4] elif(c == 'N'): dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0] elif (c == 'W'): ##4631 -- > 1463 dice[3], dice[5], dice[2],dice[0] = dice[0], dice[3], dice[5], dice[2] else: dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2],dice[0] print(dice[0])
1
226,268,417,096
null
33
33
while 1: n,m=map(int, raw_input().split()) if n==m==0: break print ("#"*m+"\n")*n
while True: h, w = map(int, input().split(" ")) if h == 0 and w == 0: break print(("#"*w + "\n") * h)
1
760,922,632,864
null
49
49
X = int(input()) flag = 0 for i in range(-150,150): for j in range(-150,150): if(i**5 - j**5 == X): print(i,j) flag = 1 break if(flag==1): break
N = int(input()) A=list(map(int,input().split())) sumxor=0 for i in range(N): sumxor=sumxor^A[i] for i in range(N): print(sumxor^A[i],"",end='') print()
0
null
19,014,501,361,508
156
123
s = input() n = len(s) a = 'x'*n print(a)
from collections import deque h,w = map(int, input().split()) hw = [input() for _ in range(h)] def bfs(s): que = deque([s]) m = [[-1]*w for _ in range(h)] sh, sw = s m[sh][sw] = 0 ret = 0 while que: now_h, now_w = que.popleft() for dh, dw in [(1,0), (-1,0), (0,-1), (0,1)]: nh = now_h + dh nw = now_w + dw if not (0<=nh<h and 0<=nw<w) or m[nh][nw] != -1 or hw[nh][nw] == '#': continue m[nh][nw] = m[now_h][now_w] + 1 que.append((nh,nw)) ret = max(ret, m[now_h][now_w] + 1) return ret ans = 0 for y in range(h): for x in range(w): if hw[y][x] == '#': continue s = (y, x) ans = max(bfs(s), ans) print(ans)
0
null
83,588,927,275,370
221
241
from itertools import product a, b, c, d = map(int, input().split()) print(max(v[0] * v[1] for v in product((a, b), (c, d))))
a,b,c,d = map(int, input().split()) m = a*c n = a*d o = b*c p = b*d if(m>n and m>o and m>p): print(m) elif (n>m and n>o and n>p): print(n) elif (o> m and o>n and o>p): print(o) else: print(p)
1
3,072,060,989,568
null
77
77
N = int(input()) S = [] for x in range(N): S += [input()] S_set = set(S) print(len(S_set))
a, b = map(int, input().split()) c = list(map(int, input().split())) if a >= sum(c): print(a - sum(c)) else: print('-1')
0
null
31,139,072,553,488
165
168
n, k, s = list(map(int, input().split())) ans = [] for i in range(k): ans.append(s) alt = s+1 if s < 1e9 else s-1 for i in range(n-k): ans.append(alt) print(" ".join(map(str, ans)))
# author: Taichicchi # created: 12.09.2020 17:49:24 from itertools import permutations import sys N = int(input()) P = int("".join(input().split())) Q = int("".join(input().split())) perm = permutations([str(i) for i in range(1, N + 1)], N) ls = [] for i in perm: ls.append(int("".join(i))) print(abs(ls.index(P) - ls.index(Q)))
0
null
95,968,862,434,442
238
246
from collections import defaultdict def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) S = [0] * (N + 1) # 累積和 for i in range(1, N + 1): S[i] = S[i - 1] + A[i - 1] T = [(s - i) % K for i, s in enumerate(S)] counter = defaultdict(int) ans = 0 for j in range(N + 1): if j >= K: counter[T[j - K]] -= 1 ans += counter[T[j]] counter[T[j]] += 1 print(ans) if __name__ == '__main__': main()
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N, K = map(int, input().split()) A = list(map(int, input().split())) acc = [0] * (N + 1) for i in range(1, N + 1): acc[i] = acc[i - 1] + A[i - 1] - 1 acc[i] %= K mp = defaultdict(int) ans = 0 for j in range(N + 1): if j >= K: mp[acc[j - K]] -= 1 ans += mp[acc[j]] mp[acc[j]] += 1 print(ans)
1
137,565,974,597,130
null
273
273
H,W = list(map(int,input().split())) N=H*W #壁のノード wall=[] for h in range(H): for w_idx,w in enumerate(list(input())): if w == '#': wall.append(W*h+w_idx+1) #道のノード path=[_ for _ in range(1,N+1) if _ not in wall] #隣接リスト ad = {} for n in range(N): ad[n+1]=[] for n in range(N): n=n+1 if n not in wall: up = n-W if up > 0 and up not in wall: ad[n].append(up) down = n+W if down <= N and down not in wall: ad[n].append(down) left = n-1 if n % W != 1 and left not in wall and left > 0: ad[n].append(left) right = n+1 if n % W != 0 and right not in wall: ad[n].append(right) from collections import deque def BFS(start): que = deque([start]) visit = deque([]) color = {} for n in range(N): color[n+1] = -1 color[start] = 0 depth = {} for n in range(N): depth[n+1] = -1 depth[start] = 0 while len(que) > 0: start = que[0] for v in ad[start]: if color[v] == -1: que.append(v) color[v] = 0 depth[v] = depth[start]+1 color[start] = 1 visit.append(que.popleft()) return depth[start] ans=-1 for start in path: ans_=BFS(start) if ans < BFS(start): ans = ans_ # print(start,ans_) print(ans)
from collections import deque h, w = map(int, input().split()) chiz = [[] for _ in range(w)] for _ in range(h): tmp_list = input() for i in range(w): chiz[i].append(tmp_list[i]) def bfs(i,j): ds = [[-1]*h for _ in range(w)] dq = deque([(i,j)]) ds[i][j] = 0 res = -1 while dq: i,j = dq.popleft() for move in [(1,0),(-1,0),(0,-1),(0,1)]: if i+move[0] >= 0 and i+move[0] < w and j+move[1] >= 0 and j+move[1] < h: if chiz[i+move[0]][j+move[1]]=='.' and ds[i+move[0]][j+move[1]] == -1: ds[i + move[0]][j + move[1]] = ds[i][j] + 1 res = max(res,ds[i + move[0]][j + move[1]]) dq.append((i + move[0],j + move[1])) return res res = -1 for j in range(h): for i in range(w): if chiz[i][j]=='.': res = max(res, bfs(i,j)) print(res)
1
94,769,752,671,860
null
241
241
a,b,c=map(int,input().split()) k=int(input()) cnt=0 while a>=b: b*=2 cnt+=1 while b>=c: c*=2 cnt+=1 print("Yes" if cnt<=k else "No")
a = list(map(int, input().split())) n = int(input()) for i in range(n): if a[0] >= a[1]: a[1] *= 2 elif a[1] >= a[2]: a[2] *= 2 if a[0] < a[1] < a[2]: print("Yes") else: print("No")
1
6,868,184,697,852
null
101
101
import sys n=int(input()) A=list(map(int,input().split())) p=10**9+7 status=[1,0,0] ans=3 if A[0]!=0: print(0) sys.exit() for i in range(1,n): count=status.count(A[i]) if count==0: print(0) sys.exit() ans=(ans*count)%p status[status.index(A[i])]+=1 print(ans)
s=list(input()) t=list(input()) count = 0 for i,w in enumerate(s): if w != t[i]: count += 1 print(count)
0
null
70,586,616,587,928
268
116
x, y = map(int, input().split()) z = map(int, input().split()) if sum(z) >= x: print("Yes") else: print("No")
a, b = map(int, input().split()) c = list(map(int, input().split()[:b])) d = sum(c) if d >= a: print("Yes") else: print("No")
1
78,050,987,699,622
null
226
226
while True: h,w = map(int, input().split()) if h == 0 and w == 0: break for j in range(h): for i in range(w): if (i + j)%2 == 0: print("#", end="") else: print(".", end="") print() print()
n = int(input()) table = list(map(int,input().split())) table.sort() print(table[0],table[-1],sum(table))
0
null
791,355,026,698
51
48
value = input() convert_value = [] for x in value: if x.isupper(): convert_value.append(x.lower()) elif x.islower(): convert_value.append(x.upper()) else: convert_value.append(x) print(''.join(x for x in convert_value))
c=str(input()) cl=list(c) for i in range(len(cl)): if cl[i].islower(): cl[i]=cl[i].upper() print(cl[i],end='') elif cl[i].isupper(): cl[i] =cl[i].lower() print(cl[i], end='') elif not cl[i].isalpha(): print(cl[i], end='') print('')
1
1,533,641,624,010
null
61
61
a, b = map(int, input().split()) ans = '-1' if a < 10 and b < 10: ans = a*b print(ans)
import sys # input = sys.stdin.readline def main(): A,B = map(int,input().split()) if A//10 +B//10 >0: print(-1) else: print(A*B) if __name__ == "__main__": main()
1
158,101,130,926,930
null
286
286
(n,m) = [int(i) for i in input().split()] A = [] for nc in range(n): A.append([int(i) for i in input().split()]) b = [] for mc in range(m): b.append(int(input())) product = [] for nc in range(n): total = 0 for mc in range(m): total += A[nc][mc] * b[mc] product.append(total) [print(p) for p in product]
nkc=input().split() K=int(nkc[1]) C=int(nkc[2]) s=input() workday_list=[] for i,youso in enumerate(s) : if youso=='o' : workday_list.append(i+1) s=1 current_num=0 current_num1=1 list1=[] list1.append(workday_list[0]) while(s<K) : if current_num1>=len(workday_list): break elif workday_list[current_num1]-workday_list[current_num]>C : current_num=current_num1 list1.append(workday_list[current_num1]) s+=1 else : current_num1=current_num1+1 m=1 current_num2=len(workday_list)-1 current_num3=len(workday_list)-2 list2=[] list2.append(workday_list[-1]) while(m<K) : if current_num3<0: break elif workday_list[current_num2]-workday_list[current_num3]>C : current_num2=current_num3 list2.append(workday_list[current_num3]) m+=1 else : current_num3=current_num3-1 list2.reverse() flag=True for i in range(len(list1)) : if list1[i]==list2[i] : flag=False print(list1[i]) if flag : print()
0
null
20,955,175,887,338
56
182
N=int(input()) A=[0]*N ans=0 for i in range(1,N+1): ii=i while N>=ii: A[ii-1]+=1 ii+=i ans+=A[i-1]*i print(ans)
#ALDS1_1_D Maximum Profit n=int(input()) A=[] max_dif=-1*10**9 for i in range(n): A.append(int(input())) min=A[0] for i in range(n-1): if(A[i+1]-min>max_dif): max_dif=A[i+1]-min if(min>A[i+1]): min=A[i+1] print(max_dif)
0
null
5,469,137,817,792
118
13
r = int(input()) s = r*r print(int(s))
import itertools N = int(input()) tbl = [0]*N for x in range(1,N): for y in range(1,N): for z in range(1,N): p = x*x + y*y + z*z + x*y + y*z + z*x if p > N: break tbl[p-1] += 1 for i in range(N): print(tbl[i])
0
null
76,809,067,801,980
278
106
# Aizu Problem ITP_1_5_D: Structured Programming # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") res = [] def CHECK_NUM2(n, i): x = i if x % 3 == 0: res.append(i) else: while True: if x % 10 == 3: res.append(i) break x //= 10 if x == 0: break i += 1 if i <= n: CHECK_NUM(n, i) def CHECK_NUM(n, i): while True: x = i if x % 3 == 0: res.append(i) else: while True: if x % 10 == 3: res.append(i) break x //= 10 if x == 0: break i += 1 if i > n: break def call(n): CHECK_NUM(n, 1) n = int(input()) #n=1000 call(n) print(' ' + ' '.join([str(r) for r in res]))
from collections import defaultdict INF = float("inf") N, *A = map(int, open(0).read().split()) I = defaultdict(lambda: -INF) O = defaultdict(lambda: -INF) O[(0, 0)] = 0 for i, a in enumerate(A, 1): j = (i - 1) // 2 for n in [j, j + 1]: I[(i, n)] = a + O[(i - 1, n - 1)] O[(i, n)] = max(O[(i - 1, n)], I[(i - 1, n)]) print(max(I[(N, N // 2)], O[(N, N // 2)]))
0
null
19,163,049,427,504
52
177