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
value = int(input()) print(value ** 3)
x = raw_input() print(int(x)**3)
1
283,969,149,880
null
35
35
from itertools import groupby s = input() A = [(key, sum(1 for _ in group)) for key, group in groupby(s)] tmp = 0 ans = 0 for key, count in A: if key == '<': ans += count*(count+1)//2 tmp = count else: if tmp < count: ans -= tmp ans += count ans += (count-1)*count//2 tmp = 0 print(ans)
import math A, B, N = map(int, input().split()) n = min(N, B-1) print(math.floor(A * n / B))
0
null
92,299,672,217,720
285
161
import numpy as np R=int(input()) circle=float(R*2*np.pi) print(circle)
def pow_mod(a, b, p): res = 1 mul = a for i in range(len(bin(b)) - 2): if (1 << i) & b: res = (res * mul) % p mul = (mul ** 2) % p return res def comb_mod(n, r, p, factorial, invert_factorial): return (factorial[n] * invert_factorial[r] * invert_factorial[n - r]) % p def main(): p = 10 ** 9 + 7 n, k = map(int, input().split()) factorial = [1] * (n + 1) for i in range(1, n + 1): factorial[i] = (factorial[i - 1] * i) % p invert_factorial = [0] * (n + 1) invert_factorial[n] = pow_mod(factorial[n], p - 2, p) for i in range(n - 1, -1, -1): invert_factorial[i] = (invert_factorial[i + 1] * (i + 1)) % p res = 0 for i in range(min(k + 1, n)): res = (res + comb_mod(n, i, p, factorial, invert_factorial) * comb_mod(n - 1, i, p, factorial, invert_factorial)) % p print(res) main()
0
null
49,447,873,886,492
167
215
import math a = list(map(int, input().strip().split())) for i in a: if a[i] == 0: o = i break else: pass print(o+1)
x = list(map(int, input().split())) # n個の数字がリストに格納される for i in range(5): if x[i] is 0: print(i+1)
1
13,498,442,576,608
null
126
126
n = int(input()) s = input() # 3桁の番号を作るにあたり、文字列から抽出して作るのではなく、000〜999までの組み合わせが存在するかを確認する。 ans = 0 for i in range(10): a = s.find(str(i)) for j in range(10): b = s.find(str(j), a+1) # aの取得位置の次から検索を行う for k in range(10): c = s.find(str(k), b+1) # bの取得位置の次から検索を行う if a == -1 or b == -1 or c == -1: continue else: ans += 1 print(ans)
import collections n = int(input()) s = input() ans = 0 for i in range(10): ind = s.find(str(i))+1 if ind == 0 or ind == len(s): continue for j in range(10): ind_j = ind + s[ind:].find(str(j))+1 if ind_j == ind or ind_j == len(s): continue cnt = collections.Counter(s[ind_j:]) ans += len(cnt) print(ans)
1
128,707,253,807,950
null
267
267
import sys input = sys.stdin.readline A = sorted(list(map(int,input().split()))) if (A[0] != A[1] and A[1] == A[2]) or (A[0] == A[1] and A[1] != A[2]) : print('Yes') else: print('No')
import numpy as np N = int(input()) A = list(map(int, input().split())) A = np.int32(A) vals, cnts = np.unique(A, return_counts=True) if len(vals) == 1: print(0 if cnts[0] > 1 else 1) elif vals[0] == 1: print(0 if cnts[0] > 1 else 1) else: sat = np.ones(vals.max() + 1, dtype=int) for x in vals: sat[2 * x::x] = 0 ans = ((sat[vals] == 1) & (cnts == 1)).sum().item() print(ans) # 1 # 1 # 5 # 2 2 2 3 3 # 5 # 2 2 2 4 4 # 5 # 1 1 1 1 2
0
null
41,211,442,235,598
216
129
(s, t), (n, m), q = input().split(), map(int, input().split()), input() print(f'{n} {m - 1}' if q == t else f'{n - 1} {m}')
x,y,z = map(str,input().split()) print(z + " " + x + " " + y)
0
null
55,142,665,176,718
220
178
n = 6 a = int(input()) b = int(input()) print(n - a - b)
H,W = map(int,input().split()) s = [input() for _ in range(H)] DP = [[1000]+[0]*W for _ in range(H+1)] re = [[0]*(W+1) for _ in range(H+1)] DP[0] = [1000]*(W+1) DP[0][1] = DP[1][0] = 0 for i in range(1,H+1): for j in range(1,W+1): if s[i-1][j-1] == ".": DP[i][j] = min(DP[i-1][j],DP[i][j-1]) else: u = DP[i-1][j]+1-re[i-1][j] l = DP[i][j-1]+1-re[i][j-1] DP[i][j] = min(u, l) re[i][j] = 1 print(DP[H][W])
0
null
80,185,655,337,542
254
194
while True: string = input().strip() if string == '0': break print(sum([int(c) for c in string]))
# coding=utf-8 import sys n, q = map(int, sys.stdin.readline().split()) queue = [] total_time = 0 finished_loop = 0 for i in range(n): name, time = input().split() queue.append([name, int(time)]) while queue: n -= finished_loop finished_loop = 0 for i in range(n): poped = queue.pop(0) name = poped[0] time = poped[1] if time > q: queue.append([name, time - q]) total_time += q else: total_time += time print(name, total_time) finished_loop += 1
0
null
810,653,413,120
62
19
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors n=int(input()) nlist=make_divisors(n) n1list=make_divisors(n-1) # print(nlist) # print(n1list) answer=len(n1list)-1#1を除きます for i in nlist[1:len(nlist)]: pra=n while (pra%i==0): pra=pra/i if pra%i==1: answer+=1 print(answer)
import numpy as np def divisors(N): return sorted(sum((list({n, N // n}) for n in range(1, int(N ** 0.5) + 1) if not N % n), [])) def prime_factorize_dict(n): d = dict() while not n & 1: d[2] = d.get(2, 0) + 1 n >>= 1 f = 3 while f * f <= n: if not n % f: d[f] = d.get(f, 0) + 1 n //= f else: f += 2 if n != 1: d[n] = d.get(n, 0) + 1 return d N = int(input()) count = 0 for n in divisors(N)[1:]: M = N while not M % n: M //= n count += M % n == 1 fact_Nm1 = np.array(list(prime_factorize_dict(N - 1).values()), dtype=np.int32) print(count + np.prod(fact_Nm1 + 1) - 1)
1
41,462,301,435,990
null
183
183
import sys input = sys.stdin.readline def main(): text = input().rstrip() n = int(input().rstrip()) for i in range(n): s = input().split() if s[0] == "print": print(text[int(s[1]):int(s[2])+1]) elif s[0] == "replace": new_text = "" new_text += text[:int(s[1])] new_text += s[3] new_text += text[int(s[2])+1:] text = new_text elif s[0] == "reverse": new_text = "" new_text += text[:int(s[1])] for i in range(int(s[2])-int(s[1]) + 1): new_text += text[int(s[2]) - i] new_text += text[int(s[2])+1:] text = new_text if __name__ == "__main__": main()
N_str, q_str = raw_input().split() N = int(N_str) q = int(q_str) A =[] B =[] total =0 for i in range(N): t = raw_input().split() A.append([t[0],int(t[1])]) while A: name, time = A.pop(0) if time <= q: total += time B.append(name+" "+ str(total)) else: time -= q total += q A.append([name, time]) print '\n'.join(B)
0
null
1,080,419,563,076
68
19
ans = '' while True: s = input() if s == '-': break n = int(input()) L = [] i = 0 while i < n: j = int(input()) s = s[j:] + s[:j] i += 1 ans += s + '\n' if ans != '': print(ans[:-1])
while True: chk_list = input() if chk_list == "-": break num = int(input()) for i in range(num): n = int(input()) chk_list = chk_list[n:] + chk_list[0:n] print(chk_list)
1
1,941,775,862,720
null
66
66
from sys import stdin def main(): #入力 readline=stdin.readline n=int(readline()) dp=[0]*(n+1) for i in range(n+1): if i==0 or i==1: dp[i]=1 else: dp[i]=dp[i-1]+dp[i-2] print(dp[n]) if __name__=="__main__": main()
a=input() b=input() if(a==b[0:len(b)-1] and len(b)-len(a)==1): print('Yes') else: print('No')
0
null
10,772,983,861,190
7
147
x = int(input()) b = int(x/1.08) x1 = int(b*1.08) x2 = int((b+1)*1.08) if x1 == x: print(b) elif x2 == x: print(b+1) else: print(":(")
import math def taxminus(X): return X/1.08,(X+1)/1.08 N=int(input()) min,max=taxminus(N) min=math.ceil(min) if min>=max: print(":(") else: print(min)
1
126,089,828,610,800
null
265
265
N = int(input()) query = [[] for _ in range(N)] color = [] m = [0]*N for n in range(N-1): a, b = map(int, input().split()) query[a-1].append(b-1) query[b-1].append(a-1) color.append((min(a, b), max(a, b))) m[a-1] += 1 m[b-1] += 1 print(max(m)) from collections import deque queue = deque() queue.appendleft(0) checked = [-1]*N checked[0] = 0 dic = {} while queue: v = queue.pop() oya = checked[v] lis = query[v] cnt = 1 for i in lis: if checked[i]!=-1: continue if cnt==oya: cnt += 1 queue.appendleft(i) dic[(min(v+1, i+1), max(v+1, i+1))] = cnt checked[i] = cnt cnt += 1 for n in range(N-1): a, b = color[n] print(dic[(min(a, b), max(a, b))])
from collections import deque n = int(input()) tree = [[] for _ in range(n)] color = dict() edge = [(0, 0)] * (n-1) for i in range(n-1): a, b = map(lambda x : int(x) - 1, input().split()) tree[a].append(b) tree[b].append(a) edge[i] = (a, b) color_n = max(map(len, tree)) q = deque() q.append((0, -1)) visited = set() while q: i, prev_c = q.popleft() visited.add(i) c = 0 for x in tree[i]: if not x in visited: if c == prev_c: c = (c + 1) % color_n p = (i, x) if i < x else (x, i) color[p] = c q.append((x, c)) c = (c + 1) % color_n print(color_n) for e in edge: print(color[e] + 1)
1
135,759,900,929,940
null
272
272
N = input() a=0 for i in range(len(N)): a+=int(N[i])%9 if a%9==0: print('Yes') if a%9!=0: print('No')
def CNT(A): tmp, Min = 0, 0 for a in A: if a == '(': tmp += 1 else: tmp -= 1 Min = min(Min, tmp) return (-Min, tmp-Min) N = int(input()) S = [input() for _ in range(N)] T = [CNT(s) for s in S] pls = [] mis = [] for l, r in T: if l <= r: pls.append((l, r)) else: mis.append((l, r)) pls.sort(key=lambda a: a[0]) mis.sort(key=lambda a: a[1], reverse=True) totl= pls + mis levl = 0 for l, r in totl: levl -= l if levl < 0: print('No') exit() levl += r print('Yes' if levl==0 else 'No')
0
null
13,967,829,359,328
87
152
N,M = map(int,input().split()) S = list(map(int,input())) S.reverse() #後ろから貪欲に a = 0 #合計何マス進んだか A = [] #何マスずつ進んでいるか while a < N: if N-a <= M: A.append(N-a) a = N else: for i in range(M,0,-1): if S[a+i] == 0: A.append(i) a += i break else: print(-1) exit() A.reverse() print(*A)
while True: x = [] x = input().split( ) y = [int(s) for s in x] if sum(y) == -3: break if y[0] == -1 or y[1] == -1: print("F") elif y[0] + y[1] < 30: print("F") elif y[0] + y[1] >= 30 and y[0] + y[1] <50: if y[2] >= 50: print("C") else: print("D") elif y[0] + y[1] >= 50 and y[0] + y[1] <65: print("C") elif y[0] + y[1] >= 65 and y[0] + y[1] <80: print("B") elif y[0] + y[1] >= 80: print("A")
0
null
70,138,875,489,450
274
57
def abc163c_management(): n = int(input()) a = list(map(int, input().split())) cnts = [0] * n for v in a: cnts[v-1] += 1 for v in cnts: print(v) abc163c_management()
a,b=map(int,input().split()) result=a-b*2 if result > 0: print(result) else: print(0)
0
null
100,117,622,949,020
169
291
import math k = 1 x = float(input()) while x*k%360 != 0: k += 1 print(k)
X = int(input()) i = 1 while i <= 360: if i * X % 360 == 0: print(i) break else: i += 1
1
13,141,539,377,380
null
125
125
def grader(mid, fin, re): """ -1 <= mid <= 50 -1 <= fin <= 50 0 <= re <= 100 >>> grader(40, 42, -1) 'A' >>> grader(20, 30, -1) 'C' >>> grader(0, 2, -1) 'F' """ score = mid + fin if mid == -1 or fin == -1 or score < 30: return 'F' elif score < 50: if re >= 50: return 'C' else: return 'D' elif score < 65: return 'C' elif score < 80: return 'B' else: return 'A' def run(): while True: m, f, r = [int(x) for x in input().split()] if m == -1 and f == -1 and r == -1: break else: print(grader(m, f, r)) run()
import sys a = sys.stdin.readlines() for i in range(len(a)): b = a[i].split() m =int(b[0]) f =int(b[1]) r =int(b[2]) if m*f < 0 : print "F" elif m==-1 and f==-1 and r==-1: break else: if m+f >= 80: print "A" elif 80 > m+f >=65: print "B" elif 65 > m+f >=50: print "C" elif 50 > m+f >=30 and r < 50: print "D" elif 50 > m+f >=30 and r >= 50: print "C" elif 30 > m+f: print "F"
1
1,227,621,310,708
null
57
57
def main(): K = int(input()) S = input() N = len(S) mod = 10**9 + 7 r = 0 t = pow(26, K, mod) s = 1 inv26 = pow(26, mod - 2, mod) inv = [0] * (K + 2) inv[1] = 1 for i in range(2, K + 2): inv[i] = -inv[mod % i] * (mod // i) % mod for i in range(K + 1): r = (r + t * s) % mod t = (t * 25 * inv26) % mod s = (s * (N + i) * inv[i + 1]) % mod return r print(main())
mod=10**9+7 k=int(input()) s=input() l=len(s) fact=[1] for i in range(1,k+l+1): fact.append((fact[-1]*i)%mod) revfact=[] for i in range(k+l+1): revfact.append(pow(fact[i],mod-2,mod)) pows=[1] for i in range(1,k+l+1): pows.append((pows[-1]*25)%mod) ans=0 for i in range(l,l+k+1): ans+=fact[l+k]*revfact[i]*revfact[l+k-i]*pows[l+k-i] ans%=mod print(ans)
1
12,811,689,350,840
null
124
124
n=int(input()) s=input() q=int(input()) query=[] for i in range(q): query.append(input()) ide_ele = set() def segfunc(x, y): return x | y class SegTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): # param k: index(0-index) # param x: update value k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): #[l, r)segfunc, 0-index res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res al = [{s[i]} for i in range(n)] seg = SegTree(al, segfunc, ide_ele) for q in query: que,a,b=q.split() if que == "1": seg.update(int(a)-1,set(b)) else: ret=seg.query(int(a)-1,int(b)) print(len(ret))
n = int(input()) s = 'abcdefghijklmnopqrstuvwxyz' ans = '' while n > 0: n -= 1 # print(n//26,n%26) ans = s[n%26] + ans n = n // 26 print(ans)
0
null
37,214,380,332,048
210
121
n,*a=map(int,open(0).read().split()) a.sort() m=a[-1]+1 cnt=[0]*m for ai in a: if cnt[ai]!=0: cnt[ai]+=1 continue for i in range(ai,m,ai): cnt[i]+=1 ans=0 for ai in a: ans+=(cnt[ai]==1) print(ans)
#import sys #input = sys.stdin.readline import math from collections import defaultdict,deque ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" t=1 for _ in range(t): l,r,d=ml() ans=0 for i in range(l,r+1): if(i%d==0): ans+=1 print(ans)
0
null
11,018,031,150,480
129
104
num = 100000 n = int(input()) for i in range(n): num*=1.05 if num % 1000 >= 1 : a = num % 1000 num = int(num+1000-a) else: num = int(num) print(num)
n, m = map(int, raw_input().split()) a = [] for _ in range(n): a.append(map(int, raw_input().split())) b = [] for _ in range(m): b.append(int(raw_input())) for i in range(n): c = [] for j in range(m): c.append(a[i][j]*b[j]) print sum(c)
0
null
571,401,496,160
6
56
import sys X, K, D = map(int, input().split()) X = abs(X) if X // D >= K: print(X - K*D) sys.exit() K = K - (X // D) A = X - X//D*D if K % 2 == 0: print(A) else: print(abs(A - D))
n = list(input()) sList = list(map(int,input().split())) q = list(input()) tList = list(map(int,input().split())) tCount = 0 for tmp_t in tList: if 0 < sList.count(tmp_t): tCount += 1 print(tCount)
0
null
2,672,063,755,680
92
22
(r1,g1,b1)=input().split() (r,g,b)=(int(r1),int(g1),int(b1)) k=int(input()) flg=0 for i in range(k): if not g > r : g *= 2 elif not b > g: b *= 2 if ( b > g > r): print ("Yes") else: print ("No")
import re S = input() rds = list(map(lambda x: len(x), re.findall('R{1,}', S))) print(max(rds)) if rds else print(0)
0
null
5,880,255,624,828
101
90
N,K = map(int,input().split()) scores = list(map(int,input().split())) for i in range(N-K): #print(scores[K-K+i:K+i+1],scores[K-K + i],scores[K+i]) if scores[K-K + i ] >= scores[K+i]: print("No") else: print("Yes")
N,K=map(int,input().split()) A=list(map(int,input().split())) s_p=sum(A[:K]) for i in range(N-K): s=s_p+A[i+K]-A[i] if s_p < s: print('Yes') else: print('No')
1
7,142,122,077,810
null
102
102
N = int(input()) ans = 1000*(1+(int)((N-1)/1000))-N print(ans)
n = int(input()) for i in range(0,10001,1000): if i - n >= 0: print(i - n) exit() else: continue
1
8,444,318,775,450
null
108
108
n=int(input()) if n%2!=0: print(0) else: ans=0 t=10 while True: ans=ans+n//t t=t*5 if n//t==0: break print(ans)
n = int(input()) if n % 2 == 1: print(0) quit() d = 10 ans = 0 while n >= d: ans += n // d d *= 5 print(ans)
1
115,948,419,472,662
null
258
258
# -*- coding: utf-8 -*- import sys import os word = input().strip().lower() c = 0 for s in sys.stdin: s = s.lower() for separated in s.split(): if word == separated: c += 1 print(c)
S = input() T = input() N = len(S) cnt = 0 for i in range(N): if S[i] != T[i]: cnt += 1 else: cnt += 0 print(cnt)
0
null
6,218,248,828,700
65
116
H,W,K=map(int,input().split()) L=[] E=[0 for i in range(W+2)] L.append(E) for i in range(H): l=[0]+list(input())+[0] L.append(l) L.append(E) #print(L) cnt=1 for i in range(1,H+1): for j in range(1,W+1): if L[i][j]=="#": L[i][j]=cnt cnt+=1 #print(L) for i in range(1,H+1): num=0 for j in range(1,W+1): if num>0 and L[i][j]==".": L[i][j]=num elif L[i][j]!=".": num=L[i][j] num=0 for j in range(1,W+1): if L[i][W+1-j]!=".": num=L[i][W+1-j] elif num!=0 and L[i][W+1-j]==".": L[i][W+1-j]=num for i in range(1,H): if L[i+1][1]==".": L[i+1]=L[i] for i in range(1,H): if L[H-i][1]==".": L[H-i]=L[H-i+1] for i in range(1,H+1): print(*L[i][1:W+1])
for i in range(10000): x = input() x = int(x) if x == 0: break else: print("Case "+ str(i+1) + ": " + str(x))
0
null
72,432,982,037,780
277
42
n=int(input()) a=[0]+list(map(int,input().split())) b=[0 for i in range(n+1)] for i in range(n): b[a[i]]+=1 [print(i) for i in b[1:]]
N = int(input()) A = list(map(int, input().split())) B = [0] * N for i in range(N - 1): B[A[i] - 1] += 1 for b in B: print(b)
1
32,573,288,873,608
null
169
169
debt = 100000 for i in range(0, input()): debt *= 1.05 debt /= 1000 if (debt - int(debt) != 0.0): debt += 1 debt = int(debt) * 1000 print debt
n = int(input()) a_line = [] b_line = [] for i in range(n): a, b = map(int, input().split()) a_line.append(a) b_line.append(b) a_line.sort() b_line.sort() if n % 2 == 0: left = a_line[n // 2 - 1] + a_line[n // 2] right = b_line[n // 2 - 1] + b_line[n // 2] print(right - left + 1) else: print(b_line[n // 2] - a_line[n // 2] + 1)
0
null
8,638,470,081,920
6
137
n = int(input()) a_list = [int(i) for i in input().split()] a_dict = {} for a in a_list: if a in a_dict: a_dict[a] += 1 else: a_dict[a] = 1 q = int(input()) si = 0 for a in a_dict: si += a * a_dict[a] for _ in range(q): bi, ci = [int(i) for i in input().split()] if not bi in a_dict: print(si) continue if not ci in a_dict: a_dict[ci] = 0 a_dict[ci] += a_dict[bi] si += (ci - bi) * a_dict[bi] a_dict[bi] = 0 print(si)
n=int(input()) a=list(map(int,input().split())) q=int(input()) b,c=[],[] for _ in range(q): bi,ci=map(int,input().split()) b.append(bi) c.append(ci) number=[0 for i in range(10**5+1)] for i in range(n): number[a[i]]+=1 s=sum(a) for i in range(q): s+=(c[i]-b[i])*number[b[i]] number[c[i]]+=number[b[i]] number[b[i]]=0 print(s)
1
12,170,941,891,082
null
122
122
s = input() t = input() cnt = 0 for i in range(len(s)): cnt += s[i] != t[i] print(cnt)
n,m = map(int,input().split()) h = list(map(int,input().split())) r = ['t'] * n for i in range(m): x,y = map(int,input().split()) if h[x-1] > h[y-1]: r[y-1] = 'f' elif h[x-1] < h[y-1]: r[x-1] = 'f' else: r[y-1] = 'f' r[x-1] = 'f' s = 0 for i in range(n): if r[i] == 't': s += 1 print(s)
0
null
17,673,363,680,820
116
155
n=int(input()) a=0 b=0 for i in range(n): c,d=input().split() if c<d: b+=3 elif c>d: a+=3 else: b+=1 a+=1 print(a,b)
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def modinv(a): b = MOD u = 1 v = 0 while b: t = a // b a -= t * b a, b = b, a u -= t * v u, v = v, u u %= MOD if u < 0: u += MOD return u def factorial(N): if N == 0 or N == 1: return 1 res = N for i in range(N - 1, 1, -1): res *= i res %= MOD return res def solve(): X, Y = Scanner.map_int() if (X + Y) % 3 != 0: print(0) return B = (2 * Y - X) // 3 A = (2 * X - Y) // 3 if A < 0 or B < 0: print(0) return n = factorial(A + B) m = factorial(A) l = factorial(B) ans = n * modinv(m * l % MOD) % MOD print(ans) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
0
null
75,633,903,701,422
67
281
a,b=map(int,input().split()) c=0 for i in range (0,a+1): for j in range (0,a+1): if (i+j)==a and (i*2 + j *4) == b: c+=1 if c== 0: print('No') else: print('Yes')
def binary_search(border, b): ok = b ng = n while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if L[mid] < border: ok = mid else: ng = mid return ok n = int(input()) L = sorted(list(map(int, input().split()))) ans = 0 for a in range(0,n-1): for b in range(a+1, n): a_b = L[a] + L[b] ans += binary_search(a_b, b) - b print(ans)
0
null
92,470,405,689,426
127
294
N = int(input()) Assertions = [] ansnum = 0 for i in range(N): b = [] n = int(input()) for j in range(n): xi,yi = map(int,input().split()) b.append([xi-1,yi]) Assertions.append(b) for i in range(2**N): select = [] ans = [0 for _ in range(N)] index = [] flag = True for j in range(N): if ((i >> j) & 1): select.append(Assertions[j]) index.append(j) ans[j] = 1 for idx in index: for Assert in Assertions[idx]: if ans[Assert[0]] != Assert[1]: flag = False break if flag: ansnum = max(ansnum,len(index)) print(ansnum)
from collections import Counter N = int(input()) *D, = map(int, input().split()) mod = 998244353 c = Counter(D) v = max(D) if c[0]!=1 or D[0]!=0: print(0) else: ans = 1 for i in range(1, v+1): ans *= pow(c[i-1], c[i], mod) ans %= mod print(ans)
0
null
138,026,990,218,080
262
284
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B x = int(input()) y = list(map(int,input().split())) z = 0 for i in range(x): minj = i for j in range(i,x): if y[j] < y[minj]: minj = j if not i == minj: y[i], y[minj] = y[minj], y[i] z += 1 print(" ".join(list(map(str,y)))) print(z)
def selectionsort(A, N): count = 0 for i in range(N): minj = i for j in range(i, N): if A[j] < A[minj]: minj = j A[i], A[minj] = A[minj], A[i] if (A[i] != A[minj]): count += 1 return count def main(): n = int(input()) data = list(map(int, input().split())) c = selectionsort(data, n) print(*data) print(c) if __name__ == "__main__": main()
1
20,635,574,720
null
15
15
import sys sys.setrecursionlimit(10 ** 8) ini = lambda: int(sys.stdin.readline()) inl = lambda: [int(x) for x in sys.stdin.readline().split()] ins = lambda: sys.stdin.readline().rstrip() def solve(): x = ini() lb, ub = 0, 0 while lb <= x: if lb <= x <= ub: return True lb += 100 ub += 105 return False print(1 if solve() else 0)
x = int(input()) cnt = x // 100 y = x % 100 print(1 if cnt * 5 >= y else 0)
1
127,343,844,769,470
null
266
266
s = input() output = s.islower() if output == True: print("a") else: print("A")
alp =['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'] a = str(input()) if a in alp: print('A') else: print('a')
1
11,354,811,351,492
null
119
119
import sys def f(P): i=0 for _ in[0]*k: s=0 while s+w[i]<=P: s+=w[i];i+=1 if i==n: return n return i n,k=map(int,input().split()) w=list(map(int,sys.stdin.read().splitlines())) l=0;r=n*100000 while r-l>1: m=(l+r)//2 if f(m)>=n:r=m else:l=m print(r)
def check(k, W, p): s = 0 count = 1 for w in W: if s + w > p: count += 1 s = 0 s += w return count <= k n, k = map(int, input().split()) W = [int(input()) for _ in range(n)] right = sum(W) left = max(right // k, max(W)) - 1 while right - left > 1: p = (left + right) // 2 if check(k, W, p): right = p else: left = p print(right)
1
84,806,420,380
null
24
24
from collections import deque K = int(input()) d = deque([1,2,3,4,5,6,7,8,9]) count = 0 while True: tag = d.popleft() tmp1 = tag % 10 tmp2 = tmp1 + tag * 10 if tmp1 == 9: d.append(tmp2 - 1) d.append(tmp2) elif tmp1 == 0: d.append(tmp2) d.append(tmp2 + 1) else: d.append(tmp2 - 1) d.append(tmp2) d.append(tmp2 + 1) count += 1 if count == K: print(tag) break
from collections import deque def main(): process_count, process_time, processes = get_input() result = run_roundrobin(processes=processes, time=process_time) for r in result: print(r.name, r.time) def run_roundrobin(processes, time, total_time=0, result=[]): while processes: p = processes.popleft() if p.time <= time: total_time += p.time p.time = total_time result.append(p) else: total_time += time p.time -= time processes.append(p) return result def get_input(): count, time = list(map(lambda x: int(x), input().split(' '))) processes = deque([]) for _ in range(count): im = input().split(' ') p = Process(im[0], int(im[1])) processes.append(p) return count, time, processes class Process(): def __init__(self, name, time): self.name = name self.time = time main()
0
null
19,957,365,547,040
181
19
N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort() M = 10**9+7 def pow(a,b,M): if b == 0: return 1 elif b % 2 == 0: return pow((a**2)%M,b//2,M) % M else: return ((a % M) * pow((a**2)%M,b//2,M)) % M def inv(a,p): return pow(a,p-2,p) ans,comb = 0,1 #i番目ではcomb = (K-1-i)_C_(K-1) #max,min以外での選ぶ個数は常にK-1であることに注目すればcomb関数はいらなかった for i in range(N-K+1): if i > 0: comb = (comb * (K-1+i) * inv(i,M)) % M ans = (ans + comb*((A[K-1+i]-A[N-K-i]) % M)) % M print(ans)
import itertools n = int(input()) tes = [[] for _ in range(n)] for i in range(n): a = int(input()) for _ in range(a): x, y = map(int, input().split()) tes[i].append([x - 1, y]) ans = 0 for tf_s in itertools.product(range(2), repeat = n): for i in range(n): if tf_s[i] == 0: continue for x, y in tes[i]: if tf_s[x] != y: break else: continue break else: ans = max(ans, tf_s.count(1)) print(ans)
0
null
108,772,410,688,084
242
262
class common_function(): """ 1. よく使いそうで予め用意してあるものをまとめた 2. よく使いそうな関数群をまとめた """ def __init__(self): """ 1. 英字の一覧をリストに格納しておいた変数 """ self.sletter = ['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'] self.bletter = ['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'] def combi(self, n:int, k:int, MOD=pow(10, 9) + 7): """ mod の下での combination nCk を高速に求めるメソッド n が大きい場合(10^6)に使用する. 1回 nCk を求めるのに O(k) かかる. """ k = min(k, n-k) numer = 1 for i in range(n, n-k, -1): numer *= i numer %= MOD denom = 1 for j in range(k, 0, -1): denom *= j denom %= MOD return (numer*(pow(denom, MOD-2, MOD)))%MOD def main(): common = common_function() X, Y = map(int, input().split()) if X <= 0 or Y <= 0 or (X + Y) % 3 != 0: print(0) return if Y > 2*X or X > 2*Y: print(0) return for i in range(X): two = i one = X-2*i if two + one*2 == Y: break ans = common.combi(two+one, one) print(ans) if __name__ == "__main__": main()
X, Y = map(int, input().split()) MD = pow(10, 9) + 7 def choose(n, a): x, y = 1, 1 for i in range(a): x = x * (n - i) % MD y = y * (i + 1) % MD return x * pow(y, MD - 2, MD) % MD a = (2*Y-X)//3 b = (Y-2*X)//-3 if a < 0 or b < 0 or (X+Y) % 3 != 0: print(0) exit() print(choose(a+b, min(a,b)))
1
149,811,936,007,972
null
281
281
count = 0 for i in range(1, int(input()) + 1): if not(i % 5 == 0) and not(i % 3 == 0): count = count + i print(count)
n = int(input()) num = [int(x) for x in range(1,n+1)] for i in num: if (i%3 == 0) or (i%5 == 0): num[i-1] = 0 print(sum(num))
1
34,713,817,039,662
null
173
173
import sys from collections import defaultdict, Counter, namedtuple, deque import itertools import functools import bisect import heapq import math MOD = 10 ** 9 + 7 # MOD = 998244353 # sys.setrecursionlimit(10**8) class Uf: def __init__(self, N): self.p = list(range(N)) self.rank = [0] * N self.size = [1] * N def root(self, x): if self.p[x] != x: self.p[x] = self.root(self.p[x]) return self.p[x] def same(self, x, y): return self.root(x) == self.root(y) def unite(self, x, y): u = self.root(x) v = self.root(y) if u == v: return if self.rank[u] < self.rank[v]: self.p[u] = v self.size[v] += self.size[u] self.size[u] = 0 else: self.p[v] = u self.size[u] += self.size[v] self.size[v] = 0 if self.rank[u] == self.rank[v]: self.rank[u] += 1 def count(self, x): return self.size[self.root(x)] n, m, k = map(int, input().split()) friends = [[] for _ in range(n)] block = [[] for _ in range(n)] uf = Uf(n) F = [list(map(int, input().split())) for _ in range(m)] B = [list(map(int, input().split())) for _ in range(k)] for e in F: friends[e[0] - 1].append(e[1] - 1) friends[e[1] - 1].append(e[0] - 1) uf.unite(e[0]-1, e[1]-1) for e in B: block[e[0] - 1].append(e[1] - 1) block[e[1] - 1].append(e[0] - 1) ans = [0]*n for i in range(n): ans[i] = uf.size[uf.root(i)] - 1 for f in friends[i]: if uf.same(i, f): ans[i] -= 1 for b in block[i]: if uf.same(i, b): ans[i] -= 1 print(*ans)
import sys from io import StringIO import unittest import os # union find木 # 参考:https://note.nkmk.me/python-union-find/ class UnionFind: def __init__(self, n): """ コンストラクタ :要素数 n: """ self.n = n # 添字x: 値yとすると・・ # root以外の場合: 要素xは集合yに所属する。 # rootの場合   : 集合xの要素数はy個である。(負数で保持する) self.parents = [-1] * n def getroot(self, x): """ 所属する集合(ルートの番号)を取得する。 :調査する要素 x: """ # 値が負数 = ルートに到達したので、ルート木の番号を返す。 if self.parents[x] < 0: return x else: # 値が正数 = ルートに到達していない場合、さらに親の情報を確認する。 # 下の行は経路圧縮の処理。 self.parents[x] = self.getroot(self.parents[x]) return self.parents[x] def union(self, x, y): """ 2つの要素が所属する集合をを同じ集合に結合する。 :結合する要素(1つ目) x: :結合する要素(2つ目) y: """ # 既に同じ集合に存在するなら何もせず終了。 x = self.getroot(x) y = self.getroot(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): """ 指定した集合に属する要素数を取得する。 :調査する集合 x: """ # 添え字[root]には、要素数が負数で格納されている。そのため、取得する際は-反転する。 return -self.parents[self.getroot(x)] def is_same(self, x, y): return self.getroot(x) == self.getroot(y) def members(self, x): root = self.getroot(x) return [i for i in range(self.n) if self.getroot(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()) # 実装を行う関数 def resolve(): # 数値取得サンプル # 1行N項目 x, y = map(int, input().split()) # N行N項目 x = [list(map(int, input().split())) for i in range(n)] n, m, k = map(int, input().split()) friends = [list(map(int, input().split())) for i in range(m)] blocks = [list(map(int, input().split())) for i in range(k)] # uf 作成(要素数を+1しているのは添え字と人番号を合わせるため) uf = UnionFind(n + 1) # 除外リスト作成(これは、本問題特有の処理) # 添字x: 値yとすると・・ 要素xの友達候補を数えるとき、y(list)に該当する人は除外する。(要素数を+1しているのは添え字と人番号を合わせるため) omits = [[] for i in range(n + 1)] # UnionFindにて集合を明確にする。 for friend in friends: uf.union(friend[0], friend[1]) # 除外リストを更新(これは、本問題特有の処理) omits[friend[0]].append(friend[1]) omits[friend[1]].append(friend[0]) # ブロックリストの情報を除外リストに加える(これは、本問題特有の処理) for block in blocks: # 同じ集合に属するウ場合のみ、リストに追加 if uf.is_same(block[0], block[1]): omits[block[0]].append(block[1]) omits[block[1]].append(block[0]) # 友達候補数を出力して終了(人は1始まりなので1からループを行う # ans = [] # for i in range(1, n + 1): # 友達候補 = 集合数 - 除外リスト(自分の友人数 + 自分がブロックしている人数) - 1(集合に含まれる自分自身を除く) # ans.append(uf.size(i) - len(omits[i]) - 1) # print(" ".join(ans)) # ans = [str(uf.size(i) - len(omits[i]) - 1) for i in range(1, n + 1)] ans = [uf.size(i) - len(omits[i]) - 1 for i in range(1, n + 1)] print(*ans) # テストクラス class TestClass(unittest.TestCase): def assertIO(self, assert_input, output): stdout, sat_in = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, sat_in self.assertEqual(out, output) def test_input_1(self): test_input = """4 4 1 2 1 1 3 3 2 3 4 4 1""" output = """0 1 0 1""" self.assertIO(test_input, output) def test_input_2(self): test_input = """5 10 0 1 2 1 3 1 4 1 5 3 2 2 4 2 5 4 3 5 3 4 5""" output = """0 0 0 0 0""" self.assertIO(test_input, output) def test_input_3(self): test_input = """10 9 3 10 1 6 7 8 2 2 5 8 4 7 3 10 9 6 4 5 8 2 6 7 5 3 1""" output = """1 3 5 4 3 3 3 3 1 0""" self.assertIO(test_input, output) # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること def tes_t_1original_1(self): test_input = """データ""" output = """データ""" self.assertIO(test_input, output) # 実装orテストの呼び出し if __name__ == "__main__": if os.environ.get("USERNAME") is None: # AtCoder提出時の場合 resolve() else: # 自PCの場合 unittest.main()
1
61,933,089,238,680
null
209
209
from bisect import bisect_left as bl H,W,K=map(int,input().split()) s=[input() for _ in range(H)] a=[[0 for _ in range(W)] for _ in range(H)] OK=[] NG=[] n=0 for h in range(H): if "#" in s[h]: OK.append(h) n+=1 f=s[h].index("#") for w in range(W): if w>f and s[h][w]=="#": n+=1 a[h][w]=n else: NG.append(h) if len(NG)>0: for n in NG: if n>max(OK): ref=max(OK) else: ref=OK[bl(OK,n)] for w in range(W): a[n][w]=a[ref][w] for A in a: print(*A)
H,W,s=list(map(int,input().split())) l=[list(input()) for i in range(H)] l_h=[0]*H for i in range(H): if "#" in set(l[i]): l_h[i]=1 cnt=0 bor=sum(l_h)-1 for i in range(H): if cnt==bor: break if l_h[i]==1: l_h[i]=-1 cnt+=1 cnt=1 import numpy as np tmp=[] st=0 ans=np.zeros((H,W)) for i in range(H): tmp.append(l[i]) if l_h[i]==-1: n_tmp=np.array(tmp) s_count=np.count_nonzero(n_tmp=="#")-1 for j in range(W): ans[st:i+1,j]=cnt if "#" in n_tmp[:,j] and s_count>0: cnt+=1 s_count-=1 st=i+1 cnt+=1 tmp=[] n_tmp=np.array(tmp) s_count=np.count_nonzero(n_tmp=="#")-1 for j in range(W): ans[st:i+1,j]=cnt if "#" in n_tmp[:,j] and s_count>0: cnt+=1 s_count-=1 for i in ans: print(*list(map(int,i)))
1
143,594,017,411,250
null
277
277
import sys from collections import * import heapq import math import bisect from itertools import permutations,accumulate,combinations,product from fractions import gcd def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) mod=pow(10,9)+7 n,k=map(int,input().split()) a=list(map(int,input().split())) f=list(map(int,input().split())) left,right=-1,10**12+1 a.sort() f.sort() # print(a) while right-left>1: mid=(right+left)//2 tmp=0 for i in range(n): tmp+=max(0,a[i]-mid//f[-1-i]) if tmp<=k: right=mid else: left=mid print(right)
def abc144_e(): import numpy as np N, K = map(int, input().split()) A = np.array(input().split(), dtype=np.int64) F = np.array(input().split(), dtype=np.int64) A = np.sort(A) F = np.sort(F)[::-1] low = -1 up = 10**12 while up - low > 1: v = (up + low) // 2 x = A - v // F if x[x > 0].sum() > K: low = v else: up = v print(up) if __name__ == '__main__': abc144_e()
1
165,103,061,819,292
null
290
290
import math h,a=map(int,input().split()) num = h/a ans = math.ceil(num) print(ans)
H, A = map(int, input().split()) ans = (H // A) + ( 1 if (H % A) != 0 else 0) print(ans)
1
76,623,913,676,192
null
225
225
n = int(input()) a = list(map(int,input().split())) s = 1 if n == 0: if a[0] != 1: print(-1) quit() else: print(1) quit() elif a[0] > 0: print(-1) quit() memo = [[0,0] for _ in range(n+1)] memo[0] = [0,1] for i in range(1,n+1): if s == 0: print(-1) quit() s = memo[i-1][1]*2 if s > 10**15: s = 10**15 memo[i][0] = a[i] memo[i][1] = s-a[i] if s-a[i] < 0: print(-1) quit() ans = [[a[i],0] for i in range(n+1)] for i in range(n-1,-1,-1): if (ans[i+1][0]+ans[i+1][1]) > memo[i][1]*2: print(-1) quit() else: ans[i][1] = min(memo[i][1],ans[i+1][0]+ans[i+1][1]) s = 0 for i in range(n+1): s += sum(ans[i]) print(s)
import fractions a,b = map(int,input().split()) def lcm(x,y): z = int(x*y/fractions.gcd(x,y)) return z print(lcm(a,b))
0
null
66,336,499,164,600
141
256
n,k = map(int,input().split()) a = [] for i in range(k): d = input() a = a+input().split() a = set(a) print(n-len(a))
n, k = map(int, input().split()) xs = set() for i in range(k): d = int(input()) xs = xs.union(set(map(int, input().split()))) print(n - len(xs))
1
24,635,206,242,218
null
154
154
#!/usr/bin/env python3 # coding: utf-8 import collections def debug(arg): if __debug__: pass else: import sys print(arg, file=sys.stderr) def main(): pass N, *A = map(int, open(0).read().split()) a = dict(enumerate(A, 1)) dp = collections.defaultdict(lambda: -float("inf")) dp[0, 0] = 0 dp[1, 0] = 0 dp[1, 1] = a[1] for i in range(2, N + 1): jj = range(max(i // 2 - 1, 1), (i + 1) // 2 + 1) for j in jj: x = dp[i - 2, j - 1] + a[i] y = dp[i - 1, j] dp[i, j] = max(x, y) print(dp[N, N // 2]) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys from itertools import chain # form bisect import bisect_left, bisect_right, insort_left, insort_right # import numpy as np # 7.n = 7 * 1.n = 101 7777 def solve(K: int): n = 7 for answer in range(1, K + 1): if n % K == 0: return answer n = 10 * (n % K) + 7 return -1 def main(): tokens = chain(*(line.split() for line in sys.stdin)) # K = map(int, line.split()) K = int(next(tokens)) # type: int answer = solve(K) print(answer) if __name__ == "__main__": main()
0
null
21,797,604,838,932
177
97
from collections import Counter N = int(input()) A = [int(i) for i in input().split()] cnt_list = Counter(A) total = sum([cnt*(cnt-1)//2 if cnt > 1 else 0 for cnt in cnt_list.values()]) print(*[total-cnt_list[a]+1 for a in A], sep='\n')
from collections import Counter N=int(input()) A=list(map(int, input().split())) count = Counter(A) vals = count.values() sum_ = 0 for v in vals: if v >= 2: sum_ += v*(v-1) sum_ //= 2 for k in range(N): if count[A[k]] < 2: print(sum_) else:print(sum_ + 1 - count[A[k]])
1
47,759,046,738,142
null
192
192
#atcoder template def main(): import sys imput = sys.stdin.readline #文字列入力の時は上記はerrorとなる。 #ここにコード #input N = int(input()) A, B = [0] * N, [0] * N for i in range(N): A[i], B[i] = map(int, input().split()) #output import statistics as st import math p = st.median(A) q = st.median(B) # %% if N % 2 == 0: print(int((q-p)/0.5)+1) else: print(int(q-p)+1) #N = 1のときなどcorner caseを確認! if __name__ == "__main__": main()
N = int(input()) As = [] Bs = [] for i in range(N): A, B = map(int, input().split()) As.append(A) Bs.append(B) As.sort() Bs.sort() if N%2 == 1: A = As[N//2] B = Bs[N//2] r = B-A+1 else: A = As[(N-1)//2]+As[N//2] B = Bs[(N-1)//2]+Bs[N//2] r = B-A+1 print(r)
1
17,293,793,132,450
null
137
137
class A: def solve(self): name = input() print(name[:3]) A().solve()
import itertools A,B,C=map(int,input().split()) K=int(input()) l=list(range(K+1)) for c in itertools.product(l, repeat=3): if sum(c) == K and A*2**c[0]<B*2**c[1] and B*2**c[1]<C*2**c[2]: print("Yes") exit(0) print("No")
0
null
10,808,649,775,660
130
101
import math A, B, C, D = map(int, input().split()) #何ターンで倒せるかを比較、ターン数が小さい方が強い。ターン数が同じなら高橋が勝ち。 if math.ceil(C / B) <= math.ceil(A / D): print("Yes") else: print("No")
d_pre=input().split() d=[int(s) for s in d_pre] A=d[0] B=d[1] C=d[2] D=d[3] for i in range(210): if i%2==0: C-=B if C<=0: print("Yes") break else: A-=D if A<=0: print("No") break
1
29,679,708,525,280
null
164
164
a=map(int,raw_input().split()) if 0<=a[2]-a[4] and a[2]+a[4]<=a[0] and 0<=a[3]-a[4] and a[3]+a[4]<=a[1]: print "Yes" else: print "No"
ini = lambda : int(input()) inm = lambda : map(int,input().split()) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y a,b = input().split() b = b[:-3] + b[-2:] ans = int(a) * int(b) ans = ans // 100 print(ans)
0
null
8,520,181,208,880
41
135
s = list(input()) days = 0 if s[1] == "R": days += 1 if s[0] == "R": days += 1 if s[2] == "R": days += 1 else: if s[0] == "R" or s[2] == "R": days = 1 print(days)
s = input() count = 0 max = 0 for i in range(len(s)): if s[i] == 'S': count =0 else: count += 1 if count > max: max = count print(max)
1
4,883,240,360,478
null
90
90
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))
Day = ['', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN'] print(Day.index(input()))
0
null
66,887,158,768,518
32
270
#from collections import defaultdict, deque #import itertools #import numpy as np #import re import bisect def main(): N = int(input()) SS = [] for _ in range(N): SS.append(input()) S = [] for s in SS: while '()' in s: s = s.replace('()', '') S.append(s) #print(S) S = [s for s in S if s != ''] sum_op = 0 sum_cl = 0 S_both_op = [] S_both_cl = [] for s in S: if not ')' in s: sum_op += len(s) elif not '(' in s: sum_cl += len(s) else: pos = s.find('(') if pos <= len(s) - pos: S_both_op.append((pos, len(s)-pos)) #closeのほうが少ない、'))((('など -> (2,3) else: S_both_cl.append((pos, len(s)-pos)) #closeのほうが多い、')))(('など -> (3,2) # S_both_opは、耐えられる中でより伸ばす順にしたほうがいい? #S_both_op.sort(key=lambda x: (x[0], x[0]-x[1])) #closeの数が小さい順にsortかつclose-openが小さい=伸ばす側にsort #S_both_cl.sort(key=lambda x: (x[0], x[0]-x[1])) #これもcloseの数が小さい順にsortかつclose-openが小さい=あまり縮まない順にsort S_both_op.sort(key=lambda x: x[0]) S_both_cl.sort(key=lambda x: -x[1]) for p in S_both_op: sum_op -= p[0] if(sum_op < 0 ): print('No') exit() sum_op += p[1] for p in S_both_cl: sum_op -= p[0] if(sum_op < 0 ): print('No') exit() sum_op += p[1] if sum_op == sum_cl: print('Yes') else: print('No') if __name__ == "__main__": main()
N = int(input()) S_s = [input() for _ in range(N)] S_data1 = [] S_data2 = [] for S in S_s: life = 0 A=0 for c in S: if c == '(': life += 1 else: if life > 0: life -= 1 else: A += 1 if(A<life): S_data1.append(tuple([A,life])) else: S_data2.append(tuple([A,life])) S_data1.sort() S_data2 = sorted(S_data2, key=lambda x:-x[1]) S_data1.extend(S_data2) S_data = tuple(S_data1) life = 0 answer = True for S_datum in S_data: life -= S_datum[0] if life < 0: answer = False break life += S_datum[1] else: if life != 0: answer = False if answer: print("Yes") else: print("No")
1
23,542,906,657,952
null
152
152
import sys for l in sys.stdin: x,y=map(int, l.split()) m=x*y while x%y:x,y=y,x%y print "%d %d"%(y,m/y)
def get_input(): while True: try: yield "".join(input()) except EOFError: break def calcGCD(a,b):#?????§??¬?´???°????±?????????????????????????????????????????????¨????????? if a>b: large = a small = b elif a<b: large = b small = a else: return a while True: if large == small: return large temp_small = large - small if temp_small < small: large = small small = temp_small else: large = temp_small small = small def calcLCM(a,b,gcd):#????°???¬?????°????±?????????? lcm = a*b/gcd return lcm if __name__ == "__main__": array = list(get_input()) for i in range(len(array)): temp_a,temp_b = array[i].split() a,b = int(temp_a),int(temp_b) gcd = calcGCD(a,b) lcm = calcLCM(a,b,gcd) lcm = int(lcm) print("{} {}".format(gcd,lcm))
1
781,346,894
null
5
5
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.insert(0, 10**6) b.insert(0, 10**6) xyc = [list(map(int, input().split())) for _ in range(M)] ans = min(a) + min(b) for n in xyc: ans = min(ans, a[n[0]] + b[n[1]] - n[2]) print(ans)
A, B, M = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] b = [int(_) for _ in input().split()] xyc = [[int(_) for _ in input().split()] for i in range(M)] rets = [min(a) + min(b)] for x, y, c in xyc: rets += [a[x-1] + b[y-1] - c] print(min(rets))
1
53,771,003,383,360
null
200
200
import math A, B = map(int, input().split()) answer = -1 for x in range(10000): if math.floor(x * 0.08) == A and math.floor(x * 0.10) == B: answer = x break print(answer)
a, b = map(int, input().split()) a1 = a/0.08 a2 = (a+1)/0.08 b1 = b/0.1 b2 = (b+1)/0.1 if a1.is_integer(): x1 = a1 else: x1 = a1 + 1 if a2.is_integer(): x2 = a2 else: x2 = a2 + 1 if b1.is_integer(): y1 = b1 else: y1 = b1 + 1 if b2.is_integer(): y2 = b2 else: y2 = b2 + 1 s1 = set([i for i in range(int(x1), int(x2))]) s2 = set([i for i in range(int(y1), int(y2))]) s = s1 & s2 if len(s) == 0: print(-1) else: print(min(s1 & s2))
1
56,842,982,411,280
null
203
203
s = list(input()) t = list(input()) t.pop(-1) for i in range(len(t)): if s[i] != t[i]: print('No') exit() print('Yes')
s = input() t = input() if(s == t[0:len(s)]): print("Yes") else: print("No")
1
21,412,429,689,920
null
147
147
A = sum([list(map(int,input().split()))for _ in range(3)],[]) N = int(input()) b = [int(input()) for _ in range(N)] f=0 for i in range(9): if A[i]in b:f|=1<<i ans=[v for v in [7,56,73,84,146,273,292,448]if f&v==v] print('Yes' if ans else 'No')
A = [input().split() for _ in range(3)] N = int(input()) c = [[False]*3 for _ in range(3)] for _ in range(N): B = input() for i in range(3): if B in A[i]: c[i][A[i].index(B)] = True def solve(c): y = "Yes" n = "No" for i in range(3): if c[i][0] and c[i][1] and c[i][2]: return y if c[0][i] and c[1][i] and c[2][i]: return y if c[0][0] and c[1][1] and c[2][2]: return y if c[0][2] and c[1][1] and c[2][0]: return y return n print(solve(c))
1
59,868,600,773,830
null
207
207
N = int(input()) ans = 0 ans = -(-N//2) print(ans)
a = int(input()) if(a%2 == 1): print((a+1)//2) if(a%2 == 0): print(a//2)
1
58,832,884,024,912
null
206
206
def selectionSort(A, N): count = 0 for i in xrange(N): minj = i cflag = 0 for j in xrange(i, N): if A[j] < A[minj]: minj = j cflag = 1 A[i], A[minj] = A[minj], A[i] count+=cflag return count # MAIN N = input() A = map(int, raw_input().split()) c = selectionSort(A, N) print " ".join(map(str, A)) print c
n = int(input()) A = list(map(int,input().split())) count = 0 for i in range(n): minj = i for j in range(i,n): if A[j] < A[minj]: minj = j if minj != i: count += 1 a = A[i] A[i] = A[minj] A[minj] = a print(' '.join(map(str,A))) print(count)
1
20,486,860,402
null
15
15
ri = lambda S: [int(v) for v in S.split()] N, A, B = ri(input()) q, r = divmod(N, A+B) blue = (A * q) + r if r <= A else (A * q) + A print(blue)
import itertools #h,w=map(int,input().split()) #S=[list(map(int,input().split())) for _ in range(h)] n=int(input()) P=list(map(int,input().split())) Q=list(map(int,input().split())) num=0 numlist=[i for i in range(1,n+1)] pall=list(itertools.permutations(numlist)) for pp in pall: if P==list(pp): pnum=num if Q==list(pp): qnum=num num+=1 print(abs(pnum-qnum))
0
null
78,239,207,888,188
202
246
y,x = [int(x) for x in input().split()] while(x > 0 or y > 0): print('#' * x) st = '#' st += '.' * (x-2) st += '#' for i in range(1, y-1): print(st) print('#' * x) print() y,x = [int(x) for x in input().split()]
def mk_tree(A,N): B = [None for _ in range(N+1)] B[0] = 1 #B[i]:深さiの頂点の個数 A_sum = [A[i] for i in range(N+1)] for i in reversed(range(N)): A_sum[i] += A_sum[i+1] for i in range(1,N+1): B[i] = min(2*(B[i-1]-A[i-1]),A_sum[i]) if B[N] == A[N]: return sum(B) else: return -1 def main(): N = int(input()) A = list(map(int,input().split())) print(mk_tree(A,N)) if __name__ == "__main__": main()
0
null
9,775,406,941,320
50
141
n = int(input()) lst = list(map(int,input().split())) lst2 = [0 for i in range(n)] for i in range(n): x = lst[i] lst2[x - 1] = i + 1 for i in range(n): if (i != n - 1): print(lst2[i], end = ' ') else: print(lst2[i])
n = int(input()) a = [int(x) for x in input().split()] ans = [0] * n for i in range(n): ans[a[i]-1] = i+1 ans = [str(x) for x in ans] print(" ".join(ans))
1
181,074,583,838,822
null
299
299
masu = [list(map(int,input().split())) for _ in range(3)] n = int(input()) li = [int(input()) for _ in range(n)] check = [[0]*3 for _ in range(3)] for num in li: for i in range(3): for j in range(3): if masu[i][j] == num: check[i][j] = 1 for row in check: if all(row) == 1: print('Yes') exit() for t in range(3): count = 0 for row in check: if row[t] == 1: count += 1 if count == 3: print('Yes') exit() if check[0][0] + check[1][1] + check[2][2] == 3: print('Yes') exit() if check[0][2] + check[1][1] + check[0][2] == 3: print('Yes') exit() print('No')
K=int(input()) s='' for _ in range(K): s+='ACL' print(s)
0
null
31,004,808,188,092
207
69
from sys import stdin s = stdin.readline().rstrip() print("Yes" if s[2] == s[3] and s[4] == s[5] else "No")
import sys def I(): return int(sys.stdin.readline().rstrip()) def S(): return sys.stdin.readline().rstrip() N = I() ST = [tuple(map(str,S().split())) for _ in range(N)] X = S() ans = 0 for i in range(N): s,t = ST[i] ans += int(t) if s == X: break print(sum(int(ST[i][1]) for i in range(N))-ans)
0
null
69,734,078,499,592
184
243
def judge99(x): if x <= 9: return True else: return False a, b = map(int,input().split()) if judge99(a) and judge99(b): print(a*b) else: print(-1)
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])
0
null
90,735,153,851,070
286
150
while True: mid_score, term_score, re_score = map(int, input().split()) if mid_score == term_score == re_score == -1: break test_score = mid_score + term_score score = '' if test_score >= 80: score = 'A' elif test_score >= 65: score = 'B' elif test_score >= 50: score = 'C' elif test_score >=30: if re_score >= 50: score = 'C' else: score = 'D' else: score = 'F' if mid_score == -1 or term_score == -1: score = 'F' print(score)
while True: m, f, r = map(int, input().split()) score = m + f if m == f == r == -1: break elif m == -1 or f == -1: print('F') elif score >= 80: print('A') elif score >= 65: print('B') elif score >= 50 or (score >= 30 and r >= 50): print('C') elif score >= 30: print('D') else: print('F')
1
1,229,244,751,020
null
57
57
N=int(input()) count=0 #N未満の値がaで割り切れさえすればいい for a in range(1,N): count = count + (N-1)//a print(count)
#!/usr/bin/python # -*- coding: utf-8 -*- # def def int_mtx(N): x = [] for _ in range(N): x.append(list(map(int,input().split()))) return np.array(x) def str_mtx(N): x = [] for _ in range(N): x.append(list(input())) return np.array(x) def int_map(): return map(int,input().split()) def int_list(): return list(map(int,input().split())) def print_space(l): return print(" ".join([str(x) for x in l])) # import import numpy as np import collections as col N = int(input()) ans = 0 for i in range(1,N): if N%i != 0: ans += N//i else: ans += N//i -1 print(ans)
1
2,569,452,818,660
null
73
73
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')))
status = ['AC','WA','TLE','RE'] li = [] N = int(input()) for n in range(N): li.append(input()) for s in status: print(s,'x',li.count(s))
1
8,673,632,317,240
null
109
109
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() counter = cl.Counter() for i in range(N): s = input() counter.update({s: 1}) item, value = zip(*counter.most_common()) ans = [] max_num = value[0] for i in range(len(value)): if value[i] == max_num: ans.append(item[i]) ans.sort() print(*ans, sep="\n") main()
# coding: utf-8 # Your code here! import bisect N,D,A=map(int,input().split()) log=[] loc=[] ene=[] for _ in range(N): X,H=map(int,input().split()) log.append([X,H]) log.sort(key=lambda x:x[0]) for X,H in log: loc.append(X) ene.append(H) syokan=[0]*N power=0 for i in range(N): temp=max(-((-ene[i]+power)//A),0)*A power+=temp rng=bisect.bisect_right(loc,loc[i]+2*D) syokan[min(rng-1,N-1)]+=temp power-=syokan[i] #print(syokan) #print(syokan) print(sum(syokan)//A)
0
null
76,028,321,241,600
218
230
n,m=map(int,input().split()) c=list(map(int,input().split())) c.sort(reverse=True) #print(c) dp=[0] for i in range(1,n+1): mini=float("inf") for num in c: if i-num>=0: mini=min(mini,dp[i-num]+1) dp.append(mini) #print(dp) print(dp[-1])
INF = 100 ** 7 def main(): n, m = map(int, input().split()) c_list = list(map(int, input().split())) dp = [INF] * (n + 1) dp[0] = 0 for c in c_list: for i in range(len(dp)): if dp[i] != INF and i + c < len(dp): dp[i + c] = min(dp[i + c], dp[i] + 1) print(dp[n]) if __name__ == '__main__': main()
1
144,503,017,330
null
28
28
# coding:utf-8 class Dice: def __init__(self): self.f = [0 for i in range(6)] def roll_z(self): self.roll(1,2,4,3) def roll_y(self): self.roll(0,2,5,3) def roll_x(self): self.roll(0,1,5,4) def roll(self,i,j,k,l): t = self.f[i]; self.f[i] = self.f[j]; self.f[j] = self.f[k]; self.f[k] = self.f[l]; self.f[l] = t def move(self,ch): if ch == 'E': for i in range(3): self.roll_y() if ch == 'W': self.roll_y() if ch == 'N': self.roll_x() if ch == 'S': for i in range(3): self.roll_x() dice = Dice() dice.f = map(int, raw_input().split()) com = raw_input() for i in range(len(com)): dice.move(com[i]) print dice.f[0]
import sys input = sys.stdin.readline def south(dice): f, u, d, b = [dice["front"], dice["up"], dice["down"], dice["back"]] dice["front"] = u dice["up"] = b dice["down"] = f dice["back"] = d return dice def north(dice): f, u, d, b = [dice["front"], dice["up"], dice["down"], dice["back"]] dice["front"] = d dice["up"] = f dice["down"] = b dice["back"] = u return dice def west(dice): d, l, r, u = [dice["down"], dice["left"], dice["right"], dice["up"]] dice["down"] = l dice["left"] = u dice["right"] = d dice["up"] = r return dice def east(dice): d, l, r, u = [dice["down"], dice["left"], dice["right"], dice["up"]] dice["down"] = r dice["left"] = d dice["right"] = u dice["up"] = l return dice def show(dice): print(" ", dice["up"], " ") print(dice["left"], dice["front"], dice["right"], dice["back"]) print(" ", dice["down"], " ") print() def init_dice(dice_data): return { "front": dice_data[1], "back": dice_data[4], "up": dice_data[0], "right": dice_data[2], "down": dice_data[5], "left": dice_data[3] } def main(): pos = list(map(int, input().split())) move = input().rstrip() dice = init_dice(pos) for i in move: if i == "W": dice = west(dice) elif i == "S": dice = south(dice) elif i == "N": dice = north(dice) elif i == "E": dice = east(dice) print(dice["up"]) if __name__ == "__main__": main()
1
229,480,745,102
null
33
33
from collections import Counter N=int(input()) S=input() C=Counter(S) r=C['R'] g=C['G'] b=C['B'] ans=r*g*b # print(r,g,b) for i in range(N-2): for j in range(i+1,N-1): if S[i]==S[j]: continue k=2*j-i if k>=N: continue if S[j]!=S[k] and S[k]!=S[i] : ans-=1 print(ans)
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n = int(input()) s = input() res = s.count('R') * s.count('G') * s.count('B') if res == 0: print(0) sys.exit() for i1 in range(n): for i2 in range(i1+1, n): i3 = i2 * 2 - i1 if i3 <= n - 1: if s[i1] != s[i2] and s[i1] != s[i3] and s[i2] != s[i3]: res -= 1 print(res) if __name__ == '__main__': main()
1
36,167,636,653,072
null
175
175
S=input() if S == "ABC":print("ARC") else : print("ABC")
a=[str(i) for i in range(1,10)] i=0 while len(a)<100000: if a[i][-1]!="0": a.append(a[i]+str(int(a[i][-1])-1)) a.append(a[i]+str(int(a[i][-1]))) if a[i][-1]!="9": a.append(a[i]+str(int(a[i][-1])+1)) i+=1 # print(a[:30]) k=int(input()) print(a[k-1])
0
null
31,990,621,170,380
153
181
#インプットdata input_data = input() #初期値 stack_list = list() area_list = list() area_sum = 0 #計算の実行 for i in range(len(input_data)): if input_data[i] == "\\": stack_list.append(i) elif len(stack_list) > 0 and input_data[i] == "/": temp_area = i - stack_list[-1] area_sum += temp_area if len(area_list) == 0 or area_list[-1][0] < stack_list[-1]: area_list.append([stack_list[-1], temp_area]) else: area_list[-1][0] = stack_list[-1] area_list[-1][1] += temp_area temp_len = len(area_list) for j in range(temp_len-1, 0, -1): if area_list[j-1][0] > area_list[j][0]: area_list[j-1][0] = area_list[j][0] area_list[j-1][1] += area_list[j][1] del area_list[j] else: break del stack_list[-1] #結果の表示 print(area_sum) print(len(area_list), end="") for i in range(len(area_list)): print(f" {area_list[i][1]}", end="") print("")
def cal_water(floods): fstack = [] astack = [] i = 0 for flood in floods: if flood == '\\': fstack.append(i) elif flood == '/' and len(fstack) > 0: s = fstack.pop(-1) area = (i - s) * 1 while len(astack) > 0 and astack[-1][0] > s: _, a = astack.pop(-1) area += a astack.append((s, area)) else: pass i += 1 tot = 0 tot_area = 0 out = '' while len(astack) > 0: _, area = astack.pop() tot += 1 tot_area += area out = ' ' + str(area) + out print(tot_area) print(str(tot) + out) if __name__ == '__main__': floods = input() cal_water(floods)
1
56,904,253,230
null
21
21
W,H,x,y,r = map(int, raw_input().split()) if (r <= x <= (W - r)) and (r <= y <= (H - r)): print "Yes" else: print "No"
W, H, x, y, r = map(int, input().split()) delta = [[r, 0], [-r, 0], [0, r], [0, -r]] for dx, dy in delta: if 0 <= x + dx <= W and 0 <= y + dy <= H: pass else: print('No') exit(0) print('Yes')
1
449,623,083,262
null
41
41
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() num = 0 for i in range(N): a, b = MI() if a == b: num += 1 if num == 3: print("Yes") return else: num = 0 print("No") main()
n=int(input()) count=0 maxs=0 for _ in range(n): d1,d2=map(int,input().split()) if d1==d2: count+=1 else: maxs=max(maxs,count) count=0 maxs=max(count,maxs) if maxs>=3: print("Yes") else: print("No")
1
2,467,435,842,300
null
72
72
import math a,b,x=map(int,input().split()) if x<a*a*b/2: t=a*b*b/2/x else: t=2*b/a-2*x/(a**3) print(math.atan(t)/math.pi*180)
import math a, b, x = map(int, input().split()) x = x / a if x >= a*b/2: K = (a*b - x)/a*2 L = K/math.sqrt(K**2+a**2) ans = math.degrees(math.asin(L)) print(ans) else: K = 2*x/b L = b/math.sqrt(K**2+b**2) ans = math.degrees(math.asin(L)) print(ans)
1
162,996,318,805,560
null
289
289
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): N = int(input()) d = defaultdict(int) maxi = 0 for _ in range(N): S = input() d[S] += 1 maxi = max(maxi, d[S]) ans = [] for k, v in d.items(): if v == maxi: ans.append(k) for a in sorted(ans): print(a) def main(): solve() if __name__ == '__main__': main()
while True: data=map(str,raw_input()) if data==['-']: break for _ in xrange(input()): index=input() data=data[index:]+data[:index] print "".join(map(str,data))
0
null
35,722,380,411,552
218
66
import sys sys.setrecursionlimit(1000000000) ii = lambda: int(input()) ii0 = lambda: ii() - 1 mis = lambda: map(int, input().split()) lmis = lambda: list(mis()) INF = float('inf') def main(): N,M,L = mis() from scipy.sparse.csgraph import floyd_warshall import numpy as np INF = np.iinfo(np.int64).max d = np.full((N,N), INF, dtype=np.uint64) for i in range(N): d[i,i] = 0 # for _ in range(M): a,b,c = mis() a -= 1 b -= 1 if c <= L: d[a,b] = c d[b,a] = c # ''' for k in range(N): for i in range(N): np.minimum(d[i,:], d[i,k]+d[k,:], out=d[i,:]) ''' d = floyd_warshall(d) # d2 = np.full((N,N), INF, dtype=np.uint64) for i in range(N): d2[i, i] = 0 for i in range(N): for j in range(N): if d[i, j] <= L: d2[i, j] = 1 # ''' for k in range(N): for i in range(N): np.minimum(d2[i,:], d2[i,k]+d2[k,:], out=d2[i,:]) ''' d2 = floyd_warshall(d2) # Q = ii() for _ in range(Q): s,t = mis() s -= 1 t -= 1 dist = d2[s,t] if dist == INF: print(-1) else: print(int(dist)-1) main()
import sys input = sys.stdin.readline N,M,L = map(int, input().split()) INF = float("inf") dist1 = [[INF]*N for i in range(N)] dist2 = [[INF]*N for i in range(N)] for i in range(M): A,B,C = map(int, input().split()) A -= 1 B -= 1 dist1[A][B] = C dist1[B][A] = C for i in range(N): dist1[i][i] = 0 dist2[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): d = dist1[i][k]+dist1[k][j] if dist1[i][j] <= d: continue dist1[i][j] = d for i in range(N): for j in range(N): if dist1[i][j] > L or i==j: continue dist2[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): d = dist2[i][k]+dist2[k][j] if dist2[i][j] <= d: continue dist2[i][j] = d Q = int(input()) for i in range(Q): s,t = map(int, input().split()) print(dist2[s-1][t-1]-1 if dist2[s-1][t-1]<=L else -1)
1
173,771,465,038,574
null
295
295
n = int(input()) s = [input() for i in range(n)] z = ['AC','WA','TLE','RE'] for j in z: print(j+' x '+str(s.count(j)))
n = int(input()) a = list(map(int, input().split())) rbg = [0]*3 ans = 1 MOD = 1000000007 for i in a: count=0 flg=True for j in range(3): if rbg[j]==i: count+=1 if flg: rbg[j]+=1 flg=False ans*=count ans%=MOD print(ans)
0
null
69,421,854,731,350
109
268
def culc(x): a = x % 10 b = x while x: b = x x //= 10 return a, b n = int(input()) l = [[0 for i in range(9)] for j in range(9)] ans = 0 for i in range(1,n+1): a,b = culc(i) if a != 0 and b != 0: l[a-1][b-1] += 1 for i in range(1,n+1): a,b = culc(i) if a != 0 and b != 0: ans += l[b-1][a-1] print(ans)
N = int(input()) C = {(i,j):0 for i in range(1,10) for j in range(1,10)} num = list(range(1,10)) for k in range(1,N+1): k = str(k) i = int(k[0]) j = int(k[-1]) if i in num and j in num: C[(i,j)] += 1 cnt = 0 for i in range(1,10): for j in range(1,10): cnt += C[(i,j)]*C[(j,i)] print(cnt)
1
86,306,418,932,920
null
234
234
N = int(input()) S = input() res = 0 f = S[0] for i in range(N): if S[i] != f: f = S[i] res += 1 print(res+1)
H, A = map(int, input().split()) res = H//A if H%A != 0 : res=res+1 print("{}".format(res))
0
null
123,375,721,979,396
293
225
s = list(map(int,input().split())) if len(set(s))==2: print("Yes") else: print("No")
N,K=map(int,input().split()) R,S,P=map(int,input().split()) T=input() cnt=[0 for _ in range(N)] score={'r':P,'s':R,'p':S} for i in range(N): if i<K: cnt[i]=score[T[i]] else: if T[i-K]!=T[i]: cnt[i]=score[T[i]] else: if cnt[i-K]==0: cnt[i]=score[T[i]] print(sum(cnt))
0
null
87,416,403,182,560
216
251
def abc167_e(): N, M, K = map(int, input().split()) Mod = 998244353 class CombiMod: ''' combination mod prime ''' def __init__(self, N, Mod): ''' 前計算 ''' self.mod = Mod self.fac = [1] * (N+1) # fac[0] = fac[1] = 1 for i in range(1, N+1): self.fac[i] = (self.fac[i-1] * i) % self.mod self.finv = [1] * (N+1) # finv[0] = finv[1] = 1 self.finv[N] = pow(self.fac[N], self.mod-2, self.mod) for i in range(N, 0, -1): self.finv[i-1] = (self.finv[i] * i) % self.mod def __call__(self, n: int, k: int): ''' nCkを実際に計算する ''' if k < 0 or n < k: return 0 ret = self.fac[n] * self.finv[k] % self.mod ret = ret * self.finv[n-k] % self.mod return ret cmb = CombiMod(N, Mod) ans = 0 for x in range(K+1): p = cmb(N-1, x) * M * pow(M-1, N-x-1, Mod) % Mod ans = (ans + p) % Mod print(ans) abc167_e()
a,b = map(int,input().split()) if b-a>=0: print('unsafe') else: print('safe')
0
null
26,149,227,912,050
151
163
m1,d1=map(int,input().split()) m2,d2=map(int,input().split()) if (m1+1)%13==m2: if d2==1: print(1) exit() print(0)
import math import sys readline = sys.stdin.readline def main(): m1, d1 = map(int, readline().rstrip().split()) m2, d2 = map(int, readline().rstrip().split()) print(1 if d2 == 1 else 0) if __name__ == '__main__': main()
1
124,113,736,345,158
null
264
264
def is_ok(x): trainings = 0 for i in range(N): t = A[i] - x // F[i] if t > 0: trainings += t return trainings <= K N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) ng = -1 ok = A[-1] * F[0] while ok - ng > 1: m = ng + (ok - ng) // 2 if is_ok(m): ok = m else: ng = m print(ok)
h, a = input().split() h = int(h) a = int(a) c = 0 while h > 0: h -= a c += 1 print(c)
0
null
120,494,854,808,452
290
225
cards = [[0 for i in range(13)] for j in range(4)] s2n = {'S': 0, 'H': 1, 'C': 2, 'D': 3} n2s = 'SHCD' n = int(input()) for i in range(n): card = list(input().split()) card[1] = int(card[1]) cards[s2n[card[0]]][card[1]-1] = 1 for i in range(4): for j in range(13): if not(cards[i][j]): print(n2s[i], j+1)
import sys SUITS = ('S', 'H', 'C', 'D') cards = {suit:{i for i in range(1, 14)} for suit in SUITS} n = input() # 読み捨て for line in sys.stdin: suit, number = line.split() cards[suit].discard(int(number)) for suit in SUITS: for i in cards[suit]: print(suit, i)
1
1,031,983,266,018
null
54
54
# n, k = map(int, input().split()) # from collections import OrderedDict # d = OrderedDict() # a = list(input().split()) # b = list(map(int, input().split())) # print(r + max(0, 100*(10-n))) # print("Yes" if 500*n >= k else "No") # s = input() # a = int(input()) # b = int(input()) # c = int(input()) s = input() print("Yes" if ('A' in s and 'B' in s) else "No")
N, M = map(int, input().split()) ans = [] if M%2 == 0: for i in range(1, M//2+1): ans.append([i, M+1-i]) ans.append([M+i, 2*M+2-i]) else: for i in range(1, M//2+1): ans.append([i, M+1-i]) for i in range(1, (M+1)//2+1): ans.append([M+i, 2*M+2-i]) for i in range(len(ans)): print(*ans[i])
0
null
42,021,288,986,888
201
162
data = input().split() A = int(data[0]) B = int(data[1]) remain = max(0, A - B * 2) print(remain)
N = int(input()) az = [chr(i) for i in range(97, 97+26)] N = N - 1 tmp1 = 0 for i in range(1, 1000): tmp1 += 26 ** i if tmp1 > N: num = i tmp1 -= 26 ** i N -= tmp1 break tmp = [0 for _ in range(num)] for i in range(num): tmp[i] = N%26 N = N // 26 ans = "" for i in range(len(tmp)): ans = az[tmp[i]] + ans print(ans)
0
null
89,351,438,806,894
291
121
from collections import defaultdict N,K=map(int,input().split()) alist=list(map(int,input().split())) #print(alist) slist=[0] for i in range(N): slist.append(slist[-1]+alist[i]) #print(slist) sslist=[] for i in range(N+1): sslist.append((slist[i]-i)%K) #print(sslist) answer=0 si_dic=defaultdict(int) for i in range(N+1): if i-K>=0: si_dic[sslist[i-K]]-=1 answer+=si_dic[sslist[i]] si_dic[sslist[i]]+=1 print(answer)
a,b,c=map(int,input().split());print('YNeos'[a/b>c::2])
0
null
70,757,354,498,866
273
81
N = int(input()) A = list(map(int, input().split())) assert len(A) == N total = 0 sum_A = sum(A) for i,ai in enumerate(A): sum_A -= ai total += ai * sum_A print(total % (10 ** 9 + 7))
n = int(input()) mod = 10**9+7 ls = list(map(int,input().split())) di = [i**2 for i in ls] print((((sum(ls)**2)-(sum(di)))//2)%mod)
1
3,783,363,543,390
null
83
83