s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s033496595
p04017
u141610915
1584206212
Python
PyPy3 (2.4.0)
py
Runtime Error
1443
254664
780
import sys from bisect import bisect_left as bl input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) L = int(input()) k = 0 while a[-1] // (L * pow(2, k)): k += 1 e = [[0] * (k + 1) for _ in range(N)] for i in range(N): t = L + a[i] ok = i ng = N while ng - ok > 1: m = (ok + ng) // 2 if a[m] <= t: ok = m else: ng = m e[i][0] = ok for j in range(len(e[i]) - 1): for i in range(N): x = e[i][j] e[i][j + 1] = e[x][j] print(e) def doubling(u, v): if u == v: return 0 x = bl(e[u], v) x = max(0, x - (e[u][x] == N - 1)) #print(u, v, x) return doubling(e[u][x], v) + pow(2, x) Q = int(input()) for _ in range(Q): x, y = map(int, input().split()) x -= 1 y -= 1 if x > y: x, y = y, x print(doubling(x, y))
s030416225
p04017
u141610915
1584205715
Python
PyPy3 (2.4.0)
py
Runtime Error
3179
368624
775
import sys from bisect import bisect_left as bl input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) N = int(input()) a = list(map(int, input().split())) L = int(input()) k = 0 while a[-1] // (L * pow(2, k)): k += 1 e = [[0] * (k + 1) for _ in range(N)] for i in range(N): t = L + a[i] ok = i ng = N while ng - ok > 1: m = (ok + ng) // 2 if a[m] <= t: ok = m else: ng = m e[i][0] = ok for j in range(len(e[i]) - 1): for i in range(N): x = e[i][j] e[i][j + 1] = e[x][j] #print(e) def doubling(u, v): if u == v: return 0 x = bl(e[u], v) #print(u, v, x) return doubling(e[u][x], v) + pow(2, x) Q = int(input()) for _ in range(Q): x, y = map(int, input().split()) x -= 1 y -= 1 if x > y: x, y = y, x print(doubling(x, y))
s392838465
p04017
u141610915
1584205622
Python
PyPy3 (2.4.0)
py
Runtime Error
456
80152
743
import sys from bisect import bisect_left as bl input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) L = int(input()) k = 0 while a[-1] // (L * pow(2, k)): k += 1 e = [[0] * (k + 1) for _ in range(N)] for i in range(N): t = L + a[i] ok = i ng = N while ng - ok > 1: m = (ok + ng) // 2 if a[m] <= t: ok = m else: ng = m e[i][0] = ok for j in range(len(e[i]) - 1): for i in range(N): x = e[i][j] e[i][j + 1] = e[x][j] #print(e) def doubling(u, v): if u == v: return 0 x = bl(e[u], v) #print(u, v, x) return doubling(e[u][x], v) + pow(2, x) Q = int(input()) for _ in range(Q): x, y = map(int, input().split()) x -= 1 y -= 1 if x > y: x, y = y, x print(doubling(x, y))
s728297907
p04017
u828766688
1579285318
Python
PyPy3 (2.4.0)
py
Runtime Error
437
92824
1460
import bisect def wantp(p,day,db): for i in range(len(db)): i = len(db)-1-i if day & (2 ** i) > 0: p = db[i][p] return p N = int(input()) x = list(map(int,input().split())) L = int(input()) able = [] for i in range(N): able.append(bisect.bisect_right(x,x[i] + L) - 1) #print (able) db = [able] while min(db[-1]) != N-1: new = [] for i in range(N): new.append(db[-1][db[-1][i]]) db.append(new) db1 = db.copy() for i in range(N): x[i] = x[-1] - x[i] x.reverse() #print (x) able = [] for i in range(N): able.append(bisect.bisect_right(x,x[i] + L) - 1) db = [able] while min(db[-1]) != N-1: new = [] for i in range(N): new.append(db[-1][db[-1][i]]) db.append(new) db2 = db #print (db2) Q = int(input()) for loop in range(Q): a,b = map(int,input().split()) a -= 1 b -= 1 if a < b: l = 0 r = N+1 while r-l != 1: m = (l+r) // 2 np = wantp(a,m,db1) #print (a,m,np) if np < b: l = m else: r = m print (r) else: a = N-1-a b = N-1-b l = 0 r = N+1 while r-l != 1: m = (l+r) // 2 np = wantp(a,m,db2) #print (a,m,np) if np < b: l = m else: r = m print (r)
s888194709
p04017
u803848678
1570062011
Python
PyPy3 (2.4.0)
py
Runtime Error
1005
99608
873
from bisect import bisect_right n = int(input()) x = list(map(int, input().split())) l = int(input()) depth = [-1]*n depth[-1] = 0 m = 18 par = [[-1]*n for i in range(m)] def dfs(i): if depth[i] >= 0: return depth[i] j = bisect_right(x, x[i]+l)-1 if j >= n: j = n-1 par[0][i] = j depth[i] = dfs(j) + 1 return depth[i] for i in range(n): dfs(i) for i in range(17): for j in range(n): par[i+1][j]=par[i][par[i][j]] def hoge(x, y): # xからk個上の頂点がy以上になる最小のkを求める k = 0 for i in range(18)[::-1]: if 0 <= par[i][x] <= y: k += 1<<i x = par[i][x] return k q = int(input()) ans = [] for i in range(q): a,b = map(int, input().split()) a,b = a-1,b-1 if a > b: a,b = b,a ans.append(hoge(a, b)) print(*ans, sep="\n")
s732070448
p04017
u039623862
1569630235
Python
Python (3.4.3)
py
Runtime Error
1792
42744
885
import bisect import math n = int(input()) x = list(map(int, input().split())) l = int(input()) max_pow = math.ceil(math.log2(x[-1]//l))+1 next_hotel = [[i for j in range(max_pow+1)] for i in range(n)] head = 1 tail = 0 while head < n: if x[tail]+l < x[head]: next_hotel[tail][1] = head-1 tail += 1 else: head += 1 else: for i in range(tail, n): next_hotel[i][1] = n-1 for i in range(1, max_pow): b = 2**i for j in range(n-1): next_hotel[j][i+1] = next_hotel[next_hotel[j][i]][i] q = int(input()) for _ in range(q): a, b = map(int, input().split()) a -= 1 b -= 1 if a > b: a, b = b, a total = 0 while a < b: t = bisect.bisect_left(next_hotel[a], b) if t == 0: break else: total += 2**(t-1) a = next_hotel[a][t] print(total)
s717196953
p04017
u389910364
1568167779
Python
Python (3.4.3)
py
Runtime Error
3163
68564
1989
import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N = int(sys.stdin.readline()) X = list(map(int, sys.stdin.readline().split())) L = int(sys.stdin.readline()) Q = int(sys.stdin.readline()) AB = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)] N += 2 X = [X[0]] + X + [X[-1]] X = np.array(X, dtype=int) # rdp[d][i]: i番のホテルから(2^d)日で何個右までいけるか rdp = np.zeros((N.bit_length(), N), dtype=int) rdp[0] = np.searchsorted(X, X + L, side='right') - np.arange(N) - 1 for d in range(1, N.bit_length()): rdp[d] = rdp[d - 1] + rdp[d - 1][np.arange(N) + rdp[d - 1]] X = -X[::-1] # ldp[d][i]: i番のホテルから(2^d)日で何個左までいけるか ldp = np.zeros((N.bit_length(), N), dtype=int) ldp[0] = np.searchsorted(X, X + L, side='right') - np.arange(N) - 1 for d in range(1, N.bit_length()): ldp[d] = ldp[d - 1] + ldp[d - 1][np.arange(N) + ldp[d - 1]] # print(rdp) # print(ldp) def solver(l, r): ret = 0 while l < r: d = np.searchsorted(rdp[:, l], r - l) if rdp[d, l] == r - l: ret += 2 ** d break if d > 0: d -= 1 ret += 2 ** d l += rdp[d, l] return ret def solvel(l, r): r = N - r - 1 l = N - l - 1 ret = 0 while l < r: d = np.searchsorted(ldp[:, l], r - l) if ldp[d, l] == r - l: ret += 2 ** d break if d > 0: d -= 1 ret += 2 ** d l += ldp[d, l] return ret # print(np.searchsorted([1, 2, 5, 8, 9], 3)) # print(np.searchsorted([1, 2, 5, 8, 9], 4)) # print(np.searchsorted([1, 2, 5, 8, 9], 5)) # print(np.searchsorted([1, 2, 5, 8, 9], 6)) # print(np.searchsorted([1, 2, 5, 8, 9], 7)) # print() for a, b in AB: if a < b: r = solver(a, b) else: r = solvel(a, b) print(r)
s283074809
p04017
u389910364
1568167710
Python
Python (3.4.3)
py
Runtime Error
3166
67812
1996
import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N = int(sys.stdin.readline()) X = list(map(int, sys.stdin.readline().split())) L = int(sys.stdin.readline()) Q = int(sys.stdin.readline()) AB = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)] N += 1 X.append(X[-1]) X = np.array(X, dtype=int) # rdp[d][i]: i番のホテルから(2^d)日で何個右までいけるか rdp = np.zeros((N.bit_length(), N), dtype=int) rdp[0] = np.searchsorted(X, X + L, side='right') - np.arange(N) - 1 for d in range(1, N.bit_length()): rdp[d] = rdp[d - 1] + rdp[d - 1][np.arange(N) + rdp[d - 1]] X = -X[::-1] # ldp[d][i]: i番のホテルから(2^d)日で何個左までいけるか ldp = np.zeros((N.bit_length(), N), dtype=int) ldp[0] = np.searchsorted(X, X + L, side='right') - np.arange(N) - 1 for d in range(1, N.bit_length()): ldp[d] = ldp[d - 1] + ldp[d - 1][np.arange(N) + ldp[d - 1]] # print(rdp) # print(ldp) def solver(l, r): ret = 0 while l < r: d = np.searchsorted(rdp[:, l], r - l) if rdp[d, l] == r - l: ret += 2 ** d break if d > 0: d -= 1 ret += 2 ** d l += rdp[d, l] return ret def solvel(l, r): r = N - r - 1 l = N - l - 1 ret = 0 while l < r: d = np.searchsorted(ldp[:, l], r - l) if ldp[d, l] == r - l: ret += 2 ** d break if d > 0: d -= 1 ret += 2 ** d l += ldp[d, l] return ret # print(np.searchsorted([1, 2, 5, 8, 9], 3)) # print(np.searchsorted([1, 2, 5, 8, 9], 4)) # print(np.searchsorted([1, 2, 5, 8, 9], 5)) # print(np.searchsorted([1, 2, 5, 8, 9], 6)) # print(np.searchsorted([1, 2, 5, 8, 9], 7)) # print() for a, b in AB: if a < b: r = solver(a - 1, b - 1) else: r = solvel(a - 1, b - 1) print(r)
s169688647
p04017
u389910364
1568166716
Python
Python (3.4.3)
py
Runtime Error
3162
66420
1866
import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N = int(sys.stdin.readline()) X = list(map(int, sys.stdin.readline().split())) L = int(sys.stdin.readline()) Q = int(sys.stdin.readline()) AB = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)] X = np.array(X, dtype=int) # rdp[d][i]: i番のホテルから(2^d)日で何個右までいけるか rdp = np.zeros((N.bit_length(), N), dtype=int) rdp[0] = np.searchsorted(X, X + L, side='right') - np.arange(N) - 1 for d in range(1, N.bit_length()): rdp[d] = rdp[d - 1] + rdp[d - 1][np.arange(N) + rdp[d - 1]] X = -X[::-1] # ldp[d][i]: i番のホテルから(2^d)日で何個左までいけるか ldp = np.zeros((N.bit_length(), N), dtype=int) ldp[0] = np.searchsorted(X, X + L, side='right') - np.arange(N) - 1 for d in range(1, N.bit_length()): ldp[d] = ldp[d - 1] + ldp[d - 1][np.arange(N) + ldp[d - 1]] # print(rdp) # print(ldp) def solver(l, r): ret = 0 while l < r: d = np.searchsorted(rdp[:, l], r - l) if d > 0 and rdp[d, l] > r - l: d -= 1 ret += 2 ** d l += rdp[d, l] return ret def solvel(l, r): r = N - r - 1 l = N - l - 1 ret = 0 while l < r: d = np.searchsorted(ldp[:, l], r - l) if d > 0 and ldp[d, l] > r - l: d -= 1 ret += 2 ** d l += ldp[d, l] return ret # print(np.searchsorted([1, 2, 5, 8, 9], 3)) # print(np.searchsorted([1, 2, 5, 8, 9], 4)) # print(np.searchsorted([1, 2, 5, 8, 9], 5)) # print(np.searchsorted([1, 2, 5, 8, 9], 6)) # print(np.searchsorted([1, 2, 5, 8, 9], 7)) # print() for a, b in AB: if a < b: r = solver(a - 1, b - 1) else: r = solvel(a - 1, b - 1) print(r)
s546454449
p04017
u729133443
1564460562
Python
PyPy3 (2.4.0)
py
Runtime Error
3529
554888
353
from bisect import* r=range n,*t=map(int,open(0).read().split()) m=2**16 x=t[:n] d=[[bisect(x,y+t[n])-1for y in x]]+[[0]*n for _ in r(m)] for i in r(m): for j in r(n): d[i+1][j]=d[i][d[i][j]] for a,b in zip(t[n+2::2],t[n+3::2]): a-=1 b-=1 if b<a:a,b=b,a c=1 for i in r(m,-1,-1): if d[i][a]<b: a=d[i][a] c+=2**i print(c)
s536197496
p04017
u729133443
1564460375
Python
PyPy3 (2.4.0)
py
Runtime Error
3550
555528
348
from bisect import* r=range n,*t=map(int,open(0).read().split()) m=2**16 x=t[:n] d=[[bisect(x,y+t[n])-1for y in x]]+[[0]*n for _ in r(m)] for i in r(m): for j in r(n): d[i+1][j]=d[i][d[i][j]] for a in zip(t[n+2::2],t[n+3::2]): a,b=sorted(i-1for i in a) c=1 for i in r(m,-1,-1): if d[i][a]<b: a=d[i][a] c+=2**i print(c)
s995795486
p04017
u729133443
1564459273
Python
PyPy3 (2.4.0)
py
Runtime Error
296
103308
426
from math import* from bisect import* n,*t=map(int,open(0).read().split()) m=int(log2(n))+1 x=t[:n] l=t[n] d=[[bisect(x,y+l)-1for y in x]]+[[0]*n for _ in range(m)] for i in range(m): for j in range(n): d[i+1][j]=d[i][d[i][j]] for a,b in zip(t[n+2::2],t[n+3::2]): a-=1 b-=1 if b<a:a,b=b,a c=1 for i in range(m,-1,-1): if d[i][a]<b: a=d[i][a] c+=2**i print(c)
s633504495
p04017
u537859408
1562658070
Python
Python (3.4.3)
py
Runtime Error
17
2940
1201
#include <bits/stdc++.h> #define FOR(i,a,b) for (int i=(a);i<(b);++i) #define REP(i,n) for (int i=0;i<(n);++i) #define RREP(i,n) for (int i=(n)-1;i>=0;--i) #define all(a) (a).begin(),(a).end() using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, L, Q; cin >> N; vector<int> x(N); REP(i, N) cin >> x[i]; cin >> L >> Q; int K = 31 - __builtin_clz(N - 1); // floor(log(max(b - a))) vector<vector<int>> dp(N, vector<int>(K + 1)); REP(i, N) { dp[i][0] = distance(x.begin(), upper_bound(all(x), x[i] + L)) - 1; //printf("dp[%d][0] = %d\n", i, dp[i][0]); } FOR(j, 1, K + 1) REP(i, N) { dp[i][j] = dp[dp[i][j - 1]][j - 1]; } REP(_, Q) { int a, b; cin >> a >> b; --a; --b; if (a > b) { swap(a, b); } int result = 0; RREP(i, K + 1) { if (dp[a][i] < b) { //printf("from x[%d] to x[%d] in %d days\n", a, dp[a][i], 1 << i); a = dp[a][i]; result += 1 << i; } } ++result; cout << result << '\n'; } cout << flush; return 0; }
s369797488
p04017
u340781749
1557809453
Python
Python (3.4.3)
py
Runtime Error
3164
210172
593
import sys from bisect import bisect_left, bisect_right from functools import lru_cache sys.setrecursionlimit(10 ** 5 + 1) @lru_cache(maxsize=None) def solve(l, r): if l >= r: return 0 return solve(rightmost[l], r) + 1 n = int(input()) xxx = list(map(int, input().split())) l = int(input()) rightmost = [] for x in xxx: rightmost.append(bisect_right(xxx, x + l) - 1) buf = [] q = int(input()) for line in sys.stdin: a, b = map(int, line.split()) a -= 1 b -= 1 if a > b: a, b = b, a buf.append(solve(a, b)) print('\n'.join(map(str, buf)))
s431405392
p04017
u340781749
1557809392
Python
Python (3.4.3)
py
Runtime Error
1223
72128
557
import sys from bisect import bisect_left, bisect_right from functools import lru_cache @lru_cache(maxsize=None) def solve(l, r): if l >= r: return 0 return solve(rightmost[l], r) + 1 n = int(input()) xxx = list(map(int, input().split())) l = int(input()) rightmost = [] for x in xxx: rightmost.append(bisect_right(xxx, x + l) - 1) buf = [] q = int(input()) for line in sys.stdin: a, b = map(int, line.split()) a -= 1 b -= 1 if a > b: a, b = b, a buf.append(solve(a, b)) print('\n'.join(map(str, buf)))
s141222912
p04017
u585482323
1552761155
Python
PyPy3 (2.4.0)
py
Runtime Error
1075
104220
1794
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): return #B def B(): return #C def C(): n = I() x = LI() l = I() k = int(math.log(n,2)) f = [[i for j in range(k+1)] for i in range(n)] for i in range(n-1): j = bisect.bisect_left(x,x[i]+l) if j < n: if x[j] > x[i]+l: f[i][0] = j-1 else: f[i][0] = j else: f[i][0] = j-1 po2 = [1]*(k+1) for i in range(k): po2[i+1] = po2[i]*2 for j in range(k): for i in range(n): f[i][j+1] = f[f[i][j]][j] q = I() for i in range(q): a,b = LI() a,b = [min(a,b)-1, max(a,b)-1] ans = 0 while a < b: i = bisect.bisect_left(f[a],b) ans += po2[i] if f[a][i] == b: break a = f[a][i-1] print(ans) #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": C()
s223282311
p04017
u585482323
1552760843
Python
PyPy3 (2.4.0)
py
Runtime Error
3161
93056
1855
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): return #B def B(): return #C def C(): n = I() x = LI() l = I() k = int(math.log(n,2)) f = [[i for j in range(k+1)] for i in range(n)] for i in range(n-1): j = bisect.bisect_left(x,x[i]+l) if j < n: if x[j] > x[i]+l: f[i][0] = j-1 else: f[i][0] = j else: f[i][0] = j-1 po2 = [1]*(k+1) for i in range(k): po2[i+1] = po2[i]*2 for j in range(k): for i in range(n): f[i][j+1] = f[f[i][j]][j] q = I() for i in range(q): a,b = LI() a,b = [min(a,b)-1, max(a,b)-1] ans = 0 while 1: i = bisect.bisect_left(f[a],b) if f[f[a][i-1]][0] < b < f[a][i] or f[a][i] == b: ans += po2[i] break ans += po2[i-1] a = f[a][i-1] print(ans) #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": C()
s328224300
p04017
u585482323
1552760183
Python
PyPy3 (2.4.0)
py
Runtime Error
3162
89020
1822
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): return #B def B(): return #C def C(): n = I() x = LI() l = I() k = int(math.log(n,2)) f = [[i for j in range(k+1)] for i in range(n)] for i in range(n-1): j = bisect.bisect_left(x,x[i]+l) if j < n: if x[j] > x[i]+l: f[i][0] = j-1 else: f[i][0] = j else: f[i][0] = j-1 po2 = [1]*(k+1) for i in range(k): po2[i+1] = po2[i]*2 for j in range(k): for i in range(n): f[i][j+1] = f[f[i][j]][j] q = I() for i in range(q): a,b = LI() a,b = [min(a,b)-1, max(a,b)-1] ans = 0 while 1: i = bisect.bisect_left(f[a],b) if f[a][i] == b: ans += po2[i] break ans += po2[i-1] a = f[a][i-1] print(ans) #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": C()
s876456479
p04017
u585482323
1552759234
Python
PyPy3 (2.4.0)
py
Runtime Error
3163
102692
1917
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): return #B def B(): return #C def C(): n = I() x = LI() l = I() k = int(math.log(n,2)) f = [[i for j in range(k+1)] for i in range(n)] for i in range(n-1): j = bisect.bisect_left(x,x[i]+l) if j < n: if x[j] > x[i]+l: f[i][0] = j-1 else: f[i][0] = j else: f[i][0] = j-1 po2 = [1]*(k+1) for i in range(k): po2[i+1] = po2[i]*2 for j in range(1,k+1): for i in range(n): f[i][j] = f[f[i][j-1]][j-1] q = I() for i in range(q): a,b = LI() a,b = [min(a,b)-1, max(a,b)-1] i = 0 while x[f[a][i]] < x[b]: i += 1 if x[f[a][i]] == x[b]: print(po2[i]) else: ans = po2[i] s = f[f[a][i-1]][0] g = f[b][0] while s < g: s = f[s][0] ans += 1 print(ans) #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": C()
s749318649
p04017
u218843509
1551328754
Python
Python (3.4.3)
py
Runtime Error
3287
1874532
1114
from bisect import bisect, bisect_left import sys n = int(input()) x = list(map(int, input().split())) l = int(input()) def search_1(start): return bisect(x, x[start] + l) - 1 route = [[] for _ in range(n)] i = 0 # 親の位置 for i in range(n - 1): if route[i] == []: j = search_1(i) # カーソルの位置 num = 1 # 何日目の場所か route[i].append(j) if route[j] == []: route[j] = (i, num) else: # 既に他の親が通っている route[i] += route[route[j][0]][route[j][1]:] continue while j < n - 1: j = search_1(j) num += 1 route[i].append(j) if route[j] == []: route[j] = (i, num) else: # 既に他の親が通っている route[i] += route[route[j][0]][route[j][1]:] break else: continue # print(route) def search_2(start, goal): if type(route[start]) == type([]): return bisect_left(route[start], goal) + 1 else: return bisect_left(route[route[start][0]][route[start][1]:], goal) + 1 q = int(input()) for _ in range(q): a, b = map(int, sys.stdin.redline().strip().split()) if a > b: a, b = b, a print(search_2(a - 1, b - 1))
s315859914
p04017
u062147869
1550810519
Python
PyPy3 (2.4.0)
py
Runtime Error
761
85536
863
import sys input = sys.stdin.readline from bisect import bisect N=int(input()) X=[int(i) for i in input().split()] L=int(input()) Q=int(input()) #T=[[int(i) for i in input().split()] for i in range(Q)] T=[] for i in range(Q): a,b=map(int,input().split()) if a>b: a,b=b,a T.append((a-1,b-1)) F=[0]*N for i in range(N): F[i]= bisect(X, X[i] + L) -1 #print(F) dp=[ [N-1] * (N) for i in range(17)] for i in range(N): #dp[0][i]=i dp[0][i]=F[i] for c in range(1,17): for i in range(N): dp[c][i] = dp[c-1][ dp[c-1][i] ] #print(dp) def f(a,b): num=0 t = a while True: for i in range(17): if dp[i][t]>=b: s=i break if s==0: num+=1 break num += pow(2, s - 1) t = dp[s-1][t] print(num) for a,b in T: f(a,b)
s624024170
p04017
u165829407
1540154345
Python
Python (2.7.6)
py
Runtime Error
10
2568
2275
#include <map> #include <set> #include <cmath> #include <ctime> #include <queue> #include <stack> #include <vector> #include <bitset> #include <cstdio> #include <cctype> #include <string> #include <cstring> #include <cassert> #include <climits> #include <cstdlib> #include <iostream> #include <algorithm> #include <functional> using namespace std ; #define rep(i, a, b) for (int (i)=(a);(i)<=(b);(i)++) #define Rep(i, a, b) for (int (i)=(a)-1;(i)<(b);(i)++) #define REP(i, a, b) for (int (i)=(a);(i)>=(b);(i)--) #define reg(i, x) for (int (i)=head[x];(i);i=e[i].next) #define clr(a) memset(a,0,sizeof(a)) #define Sort(a, len) sort(a + 1, a + len + 1) #define Sort2(a, len, cmp) sort(a + 1, a + len + 1, cmp) #define ass(a, sum) memset(a, sum, sizeof(a)) #define ull unsigned long long #define ll long long #define ls ((rt) << 1) #define rs ((rt) << 1 | 1) #define mp make_pair #define pb push_back #define fi first #define se second #define endl '\n' #define Pii pair<int, int> const int N = 25000 ; const int iinf = INT_MAX/2 ; const ll linf = LLONG_MAX/2 ; const int MOD = 1e9+7 ; inline int read(){ int X = 0,w = 0 ; char ch = 0; while(!isdigit(ch)) {w |= ch == '-';ch = getchar();} while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar(); return w ? -X : X; } void write(int x){ if(x < 0) putchar('-'),x = -x; if(x > 9) write(x / 10); putchar(x%10 + '0'); } void print(int x) { cout << x << endl ; exit(0) ; } void douout(double x){ printf("%lf\n", x + 0.0000000001) ; } ll n,m,x,y,k,num[110],h,dp[N],cnt,d2[N],ans; int main(){ ll i,j; cin>>n>>k; for(i=1;i<=n;i++) scanf("%lld",&num[i]); sort(num+1,num+n+1); dp[0]=d2[0]=1; for(i=1;num[i]<k&&i<=n;i++){ num[i]=k-num[i]; for(j=3000;j>=num[i];j--) dp[j]+=dp[j-num[i]]; } for(;num[i]==k&&i<=n;i++) cnt++; for(;i<=n;i++){ num[i]-=k; for(j=3000;j>=num[i];j--) d2[j]+=d2[j-num[i]]; } for(i=0;i<=3000;i++) ans+=dp[i]*d2[i]*(1ll << cnt); cout<<ans-1; } /* 写代码时请注意: 1.是否要开Long Long?数组边界处理好了么? 2.特殊情况处理好了么? 3.做一些总比不做好。 4.最大值和最小值问题可不可以用二分答案? 5.有没有贪心策略?否则能不能dp? 6.实数精度有没有处理? */
s748557338
p04017
u218843509
1532499976
Python
PyPy3 (2.4.0)
py
Runtime Error
3501
868964
1084
from bisect import bisect, bisect_left n = int(input()) x = list(map(int, input().split())) l = int(input()) def search_1(start): return bisect(x, x[start] + l) - 1 route = [[] for _ in range(n)] i = 0 # 親の位置 for i in range(n - 1): if route[i] == []: j = search_1(i) # カーソルの位置 num = 1 # 何日目の場所か route[i].append(j) if route[j] == []: route[j] = (i, num) else: # 既に他の親が通っている route[i] += route[route[j][0]][route[j][1]:] continue while j < n - 1: j = search_1(j) num += 1 route[i].append(j) if route[j] == []: route[j] = (i, num) else: # 既に他の親が通っている route[i] += route[route[j][0]][route[j][1]:] break else: continue # print(route) def search_2(start, goal): if type(route[start]) == type([]): return bisect_left(route[start], goal) + 1 else: return bisect_left(route[route[start][0]][route[start][1]:], goal) + 1 q = int(input()) for _ in range(q): a, b = map(int, input().split()) if a > b: a, b = b, a print(search_2(a - 1, b - 1))
s813590023
p04017
u415905784
1532406800
Python
Python (3.4.3)
py
Runtime Error
578
30316
552
N = int(input()) X = [int(x) for x in input().split()] L = int(input()) Q = int(input()) query = [[int(x) - 1 for x in input().split()] for i in range(Q)] H = [0 for i in range(N)] X.append(10 ** 9 + L + 1) s = 0 t = 1 while t < N: while X[t] - X[s] <= L: t += 1 H[s] = t - 1 s += 1 while s < N - 1: if X[t] - X[s] > L: H[s] = t - 1 s += 1 else: break def travel(a, b, k): if H[a] >= b: return k + 1 else: return travel(H[a], b, k + 1) for q in query: a = min(q) b = max(q) print(travel(a, b, 0))
s738085224
p04017
u817026203
1524370699
Python
PyPy3 (2.4.0)
py
Runtime Error
1688
119792
1060
def main(): n = int(input()) xs = [int(c) for c in input().split()] l = int(input()) xs.append(10 ** 17) nexts = list(range(n)) for fr in range(n): p, q = fr, n while q - p > 1: m = (p + q) // 2 if xs[m] - xs[fr] <= l: p = m else: q = m nexts[fr] = p doubling = [nexts] for _ in range(20): base = doubling[-1] nexts = [base[base_next] for base_next in base] doubling.append(nexts) def query(fr, to): if fr == to: return 0 p, q = 0, 20 while q - p > 1: m = (p + q) // 2 if doubling[m][fr] > to: q = m else: p = m return query(doubling[p][fr], to) + 2 ** p q_count = int(input()) for _ in range(q_count): a, b = map(int, input().split()) if a > b: a, b = b, a a -= 1 b -= 1 print(query(a, b)) if __name__ == '__main__': main()
s113495223
p04017
u226155577
1518721232
Python
Python (3.4.3)
py
Runtime Error
2042
37792
747
# seishin.py N = int(input()) *X, = map(int, input().split()) L = int(input()) K = N.bit_length() D = [[-1] for i in range(N)] j = N-1 for i in range(N-1, -1, -1): while j > 0 and X[j] - X[i] > L: j -= 1 D[i][0] = j v = 2 for k in range(K): for i in range(N-v): if i + v < N and len(D[D[i][k]]) == k+1: D[i].append(D[D[i][k]][k]) v <<= 1 def solve(a, b): if not a < b: a, b = b, a res = 1 v = 2**K for k in range(K, -1, -1): if a + v < N-1 and D[a][k] < b: a = D[a][k] res += v v >>= 1 return res Q = int(input()) ans = [] for i in range(Q): a, b = map(int, input().split()) ans.append(solve(a-1, b-1)) print(*ans, sep='\n')
s353701610
p04017
u132291455
1476811179
Python
Python (2.7.6)
py
Runtime Error
1499
43244
882
import bisect import sys import math import itertools sys.setrecursionlimit(10000) INF = float('inf') # input macro def i(): return int(raw_input()) def ii(): return map(int,raw_input().split(" ")) def s(): return raw_input() def ss(): return raw_input().split(" ") def slist(): return list(raw_input()) def join(s): return ''.join(s) ########### n=i() x=ii() l=i() q=i() a,b=[0]*q,[0]*q for j in range(q): aa,bb=ii() a[j],b[j]=min(aa,bb)-1,max(aa,bb)-1 table=[[0 for i in range(n)] for j in range(32)] for k in range(n): table[0][k]=bisect.bisect_right(x,x[k]+l)-1 for j in range(1,32): for k in range(n): table[j][k]=table[j-1][table[j-1][k]] for j in range(q): day=0 cur=a[j] for k in reversed(range(32)): if table[k][cur]<=b[j]: day=(day+2**k)%mod cur=table[k][cur] print day
s366133349
p04017
u509661905
1472436149
Python
PyPy3 (2.4.0)
py
Runtime Error
503
47984
698
#!/usr/bin/env pypy3 MAX_N = 10 ** 3 MAX_Q = 10 ** 3 def answer_query(ds, l, a, b): if a > b: a, b = b, a allowed_dist = l ans = 1 for d in ds[a:b]: if allowed_dist >= d: allowed_dist -= d else: allowed_dist = l - d ans += 1 return ans def main(): n = int(input()) assert n <= MAX_N xs = list(map(int, input().split())) ds = [xj - xi for xi, xj in zip(xs[:-1], xs[1:])] l = int(input()) q = int(input()) assert q <= MAX_Q for _ in range(q): a, b = map(lambda x: int(x) - 1, input().split()) print(answer_query(ds, l, a, b)) if __name__ == '__main__': main()
s264726530
p04018
u378667182
1584837562
Python
Python (3.4.3)
py
Runtime Error
1514
26500
611
w=list(input()) n=len(w) per=-1 def Z(s): m=len(s);z=[0]*m;c=0;f=[1]*m; for i in range(1,m): if i+z[i-c]<c+z[c]:z[i]=z[i-c] else: j=max(0,c+z[c]-i) while i+j<n and s[j]==s[i+j]:j=j+1 z[i]=j;c=i for p in range(1,m): for k in range(2,z[p]//p+2):f[k*p-1]=0 return f for j in range(1,n//2+1): if n%j==0 and w[:n-j]==w[j:]:t=j;break; if t==-1:print ('1\n1') elif t==1:print (n);print (1) else: zl=Z(w) w.reverse() zr=Z(w) cnt=0 for i in range(0,n-1): if zl[i] and zr[n-2-i]:cnt=cnt+1 print(2);print(cnt);
s113007763
p04018
u102461423
1572167010
Python
Python (3.4.3)
py
Runtime Error
907
38392
1078
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines W = list(map(int,read().rstrip())) N = len(W) def Z_Algorithm(S): # 共通接頭辞の長さを返す N=len(S) arr = [0]*N arr[0] = N i,j = 1,0 while i<N: while i+j<N and S[j]==S[i+j]: j += 1 arr[i]=j if not j: i += 1 continue k = 1 while i+k<N and k+arr[k]<j: arr[i+k] = arr[k] k += 1 i += k; j -= k return arr def find_good_substr(W): Z = Z_Algorithm(W) is_good = [True]*N for n in range(1,N//2+1): # n文字での周期をもってくる if not is_good[n]: continue for i in range(n+n-1,Z[n]+n,n): is_good[i] = False return is_good def solve(): G1 = find_good_substr(W) G2 = find_good_substr(W[::-1]) if G1[-1]: # 自分自身がoptimal return 1,1 if len(set(W)) == 1: return N,1 x,y = solve() print(x) print(y)
s825718842
p04018
u102461423
1572166905
Python
Python (3.4.3)
py
Runtime Error
895
38392
1034
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines W = list(map(int,read().rstrip())) N = len(W) def Z_Algorithm(S): # 共通接頭辞の長さを返す N=len(S) arr = [0]*N arr[0] = N i,j = 1,0 while i<N: while i+j<N and S[j]==S[i+j]: j += 1 arr[i]=j if not j: i += 1 continue k = 1 while i+k<N and k+arr[k]<j: arr[i+k] = arr[k] k += 1 i += k; j -= k return arr def find_good_substr(W): Z = Z_Algorithm(W) is_good = [True]*N for n in range(1,N//2+1): # n文字での周期をもってくる if not is_good[n]: continue for i in range(n+n-1,Z[n]+n,n): is_good[i] = False return is_good def solve(): G1 = find_good_substr(W) G2 = find_good_substr(W[::-1]) if G1[-1]: # 自分自身がoptimal return 1,1 x,y = solve() print(x) print(y)
s572828841
p04018
u102461423
1572166535
Python
Python (3.4.3)
py
Runtime Error
1610
38392
1037
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines W = list(map(int,read().rstrip())) N = len(W) def Z_Algorithm(S): # 共通接頭辞の長さを返す N=len(S) arr = [0]*N arr[0] = N i,j = 1,0 while i<N: while i+j<N and S[j]==S[i+j]: j += 1 arr[i]=j if not j: i += 1 continue k = 1 while i+k<N and k+arr[k]<j: arr[i+k] = arr[k] k += 1 i += k; j -= k return arr def find_good_substr(W): Z = Z_Algorithm(W) is_good = [True]*N for n in range(1,(N+1)//2): # n文字での周期をもってくる L=Z[n] if L<n: continue for i in range(n+n,L+n+1,n): is_good[i-1] = False return is_good def solve(): G1 = find_good_substr(W) G2 = find_good_substr(W[::-1]) if G1[-1]: # 自分自身がoptimal return 1,1 x,y = solve() print(x) print(y)
s431826903
p04019
u301302814
1600527303
Python
Python (3.8.2)
py
Runtime Error
28
9128
373
# coding: utf-8 def main(): S = input() dic = {'N':0, 'S':0, 'E':0, 'W':0} ans = 'No' for s in S: dic[s] += 1 if (dic['N'] == 0 and dic['S'] == 0) or (dic['N'] > 0 and dic['S'] > 0): if (dic['E'] == 0 and dic['W'] == 0) or (dic['E'] > 0 and mp['W'] > 0): ans = 'Yes' print(ans) if __name__ == "__main__": main()
s805799739
p04019
u860002137
1597799979
Python
Python (3.8.2)
py
Runtime Error
23
8908
196
s = input() ans1 = (("S" in s) and ("N" in s)) or (("S" not in s) & ("N" not in s)) ans2 = (("E" in s) and ("W" in s)) or (("E" not in s) & ("W" not in s) print("Yes" if ans1 and ans2 else "No")
s414469097
p04019
u125348436
1597799455
Python
Python (3.8.2)
py
Runtime Error
34
8844
339
s=input() def walk(s): ls=len(s) if ls%2==1: print("NO") return nc=0 sc=0 wc=0 ec=0 for i in range(ls): if s[i]="W": wc+=1 elif s[i]="E": ec+=1 elif s[i]="N": nc+=1 else: sc+=1 if wc==ec and nc==sc: print("YES") return else: print("NO") return walk(s)
s366596957
p04019
u357751375
1597417821
Python
Python (3.8.2)
py
Runtime Error
23
9004
166
s = list(input()) n = s.count('N') w = s.count('W') s = s.count('S') e = s.count('E') if (n + s) % 2 == 0 and (w + e) % 2 == 0: print('Yes') else: print('No')
s737699837
p04019
u163320134
1596098122
Python
Python (3.8.2)
py
Runtime Error
26
9036
218
s=input() ans=[0]*4 checK='NWSE' for i in range(len(s)): for j in range(len(check)): if s[i]==check[j]: ans[j]+=1 if (ans[0]%2+ans[2]%2)%2==0 and (ans[1]%2+ans[3]%2)%2==0: print('Yes') else: print('No')
s834662135
p04019
u357751375
1595213307
Python
Python (3.8.2)
py
Runtime Error
22
8888
295
s = input() we = [0,0] ns = [0,0] for i in range(len(s)): if s[i] == ('N'): ns[0] == 1 elif s[i] == ('W'): we[0] == 1 elif s[i] == ('S'): ns[1] == 1 else we[1] == 1 if sum(we) % 2 == 0 and sum(ns) % 2 == 0: print('Yes') else: print('No')
s378800675
p04019
u143051858
1594646140
Python
Python (3.8.2)
py
Runtime Error
23
8888
199
s = input() n = 0 e = 0 w = 0 s = 0 for v in s: if v == 'N': n+=1 if v == 'E': e+=1 if v == 'W': w+=1 if v == 'S': s+=1 if n == s and e == w: print('Yes') else: print('No')
s430983808
p04019
u075303794
1594493543
Python
Python (3.8.2)
py
Runtime Error
24
9096
209
S=set(x for x in input()) if len(S)==4: print('Yes') elif lens(S)==2: if 'W' in S and 'E' in S: print('Yes') elif 'N' in S and 'S' in S: print('Yes') else: print('No') else: print('No')
s338099337
p04019
u032222383
1594142433
Python
PyPy3 (7.3.0)
py
Runtime Error
85
74740
253
t=input() d={} n=0 s=0 w=0 e=0 for i in range(int(len(s))): if t[i] =="N": n=1 if t[i] =="S": s=1 if t[i] =="E": e=1 if t[i] =="W": w=1 if (w+e)%2==0 and (n+s)%2==0: print("Yes") else: print("No")
s565038144
p04019
u652907854
1594012055
Python
PyPy3 (7.3.0)
py
Runtime Error
88
74836
986
# JAI SHREE RAM import math; from collections import * import sys; from functools import reduce # sys.setrecursionlimit(10**6) def get_ints(): return map(int, input().strip().split()) def get_list(): return list(get_ints()) def get_string(): return list(input().strip().split()) def printxsp(*args): return print(*args, end="") def printsp(*args): return print(*args, end=" ") UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5) # sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w") # for _testcases_ in range(int(input())): s = input() n = s = e = w = False if 'N' in s: n = True if 'S' in s: s = True if 'E' in s: e = True if 'W' in s: w = True print("Yes" if not(n^s) and not(e^w) else "No") ''' >>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !! THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA ) Link may be copy-pasted here if it's taken from other source. DO NOT PLAGIARISE. >>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !! '''
s313344487
p04019
u276686572
1593277852
Python
Python (3.8.2)
py
Runtime Error
23
8896
522
string = input() c1 = True c2 = True c3 = True if ("W" in string and not("E" in string) or "E" in string and not("W" in string): c1 = False if ("N" in string and not("S" in string) or "S" in string and not("N" in string): c2 = False if "N" in string and "S" in string and "E" in string and "W" in string: N = string.count("N") S = string.count("S") W = string.count("W") E = string.count("E") if not(N/S == W/E or N/S == E/W): c3 = False if c1 and c2 and c3: print("Yes") else: print("No")
s510190202
p04019
u413165887
1592076333
Python
PyPy3 (2.4.0)
py
Runtime Error
164
38384
321
s = input() kita, minami = sorted([s.count('N'),s.count('S')]) nisi, higasi = sorted([s.count('W'),s.count('E')]) result = ['No','Yes'] r = 1 if kita==minami: continue elif kita*minami > 0: continue else: r *= 0 if nisi==higasi: continue elif nisi*higasi > 0: continue else: r = 0 print(result[r])
s768807689
p04019
u509739538
1591991473
Python
Python (3.4.3)
py
Runtime Error
18
3320
3038
import math from collections import deque from collections import defaultdict import itertools as it #自作関数群 def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() def factorization(n): res = [] if n%2==0: res.append(2) for i in range(3,math.floor(n//2)+1,2): if n%i==0: c = 0 for j in res: if i%j==0: c=1 if c==0: res.append(i) return res def fact2(n): p = factorization(n) res = [] for i in p: c=0 z=n while 1: if z%i==0: c+=1 z/=i else: break res.append([i,c]) return res def fact(n):#階乗 ans = 1 m=n for _i in range(n-1): ans*=m m-=1 return ans def comb(n,r):#コンビネーション if n<r: return 0 l = min(r,n-r) m=n u=1 for _i in range(l): u*=m m-=1 return u//fact(l) def combmod(n,r,mod): return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod def printQueue(q): r=copyQueue(q) ans=[0]*r.qsize() for i in range(r.qsize()-1,-1,-1): ans[i] = r.get() print(ans) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1]*n def find(self, x): # root if self.parents[x]<0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self,x,y): x = self.find(x) y = self.find(y) if x==y: return if self.parents[x]>self.parents[y]: x,y = y,x self.parents[x]+=self.parents[y] self.parents[y]=x def size(self,x): return -1*self.parents[self.find(x)] def same(self,x,y): return self.find(x)==self.find(y) def members(self,x): # much time root = self.find(x) return [i for i in range(self.n) if self.find(i)==root] def roots(self): return [i for i,x in enumerate(self.parents) if x<0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} # 1~n def bitArr(n):#ビット全探索 x = 1 zero = "0"*n ans = [] ans.append([0]*n) for i in range(2**n-1): ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:])))) x+=1 return ans; def arrsSum(a1,a2): for i in range(len(a1)): a1[i]+=a2[i] return a1 def maxValue(a,b,v): v2 = v for i in range(v2,-1,-1): for j in range(v2//a+1): #j:aの個数 k = i-a*j if k%b==0: return i return -1 def copyQueue(q): nq = queue.Queue() n = q.qsize() for i in range(n): x = q.get() q.put(x) nq.put(x) return nq def get_sieve_of_eratosthenes(n): #data = [2] data = [0,0,0] for i in range(3,n+1,2): data.append(i) data.append(0) for i in range(len(data)): interval = data[i] if interval!=0: for j in range(i+interval,n-1,interval): data[j] = 0 #ans = [x for x in data if x!=0] ans = data[:] return ans s = readChar() d = {"N":0,"W":0,"S":0,"E":0} for i in s: d[i]+=1 flg = 1 if !(d["N"]+d["S"]==0 or (d["N"]>0 and d["S"]>0)): flg = 0 if !(d["W"]+d["E"]==0 or (d["W"]>0 and d["E"]>0)): flg = 0 if flg==1: print("Yes") else: print("No")
s329565899
p04019
u314089899
1590624547
Python
Python (3.4.3)
py
Runtime Error
17
2940
233
S = str(input()) if ((S.count("N") !=0 and S.count("S") !=0) or (S.count("N") ==0 and S.count("S") ==0)) and ((S.count("W") !=0 and S.count("E") !=0) or (S.count("W") ==0 and S.count("E") ==0)): print("Yes") else: print("No")
s165809812
p04019
u057415180
1590288786
Python
Python (3.4.3)
py
Runtime Error
18
2940
251
s = input() if 'N' in s: if 'S' in s: ans = 'Yes' else: ans = 'No' print(ans) exit() if 'W' in s: if 'E' in s: ans = 'Yes' else: ans = 'No' print(ans) exit() print(ans)
s390203325
p04019
u057415180
1590288433
Python
Python (3.4.3)
py
Runtime Error
17
2940
251
s = input() if 'N' in s: if 'S' in s: ans = 'Yes' else: ans = 'No' print(ans) exit() if 'W' in s: if 'E' in s: ans = 'Yes' else: ans = 'No' print(ans) exit() print(ans)
s785622903
p04019
u922449550
1590116399
Python
Python (3.4.3)
py
Runtime Error
17
2940
148
S = input() n = int('N' in S) s = int('S' in S) w = int('W' in W) e = int('E' in E) if n + s == 1 or w + e == 1: print('No') else: print('Yes')
s526120935
p04019
u358254559
1590077702
Python
PyPy3 (2.4.0)
py
Runtime Error
165
38256
214
s=input() import collections c = collections.Counter(l) if (c["N"]!=0 and c["S"]==0) or (c["N"]==0 and c["S"]!=0) or (c["W"]!=0 and c["E"]==0) or (c["W"]==0 and c["E"]!=0): print("Yes") else: print("No")
s318780710
p04019
u652656291
1589376269
Python
Python (3.4.3)
py
Runtime Error
17
2940
214
s = input() N = s.count('N') S = s.count('S') E = s.count('E') W = s.count('W') if ((N >= 1 and S == 0) or (N == 0 and S >= 1) or (E >= 1 and W == 0) or (E == 0 and W >= 1): print('NO') else: print('Yes')
s239282670
p04019
u652656291
1589376203
Python
Python (3.4.3)
py
Runtime Error
17
2940
214
s = input() N = s.count('N') S = s.count('S') E = s.count('E') W = s.count('W') if ((N >= 1 and S == 0) or (N == 0 and S >= 1) or (E >= 1 and W == 0) or (E == 0 and W >= 1): print('Yes') else: print('No')
s476703190
p04019
u652656291
1589375409
Python
Python (3.4.3)
py
Runtime Error
18
3064
170
s = input() N = s.count('N') S = s.count('S') E = s.count('E') W = s.count('W') if (N >= 1 and S >= 1) or (E >= 1 and W >= 1) or s ='': print('Yes') else: print('No')
s839468239
p04019
u711238850
1589304101
Python
Python (3.4.3)
py
Runtime Error
17
3192
522
s = set(list(input())) if 'N' in s: if not 'S' in s: print("No") exit() elif s(len) == 2 or s(len)==4: print("Yes") exit() if 'S' in s: if not 'N' in s: print("No") exit() elif s(len) == 2 or s(len)==4: print("Yes") exit() if 'W' in s: if not 'E' in s: print("No") exit() elif s(len) == 2 or s(len)==4: print("Yes") exit() if 'E' in s: if not 'W' in s: print("No") exit() elif s(len) == 2 or s(len)==4: print("Yes") exit() print("No")
s636631687
p04019
u288430479
1588982034
Python
Python (3.4.3)
py
Runtime Error
18
2940
176
s = input() if "N" in s: if "S" in s: continue else: print("No") exit() if "E" in s: if "W" in s: continue else: print("no") exit() print("Yes")
s570459864
p04019
u057964173
1588887845
Python
Python (3.4.3)
py
Runtime Error
18
3060
372
def input(): return sys.stdin.readline().strip() def resolve(): s=input() if 'N' in s and 'S' in s and 'W' in s and 'E' in s: ans='Yes' elif 'N' in s and 'S' in s and 'W' not in s and 'E' not in s: ans='Yes' elif 'N' not in s and 'S' not in s and 'W' in s and 'E' in s: ans='Yes' else: ans='No' print(ans) resolve()
s989029118
p04019
u103902792
1588447444
Python
Python (3.4.3)
py
Runtime Error
18
2940
154
s = input() def f(a,b): return (a in s and b not in s) or (b in s and a not in s): if f('W', 'E') or f('N', 'S'): print('No') else: print('Yes')
s830266921
p04019
u024782094
1587000261
Python
Python (3.4.3)
py
Runtime Error
18
3064
233
s=input() n=s.count("N") w=s.count("W") s=s.count("S") e=s.count("E") ns=n+s we=w+e if n>0 and w>0 and s>0 and e>0: print("Yes") elif n>0 and w>0 and we==0: print("Yes") elif ns==0 and s>0 and e>0: print("Yes") else print("No")
s966964676
p04019
u452512115
1586092433
Python
Python (3.4.3)
py
Runtime Error
17
3064
309
S = input() d = {} for s in S: d[s] = True if 'N' in d: if 'S' not in d: print 'No' exit() if 'S' in d: if 'N' not in d: print 'No' exit() if 'E' in d: if 'W' not in d: print 'No' exit() if 'W' in d: if 'E' not in d: print 'No' exit() print 'Yes'
s254462230
p04019
u691896522
1585242522
Python
PyPy3 (2.4.0)
py
Runtime Error
165
38256
145
s = input() s = set(list(s)) if s in "N" != s in "S": print("No") exit() if s in "W" != s in "E": print("No") exit() print("Yes")
s595384205
p04019
u089142196
1585013208
Python
Python (3.4.3)
py
Runtime Error
17
3064
293
S=input() ans="NO" n=0 w=0 e=0 s=0 for str in S: if str=="N": n +=1 elif str=="E": e +=1 elif str=="S": s +=1 else: w +=1 if (n>0 and s>0) or (n==0 and s==0): tate=True if (e>0 and w>0) or (e==0 and w==0): yoko=True if tate and yoko: ans="Yes" print(ans)
s115968210
p04019
u503111914
1580668199
Python
Python (3.4.3)
py
Runtime Error
17
2940
223
S = input() print("No" if (s.count("N") == 0 and s.count("S") > 0)\ or (s.count("S") == 0 and s.count("N") > 0)\ or (s.count("W") == 0 and s.count("E") > 0)\ or (s.count("E") == 0 and s.count("W") > 0)\ else "Yes")
s507506100
p04019
u503111914
1580668147
Python
Python (3.4.3)
py
Runtime Error
17
2940
222
S = input() print("No" if(s.count("N") == 0 and s.count("S") > 0)\ or (s.count("S") == 0 and s.count("N") > 0)\ or (s.count("W") == 0 and s.count("E") > 0)\ or (s.count("E") == 0 and s.count("W") > 0)\ else "Yes")
s103417228
p04019
u102960641
1577332709
Python
Python (3.4.3)
py
Runtime Error
17
3064
230
n = int(input()) a = [int(input()) for i in range(n)] b = sorted(a[::2]) a.sort() now = 0 ans = 0 br = (n+1) // 2 for k,v in enumerate(a): if b[now] == v: ans += abs(k-now*2) now += 1 if now == br: break print(ans)
s751247339
p04019
u977642052
1574430403
Python
Python (3.4.3)
py
Runtime Error
17
2940
248
def main(s): _s = set(s) if len(_s) % 2 != 0: print('No') return if ('N' and 'S') in _s: print('Yes') elif ('W' and 'E') in _s: print('Yes') if __name__ == '__main__': s = input() main()
s069269449
p04019
u089032001
1574019204
Python
Python (3.4.3)
py
Runtime Error
17
3064
349
def inpl(): return list(map(int, input().split())) def f(a, b): if a == 0 and b == 0: return True elif a * b == 0: return False else: return True S = input() N = S.count('N') W = S.count('W') S = S.count('S') E = E.count('E') if f(N, S) is True and f(W, E) is True: print('Yes') else: print('No')
s150684430
p04019
u495699318
1573866251
Python
Python (3.4.3)
py
Runtime Error
18
2940
1487
#include <stdio.h> #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #include <chrono> #include <random> #include <time.h> #include <fstream> #define ll long long #define rep2(i,a,b) for(ll i=a;i<=b;++i) #define rep(i,n) for(ll i=0;i<n;i++) #define rep3(i,a,b) for(ll i=a;i>=b;i--) #define pii pair<int,int> #define pll pair<ll,ll> #define pq priority_queue<int> #define pqg priority_queue<int,vector<int>,greater<int>> #define pb push_back #define vec vector<int> #define vecll vector<ll> #define vecpii vector<pii> #define endl "\n" #define all(c) begin(c),end(c) using namespace std; int in() {int x;scanf("%d",&x);return x;} ll lin() {ll x;scanf("%lld",&x);return x;} void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;} void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;} void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;} #define INF 1e9+7 #define LLINF 1e18+7 #define N 250000 ll MOD=1e9+7; main(){ string s; cin>>s; int cnt[N]={}; for(auto c:s){ cnt[c]=1; } puts(cnt['N']==cnt['S']&&cnt['W']==cnt['E'] ? "Yes":"No"); }
s270199733
p04019
u296150111
1569520774
Python
Python (3.4.3)
py
Runtime Error
17
3064
245
n=int(input()) a=[] for i in range(n): x=int(input()) a.append(x) ans=0 for i in range(n-1): if a[i]>0: ans+=(a[i]//2) a[i]-=(a[i]//2)*2 if a[i]>0: a[i+1]-=min(a[i],a[i+1]) ans+=min(a[i],a[i+1]) if a[-1]>0: ans+=a[-1]//2 print(ans)
s160782219
p04019
u296150111
1569520739
Python
Python (3.4.3)
py
Runtime Error
17
3064
243
n=int(input()) a=[] for i in range(n): x=int(input()) a.append(x) ans=0 for i in range(n-1): if a[i]>0: ans+=(a[i]//2) a[i]-=(a[i]//2)*2 if a[i]>0: a[i+1]-=min(a[i],a[i+1]) ans+=min(a[i],a[i+1]) if a[-1]>0: ans+=a[-1]//2 print(ans
s447382381
p04019
u296150111
1569520705
Python
Python (3.4.3)
py
Runtime Error
17
2940
244
=int(input()) a=[] for i in range(n): x=int(input()) a.append(x) ans=0 for i in range(n-1): if a[i]>0: ans+=(a[i]//2) a[i]-=(a[i]//2)*2 if a[i]>0: a[i+1]-=min(a[i],a[i+1]) ans+=min(a[i],a[i+1]) if a[-1]>0: ans+=a[-1]//2 print(ans)
s674653066
p04019
u668503853
1569464714
Python
Python (3.4.3)
py
Runtime Error
18
2940
505
S=list(input()) ans="Yes" n=S.count("N") e=S.count("E") w=S.count("W") s=S.count("S") if n>0 and s>0: if e>0 and w>0: pass elif e==0 and w==0: pass else: ans="No" elif n==0 and s==0: if e>0 and w>0: pass elif e==0 and w==0: pass else: ans="No" elif e>0 and w>0: if n>0 and s>0: pass elif n==0 and s==0: pass else: ans="No" elif e==0 and w==0: if n>0 and s>0: pass elif n==0 and s==0: pass else: ans="No" else: ans="No" print(ans)
s173980332
p04019
u298297089
1566424731
Python
Python (3.4.3)
py
Runtime Error
18
2940
157
dire = [0,0,0,0] d = {c:i for i,c in numerate('WENS')} for c in input(): dire[d[c]] = 1 print('No' if (dire[0] ^ dire[1]) or (dire[2] ^ dire[3]) else 'Yes')
s966521128
p04019
u333190709
1566133867
Python
PyPy3 (2.4.0)
py
Runtime Error
168
38384
138
S = input() N = S.count('N') S = S.count('S') E = S.count('E') W = S.count('W') if N == S and E == W: print('Yes') else: print('No')
s102544699
p04019
u393512980
1564615982
Python
Python (3.4.3)
py
Runtime Error
17
3064
234
S = set(input()) n = 'N' in S s = 'S' in S e = 'E' in S w = 'W' in S if n^s or e^w: print('No') else: print('Yes') n = int(input()) l = list(map(int, input().split())) l.sort() print(sum([l[i] for i in range(2*n) if i%2==0]))
s346366467
p04019
u623687794
1563918770
Python
PyPy3 (2.4.0)
py
Runtime Error
185
38640
185
n=int(input()) l=[int(input()) for i in range(n)] ans=0 for i in range(n): ans+=(l[i]-l[i]%2)//2 l[i]%=2 if l[i]==1 if i==n-1:break ans+=1 l[i]=0;l[i+1]-=1 print(ans)
s221338311
p04019
u502389123
1559185414
Python
Python (3.4.3)
py
Runtime Error
17
2940
241
s = input() if 'E' in s and 'W' in s: if 'N' in s and 'S' in s: print('Yes') elif 'N' in s or in 'S' in s: print('No') else: print('Yes') elif 'E' in s or 'W' in s: print('No') else: print('Yes')
s749381730
p04019
u623687794
1558655787
Python
Python (3.4.3)
py
Runtime Error
17
3064
267
s=input() a =["N","S","W","E"] flag1=0 flag2=0 if a[0] in s and a[1] in s: flag1=1 if a[0] not in s and a[1] not in s: flag1=1 if a[2] in s and a[3] in s: flag2=1 if a[2] not in s and a[3] not in s: flag2=1 if flag1+flag2=2: print("Yes") else: print("No")
s396746143
p04019
u623819879
1558474077
Python
PyPy3 (2.4.0)
py
Runtime Error
166
38256
91
s=set(input()) ans='No' if s in (set('SN'), set('EW'), set('NEWS')): ans='Yes' peint(ans)
s574012198
p04019
u619819312
1555804256
Python
Python (3.4.3)
py
Runtime Error
17
2940
84
print(sum([1 for j in [int(input()) for i in range(int(input()))][::2] if j%2!=1]))
s933711930
p04019
u163320134
1555631035
Python
Python (3.4.3)
py
Runtime Error
17
3060
210
s=input() ans=[0]*4 checK='NWSE' for i in range(len(s)): for j in range(len(check)): if s[i]==check[j]: ans[j]+=1 if (ans[0]+ans[2])%2==0 and (ans[1]+ans[3])%2==0: print('Yes') else: print('No')
s578347710
p04019
u875291233
1554522560
Python
PyPy3 (2.4.0)
py
Runtime Error
167
38384
59
print "Yes" if set("SEWN").issubset(set(input())) else "No"
s365739409
p04019
u363610900
1554097155
Python
Python (3.4.3)
py
Runtime Error
17
2940
143
# -*- coding: utf-8 -*- s = set(input()) if s in {{'N', 'S'}, {'W', 'E'}, {'N', 'W', 'S', 'N'}}: print('Yes') else: print('No')
s962556214
p04019
u363610900
1554096826
Python
Python (3.4.3)
py
Runtime Error
18
2940
143
# -*- coding: utf-8 -*- s = set(input()) if s in {{'N', 'S'}, {'W', 'E'}, {'N', 'W', 'S', 'N'}}: print('yes') else: print('No')
s443696635
p04019
u785989355
1552970384
Python
Python (3.4.3)
py
Runtime Error
19
3064
678
def nibutan2(array,value,left,right,first = True): if first: if array[left]>value: return 0 elif array[right]<value: return len(array) if right-left<=1: return right else: i=(left+right)//2 if array[i]>value: return nibutan2(array,value,left,i,False) elif array[i]<value: return nibutan2(array,value,i,right,False) N=int(input()) A=[] B=[] for i in range(N): if i%2==0: A.append(int(input())) else: B.append(int(input())) A.sort() B.sort() count=0 for i in range(len(A)): c=nibutan2(B,A[i],0,len(B)-1) count+=abs(c-i) print(count)
s008552884
p04019
u303059352
1552777924
Python
Python (3.4.3)
py
Runtime Error
17
2940
99
print("Yes" if ('N' in s) == ('S' in s) and ('W' in s) == ('E' in s) for s in [input()] else "No")
s655310295
p04019
u303059352
1552777844
Python
Python (3.4.3)
py
Runtime Error
17
2940
91
print("Yes" if 'N' in s and 'S' in s and 'W' in s and'E' in s for s in [input()] else "No")
s510178773
p04019
u371763408
1552494820
Python
Python (3.4.3)
py
Runtime Error
18
2940
1
a
s018821110
p04019
u543954314
1552230759
Python
Python (3.4.3)
py
Runtime Error
17
2940
100
s = input() if ~("N" in s ^ "S" in s) and ~("E" in s ^ "W" in s): print("Yes") else: print("No")
s527604111
p04019
u033524082
1551582845
Python
Python (3.4.3)
py
Runtime Error
17
2940
223
s=input()s=input() if "N" in s and "S" in s and "W" in s and "E" in s: print("Yes") elif "N" in s and "S" in s: print("Yes" if "W" in s or "E" in s else "No") else: print("Yes" if "N" in s or "S" in s else "No")
s196750928
p04019
u251123951
1551325324
Python
Python (3.4.3)
py
Runtime Error
18
3060
242
s=input() judge=True if "W" in s: if "E" not in s: judge=False if "E" in s: if "W" not in s: judge=False if "S" in s: if "N" not in s: judge=False if "N" in s: if "S" not in s: judge=False print("Yes") if judge else prit("No")
s973869213
p04019
u367130284
1551238991
Python
Python (3.4.3)
py
Runtime Error
17
2940
124
s=set(input()) if len(s)%2==0: if s==set("SN") or s==set("WE"): print("Yes") else: print("No") else: print("No")
s704674214
p04019
u740284863
1550089943
Python
Python (3.4.3)
py
Runtime Error
17
3064
325
s = str(input()) n = 0 w = 0 s = 0 e = 0 for i in range(len(s)): if s[i] == "N": n += 1 elif s[i] == "W": w += 1 elif s[i] == "S": s += 1 else: e += 1 if (n == 0 and s > 0) or (s == 0 and n > 0) or (e == 0 and w > 0) or (w == 0 and e > 0): print("No") else: print("No")
s796474343
p04019
u599547273
1549919109
Python
Python (3.4.3)
py
Runtime Error
21
2940
61
s=set;print("YNeos"[s(input())in map(s,"NS","EW","NSEW")::2])
s770598458
p04019
u375616706
1549580907
Python
Python (3.4.3)
py
Runtime Error
17
3060
387
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline linp = list(map(int, input().split())) s = input() ans = "Yes" if "W" in s: if not "E" in s: ans = "No" if "E" in s: if not "W" in s: ans = "No" if "N" in s: if not "S" in s: ans = "No" if "S" in s: if not "N" in s: ans = "No" print(ans)
s172506545
p04019
u102960641
1547687610
Python
Python (3.4.3)
py
Runtime Error
18
2940
128
n = set(list(input())) if n == set("N","S") or n == set("W","E") or n == set("N","S","W","E") print("Yes") else: print("No")
s922105322
p04019
u619819312
1547613458
Python
Python (3.4.3)
py
Runtime Error
18
2940
192
if ("N" in a and"S"in a)or(not"N" in a and not "S" in a): if ("W" in a and"E"in a)or(not"W" in a and not "E" in a): print("Yes") else: print("No") else: print("No")
s845586074
p04019
u459233539
1546363579
Python
Python (3.4.3)
py
Runtime Error
18
2940
190
S = input() s = set(S) if ("N" in s and "S" not in s) or ("S" in s and "N" not in s) or ("W" in s and "E" not in s) or ("E" in s and "W" not in s): print("No") else: print("Yes")
s693140994
p04019
u459233539
1546363548
Python
Python (3.4.3)
py
Runtime Error
18
2940
178
S=input() s=set(S) if ("N" in s and "S" not in s) or ("S" in s and "N" not in s) or ("E" in s and "W" not in s) or ("W" in s and "E" not in s): print("No") else: print("Yes")
s872595893
p04019
u459233539
1546363432
Python
Python (3.4.3)
py
Runtime Error
17
2940
188
S=input() s=set(S) if ("N" in s and "S" not in s) or ("S" in s and "N" not in s) or ("E" in s and "W" not in s) or ("W" in s and "E" not in s): print("No") else: print("Yes")
s634815896
p04019
u459233539
1546360920
Python
Python (3.4.3)
py
Runtime Error
17
2940
179
s=input() if ("N" in s and "S" not in s) or ("S" in s and "N" not in s) or ("E" in s and "W" not in s) or ("W" in s and "E" not in s): print("No") else: print("Yes")