code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
# abc161_c.py
# https://atcoder.jp/contests/abc161/tasks/abc161_c
# C - Replacing Integer /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点
# 問題文
# 青木君は任意の整数 xに対し、以下の操作を行うことができます。
# 操作: xを x と Kの差の絶対値で置き換える。
# 整数 Nの初期値が与えられます。この整数に上記の操作を 0 回以上好きな回数行った時にとりうる Nの最小値を求めてください。
# 制約
# 0≤N≤1018
# 1≤K≤1018
# 入力は全て整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N K
# 出力
# 操作を 0回以上好きな回数行った時にとりうる Nの最小値を出力せよ。
# 入力例 1
# 7 4
# 出力例 1
# 1
# 最初、 N=7です。
# 1回操作を行うと、N は |7−4|=3となります。
# 2回操作を行うと、N は |3−4|=1となり、これが最小です。
# 入力例 2
# 2 6
# 出力例 2
# 2
# 1回も操作を行わなかった場合の N=2が最小です。
# 入力例 3
# 1000000000000000000 1
# 出力例 3
# 0
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
# FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
# N = int(lines[0])
N, K = list(map(int, lines[0].split()))
# values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
tmp = N % K
result = min(tmp, K-tmp)
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['7 4']
lines_export = [1]
if pattern == 2:
lines_input = ['2 6']
lines_export = [2]
if pattern == 3:
lines_input = ['1000000000000000000 1']
lines_export = [0]
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
| def solve():
X = int(input())
a,b = divmod(X, 500)
print(1000*a + 5*(b//5))
if __name__ == "__main__":
solve() | 0 | null | 41,057,612,070,580 | 180 | 185 |
string = input()
string = string*2
if string.count(input()):
print("Yes")
else:
print("No") | N = int(input())
q, r = divmod(N, 2)
print((q + r) / N)
| 0 | null | 89,337,593,694,580 | 64 | 297 |
from itertools import chain
def main():
inputs = []
r, _ = map(int, input().split())
for i in range(r):
inputs.append(tuple(map(int, input().split())))
row_sums = map(lambda row: sum(row), inputs)
column_sums = map(lambda column: sum(column), map(lambda *x: x, *inputs))
all_sum = sum(chain.from_iterable(inputs))
for i, s in zip(inputs, row_sums):
print(" ".join(map(lambda n: str(n), i)) + " {}".format(s))
else:
print(" ".join(map(lambda n: str(n), column_sums)) + " {}".format(all_sum))
if __name__ == "__main__":
main() | import math
x = int(input())
ans = x
flag = True
while True:
flag = True
for i in range(2, math.floor(math.sqrt(ans))):
if ans % i ==0:
ans += 1
flag = False
break
if flag:
print(ans)
break | 0 | null | 53,444,534,339,132 | 59 | 250 |
while 1:
l=map(str,raw_input().split())
answer = 0
if l[1] == '+':
answer = int (l[0]) + int (l[2])
if l[1] == '-':
answer = int (l[0]) - int (l[2])
if l[1] == '*':
answer = int (l[0]) * int (l[2])
if l[1] == '/':
answer = int (l[0]) / int (l[2])
if l[1] == '?':
break;
print answer | def cal(a, op, b):
if op == '+':
r = a + b
elif op == '-':
r = a - b
elif op == '*':
r = a * b
else:
r = a / b
return r
while 1:
a,op,b = raw_input().split()
if op == '?':
break
else:
print(cal(int(a), op, int(b))) | 1 | 680,160,920,840 | null | 47 | 47 |
A, B = map(int, input().split())
ans = A - B - B
if ans < 0:
ans = 0
print(ans) | A,B=(int(x) for x in input().split())
val = A-B*2
print(max(0,val)) | 1 | 166,752,742,430,846 | null | 291 | 291 |
num = list(map(int,input().split()))
print("%d %d %f" %(num[0]/num[1],num[0]%num[1],num[0]/num[1] ))
| s = input()
print("YNeos"[s[2:5:2] != s[3:6:2]::2]) | 0 | null | 21,280,205,547,948 | 45 | 184 |
#!/usr/bin/env python3
from pprint import pprint
import sys
sys.setrecursionlimit(10 ** 6)
X, Y, A, B, C = map(int, input().split())
apples_A = sorted(list(map(int, input().split())))
apples_B = sorted(list(map(int, input().split())))
apples_C = sorted(list(map(int, input().split())))
# 赤のリンゴからおいしさが大きい順に X 個選ぶ (1)
# 緑のリンゴからおいしさが大きい順に Y 個選ぶ (2)
# (1), (2) そして 無色のリンゴのから、おいしさが大きいものから順に X + Y 個選べば良い
apples_rest = sorted(apples_A[-X:] + apples_B[-Y:] + apples_C)
ans = sum(apples_rest[ -(X + Y):])
print(ans)
| def gcd(a, b):
for i in range(min(a, b), 0, -1):
if a%i == 0 and b%i == 0:
return i
A, B = map(int, input().split())
print((A*B) // gcd(A, B)) | 0 | null | 79,300,065,086,722 | 188 | 256 |
N=int(input())
S=input()
K=S
i=0
han=S[0]
kot=S[0]
for b in K:
if b != han:
kot+=b
han=b
print(len(kot)) | N = int(input())
S = input()
a = S[0]
ans = 1
for i in range(N-1):
if a != S[i+1]:
ans += 1
a = S[i+1]
print(ans) | 1 | 169,707,032,577,062 | null | 293 | 293 |
#168b
#値を受け取る
K = int(input())
S = str(input())
#Kになるまで文字を取り、K以降の文字列は'…'で表す
def answer(K: int, S: str) -> str:
if len(S) <= K:
return S
else:
return S[:K] + '...'
print(answer(K, S)) | class Dice:
def __init__(self,t,f,r,l,b,u):
self.t = t
self.f = f
self.r = r
self.l = l
self.b = b
self.u = u
self.a=[t,f,r,l,b,u]
self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
def roll(self,d):
self.a=[self.a[i] for i in self.direction[d]]
self.t = self.a[0]
self.f = self.a[1]
self.r = self.a[2]
self.l = self.a[3]
self.b = self.a[4]
self.u = self.a[5]
t,f,r,l,b,u=map(int,input().split())
dice=Dice(t,f,r,l,b,u)
n=int(input())
s='SSSEWW'
yw='YYY'
for j in range(n):
t,f=map(int,input().split())
for d in s:
if dice.t==t:
break
dice.roll(d)
for t in yw:
if dice.f==f:
break
dice.roll(t)
print(dice.r)
| 0 | null | 9,978,091,395,618 | 143 | 34 |
def f(s, n):
ans = ''
for c in s:
ans += chr(ord('A') + (ord(c)-ord('A')+n) % 26)
return ans
N = int(input())
S = input()
print(f(S, N)) | def resolve():
n = int(input())
s = input()
ans = ''
for i in s:
ans += chr(ord('A')+(ord(i)-ord('A')+n)%26)
print(ans)
resolve() | 1 | 134,282,823,040,872 | null | 271 | 271 |
n=int(input())
if n%2 == 0:
n=n-1
print(int(n/2)) | import math
n=int(input())
ans=0
for a in range(1,n+1):
for b in range(1,n+1):
d=math.gcd(a,b)
if d==1:
ans+=n
continue
if d==2:
ans+=n//2*3+n%2
continue
if d==3:
ans+=n//3*5+n%3
continue
if d==5:
ans+=n//5*9+n%5
continue
for c in range(1,n+1):
ans += math.gcd(c,d)
print(ans) | 0 | null | 94,145,131,171,872 | 283 | 174 |
# -*- coding: utf-8 -*-
num = int(raw_input())
a = int(raw_input())
b = int(raw_input())
diff = b - a
pre_min = min(a,b)
counter = 2
while counter < num:
current_num = int(raw_input())
if diff < current_num - pre_min:
diff = current_num - pre_min
if pre_min > current_num:
pre_min = current_num
counter += 1
print diff | from collections import deque
LIM=200004
L=[0]*LIM
def bin_sum(Y):
S=bin(Y)[2:]
count=0
for i in range(len(S)):
count+=int(S[i])
return count
def bin_sum2(Y):
count=0
for i in range(len(Y)):
count+=int(Y[i])
return count
for i in range(1,LIM):
L[i]+=bin_sum(i)
def pop_num(N,b,L):
if N==0:
return 0
v=N%b
return pop_num(v,L[v],L)+1
M=[0]*200005
for i in range(1,200004):
M[i]+=pop_num(i,L[i],L)
X=int(input())
Y=input()
d=bin_sum2(Y)
e=int(Y,2)%(d+1)
f=int(Y,2)%max(1,(d-1))
O=[1]*(X+2)
P=[1]*(X+2)
q=max(d-1,1)
for i in range(1,X+1):
O[i]=O[i-1]*2%q
P[i]=P[i-1]*2%(d+1)
for i in range(X):
if int(Y[i])==1:
b=max(d-1,1)
flag=max(0,d-1)
g=(f-O[X-1-i]+b)%b
else:
b=d+1
flag=1
g=(e+P[X-1-i])%b
if flag==0:
print(0)
elif g==0:
print(1)
else:
print(M[g]+1) | 0 | null | 4,133,687,220,580 | 13 | 107 |
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9+ 7
ans = 1
def answer(a):
ans =1
for x in a:
ans *= x
ans %= mod
return ans
if n == k:
print(answer(a))
return
a.sort(reverse=True, key= lambda x:abs(x))
if sum(x<0 for x in a[:k])%2 == 0:
print(answer(a[:k]))
else:
if all(x < 0 for x in a):
print(answer(a[-k:]))
else:
try:
x1, y1= min([x for x in a[:k] if x > 0]), min([x for x in a[k:] if x < 0])
except ValueError:
x1, y1 = 1, 0
try:
x2, y2= max([x for x in a[:k] if x < 0]),\
max([x for x in a[k:] if x >= 0])
except ValueError:
x2, y2 = 1, 0
if abs(x2*y1) > abs(x1*y2):
a[a.index(x1)] = y1
else:
a[a.index(x2)] = y2
print(answer(a[:k]))
if __name__ == '__main__':
main() | k,x = [int(i) for i in input().split(' ')]
print('Yes') if(500*k >= x) else print('No') | 0 | null | 54,039,463,974,868 | 112 | 244 |
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())
| # Aizu Problem 0001: List of Top 3 Hills
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input2.txt", "rt")
for h in sorted([int(input()) for _ in range(10)], reverse=True)[:3]:
print(h) | 0 | null | 6,395,506,762,700 | 124 | 2 |
while True:
m, f, r = map(int, input().split())
score = ""
if all([x < 0 for x in [m, f, r]]):
break
if any([x < 0 for x in [m, f]]):
score = "F"
elif 80 <= m+f:
score = "A"
elif 65 <= m+f:
score = "B"
elif 50 <= m+f or (30 <= m+f and 50 <= r):
score = "C"
elif 30 <= m+f:
score = "D"
else:
score = "F"
print(score)
| n = int(input())
s = [input() for _ in range(n)]
t = ('AC', 'WA', 'TLE', 'RE')
for i in t:
print(i, 'x', s.count(i))
| 0 | null | 4,966,466,482,000 | 57 | 109 |
input_line = input()
l = input_line.split()
if int(l[0]) < int(l[1]):
print("a < b")
elif int(l[0]) > int(l[1]):
print("a > b")
else:
print("a == b") | 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, lru_cache
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 = 10**6#float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
D = [LIST() for _ in range(N)]
cnt = 0
for x, y in D:
if x == y:
cnt += 1
if cnt == 3:
print("Yes")
break
else:
cnt = 0
else:
print("No") | 0 | null | 1,445,471,230,060 | 38 | 72 |
import numpy as np
n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = 2**18
f = np.array([0]*d)
for i in a:
f[i]+=1
tf = np.fft.fft(f)
f = np.fft.ifft(tf*tf)
f = [int(i+0.5) for i in f]
ans=0
for i in range(len(f)-1,0,-1):
if f[i]<=m:
ans+=i*f[i]
m-=f[i]
elif f[i]>m:
ans+=i*m
break
print(ans) | import numpy as np
from numpy.fft import fft
from numpy.fft import ifft
class FFT:
def exe(s, A, B):
N, M = 1, len(A) + len(B) - 1
while N < M: N <<= 1
A, B = s.arrN(N, A), s.arrN(N, B)
A = fft(A) * fft(B)
A = ifft(A).real[:M] + 0.5
return list(map(int, A))
def arrN(s, N, L):
return np.zeros(N) + (L + [0] * (N - len(L)))
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
MAX = max(A)
L = [0] * (MAX + 1)
for i in A:
L[i] += 1
f = FFT()
L = f.exe(L, L)
ans = 0
for i in range(len(L) - 1, -1, -1):
if L[i] < M:
ans += i * L[i]
M -= L[i]
else:
ans += i * M
break
print(ans) | 1 | 108,303,467,127,690 | null | 252 | 252 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = 10**10
while r > l + 1:
m = (r+l)//2
count = 0
for i in a:
if i <= m:
continue
count += (i)//m
if count > k:
l = m
else:
r = m
print(r)
| N=int(input())
S=input()
a=ord("A")
z=ord("Z")
result=""
for i in range(len(S)):
word=ord(S[i])+N
if word>z:
word=word-z-1+a
x=chr(word)
result+=x
print(result)
| 0 | null | 70,896,167,585,880 | 99 | 271 |
# E - Rem of Sum is Num
import queue
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = (S[i] + A[i] - 1) % K
v_set = set(S)
mp = {v: 0 for v in v_set}
ans = 0
q = queue.Queue()
for i in range(N + 1):
ans += mp[S[i]]
mp[S[i]] += 1
q.put(S[i])
if q.qsize() == K:
mp[q.get()] -= 1
print(ans) | a, b, c, d = map(int, input().split())
ans = 10**20 * -1
ans = max(ans, a * c)
ans = max(ans, a * d)
ans = max(ans, b * c)
ans = max(ans, b * d)
print(ans)
| 0 | null | 69,927,181,235,122 | 273 | 77 |
import math
a = float(input())
b = math.acos(-1)
print "%f %f" % (a * a * b , 2 * a * b) | from math import pi
r = float(input())
print('{:.5f} {:.5f}'.format(r*r*pi,r*2*pi)) | 1 | 622,230,918,848 | null | 46 | 46 |
from sys import stdin, setrecursionlimit
def main():
input = stdin.readline
n = int(input())
s_arr = []
t_arr = []
for _ in range(n):
s, t = list(map(str, input().split()))
t = int(t)
s_arr.append(s)
t_arr.append(t)
x = input()[:-1]
print(sum(t_arr[s_arr.index(x) + 1:]))
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| N = int(input())
set_list = [input().split() for _ in range(N)]
X = input()
ans = 0
flg = False
for i in range(N):
if flg == True:
ans += int(set_list[i][1])
if set_list[i][0] == X:
flg = True
print(ans) | 1 | 96,795,400,043,280 | null | 243 | 243 |
set = raw_input().split()
if int(set[0]) < int(set[1]) < int(set[2]):
print 'Yes'
else:
print 'No' | x, y, z = map(int,raw_input().split())
if(x<y and y<z):
print "Yes"
else:
print "No" | 1 | 388,168,351,762 | null | 39 | 39 |
def main():
from collections import deque
K = int(input())
if K <= 9:
print(K)
return
q = deque()
for i in range(1, 10):
q.append(i)
count = 9
while True:
get_num = q.popleft()
for i in range(-1, 2):
add_num = get_num % 10 + i
if 0 <= add_num and add_num <= 9:
q.append(get_num * 10 + add_num)
count += 1
if count == K:
print(q.pop())
return
if __name__ == '__main__':
main() | import sys
from collections import deque
input = sys.stdin.readline
n=int(input())
L=deque([i for i in range(1,10)])
if n<=9:
ans = L[n-1]
else:
cnt = 9
for i in range(1,n):
c=L.popleft()
if c%10!=0:
L.append(c*10+(c%10)-1)
cnt+=1
if cnt>=n:
break
L.append(c*10+(c%10))
cnt+=1
if cnt>=n:
break
if c%10!=9:
L.append(c*10+(c%10)+1)
cnt+=1
if cnt>=n:
break
ans = L[-1]
print(ans)
| 1 | 39,888,931,074,332 | null | 181 | 181 |
n = int(input())
a = [int(i) for i in input().split()]
cnt = [0]*(n+1)
cnt[-1] = 3
mod = 1000000007
ans = 1
for i in range(n):
ans *= cnt[a[i]-1]
ans %= mod
cnt[a[i]-1] -= 1
cnt[a[i]] += 1
print(ans) | MOD = 10**9 + 7
class ModInt:
def __init__(self, x):
self.x = x % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
return (
ModInt(self.x + other.x) if isinstance(other, ModInt) else
ModInt(self.x + other)
)
def __sub__(self, other):
return (
ModInt(self.x - other.x) if isinstance(other, ModInt) else
ModInt(self.x - other)
)
def __mul__(self, other):
return (
ModInt(self.x * other.x) if isinstance(other, ModInt) else
ModInt(self.x * other)
)
def __truediv__(self, other):
return (
ModInt(
self.x * pow(other.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(self.x, other, MOD))
)
__radd__ = __add__
def __rsub__(self, other):
return (
ModInt(other.x - self.x) if isinstance(other, ModInt) else
ModInt(other - self.x)
)
__rmul__ = __mul__
def __rtruediv__(self, other):
return (
ModInt(
other.x * pow(self.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(other * pow(self.x, MOD - 2, MOD))
)
def __rpow__(self, other):
return (
ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(other, self.x, MOD))
)
def solve(N, A):
ret = ModInt(1)
count = [3 if not i else 0 for i in range(N + 1)]
for a in A:
ret *= count[a]
if not ret:
break
count[a] -= 1
count[a + 1] += 1
return ret
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
print(solve(N, A)) | 1 | 130,303,390,554,790 | null | 268 | 268 |
s=list(input())
t=list(input())
count = 0
for i,w in enumerate(s):
if w != t[i]:
count += 1
print(count) | s=str(input())
t=str(input())
n=len(s)
ans=0
for i in range(n):
if s[i]==t[i]:
ans+=1
print(n-ans) | 1 | 10,439,164,984,670 | null | 116 | 116 |
total,amount=[int(x) for x in input().split()]
array=sorted([int(x) for x in input().split()])
print(sum(array[0:amount])) | while 1:
h,w = map(int, raw_input().split())
if h==w==0:
break
for i in range(0,h/2):
print ("#." * (w/2) + "#" * (w%2))
print (".#" * (w/2) + "." * (w%2))
if h % 2 == 1:
print ("#." * (w/2) + "#" * (w%2))
print "" | 0 | null | 6,241,470,537,860 | 120 | 51 |
S = str(input())
Q = int(input())
flip = 0
front,back = '',''
for i in range(Q):
j = input()
if len(j) == 1:
flip += 1
continue
else:
if j[2] == '1' and flip % 2 == 0:
front = j[4] + front
continue
elif j[2] == '2' and flip % 2 == 0:
back = back + j[4]
continue
elif j[2] == '1' and flip % 2 ==1:
back= back + j[4]
continue
elif j[2] == '2' and flip % 2 ==1:
front = j[4] + front
continue
S = front + S + back
if flip % 2 == 1:
S = S[::-1]
print(S) | from collections import deque
if __name__ == '__main__':
s = input()
n = int(input())
rvflg = False
d_st = deque()
d_ed = deque()
for _ in range(n):
q = input()
if len(q) == 1:
if rvflg:
rvflg = False
else:
rvflg = True
else:
i,f,c = map(str,q.split())
if f == "1":#先頭に追加
if rvflg:
#末尾に追加
d_ed.append(c)
else:
#先頭に追加
d_st.appendleft(c)
else:#末尾に追加
if rvflg:
#先頭に追加
d_st.appendleft(c)
else:
#末尾に追加
d_ed.append(c)
ans = "".join(d_st) + s + "".join(d_ed)
#最後に反転するかを決定
if rvflg:
ans = ans[::-1]
print(ans)
| 1 | 57,423,850,178,514 | null | 204 | 204 |
while True:
n = int(input())
if n == 0:
break
s = list(map(int,input().split()))
m = 0
sum = 0
for i in range(n):
sum += s[i]
m = sum/n
tmp = 0
for i in range(n):
tmp += (s[i]-m)**2
print((tmp/n)**0.5) | MOD = 998244353
n, k = map(int, input().split())
l, r = [0]*k, [0]*k
for i in range(k):
_l, _r = map(int, input().split())
l[i], r[i] = _l, _r
dp, dpsum = [0]*(n+1), [0]*(n+1)
dp[1], dpsum[1] = 1, 1
for i in range(2, n+1):
for j in range(k):
li = i - r[j]
ri = i - l[j]
if ri<0: continue
li = max(li, 1)
dp[i] += dpsum[ri] - dpsum[li-1]
dp[i] %= MOD
dpsum[i] = dpsum[i-1] + dp[i]
print(dp[n])
| 0 | null | 1,455,382,789,770 | 31 | 74 |
import math
x1, y1, x2, y2 = [ float( i ) for i in raw_input( ).split( " " ) ]
print( math.sqrt( ( x1 - x2 )**2 + ( y1 - y2 )**2 ) ) | n, x, m = map(int, input().split())
tmp = []
while True:
tmp.append(x)
x = pow(x, 2, m)
if x in tmp:
break
k = 0
while True:
if tmp[k] == x:
break
k += 1
if k > n:
print(sum(tmp[:n]))
else:
t = k
a = (n - k) // (len(tmp) - k)
s = (n - k) % (len(tmp) - k)
print(sum(tmp[:k]) + sum(tmp[k:]) * a + sum(tmp[k: k + s]))
| 0 | null | 1,476,265,129,430 | 29 | 75 |
N = int(input())
A_list = list(map(int, input().split()))
for i in range(N):
if A_list[i] % 2 == 0:
if A_list[i] % 3 == 0 or A_list[i] % 5 == 0:
continue
else:
print("DENIED")
exit()
if i == N-1:
print("APPROVED")
| import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8[:], ), cache=True)
def main(S):
N = len(S)
L = np.empty(N, np.int64)
R = np.empty(N, np.int64)
x = y = 0
n = 0
for s in S:
if s == 0:
y += 1
elif s == 1:
if y:
y -= 1
else:
x += 1
else:
L[n], R[n] = x, y
n += 1
x = y = 0
L, R = L[:n], R[:n]
L1, R1 = L[L > R], R[L > R]
L2, R2 = L[L <= R], R[L <= R]
ind = R1.argsort()
L1, R1 = L1[ind], R1[ind]
ind = L2.argsort()[::-1]
L2, R2 = L2[ind], R2[ind]
L = np.concatenate((L1, L2))
R = np.concatenate((R1, R2))
n = 0
for i in range(len(L)):
if n < R[i]:
return False
n += L[i] - R[i]
return n == 0
N = int(readline())
S = np.array(list(read()), np.int64) - ord('(')
print('Yes' if main(S) else 'No') | 0 | null | 46,387,449,666,348 | 217 | 152 |
listSi = [0,0,0,0]
ic = int(input())
icz = 0
while True:
icz += 1
i = input()
if i == "AC":
listSi[0] += 1
elif i == "WA":
listSi[1] += 1
elif i == "TLE":
listSi[2] += 1
elif i == "RE":
listSi[3] += 1
if icz == ic:
break
print(f"AC x {listSi[0]}")
print(f"WA x {listSi[1]}")
print(f"TLE x {listSi[2]}")
print(f"RE x {listSi[3]}")
| import numpy as np
#n = int(input())
a = list(map(int, input().rstrip().split()))
out=0
for i in a:
if i > 1:
out += i*(i-1)//2
print(out)
| 0 | null | 26,984,719,935,872 | 109 | 189 |
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
X = int(input())
S = make_divisors(X)
t = 0
for s in S:
a = s//2
b = a-s
while a**5 - b**5 <= X:
if a**5 - b**5 == X:
print(a,b)
break
a += 1
b += 1
if a**5 - b**5 == X:
break | import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
x = int(input())
a = 0
b = 0
done = False
for f in range(-300, 300):
for l in range(-300, 300):
if((f**5)-(l**5)==x):
a = f
b = l
done = True
break
if(done):
break
print(a,b)
| 1 | 25,736,050,870,490 | null | 156 | 156 |
a,b = map(int,input().split())
astart, aend = int(a//0.08+1), int((a+1)//0.08) #[astart, aend)
bstart, bend = int(b//0.10+1), int((b+1)//0.10)
alst = set(range(astart,aend))
blst = set(range(bstart,bend))
share = alst & blst
if len(share) == 0:
print(-1)
else:
print(list(share)[0]) | # ABC158 C - Tax Increase
a,b = map(int,input().split())
import math
c=10000
for i in range(1200):
if math.floor(i*0.08)==a and math.floor(i*0.10)==b:
c = min(c,i)
if c==10000:
print(-1)
exit()
print(c) | 1 | 56,516,839,587,780 | null | 203 | 203 |
import sys
from operator import mul
from functools import reduce
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
if len(c) != 3:
print(0)
sys.exit()
ans = reduce(mul, c.values())
for i in range(n - 1):
x, y, z = i, i + 1, i + 2
while z <= n - 1:
if s[x] != s[y] and s[x] != s[z] and s[y] != s[z]:
ans -= 1
y += 1
z += 2
print(ans) | l =int(input())
s =input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
A = r * g * b
B = 0
gapmax = (l - 3) // 2
for _ in range(gapmax+1):
for i in range(l-2-2*_):
c1, c2, c3 = s[i], s[i+1+_],s[i+2+2*_]
if not (c1 == c2) and not (c1 == c3) and not (c2 ==c3):
B += 1
print(A-B) | 1 | 36,093,349,576,960 | null | 175 | 175 |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
H, W = map(int, input().split())
grid = [list("." + input()) for _ in range(H)]
dp = [[f_inf] * (W + 1) for _ in range(H)]
dp[0][0] = 0
for h in range(H):
for w in range(W + 1):
if w == 0:
if h != 0:
continue
next_h, next_w = h, w + 1
if grid[h][w] == "." and grid[next_h][next_w] == "#":
dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
elif grid[h][w] == "." and grid[next_h][next_w] == "#":
dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
else:
dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w])
else:
for dh, dw in [(1, 0), (0, 1)]:
next_h, next_w = h + dh, w + dw
if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W + 1:
continue
if grid[h][w] == "." and grid[next_h][next_w] == "#":
dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
elif grid[h][w] == "." and grid[next_h][next_w] == "#":
dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
else:
dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w])
print(dp[-1][-1])
if __name__ == '__main__':
resolve()
| def check(i, j):
if s[i][j] == '.':
return 1
else:
return 0
H, W = map(int, input().split())
s = [input() for i in range(H)]
dp = [[0]*W for i in range(H)]
dp[0][0] = int(s[0][0] == '#')
for i in range(H):
for j in range(W):
if s[i][j] == '.':
if i > 0 and j > 0:
dp[i][j] = min(dp[i-1][j], dp[i][j-1])
elif i > 0:
dp[i][j] = dp[i-1][j]
elif j > 0:
dp[i][j] = dp[i][j-1]
else:
if i > 0 and j > 0:
dp[i][j] = min(dp[i-1][j]+check(i-1, j), dp[i][j-1]+check(i, j-1))
elif i > 0:
dp[i][j] = dp[i-1][j]+check(i-1, j)
elif j > 0:
dp[i][j] = dp[i][j-1]+check(i, j-1)
print(dp[H-1][W-1])
| 1 | 49,287,480,066,968 | null | 194 | 194 |
num = list(map(int,input().split()))
sum = 500*num[0]
if num[1] <= sum:
print("Yes")
else:
print("No") | # 配るDP、もらうDP
n, k = map(int, input().split())
mod = 998244353
kukan = []
for _ in range(k):
# 区間の問題は扱いやすいように[ ) の形に直せるなら直す
l, r = map(int, input().split())
l -= 1
kukan.append([l, r])
dp = [0 for i in range(n)]
dp[0] = 1
# 区間のL, Rは数字が大きいため、その差一つ一つを考えると時間がない!
# それゆえにL, Rの端を考えればいいようにするためにそこまでの累和を考える
ruiseki = [0 for i in range(n + 1)]
ruiseki[1] = 1
for i in range(1, n):
for l, r in kukan:
l = i - l
r = i - r
l, r = r, l
# print(l, r)
if r < 0:
continue
elif l >= 0:
dp[i] += (ruiseki[r] - ruiseki[l]) % mod
else:
dp[i] += (ruiseki[r]) % mod
ruiseki[i + 1] = (ruiseki[i] + dp[i])
# print(ruiseki, dp)
print(dp[-1] % mod)
| 0 | null | 50,172,076,357,060 | 244 | 74 |
# 高橋君と青木君がモンスターを闘わせます。
# 高橋君体力 A 攻撃力 B です。
# 青木君体力 C 攻撃力 D です。
# 高橋君→青木君→高橋君→青木君→... の順に攻撃を行います。
# このことをどちらかのモンスターの体力が 0 以下になるまで続けたとき、
# 先に自分のモンスターの体力が 0 以下になった方の負け、そうでない方の勝ちです。
# 高橋君が勝つなら Yes、負けるなら No を出力してくださ
a, b, c, d = list(map(int, input(). split()))#10 9 10 10
while True:
c -= b
if c <= 0:
print("Yes")
break
a -= d
if a <= 0:
print("No")
break
| A, B, C, D = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
i = 0
for i in range(100):
C = (C - B)
if C <= 0:
print('Yes')
break
else:
A = A - D
if A <= 0:
print('No')
break
| 1 | 29,679,666,503,740 | null | 164 | 164 |
def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x % y
x = y
y = r
return x
x, y = map(int, input().split(' '))
n = min(x, y)
print(gcd(x, y)) | 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,422,825,160 | null | 11 | 11 |
from collections import defaultdict
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
def main():
MOD = 1000000007
N = int(readline())
m = map(int, read().split())
A, B = zip(*zip(m, m))
# Ai * Aj + Bi * Bj = 0
# -> Ai * Aj = -Bi * Bj
# -> (Ai/Bi) = -(Aj/Bj)
# のとき、そのイワシ同士は入れられない
# そこで、 Ci = Ai/Bi を約分したもの(かつBi>0としておく)
# を覚えておき、Ci = -Cj となるようなペア同士を数えていく
C = defaultdict(int)
n00 = 0
for a, b in zip(A, B):
# (0, 0) はどのイワシとも仲が悪いので、考慮の対象から外して置き、
# 後で(0, 0)のイワシの本数分足す
if a == 0 and b == 0:
n00 += 1
continue
# Bが0の場合、Aが0のイワシであればなんでも仲が悪くなるので、
# C = -1 / 0 で統一する。
if b == 0:
C[(-1, 0)] += 1
continue
# Aが0の場合、Bが0のイワシであればなんでも仲が悪くなるので、
# C = 0 / 1 で統一する。
elif a == 0:
C[(0, 1)] += 1
continue
# A / B を約分して、同じ値のイワシの個数を数え上げる
g = math.gcd(a, b)
a = a // g
b = b // g
# bは常に0以上にする
if b < 0:
b = -b
a = -a
C[(a, b)] += 1
C = dict(C)
flag = {k: False for k in C.keys()}
ans = 1
for c, nc in C.items():
a, b = c
a2, b2 = (-b, a) if a >= 0 else (b, -a)
# 仲の悪いイワシの個数
nBad = C.get((a2, b2), 0)
# 仲の悪いイワシがいなければ、
# この中からイワシを選ぶ時のすべての組み合わせ(全て選択しない場合を含む)の数を考える
# = 2^nc = 1 << nc
if nBad == 0:
k = 1 << nc
else:
# (-2, 3) (3, 2) があるとき、それぞれで組み合わせを考えると重複するので、
# 片方しか数えないようにする
if flag[(a2, b2)]:
continue
# 仲の悪いイワシがいる場合、
# あるCのイワシがnc本、それと中の悪いイワシがnBad本あるとする。
# nc + nBad 本のイワシのうち、OKな組み合わせの個数は
# [nc本から1本以上選ぶ組み合わせ] + [nc本から1本以上選ぶ組み合わせ] + [イワシを全て選択しない場合]
# (2^nc - 1) + (2^nBad - 1) + 1 = 2^nc + 2^nBad - 1
k = (1 << nc) + (1 << nBad) - 1
ans = (ans * k) % MOD
flag[c] = True
# 上の数え上げだと、イワシを1本も選ばない場合も含まれているので、
# そのパターンを除外するため-1する。
# -1 するついでに(0, 0) のイワシから1本以上選ぶ場合の数も足しておく
ans = (ans + n00 - 1) % MOD
print(ans)
if __name__ == '__main__':
main() | import math
def heikatu(A,B):
c = math.gcd(A,B)
return (A//c,B//c)
def pow_r(x, n,mod=10**9+7):
"""
O(log n)
"""
if n == 0: # exit case
return 1
if n % 2 == 0: # standard case ① n is even
return pow_r((x ** 2)%1000000007 , n // 2) % mod
else: # standard case ② n is odd
return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod
def resolve():
N = int(input())
km = dict()
kp = dict()
zero = [0,0]
zerozero = 0
for i in range(N):
A,B = map(int,input().split())
if A == 0 and B == 0:
zerozero+=1
continue
if A == 0:
B = -abs(B)
if B == 0:
A = abs(A)
if A <0:
A *= -1
B *= -1
xx = heikatu(A,B)
if B < 0:
if not xx in km:
km[xx]=0
km[xx]+=1
else:
if not xx in kp:
kp[xx]=0
kp[xx]+=1
ans = 1
groups = []
for (x,y),v in km.items():
if (-y,x) in kp:
groups.append((v,kp[(-y,x)]))
del kp[(-y,x)]
else:
groups.append((v,0))
for v in kp.values():
groups.append((v,0))
for i,j in groups:
ans *= (pow_r(2,i)+pow_r(2,j)-1)%1000000007
ans %= 1000000007
print((ans+zerozero-1)%(10**9+7))
resolve() | 1 | 21,005,479,279,498 | null | 146 | 146 |
s=input()
n=len(s)
p=n//2
t=1
for i in range(p):
if s[i]==s[p-1-i]:
t=1
else:
t=0
break;
x=1
for i in range(p):
if s[p+1+i]==s[n-1-i]:
x=1
else:
x=0
break
y=1
for i in range(n):
if s[i]==s[n-1-i]:
y=1
else:
y=0
break
if (t==1 and x==1 and y==1):
print('Yes')
else:
print('No') | S = input()
s = list(S)
f = s[:int((len(s)-1)/2)]
l = s[int((len(s)+3)/2-1):]
if f == l:
while len(f) > 1:
if f[0] == f[-1]:
f.pop(0)
f.pop()
if len(f) <= 1:
while len(l) > 1:
if l[0] == l[-1]:
l.pop(0)
l.pop()
if len(l) <= 1:
print('Yes')
else:
print('No')
else:
print('No')
else:
print('No') | 1 | 46,478,886,628,828 | null | 190 | 190 |
a,b = map(int,input().split())
x = ''
if a < b:
x = ' < '
elif a > b:
x = ' > '
else:
x = ' == '
print('a'+x+'b') | a,b = [int(i) for i in input().split()]
if a>b :
print("a > b")
elif a<b :
print("a < b")
else :
print("a == b")
| 1 | 349,549,879,100 | null | 38 | 38 |
s = input()
n = int(input())
for i in range(n):
tmp = input().split()
a = int(tmp[1])
b = int(tmp[2])
if tmp[0] == "print":
print(s[a:b+1])
elif tmp[0] == "reverse":
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
elif tmp[0] == "replace":
s = s[:a] + tmp[3] + s[b+1:]
| if __name__ == '__main__':
s = input()
q = int(input())
for i in range(q):
code = input().split()
op, a, b = code[0], int(code[1]), int(code[2])
if op == 'print':
print(s[a:b+1])
elif op == 'reverse':
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
elif op == 'replace':
s = s[:a] + code[3] + s[b+1:] | 1 | 2,078,440,757,386 | null | 68 | 68 |
# B-81
# 標準入力 N
N = int(input())
num_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
j = 0
for i in range(1, 9 + 1):
if (N / i) in num_list:
j += 1
if j == 0:
print('No')
else:
print('Yes')
| import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
for i in range(1,10):
if n%i==0 and n//i<10:
ans = "Yes"
break
else:
ans = "No"
print(ans) | 1 | 160,494,121,277,948 | null | 287 | 287 |
S = input()
print(S.replace('?', 'D'))
| T = list(map(str, input()))
count = 0
ans = []
for i in range(0, len(T)):
if T[i] == '?':
ans.append('D')
else:
ans.append(T[i])
ans_ans = ''.join(ans);
print(ans_ans)
| 1 | 18,503,739,280,250 | null | 140 | 140 |
# C
import copy
import itertools
n, k = map(int, input().split())
a_list = [int(x) for x in input().split()]
for j in range(k):
b_list = [0]*n
# print("a:",*a_list)
for i in range(n):
l = max(0, i-a_list[i])
r = min(n-1, i+a_list[i])
b_list[l] += 1
if r+1 < n:
b_list[r+1] -= 1
# print("b:",*b_list)
cumsum = list(itertools.accumulate(b_list))
if cumsum == [n]*n:
break
a_list = cumsum
print(*cumsum) | import numpy as np
from numba import njit
@njit('i8[:](i8,i8,i8[:])')
def solve(N, K, A):
for _ in range(K):
B = np.zeros(N + 1, dtype=np.int64)
for i in range(N):
a = A[i]
B[max(0, i - a)] += 1
B[min(N, i + a + 1)] -= 1
A = np.cumsum(B)[:-1]
if np.all(A == N):
return A
return A
N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)
print(' '.join(map(str, solve(N, K, A)))) | 1 | 15,421,541,976,544 | null | 132 | 132 |
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
a,b = mi()
print((a*b)//math.gcd(a,b)) | N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
P = int(1e9+7)
ans = 0
kaizyo = [0]
kaizyo_inv = [0]
tmp = 1
for i in range(1, N+1):
tmp = (tmp*i) % P
kaizyo.append(tmp)
kaizyo_inv.append(pow(tmp, P - 2, P))
def comb(n, r):
if n < r or n == 0:
return 0
elif n == r or r == 0:
return 1
else:
return kaizyo[n] * kaizyo_inv[r] * kaizyo_inv[n - r]
combs=[comb(i, K - 1)%P for i in range(N+1)]
for i, a in enumerate(A):
ans = (ans + a * combs[i]) % P
ans = (ans - a * combs[N - i - 1]) % P
print(ans)
| 0 | null | 104,958,874,707,638 | 256 | 242 |
n = int(input())
li = list(map(int, input().split()))
s = li[0]
for i in range(1,n):
s ^= li[i]
ans = []
for i in li:
tmp = s^i
ans.append(tmp)
print(*ans) | length = int(input())
nums = input().split()
print(" ".join(nums[::-1])) | 0 | null | 6,708,903,477,988 | 123 | 53 |
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
ls=[a,b,c]
ls.sort()
if ls[0]==ls[1]:
if ls[1]==ls[2]:
print("No")
else:
print("Yes")
else:
if ls[1]==ls[2]:
print("Yes")
else:
print("No") | i = 0
while True:
x = int(input()); i += 1
if x == 0:
break
print("Case {}: {}".format(i, x))
| 0 | null | 34,309,617,125,728 | 216 | 42 |
import operator
def poland(A):
l = []
ops = { "+": operator.add, "-": operator.sub, '*' : operator.mul }
for i in range(len(A)):
item = A.pop(0)
if item in ops:
l.append(ops[item](l.pop(-2),l.pop()))
else:
l.append(int(item))
return l.pop()
if __name__ == '__main__':
A = input().split()
print (poland(A[:])) | ts = input().split(" ")
stack = []
for t in ts:
if t not in ("-", "+", "*"):
stack.append(int(t))
else:
n2 = stack.pop()
n1 = stack.pop()
if t == "-":
stack.append(n1 - n2)
elif t == "+":
stack.append(n1 + n2)
else:
stack.append(n1 * n2)
print(stack.pop()) | 1 | 36,976,061,990 | null | 18 | 18 |
import string
S = list(string.ascii_lowercase)
n = S.index(input())
print(S[n+1]) | # Next Alphabet
C = input()
from string import ascii_lowercase as alp
ans = alp[alp.index(C) + 1]
print(ans)
| 1 | 92,062,328,292,818 | null | 239 | 239 |
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, X, Y = NMI()
counts = [0] * N
for i in range(1, N):
for j in range(i+1, N+1):
dist = min(abs(j-i), abs(i-X) + 1 + abs(Y-j))
counts[dist] += 1
for d in counts[1:]:
print(d)
if __name__ == "__main__":
main() | n = int(input())
ns = list(map(int, input().split()))
print(min(ns), max(ns), sum(ns))
| 0 | null | 22,488,380,363,370 | 187 | 48 |
x=str(input())
for i in range(len(x)):
if int(x[i]) == 7:
print('Yes')
exit()
print('No') | a,b=input().split()
a=int(a)
b=int(b)
e=a
d=b
c=1
if a>b:
for i in range(1,e):
if a%(e-i)==0 and b%(e-i)==0:
a=a/(e-i)
b=b/(e-i)
c=c*(e-i)
print(int(a*b*c))
if a<b:
for i in range(1,d):
if a%(d-i)==0 and b%(d-i)==0:
a=a/(d-i)
b=b/(d-i)
c=c*(d-i)
print(int(a*b*c)) | 0 | null | 73,600,885,400,380 | 172 | 256 |
k = int(input())
def rec(d, n, array):
array.append(n)
if d == 10:
return
for i in [-1, 0, 1]:
add = n % 10 + i
if 0 <= add <= 9:
rec(d + 1, 10 * n + add, array)
array = []
for i in range(1, 10):
rec(1, i, array)
s_array = sorted(array)
ans = s_array[k - 1]
print(ans) | #!/usr/bin/env python3
from heapq import *
a = [*range(1, 10)]
heapify(a)
i = 0
k = int(input())
c = 0
while True:
t = str(heappop(a))
i += 1
if i == k:
break
if t[-1] != "0":
heappush(a, int(t + str(int(t[-1]) - 1)))
heappush(a, int(t + t[-1]))
if t[-1] != "9":
heappush(a, int(t + str(int(t[-1]) + 1)))
print(t)
| 1 | 39,776,391,850,958 | null | 181 | 181 |
h, w, k, = map(int, input().split())
c = [0] * h
for i in range(h):
c[i] = input()
y = 0
for i in range(2 ** (h + w)):
x = 0
a = [0] * (h + w)
for j in range(h + w):
if (i // (2 ** j)) % 2 == 1:
a[j] = 1
for j in range(h):
if a[j] == 0:
for l in range(w):
if a[h+l] == 0:
if c[j][l] == '#':
x += 1
if x == k:
y += 1
print(y) | h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h):
for paint_w in range(2**w):
cnt=0
for i in range(h):
for j in range(w):
if (paint_h>>i)&1==0 and (paint_w>>j)&1==0:
if board[i][j]=='#':
cnt+=1
if cnt==k:
ans+=1
print(ans) | 1 | 8,975,292,554,228 | null | 110 | 110 |
import sys
sys.setrecursionlimit(100000)
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
h, w, k = input_int_list()
num = 0
grid = []
for _ in range(h):
grid.append(list(input()))
# 分割統治法
def solver(x_b, y_b, x_e, y_e): # x_end,y_endは包含/排他範囲
# いちごの数を数える
cnt = 0
first = None
second = None
for i in range(x_b, x_e):
for j in range(y_b, y_e):
if grid[i][j] == "#":
cnt += 1
if not first:
first = [i, j]
elif not second:
second = [i, j]
if cnt == 1:
nonlocal num
num += 1
for i in range(x_b, x_e):
for j in range(y_b, y_e):
grid[i][j] = num
return
# いちごが少なくとも1つ含まれるように分割する
if cnt > 1:
if first[0] != second[0]:
x_edge = max(first[0], second[0])
solver(x_b, y_b, x_edge, y_e)
solver(x_edge, y_b, x_e, y_e)
elif first[1] != second[1]:
y_edge = max(first[1], second[1])
solver(x_b, y_b, x_e, y_edge)
solver(x_b, y_edge, x_e, y_e)
solver(0, 0, h, w)
for line in grid:
print(*line)
return
if __name__ == "__main__":
main()
| while True:
m, f, r = map(int, input().strip().split())
if m == f == r == -1: break
if m == -1 or f == -1 or m + f < 30:
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50:
print('C')
elif m + f >= 30:
print('C' if r >= 50 else 'D') | 0 | null | 72,720,425,286,322 | 277 | 57 |
N, M = map(int, input().split())
H = [int(x) for x in input().split()]
adj = [0] * N
good = [1]*N
for j in range(N):
adj[j] = set()
for k in range(M):
A, B = map(int, input().split())
if H[A - 1] >= H[B - 1]:
good[B - 1] = 0
if H[A - 1] <= H[B - 1]:
good[A - 1] = 0
print(sum(good))
| n,m=map(int,input().split())
height=list(map(int,input().split()))
hoge=[1 for i in range(n)]
#print(hoge)
for i in range(m):
a,b=map(int,input().split())
#print(a,b,height[a-1],height[b-1])
if(height[a-1]>height[b-1]):
hoge[b-1]=0
elif(height[a-1]<height[b-1]):
hoge[a-1]=0
else:
hoge[a-1],hoge[b-1]=0,0
print(sum(hoge)) | 1 | 25,022,870,400,070 | null | 155 | 155 |
'''
ITP-1_6-B
????¶???????????????????????????????
???????????±?????¨?????????????????????????????????????????¨????????¨?????????52?????????????????????????????? n ???????????????????????????????????????????????????????????? n ????????????????????\?????¨??????????¶??????????????????????????????????????????°?????????????????????????????????
???????????????????????£?????????????????????????????§??????????????????52?????????????????§??????
52??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????13??????????????????????????????
???Input
?????????????????????????????£??????????????????????????° n (n ??? 52)????????????????????????
?¶??????? n ??????????????????????????????????????????????????????????????????????????????????????§???????????????????????¨??´??°??§??????
????????????????????????????????¨?????????????????????'S'???????????????'H'???????????????'C'???????????????'D'??§??¨?????????????????????
??´??°??????????????????????????????(1 ??? 13)?????¨??????????????????
???Output
?¶??????????????????????????????????1???????????????????????????????????????????????\?????¨????§?????????????????????§???????????????????????¨??´??°??§?????????????????????????????????????????\????????¨????????¨????????????
???????????????????????????????????????????????????????????????????????§???????????????????????????
????????????????????´??????????????????????°????????????????????????????
'''
# import
# ?????°??????????????????
trumpData = {
"S": list(range(1,14)),
"H": list(range(1,14)),
"C": list(range(1,14)),
"D": list(range(1,14)),
}
taroCard = int(input())
# ??????????????§??????????????????????????????????????????
for nc in range(taroCard):
(trumpDataLostMark, trumpDataLostCnt) = input().split()
index = trumpData[trumpDataLostMark].index(int(trumpDataLostCnt))
del trumpData[trumpDataLostMark][index]
# ????¶???????????????????????????????
for trumpDataMark in ['S', 'H', 'C', 'D']:
for trumpDataCnt in trumpData[trumpDataMark]:
# Output
print(trumpDataMark, trumpDataCnt) | import sys
input = lambda: sys.stdin.readline().rstrip()
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
F = sorted(list(map(int, input().split())))
def binary_search(min_n, max_n):
while max_n - min_n != 1:
tn = (min_n + max_n) // 2
if judge(tn):
max_n = tn
else:
min_n = tn
return max_n
def judge(tn):
k = 0
for i in range(N):
if A[i] * F[i] > tn:
k += A[i] - (tn // F[i])
if k > K:
return False
return True
def solve():
ans = binary_search(-1, 10**12)
print(ans)
if __name__ == '__main__':
solve()
| 0 | null | 82,579,767,703,240 | 54 | 290 |
def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
mod=10**9+7
def bp(a,n):
r=1
while(n):
if n%2:
r=r*a%mod
a=a*a%mod
n>>=1
return r
[n,k]=i2()
if n<=k:
x=1
for i in range(n-1):
x*=2*n-1-i
x%=mod
y=1
for i in range(n-1):
y*=i+1
y%=mod
print((x*bp(y,10**9+5))%mod)
else:
x=1
y=1
t=1
for i in range(k):
t*=i+1
t%=mod
y*=n-1-i
y%=mod
y*=n-i
y%=mod
c=bp(t,10**9+5)
x+=y*c*c
x%=mod
print(x) | import sys
input = sys.stdin.buffer.readline
import copy
def main():
N,K = map(int,input().split())
MOD = 10**9+7
fac = [0 for _ in range(2*10**5+1)]
fac[0],fac[1] = 1,1
inv = copy.deepcopy(fac)
invfac = copy.deepcopy(fac)
for i in range(2,2*10**5+1):
fac[i] = (fac[i-1]*i)%MOD
inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD
invfac[i] = (invfac[i-1]*inv[i])%MOD
def coef(x,y):
num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD)
return num
ans = 0
for i in range(min(N,K+1)):
a = coef(N,i)
b = coef(N-1,N-i-1)
ans += ((a*b)%MOD)
print(ans%MOD)
if __name__ == "__main__":
main() | 1 | 67,134,044,118,740 | null | 215 | 215 |
n = int(input())
print(int((n - 1) // 2)) | n,k,s = map(int, input().split())
ans = []
if s == 10**9:
for i in range(k):
ans.append(10**9)
for i in range(n-k):
ans.append(1)
else:
for i in range(k):
ans.append(s)
for i in range(n-k):
ans.append(s+1)
print(*ans) | 0 | null | 122,088,314,329,760 | 283 | 238 |
S=input()
q=int(input())
s=[]
r=[]
for i in S:
s.append(i)
t=1
for i in range(q):
qv=list(input().split())
if qv[0]=='1':
t^=1
else:
if int(qv[1])^t==0 or int(qv[1])^t==2:
r.append(qv[2])
else:
s.append(qv[2])
if t==0:
ss=s.copy()
s=[]
for j in range(len(ss)):
s.append(ss[-1-j])
ans=s
ans.extend(r)
else:
rr=r.copy()
r=[]
for j in range(len(rr)):
r.append(rr[-1-j])
ans=r
ans.extend(s)
answer=''.join(ans)
print(answer) | S = input()
Q = int(input())
lS = ''
for _ in range(Q):
query = input().split()
if query[0] == '1':
lS, S = S, lS
else:
if query[1] == '1':
lS += query[2]
else:
S += query[2]
print(lS[::-1] + S) | 1 | 57,468,394,201,970 | null | 204 | 204 |
def resolve():
N = int(input())
L = sorted(list(map(int, input().split())))
# print(L)
ans = 0
import bisect
for i in range(N):
for j in range(i+1, N):
a, b = L[i], L[j]
idx1 = bisect.bisect_left(L,b+a)
idx2 = bisect.bisect_right(L,b-a)
cnt = idx1 - idx2
if idx2 <= i <= idx1:
cnt -= 1
if idx2 <= j <= idx1:
cnt -= 1
if cnt > 0:
ans += cnt
# print("a: {} b: {} i: {} j: {} idx1: {}, idx2: {}".format(a, b, i, j, idx1, idx2))
# print(ans)
print(ans//3)
if '__main__' == __name__:
resolve() | import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(mi())
l=sorted(l)
ans=0
for i in range(a-2):
for j in range(i+1,a-1):
s=bisect.bisect_left(l,l[i]+l[j])
ans+=s-j-1
print(ans) | 1 | 172,017,252,855,370 | null | 294 | 294 |
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
k = int(input())
ans = 0
for a in range(1, k + 1):
for b in range(a, k + 1):
for c in range(b, k + 1):
d = gcd(a, b)
if len({a, b, c}) == 1:
ans += gcd(c, d)
elif len({a, b, c}) == 2:
ans += 3 * gcd(c, d)
else:
ans += 6 * gcd(c, d)
print(ans)
| n, a, b = map(int, input().split())
mod = pow(10,9)+7
bunbo = 1
bunshi = 1
ans = pow(2, n, mod)
for i in range(a):
bunshi = (bunshi*(n-i)) % mod
bunbo = (bunbo*(i+1)) % mod
ans =(ans-bunshi*pow(bunbo, -1,mod)) % mod
for i in range(a, b):
bunshi = (bunshi*(n-i)) % mod
bunbo = (bunbo*(i+1)) % mod
ans = (ans-bunshi*pow(bunbo, -1,mod)) % mod
print(ans-1) | 0 | null | 50,860,688,591,460 | 174 | 214 |
S = input()
T = input()
count = 0
for i in range(len(S)):
if S[i] != T[i]:
count += 1
else:
pass
print(count) | s = input()
t = input()
print(sum([1 for a,b in zip(list(s), list(t)) if a != b])) | 1 | 10,454,519,164,830 | null | 116 | 116 |
s = input()
k = int(input())
ans = 0
soui = 0
moji = s[0]
for i in range(1,len(s)):
if s[i] == s[i-1] and soui == 0:
ans += 1
soui = 1
elif soui == 1:
soui = 0
flag = 0
a = 0
b = 0
while s[0] == s[a] and a != len(s)-1:
a += 1
while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1:
b += 1
if s[0] == s[len(s)-1]:
flag = 1
for i in range(len(s)):
if moji != s[i]:
break
elif i == len(s)-1:
flag = 2
if flag == 1:
print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2))))
elif flag == 2:
print((k*len(s))//2)
else:
print(k*ans)
| from copy import deepcopy
s = list(input())
k = int(input())
n = len(s)
if len(list(set(s))) == 1:
print(n*k//2)
exit()
n1 = 0
n2 = 0
s1 = deepcopy(s)
s2 = deepcopy(s) + deepcopy(s)
for i in range(n-1):
if s1[i] == s1[i+1]:
s1[i+1] = "?"
n1 += 1
for i in range(2*n - 1):
if s2[i] == s2[i+1]:
s2[i+1] = "?"
n2 += 1
d = n2 - n1
ans = n1 + d*(k-1)
print(ans) | 1 | 174,985,847,075,172 | null | 296 | 296 |
a = input()
print('a' if a.islower() else 'A') | a=input()
if a in "abcdefgeijklmnopqrstuvwxyz":
print('a')
else:
print('A') | 1 | 11,383,453,999,428 | null | 119 | 119 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = n - sum(a)
print(-1 if ans < 0 else ans) | line = '#.'*150
while True:
H, W = map(int, raw_input().split())
if H == W == 0: break
for i in range(H):
print line[i%2:i%2+W]
print '' | 0 | null | 16,504,415,722,340 | 168 | 51 |
n=int(input())
a=1
ans=n
while a*a<=n:
if n%a==0:
ans=min(a+n//a-2,ans)
a+=1
print(ans) | f = open(0)
N, M, L = map(int, f.readline().split())
A = [list(map(int, f.readline().split())) for i in range(N)]
B = [list(map(int, f.readline().split())) for i in range(M)]
C = [[0]*L for i in range(N)]
for i in range(N):
for j in range(L):
C[i][j] = str(sum(A[i][k]*B[k][j] for k in range(M)))
for line in C:
print(*line)
| 0 | null | 81,722,176,539,680 | 288 | 60 |
import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, M, *A = map(int, read().split())
A.sort(reverse=True)
counter = [0] * (A[0] + 1)
for a in A:
counter[a] += 1
for i in range(A[0] - 1, -1, -1):
counter[i] += counter[i + 1]
def is_ok(x):
c = 0
for a in A:
if x - a <= A[0]:
c += counter[max(x - a, 0)]
pass
return c <= M
ok = 2 * A[0] + 1
ng = 2 * A[-1] - 1
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
x = ok
ans = 0
csum = [0]
csum.extend(accumulate(A))
for a in A:
if x - a <= A[0]:
c = counter[max(x - a, 0)]
ans += a * c + csum[c]
M -= c
ans += (x - 1) * M
print(ans)
return
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
input = sys.stdin.readline
import bisect
n, m = map(int, input().split())
a = [int(item) for item in input().split()]
a.sort()
a_rev = sorted(a, reverse=True)
cumsum = [0]
for item in a:
cumsum.append(cumsum[-1] + item)
# Use pair which sum goes over mid
l = 0; r = 10**10
while r - l > 1:
mid = (l + r) // 2
to_use = 0
for i, item in enumerate(a_rev):
useless = bisect.bisect_left(a, mid - item)
to_use += n - useless
if to_use >= m:
l = mid
else:
r = mid
ans = 0
total_use = 0
for i, item in enumerate(a_rev):
useless = bisect.bisect_left(a, l - item)
to_use = n - useless
total_use += to_use
ans += item * to_use + cumsum[n] - cumsum[n - to_use]
print(ans - l * (total_use - m)) | 1 | 108,110,648,240,868 | null | 252 | 252 |
N,K = map(int,input().split())
import numpy as np
A = np.array(input().split(),np.int64)
B = np.array(input().split(),np.int64)
A.sort() ; B.sort()
B=B[::-1]
right = max(A*B) #時間の可能集合の端点
left = -1 #時間の不可能集合の端点
def test(t):
C = A-t//B
D= np.where(C<0,0,C)
return D.sum()<=K
while left+1<right:
mid = (left+right)//2
if test(mid):
right=mid
else:
left = mid
print(right) | 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
from itertools import permutations
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()))
F = list(map(int, input().split()))
A = sorted(A)
F = sorted(F, reverse=True)
def check(x):
s = 0
for i in range(N):
s += max(0, A[i] - x // F[i])
return s <= K
l = -1
r = 10 ** 18
while r - l > 1:
m = (r + l) // 2
if check(m):
r = m
else:
l = m
print(r) | 1 | 165,126,014,384,432 | null | 290 | 290 |
S = input()
if(S == 'RRR'):
print(3)
elif(S=='RRS' or S=='SRR'):
print(2)
elif(S == 'SSS'):
print(0)
else:
print(1) | import itertools
n=int(input())
l=[int(i) for i in range(n)]
ans=chk=p=0
w=[]
for i in range(n):
x,y=map(int,input().split())
w.append((x,y))
for i in list(itertools.permutations(l,n)):
chk=0
for j in range(n-1):
chk+=((w[i[j]][0]-w[i[j+1]][0])**2+(w[i[j]][1]-w[i[j+1]][1])**2)**0.5
ans+=chk
p+=1
print(ans/p) | 0 | null | 76,689,395,208,228 | 90 | 280 |
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()
| def bfs(x0, y0, maze, dis):
from collections import deque
max_x = len(maze[0])
max_y = len(maze)
dis[y0][x0] = 0
dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]
q = deque()
q.append([x0, y0, dis[y0][x0]])
while len(q) > 0:
x, y, d = q.popleft()
for dx, dy in dxy:
nx = x + dx
ny = y + dy
if 0 > nx or max_x <= nx or 0 > ny or max_y <= ny:
continue
if maze[ny][nx] == "#":
continue
if dis[ny][nx] != -1:
continue
dis[ny][nx] = d + 1
q.append([nx, ny, dis[ny][nx]])
return
h, w = map(int, input().split())
s = [[] for _ in range(h)]
for i in range(h):
s[i] = input()
ans = 0
for i in range(h):
for j in range(w):
dis = [[-1] * w for _ in range(h)]
if s[i][j] != "#":
bfs(j, i, s, dis)
d = 0
for k in range(h):
for l in range(w):
d = max(d, dis[k][l])
ans = max(ans, d)
print(ans) | 0 | null | 47,956,933,953,240 | 57 | 241 |
import math
A,B,C,D = list(map(int,input().split()))
if (math.ceil(C/B)-math.ceil(A/D))<1:
print("Yes")
else:
print("No")
| X=int(input())
a=100
cnt=0
while a<X:
a=a+a//100
cnt+=1
print(cnt) | 0 | null | 28,489,246,265,230 | 164 | 159 |
n, m, k = map(int, input().split())
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n-r)
return fact[n] *factinv[r]* factinv[n-r] %p
p = 998244353
N = 2 * 10**5 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
y = [0,m]
for i in range(n):
y.append((y[-1]*(m-1))%p)
r = 0
for i in range(k+1):
r = (r + y[n-i]*cmb(n-1, i, p))%p
print(r) | # https://kmjp.hatenablog.jp/entry/2020/05/10/0900
# 数学的な問題
mod = 998244353
class COM:
def __init__(self, n, MOD):
self.n = n
self.MOD = MOD
self.fac = [0] * (n+1)
self.finv = [0] * (n+1)
self.inv = [0] * (n+1)
self.fac[0] = self.fac[1] = 1
self.finv[0] = self.finv[1] = 1
self.inv[1] = 1
for i in range(2, n+1):
self.fac[i] = self.fac[i-1] * i % MOD
self.inv[i] = MOD - self.inv[MOD % i] * (MOD // i) % MOD
self.finv[i] = self.finv[i-1] * self.inv[i] % MOD
def calc(self, k):
if k < 0:
return 0
return self.fac[self.n] * (self.finv[k] * self.finv[self.n-k] % self.MOD) % self.MOD
def main():
N, M, K = map(int,input().split())
# 隣り合う組がK以下のパターンを総当たりして解く
if N > 1:
cmbclass = COM(N-1, mod)
cmb = cmbclass.calc
else:
cmb = lambda x:1
res = 0
for i in range(K+1):
res += M * cmb(i) % mod * pow(M-1, N-i-1, mod)
print(res % mod)
if __name__ == "__main__":
main()
| 1 | 23,389,536,402,584 | null | 151 | 151 |
a,*b=[],
for z in[*open(0)][1:]:x,y=map(int,z.split());a+=x+y,;b+=x-y,
print(max(max(a)-min(a),max(b)-min(b))) | n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
a1=float('inf')
a2=-float('inf')
a3=float('inf')
a4=-float('inf')
for i in range(n):
cnt=a[i][0]+a[i][1]
cnt1=a[i][0]-a[i][1]
a1=min(a1,cnt)
a2=max(a2,cnt)
a3=min(cnt1,a3)
a4=max(cnt1,a4)
print(max(a2-a1,a4-a3)) | 1 | 3,439,670,458,370 | null | 80 | 80 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def resolve():
class BinaryIndexedTree():
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
def add(self, item, pos):
index = pos
while index < self.n+1:
self.bit[index] += item
index += index & (-index)
def sum(self, pos):
ret = 0
index = pos
while index > 0:
ret += self.bit[index]
index -= index & -index
return ret
N = int(input())
S = list(input())
Q = int(input())
Query = [input().split() for _ in range(Q)]
pos_bit_list = [BinaryIndexedTree(len(S)) for _ in range(26)]
for i, c in enumerate(S):
pos_bit_list[ord(c)-ord('a')].add(1, i+1)
for q in Query:
if q[0] == '1':
pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
S[int(q[1])-1] = q[2]
else:
print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0]))
if __name__ == '__main__':
resolve()
| mod=998244353
n,k=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(k)]
DP=[0 for _ in range(n+1)]
SDP=[0 for _ in range(n+1)]
DP[1]=1
SDP[1]=1
for i in range(2,n+1):
for l,r in LR:
DP[i] +=(SDP[max(i-l,0)]-SDP[max(i-r,1)-1])%mod
DP[i] %=mod
SDP[i]=(SDP[i-1]+DP[i])%mod
print(DP[n]) | 0 | null | 32,558,563,618,112 | 210 | 74 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
dx = [-1,0,1,0]
dy = [0,-1,0,1]
h,w = readInts()
S = [list(input()) for _ in range(h)]
def bfs(y,x):
dq = deque()
dq.append((y,x))
res = -1
dist = [[-1] * w for _ in range(h)]
dist[y][x] = 0
while dq:
y,x = dq.popleft()
res = max(res,dist[y][x])
for i in range(4):
ny = y + dy[i]
nx = x + dx[i]
if not(0 <= ny < h and 0 <= nx < w):
continue
if S[ny][nx] == '#' or dist[ny][nx] != -1:
continue
dist[ny][nx] = dist[y][x] + 1
dq.append((ny,nx))
return res
ans = -1
for y in range(h):
for x in range(w):
if S[y][x] != '#':
ans = max(ans,bfs(y,x))
print(ans)
| import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7
H,W = I()
maze = [list(s()) for _ in range(H)]
ans = 0
for i in range(H):
for j in range(W):
if maze[i][j] == '#':
continue
dist = [[-1]*W for _ in range(H)]
dist[i][j] = 0
que = deque([[i,j]])
while que:
h,w = que.pop()
for dh,dw in [[1,0],[0,1],[-1,0],[0,-1]]:
nh = h+dh
nw = w+dw
if nh < 0 or nw < 0 or nh >= H or nw >= W:
continue
if maze[nh][nw] == '#':
continue
if dist[nh][nw] == -1:
dist[nh][nw] = dist[h][w]+1
que.appendleft([nh,nw])
ans = max(ans,max([max(d) for d in dist]))
print(ans)
| 1 | 95,005,682,727,086 | null | 241 | 241 |
import sys,math
n=0
max_v=-math.pow(10,10)
s=math.pow(10,10)
for line in sys.stdin:
l=int(line)
if n == 0:
n=l
continue
diff=l-s
if diff>max_v:
max_v=diff
if diff<0:
s=l
print max_v | n = int(raw_input())
maxprofit = -2 * 10 ** 9
minval = int(raw_input())
for _ in xrange(n-1):
R = int(raw_input())
maxprofit = max(maxprofit, R-minval)
minval = min(minval, R)
print maxprofit | 1 | 12,685,143,630 | null | 13 | 13 |
N = int(input())
A = list(map(int, input().split()))
flag = True
for i in range(N):
if A[i]%2 == 0:
if A[i]%3!=0 and A[i]%5!=0:
flag = False
if flag:
print("APPROVED")
else:
print("DENIED") | import sys
def solve(a_list):
for a in a_list:
if a % 2 == 0:
if a % 3 != 0 and a % 5 != 0:
return False
return True
def main():
input = sys.stdin.buffer.readline
_ = int(input())
a_list = list(map(int, input().split()))
print("APPROVED" if solve(a_list) else "DENIED")
if __name__ == "__main__":
main()
| 1 | 69,135,861,364,272 | null | 217 | 217 |
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)
mod = 998244353
N, K = rl()
lr = []
for i in range(K):
l, r = rl()
lr.append((l,r))
lr.sort()
dp = [0] * (N+1)
dp[1] = 1
dp[2] = -1
ans = 0
s = 0
flags = [1] * K
for i in range(1, N+1):
s += dp[i]
s %= mod
for k in range(K):
if flags[k] == 0:
break
l, r = lr[k]
if i+l <= N:
dp[i+l] += s
if i+r+1 <= N:
dp[i+r+1] -= s
else:
ans += s
ans %= mod
break
else:
flags[k] = 0
break
print(ans)
| import numpy as np
T=[]
T=list(input())
values = np.array(T)
searchval = '?'
ii = np.where(values == searchval)[0]
if len(ii)>0:
for k in ii:
if k==0:
if len(T)>1:
if T[k+1]=='D':
T[k]='P'
else:
T[k]='D'
else:
T[k] = 'D'
else:
if T[k-1] == 'P':
T[k] = 'D'
else:
if k+1<len(T):
if T[k+1] == 'D':
T[k] = 'P'
else:
T[k]='D'
else:
T[k] = 'D'
newT=''.join(map(str,T))
print(newT) | 0 | null | 10,468,501,280,328 | 74 | 140 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
H,N=MI()
A=[0]*N
B=[0]*N
for i in range(N):
A[i],B[i]=MI()
inf =10**20
dp=[[inf]*(H+1)for _ in range(N+1)]
# dp[i]はi番目の魔法まででhpをj減らす方法
dp[0][0]=0
for i in range(N):
a=A[i]
b=B[i]
for j in range(H+1):
if j-a>=0:
dp[i+1][j]=min(dp[i+1][j],
dp[i][j],
dp[i+1][j-a]+b)
else:
dp[i+1][j]=min(dp[i+1][j],
dp[i][j],
dp[i+1][0]+b)
print(dp[-1][-1])
main()
| n = int(input())
s = input()
if n % 2 == 1:
print('No')
else:
sa = s[:n//2]
sb = s[n//2:]
if sa == sb:
print('Yes')
else:
print('No') | 0 | null | 114,001,208,241,250 | 229 | 279 |
n, m = map(int, input().split())
h = list(map(int, input().split()))
d = [1] * n
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
if h[a] > h[b]:
d[b] = 0
elif h[b] > h[a]:
d[a] = 0
else:
d[a] = 0
d[b] = 0
print(sum(d)) | def gcd(x,y):
while y>0:
x,y = y,x%y
return x
K = int(input())
cnt = 0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
x = a
x = gcd(x,b)
x = gcd(x,c)
cnt += x
print(cnt) | 0 | null | 30,439,145,382,252 | 155 | 174 |
X,N = map(int,input().split())
p = list(map(int,input().split()))
diff = 1
if(X not in p):
print(X)
exit()
while(diff < 200):
if(X-diff not in p):
print(X-diff)
exit()
elif(X+diff not in p):
print(X+diff)
exit()
diff += 1 | floor = [[[0] * 10 for x in range(3)] for y in range(4)]
for c in range(int(input())):
(b,f,r,v) = [int(x) for x in input().split()]
floor[b-1][f-1][r-1] += v
for x in range(3 * 4):
if x % 3 == 0 and not x == 0:
print('#' * 20)
print('',' '.join(str(y) for y in floor[int(x / 3)][x % 3])) | 0 | null | 7,608,457,087,882 | 128 | 55 |
# coding: UTF-8
line = str(raw_input()*2)
word = str(raw_input())
if line.count(word):
print "Yes"
else: print "No"
| N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (100001)
ans = sum(A)
for a in A:
cnt[a] += 1
Q = int(input())
for _ in range(Q):
B, C = map(int, input().split())
cnt[C] += cnt[B]
ans += cnt[B] * (C-B)
cnt[B] = 0
print(ans) | 0 | null | 6,910,088,341,322 | 64 | 122 |
import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
def input():
return sys.stdin.readline()[:-1]
def dfs(v,prev = -1):
for u in graph[v]:
if u == prev:
continue
sign[u] = v
dfs(u,v)
def bfs(v):
que = deque([])
que.append(v)
while que:
p = que.popleft()
if visited[p] == 0:
visited[p] = 1
for u in graph[v]:
que.append(u)
import heapq
def dijkstra(s):
hq = [(0, s)]
heapq.heapify(hq) # リストを優先度付きキューに変換
cost = [float('inf')] * (N+1) # 行ったことのないところはinf
cost[s] = 0 # 開始地点は0
while hq:
c, v = heapq.heappop(hq)
if c > cost[v]: # コストが現在のコストよりも高ければスルー
continue
for u in graph[v]:
tmp = 1 + cost[v]
if tmp < cost[u]:
cost[u] = tmp
path[u] = v
heapq.heappush(hq, (tmp, u))
return path
N,M = map(int,input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
a,b = map(int,input().split())
graph[a].append(b)
graph[b].append(a)
path = [0]*(N+1)
c = dijkstra(1)
print("Yes")
for i in range(2,N+1):
print(c[i])
| n=int(input())
for i in range(1,361):
if (n*i)%360==0:
print(i);exit() | 0 | null | 16,749,390,741,710 | 145 | 125 |
n = int(input())
s = input()
print(sum([1 for i in range(n-2) if s[i:i+3] == 'ABC'])) | N = int(input())
s = list(input())
cnt = 0
for i in range(N-2):
if s[i] == 'A':
if s[i+1] == 'B':
if s[i+2] == 'C':
cnt += 1
print(cnt) | 1 | 99,461,089,761,696 | null | 245 | 245 |
n,k = map(int,input().split())
res = n*500
if res >= k:
print("Yes")
else:
print("No") | K,X=input().split()
K=int(K)
X=int(X)
if 500*K>=X:
print('Yes')
else:
print('No') | 1 | 98,224,681,405,500 | null | 244 | 244 |
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
def nibu(x,n,r):
ll = 1
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if cou(x,mid) <= n:
rr = mid
else:
ll = mid+1
def cou(x,le):
co = 0
for i in range(len(x)):
if le != 0:
co += -(-x[i]//le) - 1
return co
n,k = m()
a = l()
left = 0
right = 10**9
aaa = nibu(a,k,right)
print(aaa)
| s = input()
x = ""
y = ""
Q = int(input())
rev = 0
for i in range(Q):
q = list(input().split())
if q[0] == "2":
q[1] = int(q[1])
q[1] -= 1
if rev:
q[1] = 1 - q[1]
if q[1] == 0:
x += q[2]
else:
y += q[2]
else:
rev = 1 - rev
x = x[::-1]
ans = x + s + y
if rev:
ans = ans[::-1]
print(ans) | 0 | null | 31,955,526,573,660 | 99 | 204 |
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions
def main():
a,b = map(int, input().split())
print(a*b//fractions.gcd(a, b))
if __name__ == '__main__':
main()
| def solve():
from math import gcd
n, k = map(int, input().split())
print(n * k // gcd(n, k))
solve()
| 1 | 113,264,254,175,072 | null | 256 | 256 |
a = []
while True:
b = list(map(int,input().split()))
if b[0] == 0 and b[1]==0:
break
b.sort()
a.append(b)
for i in a:
print(i[0],i[1]) | while(1):
x,y = map(int, raw_input().split())
if x == 0 and y == 0:
break;
if x > y:
temp = x
x = y
y = temp
print x, y | 1 | 513,210,033,998 | null | 43 | 43 |
X = int(input())
if 30 <= X:
print('Yes')
else:
print('No') | n = int(input())
if 30 <= n:
print("Yes")
else:
print("No") | 1 | 5,698,242,870,762 | null | 95 | 95 |
a,b = input().split()
a=int(a);b=int(b)
if a>b:
s = 'a > b'
elif a<b:
s = 'a < b'
else:
s = 'a == b'
print(s) | n =raw_input()
m =n.split(" ")
a = int(m[0])
b = int(m[1])
if a < b :print "a < b"
if a > b :print "a > b"
if a == b :print "a == b" | 1 | 358,740,640,972 | null | 38 | 38 |
N, M, X = map(int,input().split())
CA = list(list(map(int,input().split())) for _ in range(N))
cost = (10 ** 5) * 12
for i in range(2 ** N):
total, a = 0, [0] * M
for j in range(N):
if i >> j & 1:
total += CA[j][0]
for k in range(M): a[k] += CA[j][k + 1]
for j in range(M):
if a[j] < X:
if i == 2 ** N - 1: cost = -1
break
else: cost = min(cost, total)
print(cost) | #!/usr/bin/env python3
N = int(input().split()[0])
a_list = list(map(int, input().split()))
before_a = 0
total = 0
for i, a in enumerate(a_list):
if i == 0:
before_a = a
continue
total += max(before_a - a, 0)
before_a = a + max(before_a - a, 0)
ans = total
print(ans)
| 0 | null | 13,382,890,136,318 | 149 | 88 |
x = int(input())
import math
def check(n):
if n == 1: return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
n = x
while check(n) == False:
n += 1
print(n)
| X = int(input())
for i in range(X, 9999999999999999):
flag = 1
for j in range(2, X//2 +1):
if i % j == 0:
flag = -1
break
if X == 2:
print(2)
break
elif X == 3:
print(3)
break
elif flag == 1:
print(i)
break | 1 | 105,731,026,295,518 | null | 250 | 250 |
x = int(input())
x_ = divmod(x, 100)
if 5*x_[0] >= x_[1]:
print(1)
else:
print(0) | def make_divisors(n):
'''
nの約数の配列を返す
'''
lower_divisors, upper_divisors = [], []
i = 1
while i * i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n // i)
i += 1
return lower_divisors + upper_divisors[::-1]
def solve():
N = int(input())
D = make_divisors(N)
ans = N - 1
for d in D:
ans = min(ans, N // d - 1 + d - 1)
print(ans)
if __name__ == "__main__":
solve()
| 0 | null | 144,155,884,017,978 | 266 | 288 |
X = int(input())
K = 1
d = X
while d % 360 != 0:
d += X
K += 1
print(K)
| N = int(input())
for i in range(N):
a, b, c = map(int, input().split())
a2 = a ** 2
b2 = b ** 2
c2 = c ** 2
if a2 + b2 == c2 or a2 + c2 == b2 or b2 + c2 == a2:
print('YES')
else:
print('NO') | 0 | null | 6,606,676,708,686 | 125 | 4 |
import math
def average(l):
return sum(l) / len(l)
def var(l):
a = average(l)
return sum(map(lambda x: (x-a)**2, l)) / len(l)
def std(l):
return math.sqrt(var(l))
if __name__ == '__main__':
while True:
n = int(input())
if n == 0:
break
l = [int(i) for i in input().split()]
print("{0:.5f}".format(std(l))) | import math
while 1:
n = int(input())
if n == 0:
break
s = list(map(int,input().split()))
m = sum(s) / len(s)
x = 0
for i in range(n):
x += (s[i] -m )**2 / n
a = math.sqrt(x)
print(a) | 1 | 193,100,608,668 | null | 31 | 31 |
K = int(input())
S = input()
if len(S) >K:
S = S[:K] + '...'
print(S) | #coding: utf-8
def GCM(m, n):
while 1:
if n == 0: return m
m -= (m/n)*n
m,n = n,m
while 1:
try:
a,b = map(int, raw_input().split())
x = GCM(a,b)
y = a*b / x
print "%d %d" % (x, y)
except EOFError:
break | 0 | null | 9,879,160,694,080 | 143 | 5 |
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def read_values():
return map(int, input().split())
def read_index():
return map(lambda x: x - 1, map(int, input().split()))
def read_list():
return list(read_values())
def read_lists(N):
return [read_list() for n in range(N)]
def functional(N, mod):
F = [1] * (N + 1)
for i in range(N):
F[i + 1] = (i + 1) * F[i] % mod
return F
INV = dict()
def inv(a, mod):
if a in INV:
return INV[a]
i = pow(a, mod - 2, mod)
INV[a] = i
return i
def C(F, a, b, mod):
return F[a] * inv(F[a - b], mod) * inv(F[b], mod) % mod
def main():
N, K = read_values()
mod = 10 ** 9 + 7
F = functional(5 * 10 ** 5, mod)
res = 0
if N <= K:
res = C(F, 2 * N - 1, N - 1, mod)
else:
for k in range(K + 1):
res += C(F, N, k, mod) * C(F, N - 1 , k, mod) % mod
print(res % mod)
if __name__ == "__main__":
main() | import copy
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
count = 0
for i in range(len(a)-1):
count += a[(i+1)//2]
print(count) | 0 | null | 37,909,385,185,980 | 215 | 111 |
n,k= map(int, input().split())
p= list(map(int, input().split()))
c= list(map(int, input().split()))
ans=-float('inf')
x=[0]*n
for i in range(n):
if x[i]==0:
x[i]=1
y=p[i]-1
# 累積和を格納
aa=[0,c[i]]
# 2周させる
life=2
for j in range(2*n+2):
x[y]=1
if life>0:
aa.append(aa[-1]+c[y])
y=p[y]-1
if y==i:
life-=1
else:
break
# 各回数での取れるスコアの最大値
x1=(len(aa)-1)//2
a=[-float('inf')]*(x1+1)
for ii in range(len(aa)-1):
for j in range(ii+1,len(aa)):
if j-ii<=x1:
a[j - ii] = max(a[j - ii], aa[j] - aa[ii])
v=k//x1
w=k%x1
if v==0:
ans=max(ans,max(a[:k+1]))
elif v==1:
ans = max(ans, max(a), v * aa[x1] + max(a[:w + 1]))
else:
ans=max(ans,max(a),v * aa[x1] + max(a[:w + 1]),(v-1)*aa[x1]+max(a))
print(ans) | def fibonacci(n, memo=None):
if memo==None:
memo = [None]*n
if n<=1:
return 1
else:
if memo[n-2]==None:
memo[n-2] = fibonacci(n-2, memo)
if memo[n-1]==None:
memo[n-1] = fibonacci(n-1, memo)
return memo[n-1] + memo[n-2]
n = int(input())
print(fibonacci(n)) | 0 | null | 2,661,181,015,742 | 93 | 7 |
from collections import namedtuple
Task = namedtuple('Task', 'name time')
class Queue:
def __init__(self, n):
self.n = n
self._l = [None for _ in range(self.n + 1)]
self._head = 0
self._tail = 0
def enqueue(self, x):
self._l[self._tail] = x
self._tail += 1
if self._tail > self.n:
self._tail -= self.n
def dequeue(self):
if self.isEmpty():
raise IndexError("pop from empty queue")
else:
e = self._l[self._head]
self._l[self._head] = None
self._head += 1
if self._head > self.n:
self._head -= self.n
return e
def isEmpty(self):
return self._head == self._tail
def isFull(self):
return self._tail == self.n
if __name__ == '__main__':
n, q = map(int, input().split())
queue = Queue(n+1)
for _ in range(n):
name, time = input().split()
time = int(time)
queue.enqueue(Task(name=name, time=time))
now = 0
while not queue.isEmpty():
task = queue.dequeue()
t = task.time
if t <= q:
now += t
print(task.name, now)
else:
now += q
queue.enqueue(Task(task.name, t - q))
| n = int(input())
A = list(map(int, input().split()))
cumsum = [[0 for j in range(2)] for i in range(60)]
ans = [0] * 60
#print(cumsum)
for i in range(len(A) - 1, -1, -1):
plus_num = A[i]
bit_num = format(plus_num, "060b")
#print(bit_num)
for i, bit in enumerate(bit_num):
bit = int(bit)
if bit == 0:
ans[i] += cumsum[i][1]
else:
ans[i] += cumsum[i][0]
cumsum[i][bit] += 1
#print(ans)
#print(cumsum)
ans_num = 0
mod = 10**9 + 7
for i, cnt in enumerate(ans):
ans_num += 2**(59-i) * cnt
ans_num %= mod
print(ans_num)
| 0 | null | 61,674,674,099,482 | 19 | 263 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.