text
stringlengths
37
1.41M
while True: oddline = '' evenline = '' h, w = map(int, raw_input().split()) if h+w==0: break for y in xrange(w): if y%2==0: oddline += '#' evenline += '.' else: oddline += '.' evenline += '#' for x in xrange(h): if x...
from collections import defaultdict N = input() dic = defaultdict(int) for s in N: dic[s] += 1 if dic[s] > 1: print('no') exit() print('yes')
# -*- coding: utf-8 -*- def main(): h,w = map(int, input().split()) if h == 1 or w == 1: print(1) return if h*w %2 == 0: print(int(h*w/2)) else: print(int((h*w+1)/2)) return if __name__ == '__main__': main()
while True : H, W = [int(temp) for temp in input().split()] if H == W == 0 : break for making in range(H): print('#' * W) print()
# coding: utf-8 import math x1,y1,x2,y2 = input().split() X = float(x2) - float(x1) Y = float(y2) - float(y1) length = math.sqrt( X**2 + Y**2 ) print(length)
N = int(input()) C1 = list(input().split()) C2 = C1[:] def get_card_suit(card): return card[:1] def get_card_value(card): return card[1:] def bubble_sort(card): r_exists = True while r_exists == True: r_exists = False i = N - 1 while i >= 1: if get_card_value...
def resolve(): A = [list(map(int, input().split())) for _ in range(3)] N = int(input()) B = [int(input()) for _ in range(N)] for b in B: for i in range(3): for j in range(3): if A[i][j] == b: A[i][j] = None break for i in ra...
S = input() mydict = {"A":"T","T":"A","G":"C","C":"G"} print(mydict[S])
def main(): a = int(input()) b = int(input()) h = int(input()) square = a * h triangle = ((b - a) * h) //2 print(square + triangle) main()
import math from functools import reduce def lcm_base(x, y): return (x * y) // math.gcd(x, y) def lcm(numbers): return reduce(lcm_base, numbers, 1) def solve(): N, M = [int(x) for x in input().split()] S = input() T = input() L = lcm([N, M]) ic, jc = 0, 0 i, j = ic * L // N + 1, j...
def lcm(x, y): if x > y: greater = x else: greater = y while(True): if((greater % x == 0) and (greater % y == 0)): lcm = greater break greater += 1 return lcm x = int(input()) if 360%x == 0: print(int(360/x)) else : print(int(lcm(360,x)/x))
def gcd (a,b): if a%b==0: return b if b%a==0: return a if a>b: return gcd(b,a%b) return gcd(a,b%a) def lcm (a,b): return ((a*b)//gcd(a,b)) inp=list(map(int,input().split())) a=inp[0] b=inp[1] print (lcm(a,b))
while True: num = raw_input() if num == "0": break output = 0 for i in num: output += int(i) print output
import sys input = sys.stdin.readline from collections import * S = input()[:-1] if S=='Sunny': print('Cloudy') elif S=='Cloudy': print('Rainy') else: print('Sunny')
n = input() for i in range(n): a, b, c = map(int, raw_input().strip().split(' ')) if a*a+b*b == c*c or a*a+c*c == b*b or c*c+b*b == a*a: print "YES" else: print "NO"
from collections import Counter def main(): MOD = 10**9 + 7 N = int(input()) counter = Counter(input()) ans = 1 for c in counter.values(): ans *= c + 1 ans %= MOD print(ans - 1) if __name__ == '__main__': main()
s = input() a = s.find("C") b = s.rfind("F") if -1 < a < b: print("Yes") else: print("No")
n=input() if n[1:]=='9'*(len(n)-1): print(9*(len(n)-1)+int(n[0])) else: print(9*(len(n)-1)+int(n[0])-1)
x,y = map(int,input().split()) if x%y==0:print(-1) else:print(x*3 if (x*2)%y==0 else x*2)
import math A, B, N = map(int,input().split(' ')) def f(x): return math.floor(A*x/B)-A*math.floor(x/B) def main(): if N >= B: print(f(B-1)) else: print(f(N)) if __name__ == "__main__": main()
S = str(input()) A = "es" B = "s" if S[-1] == B: print(S+A) else: print(S+B)
N = int(input()) A_lst = [int(n) for n in input().split()] odd = 0 even = 0 for A in A_lst: if A%2 == 0: even += 1 else: odd += 1 print('YES') if odd%2 == 0 else print('NO')
import sys input = sys.stdin.readline def main(): A = {1, 3, 5, 7, 8, 10, 12} B = {4, 6, 9, 11} C = {2} xy = set(map(int, input().split())) if xy <= A or xy <= B or xy <= C: print('Yes') else: print('No') if __name__ == "__main__": main()
N = int(input()) v = list(map(int,input().split())) v = sorted(v, reverse = False) def average(x,y): XY = (x + y) / 2 return XY gen = v[0] for i in range(1,N): gen = average(gen ,v[i]) print(gen)
from sys import stdin def main(): #入力 readline=stdin.readline s=readline().strip() if s=="Sunny": print("Cloudy") elif s=="Cloudy": print("Rainy") else: print("Sunny") if __name__=="__main__": main()
from math import gcd from functools import reduce def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm(*numbers): return reduce(lcm_base, numbers, 1) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) ...
#!/usr/bin/env python3 import sys def f(B, d): ''' >>> f(6, 0) # 1, 3, 5 3 >>> f(6, 1) # 2, 3, 6 3 >>> f(6, 2) # 4, 5, 6 3 >>> f(6, 3) 0 ''' r = 2**(d+1) rr = 2 ** d return B // r * rr + max(B % r - rr + 1, 0) def g(A, B, d): ''' >>> g(0, 6, 0) # 1, 3, ...
x = int(input()) ans = x // 11 * 2 mod = x % 11 if mod != 0: if mod > 6: ans += 2 else: ans += 1 print(ans)
S = str(input()) s_between_len = len(S) - 2 a = S[:1] + str(s_between_len) + S[-1] print(a)
import re _S = input().replace('?', '_')[::-1] T = input()[::-1] pattern = '' for c in T: pattern += '[_' + c + ']' match = re.search(pattern, _S) if not match: print('UNRESTORABLE') else: S = _S[:match.start()] + T + _S[match.end():] S = S.replace('_', 'a') print(S[::-1])
import math class coordinate: def __init__(self, x, y): self.x = x self.y = y def koch(n, p1, p2): if n == 0: return str(p2.x) + " " + str(p2.y) else: s = coordinate((2*p1.x + p2.x)/3, (2*p1.y + p2.y)/3) t = coordinate((p1.x + 2*p2.x)/3, (p1.y + 2*p2.y)/3)...
if __name__ == "__main__": nums =map( int, raw_input().split()) if nums[0] < nums[1] : print "a < b" elif nums[0] > nums[1] : print "a > b" else: print "a == b"
from math import sqrt a, b = input().split() n = int(a+b) print('Yes' if sqrt(n) == int(sqrt(n)) else 'No')
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def ngram(numbers,n): return list([numbers[i:i+n] for i in range(len(numbers)-2)]) def main(): numbers=[] n,m = map(int,input().split()) [numbers.append(int(input())) for _ in range(n)] numbers.sort() print(min(numbers[i+m-1] - numbers[i]...
X =int(input()) Now_Rate = 100 Counter = 0 while Now_Rate < X: Now_Rate += Now_Rate//100 Counter += 1 print(Counter)
ins = input() pat = input() arr = ins + ins if arr.find(pat) != -1: print("Yes") else: print("No")
s = input().split() h = int(s[0]) w = int(s[1]) strings = [] for i in range(h): p = input() strings.append(p) for i in range(w + 2): print('#', end='') print('') for i in range(h): print('#', end='') print(strings[i], end='') print('#') for i in range(w + 2): print('#', end='') ...
import math S=str(input()) s = "" for i in range(math.ceil(len(S)/2)): s = s + S[2*i] print(s)
N = int(input()) T = [int(input()) for _ in range(N)] def gcd(a, b): if b == 0: return a return gcd(b, a % b) lcm = 1 for t in T: lcm *= t // gcd(t, lcm) print(lcm)
S=input() if all(a!="L" for a in S[::2]) and all(a!="R" for a in S[1::2]): print("Yes") else: print("No")
while True: a = input().split(' ') if a[0] == '-1' and a[1] == '-1' and a[2] == '-1': break elif int(a[0]) == -1 or int(a[1]) == -1: print('F') elif int(a[0]) + int(a[1]) >= 80: print('A') elif 65 <= int(a[0]) + int(a[1]) < 80: print('B') elif 50 <= int(a[0]) + in...
def main(): N = [x for x in input().split(' ')] #データを格納するための整数型1次元配列 stack = [] for i in N: # +が入っていた場合 if i == '+': num1 = stack.pop() num2 = stack.pop() stack.append(num1 + num2) # -が入っていた場合 elif i == '-': num2 = stack.pop...
abclist=list(map(int,input().split())) abclist.sort() A,B,C=abclist if A==B: print(C) else: print(A)
import sys def insertionSort( nums, n, g ): cnt = 0 i = g while i < n: v = nums[i] j = i - g while 0 <= j and v < nums[j]: nums[ j+g ] = nums[j] j -= g cnt += 1 nums[ j+g ] = v i += 1 return cnt def shellSort( nums, n ): g = [] val = 1 while val <= n: g.append( val ) val = 3*val+1 g...
N = int(input()) lst = [] for i in range(N): s, p = input().split() lst.append([s, int(p), i+1]) lst = sorted(lst, key = lambda x: x[1], reverse=True) lst = sorted(lst, key = lambda x: x[0]) for j in range(N): print(lst[j][2], end=" ")
print("NO" if input().count("x") > 7 else "YES")
import math n = int(input()) n += 1 ans = 0 for i in range(1, n): for j in range(1, n): for k in range(1, n): ans += math.gcd(i, math.gcd(j, k)) print(ans)
S = input() T = input() ins = -1#挿入場所(できるだけうしろにして前はAでつめる) for i in range(0,len(S)-len(T)+1,1): isOk = True for j in range(i,i+len(T),1): if not(T[j-i]==S[j] or S[j]=="?"): isOk = False break if isOk: ins = i if ins == -1: print("UNRESTORABLE") ...
class Trio: __pre=None __val=None __nex=None def __init__(self,val,p=None,n=None): self.__pre=p self.__val=val self.__nex=n def get_pre(self):return self.__pre def get_nex(self):return self.__nex def set_nex(self,n):self.__nex=n def set_val(sel...
import math a, b = input().split() n1 = int(a + b) n2 = int(math.sqrt(n1)) ** 2 print('Yes') if n1 == n2 else print('No')
def is_prime(n):# O(logn) if n == 2: return 1 elif n == 1 or n % 2 == 0: return 0 for i in range(3, int(n ** .5) + 1, 2): if n % i == 0: return 0 return 1 X = int(input()) while True: if is_prime(X): print(X) exit() X += 1
a,b = input().split(" ") count = 0 sum = 1 while sum < int(b): sum = sum + int(a) -1 count += 1 print(count)
from decimal import Decimal p=3.141592653589 r=float(raw_input()) print Decimal(r*r*p),Decimal(r*2*p)
NUM = list(map(int,input().split())) if(NUM[0] > NUM[1]): print("safe") elif(NUM[0] <= NUM[1]): print("unsafe")
X = int(input()) acc = 0 # X > 0 なのでマイナス方向にジャンプする選択肢は選ばない for i in range(X + 1): acc += i if X <= acc: ans = i break print(i)
#162B #FizzBuzz Sum n=int(input()) print(sum(x for x in range(1,n+1) if x%3!=0 and x%5!=0))
h,w=map(int, input().split()) new_image=["#"*(w+2)] for i in range(h): new_image.append("#"+input()+"#") new_image.append("#"*(w+2)) for i in range(h+2): print(new_image[i])
A,B,C = map(int,input().split()) def gcd(a,b): if b == 0: return a else: return gcd(b,a%b) A,B = (A,B) if A>B else (B,A) g = gcd(A,B) if C%g==0: print('YES') else: print('NO')
N = int(input()) ans = "second" for i in range(N): a = int(input()) if a % 2 == 1: ans = "first" break print(ans)
num = int(input()) for i in range(1, num + 1): if i % 3 == 0: print(f' {i}', end='') continue x = i while True: if x % 10 == 3: print(f' {i}', end='') break x = int(x / 10) if x < 1: break print()
import math N = int(input()) lst = [True]*(N*2) for i in range(2,int(math.sqrt(N*2))+1): for j in range(i+i,N*2,i): lst[j] = False for i in range(N,len(lst)): if lst[i]: print(i) break
x = int(input()) a = x//(5+6) if x-11*a==0: print(2*a) elif 1<=x-11*a<=6: print(2*a+1) else: print(2*a+2)
import math def lcm(a, b): return (a * b) // math.gcd(a, b) def main(): n = int(input()) As = list(map(int, input().split())) lcm_num = lcm(As[0], As[1]) for i in range(2, n): lcm_num = lcm(As[i], lcm_num) ans = 0 for i in range(n): ans += (lcm_num-1) % As[i] print(...
def main(): N, M = (int(i) for i in input().split()) from math import gcd def lcm(x, y): return x*y//gcd(x, y) def prime_factorize(n): res = {2: 0} for i in range(2, 3): if i*i > n: break if n % i != 0: continue ...
cnt = 0 def show_list(a): for x in a: print x def g_decide(n): g = [] i = 1 while True: tmp = (3**i-1)/2 if tmp>=n: if len(g)==0: g.append(1) break g.append(tmp) i+=1 return g def insertion_sort(a,n,g): global cnt ...
while 1: input_data = [i for i in input().split()] if input_data[1] == '?': break; a = int(input_data[0]) op = input_data[1] b = int(input_data[2]) if op == '+': print(a+b) elif op == '-': print(a-b) elif op == '*': print(a*b) elif op == '/': print(int(a/b))
S = input() dic = {} for s in S: dic[ord(s)] = True for i in range(97, 97+26): if i not in dic: print(chr(i)) exit() print('None')
a,b,c=map(int,input().split()) f= a<=c<=b or b<=c<=a print("Yes" if f==True else "No")
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def main(): enemy_hp = int(input()) enemy_count=1 attack_count=1 if enemy_hp==1: print(1) exit() else: while enemy_hp >1: enemy_hp = int(enemy_hp/2) enemy_count*=2 attack_count+=enem...
N = int(input()) A = [int(i) for i in input().split()] # A = [5, 3, 2, 4, 1] def bubbleSort(arr): arr_len = len(arr) flg = True cnt = 0 while flg: flg = False for i in range(arr_len -1, 0, -1): if arr[i] < arr[i-1]: arr[i], arr[i-1] = arr[i-1], arr[i] ...
# バスと電車の組み合わせ運賃の最小値を求める A = int(input()) B = int(input()) C = int(input()) D = int(input()) fare = [A+C, A+D, B+C, B+D] print(min(fare))
n = int(input()) s = str(input()) a = len(s) count =0 for i in range(n-2): if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C": count+=1 print(count)
def main(): n = int(input()) ans = solve1(n) print(ans) def solve1(n): if n <= 1: return 1 a, b = 1, 1 for _ in range(2, n + 1): a, b = b, a + b return b if __name__ == '__main__': main()
a = list(map(int,input().split())) if a[0] > 8 or a[1] > 8: print(":(") else: print("Yay!")
word = input() if word.count('a') == 1 and word.count('b') == 1: print('Yes') else: print('No')
def gcd(a,b): if b==0: return a return gcd(b,a%b) a,b,c = map(int,input().split()) print('YES' if c%gcd(a,b)==0 else 'NO')
# "#"と"."だけで行き来できるエリアを"島"とする # 島にある"#"から"."には必ず行けるので、 # "#"の数 * "."がその島の場合の数。これをすべて足し合わせる # visitedになっていない点をすべて捜査する。 # 進めなかった("#"もしくは"."が連続した)マスはvisitedにしない。 H,W = map(int,input().split()) grid = [None] * H for i in range(H): grid[i] = input() visited = [[False] * W for i in range(H)] def get_next_unvisited(che...
s = list(input()) t = list(input()) s.sort() t.sort(reverse=True) for i in range(min(len(s), len(t))): if ord(s[i]) < ord(t[i]): print("Yes") exit() elif ord(s[i]) > ord(t[i]): print("No") exit() print("Yes" if len(s) < len(t) else "No")
t = input() ans = [] for i in t: if i == "?": i = "D" ans.append(i) print("".join(ans))
import math H = int(input()) cnt = 0 monster = 1 while(H >= 1): cnt += monster H = math.floor(H/2) monster *= 2 print(cnt)
def readinput(): n,m,x,y=map(int,input().split()) xx=list(map(int,input().split())) yy=list(map(int,input().split())) return n,m,x,y,xx,yy def main(n,m,x,y,xx,yy): xx.append(x) yy.append(y) xx.sort() yy.sort() if xx[-1]<yy[0]: return 'No War' else: return 'War' ...
str = input() check = str.find("YAKI") if check == 0: print("Yes") else: print("No")
a,b,c = map(str,input().split()) isOK = False if a[-1]==b[0] and b[-1]==c[0]: isOK = True if isOK: print('YES') else: print('NO')
S = input() S_len = len(S) S_list = list(S) ans = '' if S_len == 2: print(S) elif S_len == 3: for i in range(S_len-1, -1, -1): ans += S_list[i] print(ans)
# -*- coding: utf-8 -*- # モジュールのインポート import math def get_input() -> int: """ 標準入力を取得する. Returns:\n int: 標準入力 """ N = int(input()) return N def main(N: int) -> None: """ メイン処理. Args:\n N (int): 正整数(2 <= N <= 10**6) """ # 求解処理 ans = 0 for a in ra...
while True: (H, W) = tuple([int(i) for i in input().split(' ')]) if (H == W == 0): break for i in range(H): print('#' * W) print()
a = input() if (a[0] == a[-1]): print("Yes") else: print("No")
a,b = (int(x) for x in input().split()) multi = a * b if multi %2 == 0: print("Even") else: print("Odd")
s = input() ans = [] for i in range(len(s)): if s[i] == '0' or s[i]=='1': ans.append(s[i]) else: ans = ans[:-1] print(''.join(ans))
S = list(input()) ans = 'AC' if not S[0] == 'A': ans = 'WA' if not 'C' in (S[2:-1]): ans = 'WA' if ans == 'AC': S.remove('A') S.remove('C') if not S == [s.lower() for s in S]: ans = ('WA') print(ans)
a = int(input().replace(" ","")) c=0 for i in range(10**4): if i**2 <= a:c=i**2 else:break print("Yes" if c == a else "No")
s=str(input()) list=["a","b","c"] S=[s[0],s[1],s[2]] S.sort() if S==list: print('Yes') else: print('No')
#安定なソート #4つの絵柄と9つの数字から成る36枚のカード def bubble(nums,N): for i in range(N-1): #先頭が確定するまで調べる(確定したら先頭の次の値が先頭になる) j = N-1 while j > i: if nums[j-1][1] > nums[j][1]: nums[j-1], nums[j] = nums[j], nums[j-1] j = j - 1 #交換したら次の値に移動する return nums def selection(nums,N)...
n = int(input()) res = 0 while n: res += n % 10 n //= 10 if res == 1: print(10) else: print(res)
dic = {} dic.setdefault('a',str(input())+'E') dic.setdefault('b',str(input())+'E') dic.setdefault('c',str(input())+'E') dare = dic['a'][0] dic['a'] = dic['a'][1:] while len(dic['a'])>0 and len(dic['b'])>0 and len(dic['c'])>0: tmp = dic[dare][0] dic[dare] = dic[dare][1:] if tmp=='E': ans = dare.upper...
c = [] for i in range(3): c.append(input()) for i in range(3): for j in range(3): if i == j: print(c[i][j],end="") print()
def check(r): if r == r[::-1]: return True def main(): s = input() n = len(s) print("Yes" if check(s) and check(s[:(n-1)//2]) and check(s[((n-1)//2) + 1:]) else "No") if __name__ == "__main__": main()
str = str(input()) list = list(str) a = len(list) if a == 2: print(str) else: list.reverse() ans = ' ' for i in list: ans += i print(ans)
N = int(input()) list1 = [] for i in range(N+1): if i%3 ==0 or i%5 ==0: list1.append(i) total1 =0 total2 = 0 for i in list1: total1 += i for i in range(N+1): total2 += i print(total2 -total1)
def shuffle(l,h): l.extend(l[0:h]) del l[0:h] while True : card_list = list(raw_input()) if card_list == ['-']: break else : m = input() h_count = [0]*m for i in range(m): h_count[i] = input() shuffle(card_list,h_count[i]) print("".join(card_list))