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
n = int(input()) print(- n % 1000)
S, T = map(str, input().split()) A, B = map(int, input().split()) U = input() if U == S: A -= 1 A = str(A) B = str(B) print(A+' '+B) else : B -= 1 A = str(A) B = str(B) print(A+' '+B)
0
null
40,315,717,648,508
108
220
n, a, b = list(map(int, input().split())) whole = n // (a + b) rest = n % (a + b) blue = whole * a if rest <= a: blue += rest else: blue += a print(blue)
N,A,B=map(int,input().split()) print(A*(N//(A+B))+min(A,N%(A+B)))
1
55,589,613,676,412
null
202
202
S = input() ans = {0:1} memo = [0] last = 1 for ind, s in enumerate(S[::-1]): memo.append((int(s) * last + memo[-1]) % 2019) last *= 10 last %= 2019 if(memo[-1] in ans): ans[memo[-1]] += 1 else: ans[memo[-1]] = 1 res = 0 for key in ans.keys(): res += ans[key]*(ans[key]-1)//2 print(res)
import sys read = sys.stdin.read readlines = sys.stdin.readlines from collections import defaultdict def main(): s = tuple(map(int, input())) lens = len(s) d1 = defaultdict(int) ss = 0 num10 = 1 for se in s[::-1]: ss += (int(se) * num10) % 2019 ss = ss % 2019 d1[ss] += 1 num10 = (num10 * 10) % 2019 r = d1[0] for v in d1.values(): r += v * (v - 1) // 2 print(r) if __name__ == '__main__': main()
1
30,850,728,417,212
null
166
166
import sys def solve(): n = int(sys.stdin.readline()) ans = 0 for i in range(n): num = int(sys.stdin.readline()) ans += is_prime(num) print(ans) def is_prime(n): if n < 2: return False for p in range(2, n + 1): if p*p > n: break if n % p == 0: return False return True if __name__ == '__main__': solve()
# -*- coding: utf-8 -*- import math def prime_number_identifier(num): for candidate in range(2, int(math.sqrt(num)) + 1): if num % candidate == 0: return False return True input_num = int(raw_input()) counter = 0 found_number = 0 while counter < input_num: candidate_number = int(raw_input()) if prime_number_identifier(candidate_number): found_number += 1 counter += 1 print found_number
1
10,578,811,410
null
12
12
a2=list(input()) if a2[0]!=a2[1] and a2[2]==a2[3] and a2[4]==a2[5]: print('Yes') else: print('No')
import sys sys.setrecursionlimit(10**7) input = lambda: sys.stdin.readline().strip() def main(): S = input() print("Yes" if S[2]==S[3] and S[4]==S[5] else "No") main()
1
42,076,931,863,020
null
184
184
n=int(input()) m=int(n/1.08) for i in range(-2,3): if int((m+i)*1.08)==n: print(m+i) exit() print(":(")
n = int(input()) if n/1.08==n//1.08: print(n//1.08) elif int(-(-n//1.08) * 1.08) == n: print(int(-(-n//1.08))) else: print(':(')
1
126,051,815,446,888
null
265
265
data = input() #data = '\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\' diff = {'\\':-1, '_':0, '/':1} height = [0] [height.append(height[-1]+diff[i]) for i in data] bottom = min(height) height = [h-bottom for h in height] m = max(height) water = [m for h in height] height00 = [0] + height + [0] water00 = [0] + water + [0] roop = True forward = 1 while roop: temp = water00[:] for i in range(1,len(water00)-1)[::forward]: water00[i] = max(height00[i],min(water00[i-1:i+2])) roop = temp != water00 forward *= -1 water = water00[1:-1] depth = [w-h for w,h in zip(water,height)] paddles = [0] for d1,d2 in zip(depth[:-1],depth[1:]): if d1==0 and d2>0: paddles.append(0) paddles[-1] += min(d1,d2) + 0.5*abs(d1-d2) paddles = [int(p) for p in paddles[1:]] print(sum(paddles)) print(len(paddles), *paddles)
f = list(input()) s = [] for i, v in enumerate(f): if v == '\\': s.append([v, i]) elif v == '/' and len(s) > 0: n = s.pop() if n[0] == '\\': t = i-n[1] s.append(['.', t]) elif len(s) > 0: j = len(s)-1 n1 = n[1] while j >= 0 and s[j][0] == '.': #print(n1, s[j][1]) n1 += s[j][1] j -= 1 if j >= 0: m = s[j] # print(m) n1 += i-m[1] s = s[:j] s.append(['.', n1]) else: # print("err") s.append(n) else: s.append(n) #print(v, s, i) a = [v[1] for v in s if v[0] == '.'] print(sum(a)) a.insert(0, len(a)) print(" ".join([str(v) for v in a]))
1
58,048,545,860
null
21
21
#!/usr/bin/env python3 import sys from collections import deque YES = "Yes" # type: str def solve(N: int, M: int, A: "List[int]", B: "List[int]"): dq = deque([]) traversed = [False for _ in range(N+1)] ans = [None for _ in range(N+1)] G = {n : set([]) for n in range(1, N+1)} for a, b in zip(A,B): G[a].add(b) G[b].add(a) dq.append(1) traversed[1] = True while dq: s = dq.popleft() for node in G[s]: if not traversed[node]: dq.append(node) traversed[node] = True ans[node] = s print(YES) for s in ans: if s != None: print(s) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int A = [int()] * (M) # type: "List[int]" B = [int()] * (M) # type: "List[int]" for i in range(M): A[i] = int(next(tokens)) B[i] = int(next(tokens)) solve(N, M, A, B) if __name__ == '__main__': main()
import sys import math input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import defaultdict MOD = 10**9+7 N = int(input()) dic = defaultdict(int) zero = 0 left_zero = 0 right_zero = 0 for i in range(N): a, b = map(int, input().split()) if b < 0: a = -a b = -b if a == 0 and b == 0: zero += 1 elif a == 0: left_zero += 1 elif b == 0: right_zero += 1 else: g = math.gcd(a, b) a //= g b //= g dic[a,b] += 1 done = set() ans = 1 for a,b in dic: k = (a, b) if k in done: continue rk = (-b, a) rk2 = (b, -a) done.add(k) done.add(rk) done.add(rk2) c = pow(2, dic[k], MOD)-1 if rk in dic: c += pow(2, dic[rk], MOD)-1 if rk2 in dic: c += pow(2, dic[rk2], MOD)-1 c += 1 ans *= c ans %= MOD c1 = pow(2, left_zero, MOD)-1 c2 = pow(2, right_zero, MOD)-1 c = c1+c2+1 ans *= c ans += zero print((ans-1)%MOD)
0
null
20,630,106,229,008
145
146
#! /usr/bin/env python #-*- coding: utf-8 -*- ''' ?????\????????? ''' # # ?¨??????????O() def insertion_sort(A, N): for i in range(N): tmp = A[i] j = i - 1 while j >= 0 and A[j] > tmp: A[j + 1] = A[j] j -= 1 A[j + 1] = tmp print(' '.join(map(str, A))) return A if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) # N = 6 # A = [5, 2, 4, 6, 1, 3] array_sorted = insertion_sort(A, N)
from collections import defaultdict N = int(input()) dic = defaultdict(int) for n in range(1,N+1): s = str(n) dic[(int(s[0]), int(s[-1]))] += 1 res = 0 for key, value in dic.items(): a, b = key cnt = dic.get((b,a),0) res += value * cnt print(res)
0
null
43,168,874,475,168
10
234
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))
import bisect N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-1, 1, -1): for j in range(i-1, 0, -1): a, b = L[i], L[j] c = a - b + 1 if c > b: continue ans += (j - bisect.bisect_left(L, c)) print(ans)
0
null
87,591,900,464,992
83
294
N = int(input()) if N % 2 == 1: print(0) exit() ans = 0 i = 1 while 5 ** i * 2 <= N: ans += N // (5 ** i * 2) i += 1 print(ans)
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n = int(input()) if n & 1: print(0) exit() ans = 0 n //= 2 while n: ans += n // 5 n //= 5 print(ans)
1
115,853,859,362,010
null
258
258
class diceClass: label = [] def __init__(self,l): if len(l) == 6: self.label = l def move(self,c): if c.upper() == 'N': buf = [] buf.append(self.label[1]) buf.append(self.label[5]) buf.append(self.label[2]) buf.append(self.label[3]) buf.append(self.label[0]) buf.append(self.label[4]) self.label = buf elif c.upper() == 'E': buf = [] buf.append(self.label[3]) buf.append(self.label[1]) buf.append(self.label[0]) buf.append(self.label[5]) buf.append(self.label[4]) buf.append(self.label[2]) self.label = buf elif c.upper() == 'W': buf = [] buf.append(self.label[2]) buf.append(self.label[1]) buf.append(self.label[5]) buf.append(self.label[0]) buf.append(self.label[4]) buf.append(self.label[3]) self.label = buf elif c.upper() == 'S': buf = [] buf.append(self.label[4]) buf.append(self.label[0]) buf.append(self.label[2]) buf.append(self.label[3]) buf.append(self.label[5]) buf.append(self.label[1]) self.label = buf def get_label(self): return self.label[0] in_line = raw_input().split() dice = diceClass(in_line) move = raw_input() for c in move: dice.move(c) print dice.get_label()
import sys input = sys.stdin.readline class Dice: """ 0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom """ def __init__(self, surfaces): self.surface = surfaces def roll(self, direction: str): if direction == "E": self.surface = [self.surface[3], self.surface[1], self.surface[0], self.surface[5], self.surface[4], self.surface[2]] elif direction == "N": self.surface = [self.surface[1], self.surface[5], self.surface[2], self.surface[3], self.surface[0], self.surface[4]] elif direction == "S": self.surface = [self.surface[4], self.surface[0], self.surface[2], self.surface[3], self.surface[5], self.surface[1]] elif direction == "W": self.surface = [self.surface[2], self.surface[1], self.surface[5], self.surface[0], self.surface[4], self.surface[3]] return def get_top(self): return self.surface[0] def main(): surface = [int(i) for i in input().strip().split()] spins = input().strip() dice = Dice(surface) for d in spins: dice.roll(d) print(dice.get_top()) if __name__ == "__main__": main()
1
239,952,423,528
null
33
33
s=list(map(int,input().split())) ans="Yes" if len(set(s))==2 else "No" print(ans)
N= int(input()) n = N % 10 if n == 2 or n==4 or n ==5 or n == 7 or n == 9: print('hon') elif n == 0 or n ==1 or n == 6 or n == 8: print('pon') elif n == 3: print('bon')
0
null
43,902,238,948,572
216
142
W = input() ans = 0 count = 0 for i in range(len(W)): if W[i] == "R": count += 1 ans = max(ans,count) else: count = 0 print(ans)
s = input() cnt = 0 if s == 'RSR': cnt = 1 else: for i in range(3): if s[i] == 'R': cnt += 1 print(cnt)
1
4,872,310,555,250
null
90
90
import math r = float(input()) a = math.pi * r * r l = 2 * math.pi * r print(f'{a} {l}')
# coding=utf-8 from math import pi r = float(raw_input().strip()) print "{0:f} {1:f}".format(pi * r * r, 2 * pi * r)
1
634,527,398,560
null
46
46
n = int(input()) a = list(map(int,input().split())) a.reverse() for i in range(n-1): print(a[i],end = " ") print(a[n-1])
count = int(raw_input()) arr = map(int, raw_input().split()) arr.reverse() print(" ".join(map(str, arr)))
1
959,361,917,728
null
53
53
se = set([]) n = int(raw_input()) for i in range(n): s = raw_input().split() if s[0] == 'insert': se.add(s[1]) elif s[0] == 'find': if s[1] in se: print 'yes' else: print 'no'
dic = set() n = int(input()) for i in range(n): s = input() if s[0] == 'i': dic.add(s[7:]) else: print("yes" if s[5:] in dic else "no")
1
77,469,898,110
null
23
23
string = input() if string == "ARC": print("ABC") else: print("ARC")
read = lambda: list(map(int, input().split())) d, t, s = read() if d / s > t: print("No") else: print("Yes")
0
null
13,874,118,991,520
153
81
while True: n,x = map(int,input().split(" ")) if n == 0 and x == 0: break #データリスト作成 data = [m for m in range(1,n+1)] data_list = [] cnt = 0 #n種類の数字があって、xになる組み合わせは? for i in range(1,n+1): for j in range(1+i,n+1): for k in range(1+j,n+1): if i+j+k == x: cnt += 1 print(cnt)
while True: (n, x) = [int(i) for i in input().split()] if n == x == 0: break dataset = [] for a in range(1, n + 1): for b in range(a + 1, n + 1): for c in range(b + 1, n + 1): dataset.append([a,b,c]) count = 0 for data in dataset: if sum(data) == x: count += 1 print(count)
1
1,302,982,983,356
null
58
58
nn=int(input()) nc = [0] * (nn + 1) for x in range(1, 100): for y in range(1, 100): for z in range(1, 100): a = x * x + y * y + z * z + x * y + x * z + y * z if a > nn: break nc[a] += 1 for i in range(1, nn + 1): print(nc[i])
N = int(input()) ans = 0 if N % 1000 == 0: print(ans) else: a = N // 1000 ans = (a+1)*1000 - N print(ans)
0
null
8,214,994,288,082
106
108
n = int(input()) x = list(map(int,input().split())) a = min(x) b = max(x) + 1 ans = 10 ** 8 for p in range(a,b): m = 0 for i in range(n): m += (x[i] - p) ** 2 ans = min(ans,m) print(ans)
N=int(input()) X=list(map(int,input().split())) Y=[] for i in range(1,101): tot=0 for n in range(N): tot+=(X[n]-i)**2 Y.append(tot) print(min(Y))
1
65,109,918,848,352
null
213
213
n=int(input()) if n%2==0: print("0.5") if n%2==1: print((int(n/2)+1)/n)
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(read()) odd = 0 for n in range(N): n += 1 if n%2==1: odd += 1 print(odd/N)
1
177,254,185,202,810
null
297
297
n, k = map(int, input().split()) print(sum(int(i) >= k for i in input().split()))
n,k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] res = 0 for i in range(n): if k <= a[i]: res += 1 print(res)
1
178,587,492,295,126
null
298
298
d = list(map(int, input().split())) op = list(input()) for o in op: b = [x for x in d] if o == "S": b[0] = d[4] b[1] = d[0] b[4] = d[5] b[5] = d[1] elif o == "E": b[0] = d[3] b[2] = d[0] b[3] = d[5] b[5] = d[2] elif o == "W": b[0] = d[2] b[2] = d[5] b[3] = d[0] b[5] = d[3] elif o == "N": b[0] = d[1] b[1] = d[5] b[4] = d[0] b[5] = d[4] for i in range(6): d[i] = b[i] print(d[0])
a,b,c,d = list(map(int,(input().split()))) ans='' for i in range(100): c-=b if c<=0: ans='Yes' break a-=d if a<=0: ans='No' break print(ans)
0
null
14,962,662,125,020
33
164
MOD = 1000000007 def mod_pow(x , y): if y == 0: return 1 if y == 1: return x r = mod_pow(x , y // 2) r2 = (r * r) % MOD if y % 2 == 0: return r2 % MOD else: return (r2 * x) % MOD N , K = map(int , input().split()) result = 0 memo = {} for g in range(K , 0 , -1): comb = mod_pow(K // g , N) for j in range(2 , K // g + 1): comb = (comb - memo[j * g] + MOD) % MOD memo[g] = comb result = (result + comb * g) % MOD print(result)
from math import * n = input() x = map(float, raw_input().split()) y = map(float, raw_input().split()) for i in range(1,4): temp = 0 for j in range(n): temp += fabs(x[j]-y[j])**i print pow(temp,1.0/i) d = 0 for i in range(n): if(fabs(x[i]-y[i]) > d): d = fabs(x[i]-y[i]) print d
0
null
18,368,176,857,370
176
32
K=int(input()) A,B=map(int,input().split()) print("OK" if B//K*K >= A else "NG")
K = int(input()) A, B = map(int, input().split()) if (B // K)*K >= A: print('OK') else: print('NG')
1
26,565,295,793,570
null
158
158
def Base_10_to_n(X, n): if int(X/n): return Base_10_to_n(int(X/n), n) + str(X%n) return str(X%n) N, K = map(int, input().split()) print(len(Base_10_to_n(N,K)))
import math N, K = map(int, input().split()) if N != 1: res = math.log(N, K) else: res = 1 print(math.ceil(res))
1
64,296,802,540,818
null
212
212
def find(x): if par[x] == x: return x else: par[x] = find(par[x]) #経路圧縮 return par[x] def same(x,y): return find(x) == find(y) def unite(x,y): x = find(x) y = find(y) if x == y: return 0 par[x] = y size[y] = size[x] + size[y] size[x] = 0 N,M = map(int,input().split()) par = [ i for i in range(N+1)] size = [1 for _ in range(N+1)] for _ in range(M): a,b = map(int,input().split()) unite(a,b) A = size.count(0) print(N-A-1)
class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if(x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める elif(self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] n,m = map(int,input().split()) uf = UnionFind(n) for i in range(m): a,b = map(int,input().split()) a -= 1 b -= 1 uf.Unite(a,b) s = set() for i in range(n): s.add(uf.Find_Root(i)) print(len(s)-1)
1
2,293,722,742,302
null
70
70
#E N,K = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort(reverse=True) F.sort() left = 0 right = 10**12 while True: mid = (left+right)//2 if right - left <= 1: count = 0 for i in range(N): a = left//F[i] count+=max(0,A[i]-a) if count <= K: ans = left else: ans = right break count = 0 for i in range(N): a = mid//F[i] count+=max(0,A[i]-a) if count <= K: right = mid else: left = mid print(ans)
import sys import collections s=sys.stdin.readlines() n,q=map(int,s[0].split()) d=collections.deque(e.split()for e in s[1:]) t=0 while d: k,v=d.popleft() v=int(v) if v>q: v-=q t+=q d.append([k,v]) else: t+=v print(k,t)
0
null
82,739,537,236,512
290
19
n = int(input()) r = [int(input()) for _ in range(n)] mi = r[0] mx = -1e10 for j in range(1, len(r)): mx = max(mx, (r[j] - mi)) mi = min(mi, r[j]) print(mx)
while(True): h,w=map(int,input().split()) if h==0 and w==0: break rect='#'*w+'\n' rect+=('#'+'.'*(w-2)+'#\n')*(h-2) rect+='#'*w+'\n' print(rect)
0
null
430,959,479,240
13
50
x = int(input()) print((x == 0) * 1 + (x == 1) * 0)
N = int(input()) if N%2 == 1 or N <= 9: print(0) else: t = 10 ans = 0 while N >= t: ans += N//t t *= 5 print(ans)
0
null
59,266,126,364,032
76
258
import math def koch(d, a, b): if d== 0: return s=[0,0] t=[0,0] u=[0,0] s[0] = (2.0*a[0]+1.0*b[0])/3.0 s[1] = (2.0*a[1]+1.0*b[1])/3.0 t[0] = (1.0*a[0]+2.0*b[0])/3.0 t[1] = (1.0*a[1]+2.0*b[1])/3.0 u[0] = (t[0] - s[0])*math.cos(math.radians(60))-(t[1] - s[1])*math.sin(math.radians(60)) + s[0] u[1] = (t[0] - s[0])*math.sin(math.radians(60))+(t[1] - s[1])*math.cos(math.radians(60)) + s[1] koch(d-1,a,s) print("{:.8f}".format(s[0]), "{:.8f}".format(s[1])) koch(d-1,s,u) print("{:.8f}".format(u[0]), "{:.8f}".format(u[1])) koch(d-1,u,t) print("{:.8f}".format(t[0]), "{:.8f}".format(t[1])) koch(d-1, t, b) n = int(input()) p1=[0,0] p2=[100,0] print("{:.8f}".format(p1[0]), "{:.8f}".format(p1[1])) koch(n, p1, p2) print("{:.8f}".format(p2[0]), "{:.8f}".format(p2[1]))
import math dig_six = math.radians(60) def koch(d, p1, p2): if d == 0: return d #calc s, u, t from p1, p2 s_x = (2*p1[0]+1 * p2[0]) / 3 s_y = (2*p1[1]+1 * p2[1]) / 3 s = (s_x, s_y) t_x = (1*p1[0]+2 * p2[0]) / 3 t_y = (1*p1[1]+2 * p2[1]) / 3 t = (t_x, t_y) u_x = (t_x - s_x)*math.cos(dig_six) - (t_y - s_y)*math.sin(dig_six) + s_x u_y = (t_x - s_x)*math.sin(dig_six) + (t_y - s_y)*math.cos(dig_six) + s_y u = (u_x, u_y) koch(d-1, p1, s) print (' '.join([str(x) for x in s])) koch(d-1, s, u) print (' '.join([str(x) for x in u])) koch(d-1, u, t) print (' '.join([str(x) for x in t])) koch(d-1, t, p2) if __name__ == '__main__': iterate = int(input()) p1 = (0.0, 0.0) p2 = (100.0, 0.0) print (' '.join([str(x) for x in p1])) koch(iterate, p1, p2) print (' '.join([str(x) for x in p2]))
1
120,288,492,672
null
27
27
n = [int(x) for x in input().split()] print(*sorted(n))
arr = map(int,raw_input().split()) arr.sort() arr = map(str,arr) print ' '.join(arr)
1
411,393,977,468
null
40
40
# -*- coding: utf-8 -*- import math errerN=1 while errerN: try: a=list(map(int, input().split())) gcdN=math.gcd(a[0],a[1]) print(gcdN, int(a[0]*a[1]/gcdN)) except : errerN=0
def get_depth(graph,tmp_depth,vertex_list,depth_list): new_vertex_list=[] for vertex in vertex_list: for j in range(len(depth_list)): if(graph[vertex][j]!=0 and depth_list[j]==-1): depth_list[j]=tmp_depth + 1 new_vertex_list.append(j) if(len(new_vertex_list)!=0): get_depth(graph,tmp_depth+1,new_vertex_list,depth_list) #グラフの作成 n=int(input()) graph=[[0]*n for loop in range(n)] for loop in range(n): tmp_ope=list(map(int,input().split())) for j in range(tmp_ope[1]): graph[tmp_ope[0]-1][tmp_ope[j+2]-1]=1 depth_list=[-1]*n depth_list[0]=0 vertex_list=[0] get_depth(graph,0,vertex_list,depth_list) for i in range(n): print(f"{i+1} {depth_list[i]}")
0
null
2,725,928,842
5
9
import math r=input() a=r*r*math.pi b=2*r*math.pi print "%f %f"%(a,b)
N = int(input()) mod = 10 ** 9 +7 x = (10**N)%mod y = (2*(9**N))%mod z = (8**N)%mod print((x-y+z)%mod)
0
null
1,913,998,605,508
46
78
import numpy as np #numpyの練習がてら n = int(input()) tmp = list(map(int,input().split())) mod = 10**9 + 7 a = np.array(tmp,np.int64) ans = 0 for i in range(60 + 1): b = (a >> i) & 1 #すべてのaについて2**n乗目のビットが1か否か iti = np.count_nonzero(b) #すべてのaのうち2**n乗目が1であるものの個数 zero = n - iti #同様に0であるものの個数 ans += (iti * zero) * pow(2,i,mod) % mod#片方1で片方0なら1なので1の個数×0の個数 ans %= mod print(ans)
n,k=map(int,input().split()) ans=[1]*n for _ in range(k): d=int(input()) li=list(map(int,input().split())) for i in li: ans[i-1]=0 print(sum(ans))
0
null
74,140,716,070,080
263
154
S, W = [int(n) for n in input().split()] print('unsafe' if S <= W else 'safe')
n=int(input()) s=list(input()) ans=0 for i in range(10): if str(i) in s: first=s.index(str(i)) ss=s[first+1:] for j in range(10): if str(j) in ss: sec=ss.index(str(j)) for k in range(10): if str(k) in ss[sec+1:]: ans+=1 print(ans)
0
null
79,167,990,217,120
163
267
n = int(input()) print(sum([(n-1)//a for a in range(1, n)]))
import sys def input(): return sys.stdin.readline().rstrip() class mod_comb3: def __init__(self,mod=10**9+7,n_max=1): self.mod,self.n_max=mod,n_max self.fact,self.inv,self.factinv=[1,1],[0,1],[1,1] if 1<n_max:setup_table(n_max) def comb(self,n,r): if r<0 or n<r:return 0 if self.n_max<n:self.setup_table(n) return self.fact[n]*(self.factinv[r]*self.factinv[n-r]%self.mod)%self.mod def setup_table(self,t): for i in range(self.n_max+1,t+1): self.fact.append(self.fact[-1]*i%self.mod) self.inv.append(-self.inv[self.mod%i]*(self.mod//i)%self.mod) self.factinv.append(self.factinv[-1]*self.inv[-1]%self.mod) self.n_max=t def main(): n,k=map(int,input().split()) A=list(map(int,input().split())) com=mod_comb3() A.sort() mod=10**9+7 max_a,min_a=0,0 for i in range(n): max_a=(max_a+A[i]*com.comb(i,k-1))%mod min_a=(min_a+A[i]*com.comb(n-i-1,k-1))%mod print((max_a-min_a)%mod) if __name__=='__main__': main()
0
null
49,040,580,280,242
73
242
import sys # import re # import math # import collections # import decimal # import bisect # import itertools # import fractions # import functools import copy # import heapq # import decimal # import statistics import queue sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): h, w, k = ns() mat = [list(input()) for _ in range(h)] ans_mat = [[0 for i in range(w)] for j in range(h)] cnt = 1 for i in range(h): for j in range(w): if mat[i][j] == "#": ans_mat[i][j] = copy.deepcopy(cnt) cnt += 1 for i in range(h): for j in range(1, w): if ans_mat[i][j] == 0: ans_mat[i][j] = copy.deepcopy(ans_mat[i][j - 1]) for j in range(w - 2, -1, -1): if ans_mat[i][j] == 0: ans_mat[i][j] = copy.deepcopy(ans_mat[i][j + 1]) for i in range(1, h): if max(ans_mat[i]) == 0: ans_mat[i] = copy.deepcopy(ans_mat[i - 1]) for i in range(h - 2, -1, -1): if max(ans_mat[i]) == 0: ans_mat[i] = copy.deepcopy(ans_mat[i + 1]) for ai in ans_mat: print(*ai, sep=" ") if __name__ == '__main__': main()
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): h,w,k=LI() field=[list(S()) for _ in range(h)] ans=[[0]*w for _ in range(h)] l=[] f=False y1=0 x1=0 for i in range(h): for j in range(w): if field[i][j]=='#': if f: l.append([y1,x1,i-1,w-1]) y1=i x1=0 f=True break l.append([y1,x1,h-1,w-1]) # print(l) l2=[] while len(l)>0: y1,x1,y2,x2=l.pop() st=0 f=False for j in range(x1,x2+1): for i in range(y1,y2+1): if field[i][j]=='#': if f: l2.append([y1,st,y2,j-1]) st=j f=True break l2.append([y1,st,y2,x2]) cnt=1 while len(l2)>0: y1,x1,y2,x2=l2.pop() for i in range(y1,y2+1): for j in range(x1,x2+1): ans[i][j]=cnt cnt+=1 for x in ans: print(' '.join([str(y) for y in x])) main() # print(main())
1
143,075,957,805,450
null
277
277
n=input() count=0 while 1 : x=[i for i in input().split()] if x[0]=="END_OF_TEXT": break for i in range(len(x)): if x[i].lower()==n.lower(): count=count+1 print(count)
a = input().lower() cnt = 0 while 1: c = input() if c == 'END_OF_TEXT': break cnt += c.lower().split().count(a) print(cnt)
1
1,799,811,739,652
null
65
65
n=int(input()) s=input() c=n for i in range(0,n-1): if s[i]==s[i+1]: c-=1 print(c)
N = int(input()) S = input() count = 1 check = S[0] for c in S: if c != check: count += 1 check = c print(count)
1
170,112,627,560,788
null
293
293
x = int(input()) c1 = x//500 x -= 500*c1 c2 = x//5 print(1000*c1 + 5*c2)
X = int(input()) answer = (X // 500) * 1000 X %= 500 answer += (X // 5) * 5 print(answer)
1
42,667,462,473,502
null
185
185
user_input = int(input()) print(user_input + user_input**2 + user_input**3)
from itertools import accumulate from collections import defaultdict n, k = map(int, input().split()) a = list(map(int, input().split())) acc = [0] + list(accumulate(a)) sm = [(e - i) % k for i, e in enumerate(acc)] d = defaultdict(int) ans = 0 for r in range(1, n + 1): if r - k >= 0: e = sm[r - k] d[e] -= 1 e = sm[r - 1] d[e] += 1 e = sm[r] ans += d[e] print(ans)
0
null
74,132,872,205,500
115
273
A,B,N = map(int,input().split()) if B<=N: print(int((A*(B-1))/B)-(A*int((B-1)/B))) else: print(int((A*N)/B)-(A*int(N/B)))
""" 最大限傾けたとき、水と接している面は横から見ると台形ないし三角形となる 水と接している面の面積 x/a が a*b/2 より大きい場合は台形となり、以下の場合は三角形となる 台形の場合 最大限傾けたとき、水と接している台形の上辺の長さをnとすると (n+b)*a/2 = x/a n = 2*x/(a**2) - b 求める角度をthetaとすると tan(theta) = (b-n)/a theta = arctan((b-n)/a) 三角形の場合 最大限傾けたとき、水と接している三角形の底辺の長さをnとすると n*b/2 = x/a n = 2*x/(a*b) 求める角度をthetaとすると tan(theta) = b/n theta = arctan(b/n) """ import sys sys.setrecursionlimit(10**6) a,b,x = map(int, input().split()) import numpy as np if x/a > a*b/2: n = 2*x/(a**2) - b theta = np.arctan((b-n)/a) # radian表記なので戻り値の範囲は[-pi/2, pi/2] theta = np.rad2deg(theta) else: n = 2*x/(a*b) theta = np.arctan(b/n) theta = np.rad2deg(theta) print(theta)
0
null
95,978,647,537,660
161
289
n = int(input()) a = [int(i) for i in input().split()] if n // 2 == 1: print(max(a)) exit() if n < 20: d = a.copy() for i in range(1, n // 2): b = [0] * n c = -10 ** 24 ans = -10 ** 24 for j in range(i * 2, n): c = max(c, a[j - 2]) b[j] = c + d[j] ans = max(ans, c + d[j]) a = b.copy() print(ans) exit() b = a[:10] e = [True]*10 for i in range(1, n // 2): c = [0] * 10 f = [False]*10 d = -10**24 for j in range(10): if 2 * i + j >= n: continue if not e[j]: continue d = max(d, b[j]) c[j] = d + a[2 * i + j] f[j] = True e = f.copy() b = c.copy() ans = -10 ** 24 for i in range(10): if e[i]: ans = max(ans, b[i]) print(ans)
n = int(input()) al = list(map(int, input().split())) if n%2 == 1: dp = [ [0]*4 for _ in range(n//2+1) ] for i in range(n//2): dp[i+1][0] = dp[i][0] + al[i*2] dp[i+1][1] = max(dp[i][1]+al[i*2+1], dp[i][0]+al[i*2+1]) dp[i+1][2] = max(dp[i][2]+al[i*2+2], dp[i][0]+al[i*2+2]) dp[i+1][3] = max(dp[i][3]+al[i*2+2], dp[i][1]+al[i*2+2]) ans = max(dp[-1]) print(ans) else: dp = [ [0]*2 for _ in range(n//2+1) ] for i in range(n//2): dp[i+1][0] = dp[i][0] + al[i*2] dp[i+1][1] = max(dp[i][1]+al[i*2+1], dp[i][0]+al[i*2+1]) ans = max(dp[-1]) print(ans)
1
37,453,737,624,292
null
177
177
x = int(input()) b = x a = 1 while b%360!=0: a += 1 b += x print(a)
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(x): if DBG: print(x) s = ins() t = ins() ls = len(s) lt = len(t) mn = BIG for i in range(ls-lt+1): x = 0 for j in range(lt): if s[i+j]!=t[j]: x += 1 mn = min(mn,x) print(mn)
0
null
8,441,337,660,158
125
82
import sys x,k,d=map(int,input().split()) x=abs(x) a=x//d if a>=k: ans=x-k*d elif (k-a)%2==0: ans=x-d*a else: ans=x-d*a-d print(abs(ans))
x,k,d = list(map(int,input().split())) x = abs(x) point =x % d num = x//d if num<k: rest = k - num if rest%2==0: pass else: point = d -point else: point = x - k*d print(point)
1
5,180,565,757,114
null
92
92
N, K = [int(a) for a in input().split()] num_count = (N-N%K)//K ans = min(abs(N - num_count*K), abs(N - (num_count+1)*K)) if num_count > 0: ans = min(abs(N - (num_count-1)*K), ans) print(ans)
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): N, K = MI() a = N % K b = K - a print(min(a, b)) if __name__ == "__main__": main()
1
39,302,851,103,918
null
180
180
def award(x): return max(0, 4*(10**5) - x*(10**5)) x,y = map(int,input().split()) ans = award(x) ans += award(y) if x == 1 and y == 1: ans += 4*(10**5) print(ans)
X, Y = map(int, input().split()) ans = 0 if X <= 3: ans += (4-X) * 100000 if Y <= 3: ans += (4-Y) * 100000 if X == Y == 1: ans += 400000 print(ans)
1
140,399,367,902,048
null
275
275
# -*- coding: utf-8 -*- def selection_sort(n, a): cnt = 0 for i in range(n): minj = i for j in range(i, n): if a[j] < a[minj]: minj = j if i != minj: tmp = a[minj] a[minj] = a[i] a[i] = tmp cnt += 1 return a, cnt if __name__ == '__main__': n = int(input()) a = [int(n) for n in input().split()] ans, cnt = selection_sort(n, a) print(' '.join(map(str, ans))) print(cnt)
n, m = map(int, input().split()) if n%2 == 1: a = 1 b = n+1 ans = [] for i in range(m): a += 1 b -= 1 ans.append((a, b)) else: a = 1 b = n+1 S = set() ans = [] for i in range(m): a += 1 b -= 1 r = min(b-a, n-(b-a)) if r in S or r == n//2: b -= 1 r = min(b-a, n-(b-a)) ans.append((a, b)) S.add(r) for i in range(m): print(*ans[i])
0
null
14,441,328,215,620
15
162
# --*-coding:utf-8-*-- def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) B = [0]*(N+1) b = 0 for i, a in enumerate(A): b += a - 1 b %= K B[i+1] = b Q = {} X = 0 for i, b in enumerate(B): if i>=K: Q[B[i-K]] -= 1 if b in Q: X += Q[b] Q[b] += 1 else: Q[b] = 1 print(X) if __name__ == '__main__': main()
import sys input = sys.stdin.readline from collections import deque N, K = map(int, input().split()) A = list(map(int, input().split())) B = [0] for a in A: b = (B[-1] + (a-1)) % K B.append(b) ans = 0 dic = {} for i, b in enumerate(B): if b in dic: dic[b].append(i) else: dic[b] = deque() dic[b].append(i) while len(dic[b]) > 0 and dic[b][0] <= i - K: dic[b].popleft() ans += len(dic[b])-1 print(ans)
1
138,038,822,384,468
null
273
273
N = int(input()) a = [int(i) for i in input().split()] cnt = 0 for i,v in enumerate(a,1): if i%2 != 0 and v%2 != 0: cnt += 1 print(cnt)
N = int(input()) A = list(map(int, input().split())) ct = 0 for n in range(N + 1): if n % 2: if A[n - 1] % 2: ct +=1 print(ct)
1
7,730,316,470,930
null
105
105
# coding=utf-8 def solve_gcd(number1: int, number2: int) -> int: two_list = [number1, number2] two_list.sort() if two_list[1] % two_list[0] == 0: return two_list[0] r = two_list[1] % two_list[0] return solve_gcd(two_list[0], r) def solve_lcm(number1: int, number2: int, number3: int) -> int: return number1*number2//number3 if __name__ == '__main__': while True: try: a, b = map(int, input().split()) except EOFError: break gcd = solve_gcd(a, b) lcm = solve_lcm(a, b, gcd) print(gcd, lcm)
def comb(n, k): nu, de = 1, 1 for i in range(k): de *= n - i nu *= i + 1 return de // nu def ans(N, K): if K == 0: return 1 N = str(int(N)) if len(N) < K or int(N) == 0: return 0 ret = sum([9 ** K * comb(max(dig - 1, 1), K - 1) for dig in range(K, len(N))]) ret += (int(N[0]) - 1) * 9 ** (K - 1) * comb(len(N) - 1, K - 1) return ret + ans(N[1:], K - 1) N = input() K = int(input()) print(ans(N, K))
0
null
37,855,539,614,300
5
224
N = int(input()) D = list(map(int, input().split())) mod = 998244353 counter = [0] * N for d in D: counter[d] += 1 if counter[0] != 1: print(0) exit() ans = 1 for d in D[1:]: ans = ans * counter[d-1] % mod print(ans)
n=int(input()) d=list(map(int,input().split())) mx=max(d) l=[0]*(10**5) mx=0 for i in range(n): if (i==0 and d[i]!=0) or (i!=0 and d[i]==0): print(0) exit() l[d[i]]+=1 mx=max(mx,d[i]) t=1 ans=1 for i in range(1,mx+1): ans *= t**l[i] t=l[i] print(ans%998244353)
1
154,809,243,970,180
null
284
284
H, W, K = map(int, input().split()) grid = [input() for _ in range(H)] ans = [[0]*W for _ in range(H)] empty_index = [False]*H first_flg = False cnt = 0 for i in range(H): if '#' not in grid[i]: empty_index[i] = True for i in range(H): if not empty_index[i] and not first_flg: first_flg = True first_index = i if not first_flg: continue if empty_index[i]: for k in range(W): ans[i][k] = ans[i-1][k] else: cnt += 1 flg = False for k in range(W): if grid[i][k] == '#': if not flg: flg = True else: cnt += 1 ans[i][k] = cnt for i in range(H): if not empty_index[i]: break for k in range(W): ans[i][k] = ans[first_index][k] for i in ans: print(*i)
H,W,K = map(int,input().split()) S = [input().strip() for _ in range(H)] Ar = [] for i in range(H): for j in range(W): if S[i][j]=="#": Ar.append(i) break Ar.append(H) if len(Ar)==2: Ac = [] for j in range(W): if S[Ar[0]][j]=="#": Ac.append(j) A = [[1 for _ in range(W)] for _ in range(H)] Ac.append(W) Ac[0]=0 if len(Ac)>2: for k in range(len(Ac)-1): for j in range(Ac[k],Ac[k+1]): for i in range(H): A[i][j] = k+1 else: Ac = {i:[] for i in range(len(Ar)-1)} for i in range(len(Ar)-1): for j in range(W): if S[Ar[i]][j]=="#": Ac[i].append(j) A = [[1 for _ in range(W)] for _ in range(H)] Ar[0] = 0 cnt = 1 for i in range(len(Ar)-1): Ac[i][0] = 0 Ac[i].append(W) for j in range(len(Ac[i])-1): for j1 in range(Ac[i][j],Ac[i][j+1]): for i1 in range(Ar[i],Ar[i+1]): A[i1][j1] = cnt cnt += 1 for i in range(H): print(*A[i])
1
143,169,035,515,452
null
277
277
N = int(input()) X = list(map(int,input().split())) minimum = 10000000 for n in range(1,max(X)+1): kyori = 0 for i in range(N): kyori += (X[i]-n)**2 if kyori < minimum: minimum = kyori print(minimum)
day = ["SUN","MON","TUE","WED","THU","FRI","SAT" ] s = input() pos = day.index(s) print(7-pos)
0
null
99,241,154,834,540
213
270
n = int(input()) dictionary = {} for i in range(n): a = input().split() if a[0] == "insert": dictionary[a[1]] = 0 if a[0] == "find": if a[1] in dictionary: print("yes") else: print("no")
import math a, b, x = map(int, input().split()) theta = math.atan((-2) * x / (a ** 3) + 2 * b / a) if a * math.tan(theta) > b: theta = math.atan2(a * b * b, 2 * x) print(math.degrees(theta))
0
null
81,400,623,500,930
23
289
import sys input = lambda: sys.stdin.readline().rstrip() n = int(input()) a = [int(x) for x in input().split()] from itertools import accumulate a_csum = list(accumulate(a)) ans = 10**10 for i in range(n - 1): ans = min(ans, abs(a_csum[i] - (a_csum[-1] - a_csum[i]))) print(ans)
def resolve(): N = int(input()) A = list(map(int, input().split())) diff = 10 ** 10 partA = 0 partB = sum(A) for i in range(N): diff = min(diff, abs(partA-partB)) partA += A[i] partB -= A[i] print(diff) return resolve()
1
142,513,202,319,328
null
276
276
n, *s = open(0).read().split() n = int(n) c0 = s.count('AC') c1 = s.count('WA') c2 = s.count('TLE') c3 = n - (c0 + c1 + c2) print('AC x ' + str(c0), 'WA x ' + str(c1), sep='\n') print('TLE x ' + str(c2), 'RE x ' + str(c3), sep='\n')
import math a, b, x = map(int, input().split(' ')) x = x / a if x > a * b / 2: print(math.atan2((a * b - x) * 2, a ** 2) * 180 / math.pi) else: print(math.atan2(b ** 2, x * 2) * 180 / math.pi)
0
null
85,896,981,922,180
109
289
H,A = map(int,input().split()) ans = H // A if H % A != 0: ans += 1 print(ans)
x = int(input()) xSum = 0 cnt = 1 while True: xSum += x if xSum%360 == 0: break cnt += 1 print(cnt)
0
null
44,871,246,870,858
225
125
#template def inputlist(): return [int(j) for j in input().split()] #template N = int(input()) lis = ['0']*N time = [0]*N for i in range(N): lis[i],time[i] = input().split() sing = input() index = -1 for i in range(N): if lis[i] == sing: index = i break ans = 0 for i in range(index+1,N): ans += int(time[i]) print(ans)
n = int(input()) title = [] length = [] for i in range(n): a, b = input().split() title.append(a) length.append(int(b)) i = title.index(input()) print(sum((length[i+1:])))
1
96,987,541,073,010
null
243
243
H=int(input()) W=int(input()) N=int(input()) if N%max(H,W)==0: print(N//max(H,W)) else: print(N//max(H,W)+1)
N,M=map(int,input().split()) S,r,s=input(),[],N for _ in range(2*N): if S[s]=='1': s += 1 else: r.append(str(N-s)) N,s=s,max(0,s-M) if N == 0: break print(*[-1] if s else r[1:][::-1])
0
null
114,234,256,224,800
236
274
from collections import Counter N = int(input()) D = list(map(int, input().split())) mod = 998244353 c = Counter(D) m = max(c.keys()) if D[0] == 0 and c[0] == 1: ans = 1 for i in range(1, m+1): ans *= c[i-1]**c[i] ans %= mod print(ans) else: print(0)
def check(k, p, w_list): i_w = 0 for i_k in range(k): sum_w = 0 while True: if i_w >= len(w_list): return len(w_list) if sum_w + w_list[i_w] > p: break sum_w += w_list[i_w] i_w += 1 return i_w n, k = list(map(int, input().split())) w_list = list() for _ in range(n): w = int(input()) w_list.append(w) left = 0 right = 100000 * 10000 mid = None while left < right: mid = (left + right) // 2 v = check(k, mid, w_list) if v >= n: right = mid else: left = mid + 1 print(right)
0
null
77,803,821,956,058
284
24
# coding: UTF-8 line = str(raw_input()*2) word = str(raw_input()) if line.count(word): print "Yes" else: print "No"
s=input() p=input() s2=s*2 ren=s2.count(p) if ren==0: print('No') else: print('Yes')
1
1,743,154,127,520
null
64
64
from collections import deque import copy N, K, C = map(int,input().split()) S = input().split()[0] TW = 0 q = [] for s in range(len(S)): if S[s] == 'o': q.append(s+1) WD = [] LD = 0 for s in q: if len(WD) > K: break if LD == 0: WD.append(s) LD = s elif s-LD <= C: continue else: WD.append(s) LD = s WDR = [] LD = 0 q.reverse() for s in q: if len(WDR) > K: break if LD == 0: WDR.append(s) LD = s elif LD - s <= C: continue else: WDR.append(s) LD = s for d in range(len(WD)): if WD[d] == WDR[len(WD)-d-1]: print(WD[d])
N, K, C = map(int, input().split()) S = input() L, R = [-1] * K, [-1] * K k = 0; temp = -C for i, s in enumerate(S, 1): if s == 'o' and i > temp + C: L[k] = i; k += 1; temp = i if k == K: break k = K - 1; temp = N + C + 1 for i, s in reversed(list(enumerate(S, 1))): if s == 'o' and i < temp - C: R[k] = i; k -= 1; temp = i if k == -1: break ans = [] for l, r in zip(L, R): if l == r: ans.append(l) for a in ans: print(a)
1
40,581,271,199,900
null
182
182
t,T,a,A,b,B=map(int, open(0).read().split()) x,y=(a-b)*t,(A-B)*T if x+y==0: r="infinity" else: s,t=divmod(-x, x+y) r=0 if s<0 else s*2+(1 if t else 0) print(r)
import sys sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def main(): t1, t2 = LI() a1, a2 = LI() b1, b2 = LI() if a1 < b1: tmp = b1 b1 = a1 a1 = tmp tmp = b2 b2 = a2 a2 = tmp l1 = (a1 - b1) * t1 l2 = (a2 - b2) * t2 l3 = l1 + l2 if l3 == 0: print("infinity") return if l3 > 0: print(0) return ans = 1 if l1 % (-l3) == 0: print(ans + 2 * (l1 // (-l3)) - 1) return print(ans + 2 * (l1 // (-l3))) if __name__ == '__main__': main()
1
131,551,113,769,932
null
269
269
x = input().strip() if x[-1] == 's': x += "es" else: x += 's' print(x)
ans = "" k = int(input()) for a in range(k): ans = ans + "ACL" print(ans)
0
null
2,270,663,097,444
71
69
S = input() N = len(S) flag = True if S!=S[::-1]: flag=False if S[:int((N-1)/2)]!=S[:int((N-1)/2)][::-1]: flag=False print("Yes" if flag else "No")
while True: H,W = map(int,input().split()) if H == 0 and W == 0: break for i in range(H): for k in range(W): if i == 0 or i == H-1 or k == 0 or k == W-1: print("#",end = "") else: print(".",end = "") print() print()
0
null
23,652,729,025,988
190
50
a, b, c, k = map(int, input().split()) if k <= a: ans = k elif k <= a + b: ans = a else: ans = a * 2 + b - k # a-(k-(a+b)) print(ans)
A,B,C,K = map(int,input().split()) if K<=A: Ans = K elif K<=A+B: Ans = A elif K<=A+B+C: Ans = A-(K-A-B) else: Ans = A-C print(Ans)
1
21,786,240,901,490
null
148
148
#!/usr/local/bin/python3 # https://atcoder.jp/contests/agc014/tasks/agc014_a # int(input()) # input().split() # map(int, input().split()) # list(map(int, input().split())) S = input() if S[2] == S[3] and S[4] == S[5]: print("Yes") else: print("No")
a,b,c,d,e,f=input() if c==d and e==f: print('Yes') else: print('No')
1
42,181,851,041,330
null
184
184
from decimal import Decimal import math AB = input().split() A, B = int(AB[0]), Decimal(AB[1]) print(math.floor(A*B))
import decimal a, b = input().split() x, y = decimal.Decimal(a), decimal.Decimal(b) print(int(x * y))
1
16,434,763,063,752
null
135
135
n = int(input()) def memoize(f): memo = [1, 1] + [0] * max(0, n - 1) def main(i): if memo[i]: return memo[i] result = memo[i] = f(i) return result return main @memoize def fibonacci(i): return fibonacci(i - 1) + fibonacci(i - 2) print(fibonacci(n))
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A&lang=ja import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): n = int(readline()) dp = [0] * (n+1) dp[0] = 1 dp[1] = 1 for i in range(2,n+1): dp[i] = dp[i-1] + dp[i-2] print(dp[n]) if __name__ == "__main__": main()
1
1,650,594,848
null
7
7
# coding: UTF-8 import sys import numpy as np # f = open("input.txt", "r") # sys.stdin = f s = str(input()) t = str(input()) ans = 0 for i, j in zip(s,t): if i != j: ans += 1 print(ans)
ans=0 for i,j in zip(input(),input()): if i!=j:ans+=1 print(ans)
1
10,527,954,560,790
null
116
116
import sys input = sys.stdin.readline ''' ''' s = input().rstrip() if s == "MON": print(6) elif s == "SAT": print(1) elif s == "FRI": print(2) elif s == "THU": print(3) elif s == "WED": print(4) elif s == "TUE": print(5) else: print(7)
s = input() dl = ["SUN","MON","TUE","WED","THU","FRI","SAT"] for i in range(7): if s == dl[i]: print(7-i)
1
132,801,244,815,372
null
270
270
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, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * #階乗# lim = 10**6 #必要そうな階乗の限界を入力 fact = [1] * (lim+1) for n in range(1, lim+1): fact[n] = n * fact[n-1] % mod #階乗の逆元# fact_inv = [1]*(lim+1) fact_inv[lim] = pow(fact[lim], mod-2, mod) for n in range(lim, 0, -1): fact_inv[n-1] = n*fact_inv[n]%mod def C(n, r): return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod X, Y = MAP() a = (Decimal("2")*Decimal(str(X))-Decimal(str(Y)))/Decimal("3") b = (Decimal("2")*Decimal(str(Y))-Decimal(str(X)))/Decimal("3") if a%1 == b%1 == 0 and 0 <= a and 0 <= b: print(C(int(a+b), int(a))) else: print(0)
n = int(input()) s = input() res = "No" if n%2 == 0 and s[:n//2] *2 ==s:res ="Yes" print(res)
0
null
148,254,425,725,462
281
279
import sys from bisect import bisect_left input = sys.stdin.readline def main(): N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for a in range(N - 2): for b in range(a + 1, N - 1): x = bisect_left(L, L[a] + L[b]) ans += (x - 1 - b) print(ans) if __name__ == "__main__": main()
def main(): N = int(input()) zoro = [] for i in range(N): a, b = map(int, input().split()) if a == b: zoro.append(1) if i >= 2: if zoro[i-2] == zoro[i-1] and zoro[i-1] == zoro[i]: print('Yes') return else: zoro.append(0) print('No') main()
0
null
86,800,518,221,332
294
72
N=int(input()) def cf(n): a=[] for f in range(1,int(n**(1/2)+1)): if n%f==0: a.append(f) if n//f!=f: a.append(n//f) return a def pf(n): a=[] while n%2==0: a.append(2) n//=2 f=3 while f*f<=n: if n%f==0: a.append(f) n//=f else: f+=2 if n!=1: a.append(n) return sorted(a) def main(): c,p,t=1,N+1,1 for f in pf(N-1): if p==f: t+=1 else: c*=t t=2 p=f c=c*t-1 for f in cf(N): t=N if f!=1: while t%f==0: t//=f if t%f==1: c+=1 print(c) main()
N = int(input()) if N == 2: print(1) exit() def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+100): if i > temp / i: break if i * i == temp: arr.append(i) break if temp % i == 0: arr.append(i) arr.append(temp // i) arr.append(n) return arr N_div = factorization(N) N_1_div = factorization(N-1) ans = len(N_1_div) for K in N_div: temp = N while temp % K == 0: temp = temp // K if temp % K == 1: ans += 1 print(ans)
1
41,428,390,617,558
null
183
183
D, T, S = list(map(int, input().split())) if D <= S * T: print("Yes") else: print("No")
n = int(input()) ans = 1 while ans <= n: ans *= 2 print(ans -1)
0
null
41,988,282,334,270
81
228