akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
using P = pair<int, int>;

P get_num(string &str) {  // first: 開始位置から最大いくつ下るか  second: 最終的にいくつ増減するか
    int n = (int)str.size();
    P ret(0, 0);
    int h = 0;
    for (int i = 0; i < n; i++) {
        if (str[i] == '(') {
            h++;
        } else {
            h--;
            chmin(ret.first, h);
        }
    }
    ret.second = h;
    return ret;
}

bool comp(P l, P r) {
    if (l.second > r.second) {
        return l.second > r.second;
    } else {
        return l.first > r.first;
    }
}

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
    }

    vector<P> L, R;  // 左右から見た時の、first: 開始からどれだけ下がるか second: 開始からどれだけ上がるか
    for (int i = 0; i < N; i++) {
        int n = (int)S[i].size();
        int b = 0;
        int h = 0;
        for (int j = 0; j < n; j++) {
            if (S[i][j] == '(') {
                h++;
            } else {
                h--;
                chmin(b, h);
            }
        }
        if (h > 0) {  // 右肩上がりのもの
            L.push_back(P(b, h));
        } else {  //右肩下がりのもの
            R.push_back(P(b - h, -h));
        }
    }

    sort(ALL(L), greater<P>());
    sort(ALL(R), greater<P>());

    int l = 0;
    for (int i = 0; i < (int)L.size(); i++) {
        // cerr << l << " " << L[i].first << " " << L[i].second << endl;
        if (l + L[i].first < 0) {
            cout << "No\n";
            return 0;
        }
        l += L[i].second;
    }
    int r = 0;
    for (int i = 0; i < (int)R.size(); i++) {
        //cerr << r << " " << R[i].first << " " << R[i].second << endl;
        if (r + R[i].first < 0) {
            cout << "No\n";
            return 0;
        }
        r += R[i].second;
    }
    if (l == r) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

/*
4
)((
))(((
)))
(
*/


Measured memory_bytes: 42416
#include <iostream>
#include <string>

using namespace std;

//strのa文字目からb文字目までを出力する
void print(string str, int a, int b)
{
	for(int i = a; i <= b; i++)
	{
		cout << str[i];
	}
	cout << endl;
}

//strのa文字目からb文字目までを逆順にする
void reverse(string& str, int a, int b)
{
	for(int i = 0; i < (b-a+1)/2; i++)
	{
		char tmp = str[a+i];
		str[a+i] = str[b-i];
		str[b-i] = tmp;
	}
}

//strのa文字目からb文字目までをpに置き換える
void replace(string& str, int a, int b, string p)
{
	str.replace(a, b-a+1, p);
}

int main(void)
{
	string str;	//入力文字列
	string op;	//命令
	string replace_str;	//置き換え文字列

	int op_num;	//命令数
	int a, b;	//対象範囲
	
	//操作する文字列を入力
	cin >> str;

	//命令数を入力
	cin >> op_num;

	for(int i = 0; i < op_num; i++)
	{
		//命令を入力
		cin >> op;
		if(op == "print")		//print命令の場合
		{
			cin >> a >> b;
			print(str, a, b);
		}
		else if(op == "reverse")	//reverse命令の場合
		{
			cin >> a >> b;
			reverse(str, a, b);
		}
		else if(op == "replace")	//replace命令の場合
		{
			cin >> a >> b >> replace_str;
			replace(str, a, b, replace_str);
		}
	}

	return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
int N , D , K;
cin >> N;
cin >> D;
K = 2*D+1;
if(N%K==0){
cout << N/K << endl;
}
else{
cout << N/K+1 << endl;
}
return 0;
}


Measured memory_bytes: 256
#include "./bits/stdc++.h"
using namespace std;

int MIN = (1<<21);
string S;
int N=753;

int main(){
    cin >> S;
    for(int i=0;i<S.size()-2;i++){
        int X=100*(int(S[i])-48)+10*(int(S[i+1]-48))+(int(S[i+2])-48);
        if(MIN > abs(X-N)){
            MIN=abs(X-N); 
        }

    }
    cout << MIN << endl;
    return 0;
}

Measured memory_bytes: 3592
def fromAdjRow(xs, n)
  a = []
  1.upto(n) do |i|
    a << i if xs[i-1] == 1
  end
  a
end

def toAdj(g, n)
  g.map do |xs|
    a = [0]*n
    unless xs[1] == 0
      xs[2..-1].each do |x|
        a[x-1] = 1
      end
    end
    a
  end
end

if __FILE__ == $0
  n = gets.to_i
  g = toAdj(n.times.map{ gets.split.map(&:to_i) }, n)

  q = [1]
  visited = Array.new(n, false)
  visited[0] = true
  ds = Array.new(n, -1)
  ds[0] = 0
  until q.empty?
    u = q.shift
    fromAdjRow(g[u-1], n).each do |v|
      unless visited[v-1]
        ds[v-1] = ds[u-1]+1
        visited[v-1] = true
        q.push(v)
      end
    end
  end

  ds.each.with_index{ |x, i| puts (i+1).to_s + " " + x.to_s }
end

Measured memory_bytes: 6172
c = input()
a = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t" ,"u", "v", "w", "x", "y", "z"]
n = a.index(c) + 1
print(a[n])


Measured memory_bytes: 2940
n = int(input())
s = list(map(int, input().split()))
sum_s = sum(s)

q = int(input())
m = list(map(int, input().split()))

def slove(i, m):
    if m == 0:
        return True
    if i >= n or m < 0 or m > sum_s:
        return False
        
    return slove(i + 1, m) or slove(i + 1, m - s[i])

answer_cache = dict()
for j in m:
    if j in answer_cache:
        print(answer_cache[j])
        continue

    word = "yes" if slove(0, j) else "no"
    print(word)
    answer_cache[j] = word
    


Measured memory_bytes: 5632
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#define lli long long int
#define Div 1000000007
long long int Pow(lli m, lli n);
int main() {
	long long int m,n,a;
	scanf("%lld%lld", &m, &n);
	a=Pow(m,n)%Div;
	printf("%lld\n", a);
	return 0;
}

long long int Pow(lli m, lli n)
{	
	long long res = 1;
	if (n == 0) return 1;
	res = Pow(m*m%Div, n / 2);
	if (n % 2 == 1) res = res*m%Div;
	return res;
}

Measured memory_bytes: 596
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  alias T=long;

  int n, m, s, t; rd(n, m, s, t);
  s--; t--;
  struct Edge{
    int to;
    T cost;
  }
  auto g_yen=new Edge[][](n);
  auto g_snu=new Edge[][](n);
  foreach(_; 0..m){
    int u, v; T a, b; rd(u, v, a, b);
    u--; v--;
    g_yen[u]~=Edge(v, a);
    g_yen[v]~=Edge(u, a);
    g_snu[u]~=Edge(v, b);
    g_snu[v]~=Edge(u, b);
  }

  const T inf=1e18.to!(long);
  T[] dijkstra(Edge[][] g, int s){
    auto d=new T[](n);
    fill(d, inf);
    struct P{int v; T d;}
    import std.container;
    auto Q=new RedBlackTree!(P, "a.d<b.d", true);
    Q.insert(P(s, 0)); d[s]=0;
    while(Q.empty==false){
      auto cur=Q.front; Q.removeFront;
      foreach(e; g[cur.v]){
        if(d[e.to]<=d[cur.v]+e.cost) continue;
        d[e.to]=d[cur.v]+e.cost;
        Q.insert(P(e.to, d[e.to]));
      }
    }
    return d;
  }
  
  auto d_yen=dijkstra(g_yen, s),
       d_snu=dijkstra(g_snu, t);
  auto ans=new long[](n);
  foreach_reverse(i; 0..n){
    ans[i]=1e15.to!(long)-d_yen[i]-d_snu[i];
    if(i+1<n) chmax(ans[i], ans[i+1]);
  }
  writefln("%(%s\n%)", ans);
}

void chmax(Type)(ref Type l, Type r){if(l<r)l=r;}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

Measured memory_bytes: 48124
# coding: utf-8
# ABC138C

n = int(input())
v = list(map(int, input().split()))

while len(v) > 1:
    v.sort(reverse=True)
    a = v.pop()
    b = v.pop()
    v.append((a + b) / 2)

res = v.pop()
if res.is_integer():
    res = int(res)
print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

int main(){
   int n,m;
   cin>>n>>m;
   int h[n];
   rep(i,n){
      cin>>h[i];
   }
   vector<bool> f(n,true);

   rep(i,m){
       int a,b;
       cin>>a>>b;
       int c=min(a,b);
       int d=max(a,b);
       if(h[c-1]>h[d-1]) f[d-1]=false;
       else if(h[c-1]<h[d-1]) f[c-1]=false;
       else {
           f[c-1]=false;
           f[d-1]=false;
       }
   }
   ll ans=0;
   rep(i,n){
       if(f[i]==true) {
           ans++;
          
       }
   
   }

   cout<<ans;


   


return 0;
}



Measured memory_bytes: 4008
n = int(input())
list_a = list(map(int, input().split()))
list_a_complete = []
k = 1
ans = -2

for i in range(n):
    if list_a[i] == k:
        list_a_complete.append(k)
        k += 1

if len(list_a_complete) == 0:
    ans = -1

else:
    ans = len(list_a) - len(list_a_complete)

print(ans)

Measured memory_bytes: 26012
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 1e18, sum = 0, cnt = 0;
    int flag = 1;
    rep(i,n){
        if(flag == 1){
            if(sum + a[i] <= 0){
                cnt += 1-sum-a[i];
                sum = 1;
            }
            else sum += a[i];
        }
        else{
            if(sum + a[i] >= 0){
                cnt += abs(-1-sum-a[i]);
                sum = -1;
            }
            else sum += a[i];
        }
        flag = -flag;
        //cout << sum << endl;
    }
    ans = min(ans, cnt);

    flag = -1, sum = 0, cnt = 0;
    rep(i,n){
        if(flag == 1){
            if(sum + a[i] <= 0){
                cnt += 1-sum-a[i];
                sum = 1;
            }
            else sum += a[i];
        }
        else{
            if(sum + a[i] >= 0){
                cnt += abs(-1-sum-a[i]);
                sum = -1;
            }
            else sum += a[i];
        }
        flag = -flag;
        //cout << sum << endl;
    }
    ans = min(ans, cnt);
    cout << ans << endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;

int main() {
    int X, Y, a, b, c;
    cin >> X >> Y >> a >> b >> c;
    vector<int> P(a), Q(b), R(c);
    for(auto &e : P) cin >> e;
    for(auto &e : Q) cin >> e;
    for(auto &e : R) cin >> e;
    sort(P.begin(), P.end(), greater<int>());
    sort(Q.begin(), Q.end(), greater<int>());
    for(int i = 0; i < X; ++i) R.push_back(P[i]);
    for(int i = 0; i < Y; ++i) R.push_back(Q[i]);
    sort(R.begin(), R.end(), greater<int>());
    cout << accumulate(R.begin(), R.begin() + X + Y, 0LL) << '\n';
    return 0;
}


Measured memory_bytes: 2552
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 8292
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
int main() {
  int H, W; // 高さH、幅W
  cin >> H >> W;

  bool WHITE = true, BLACK = false;
  vector< vector<bool> > s;
  s.resize(H);
  for(int i = 0; i < H; i++) {
    s[i].resize(W);
    for (int j = 0; j < W; j++)
      s[i][j] = WHITE;
  }

  // 初期化
  int white_count = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char s_ij;
      cin >> s_ij;
      if (s_ij == '.') {
        s[i][j] = WHITE;
        white_count++;
      } else
        s[i][j] = BLACK;
    }
  }

  queue<int> q; // i * W + jで管理
  vector<int> visited(W * H, 1000000);
  visited[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int pos = q.front(); q.pop();
    int i = pos / W, j = pos % W;
    for (int dir = 0; dir < 4; dir++) {
      int direction[] = {1, -1, 0, 0};
      int di = direction[dir], dj = direction[3 - dir];
      if (0 <= i + di && i + di < H &&
          0 <= j + dj && j + dj < W &&
          s[i+di][j+dj] == WHITE)
        if (visited[pos] + 1 < visited[(i+di)*W+j+dj]) {
          visited[(i+di)*W+j+dj] = visited[pos] + 1;
          q.push((i+di)*W+j+dj);
        }
    }
  }
  if (visited[W*H - 1] == 1000000)
    cout << -1 << endl;
  else
    cout << white_count - visited[W*H - 1] - 1 << endl;
}


Measured memory_bytes: 256
"""
Writer: SPD_9X2

すべて0にする、すべて1にするは自明に可能
なので A >= B としてよい(A<Bの時は01を入れ替えて考えればよい)

最後に置いた場所の周囲がどんな状況か考える

0*Aがある場合、その周囲はすべての場合構成可能
ない場合は…？
1*Bがある場合を考える。長さB以上の1列は後からおけるからおｋだが…
長さB以上の1をすべて0に変えたときに、長さA以上の0があればおｋ

どう数え上げる？
ダメな場合を引くのがよさそう？
→dp[i][last][num] = i番目まで見て、lastを現在num個連続しておいている場合の通り数
ただし、dp[?][1][B-1]はdp[?][0][B]に伝播する
これまずいか

ブロックで考えるやり方はどうなんだろう
つまり、連鎖を断ち切れるのは長さB以下の1列だけ

0 or B以上連続する1の列のみで構成されたブロックX(Yに隣接する端は0である必要あり)
B未満の1列であるブロックYを交互に置いていく

dp[i][XorY] = i番目の文字を次に置けるとき、最後に置いたブロックがXorYの時の通り数
初期値は
dp[0][X] = 1
dp[0][Y] = 1 ←これ、かなり注意する必要がある左端が1でもいいから
同様に、Nに移行する時にXを置くときも右端を1にできるのに注意

B以上連続する1を0に変えるとすべて0になる文字列の数をまず求める
上と同様にブロックdp?
0のブロックは,1以上のどんな長さでも置ける
1のブロックは,B以上の長さ置ける
dp[0][Z] = 1
dp[0][O] = 1

"""

N,A,B = map(int,input().split())

fdp = [[0,0] for i in range(N+1)]
fdp[0] = [1,1]
mod = 10**9+7

if A < B:
    tmp = B
    B = A
    A = tmp

for i in range(N):

    for j in range(i+1,N+1):
        fdp[j][0] += fdp[i][1]
        fdp[j][0] %= mod

    for j in range(i+B,N+1):
        fdp[j][1] += fdp[i][0]
        fdp[j][1] %= mod

#print (fdp)

dp = [[0,0] for i in range(N+1)]
dp[0] = [1,1]

for i in range(N):

    for j in range(i+1,min(N+1,i+B)):
        dp[j][1] += dp[i][0]
        dp[j][1] %= mod

    #ここかなり注意
    for j in range(i+1,min(N+1,i+A)):

        l = j-i

        if i == 0 or j == N:
            if l == 1:
                dp[j][0] += dp[i][1]
                dp[j][0] %= mod
            else:
                dp[j][0] += dp[i][1] * sum(fdp[l-1])
                dp[j][0] %= mod

        else:
            if l <= 2:
                dp[j][0] += dp[i][1]
                dp[j][0] %= mod
            else:
                dp[j][0] += dp[i][1] * sum(fdp[l-2])
                dp[j][0] %= mod

#print (dp)          
print ((pow(2,N,mod)-sum(dp[N])) % mod)


Measured memory_bytes: 75548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i,n) for (int i = 0; i < (n); ++i)


void solve(long long N, std::vector<long long> L){
    ll ans = 0;
    rep(i,N){
        for(int j=i+1; j<N; j++){   
            for(int k=j+1; k<N; k++){
                if(L[i] == L[j] || L[j] == L[k] || L[i] == L[k]) continue;
                if(L[i] + L[j] <= L[k] || L[j] + L[k] <= L[i] || L[i] + L[k] <= L[j]) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int N,K;cin>>N>>K;
  int ans=0;
  vector<int> x(N+1,0);
  for(int i=1;i<=N;i++) cin>>x[i];
  for(int i=1;i<=N;i++){
    ans+=(abs(x[i]*2)<abs((K-x[i])*2)?abs(x[i]*2):abs((K-x[i])*2));
  }

  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
N=int(input())
A_list=sorted(list(map(int, input().split())), reverse=True)
ans=1

if 0 in A_list:
  print(0)
  exit()
else:
  for a in A_list:
    ans*=a
    if ans>1e+18:
      print(-1)
      exit()
  print(ans)










Measured memory_bytes: 21680
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
int main()
{
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    printf("%d\n",a[0]+a[1]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

string s;
bool ok(string x) {
    if (sz(s) == sz(x)) {
        return x <= s;
    } else {
        return sz(x) < sz(s);
    }
}
int main() {
    int k;
    cin >> s >> k;
    int n = sz(s);
    if (k == 1) {
        int ans = 0;
        for (char d = '1'; d <= '9'; d++) {
            string now = "";
            now += d;
            rep(i, 110) {
                ans += ok(now);
                now += '0';
            }
        }
        cout << ans << endl;
    }
    if (k == 2) {
        int ans = 0;
        string now = "00";
        for (int len = 2; len < 110; len++) {
            for (char a = '1'; a <= '9'; a++) {
                now[0] = a;
                for (int pos = 1; pos < len; pos++) {
                    for (char b = '1'; b <= '9'; b++) {
                        now[pos] = b;
                        ans += ok(now);
                    }
                    now[pos] = '0';
                }
            }
            now += '0';
        }
        cout << ans << endl;
    }
    if (k == 3) {
        int len = sz(s);
        ll ans = (ll)(s[0] - '1') * (len - 1) * (len - 2) / 2 * 81;
        for (ll l = 3; l < len; l++) {
            ans += 9 * (l - 1) * (l - 2) / 2 * 81;
        }
        string now;
        rep(i, len) now += '0';
        now[0] = s[0];

        for (int pos1 = 1; pos1 < len; pos1++) {
            for (int pos2 = pos1 + 1; pos2 < len; pos2++) {
                for (char b = '1'; b <= '9'; b++) {
                    for (char c = '1'; c <= '9'; c++) {
                        now[pos1] = b;
                        now[pos2] = c;
                        ans += ok(now);
                        now[pos1] = '0';
                        now[pos2] = '0';
                    }
                }
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type task struct{ a, b int }
type tasks []task

func (ts tasks) Len() int           { return len(ts) }
func (ts tasks) Swap(i, j int)      { ts[i], ts[j] = ts[j], ts[i] }
func (ts tasks) Less(i, j int) bool { return ts[i].b < ts[j].b }

func solve() {
	n := getInt()
	ts := make(tasks, n)
	for i := range ts {
		ts[i].a = getInt()
		ts[i].b = getInt()
	}
	sort.Sort(ts)

	sum := 0
	ans := "Yes"
	for _, t := range ts {
		sum += t.a
		if t.b < sum {
			ans = "No"
		}
	}
	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;

int h,w;
const int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};
const string dir = "URDL";
vector<string> g;

string dfs(int y,int x,int d,int rem,string s){
  if(rem==0)return s;
  char tmp = g[y][x];
  g[y][x] = '.';

  for(int i=3;i<=5;i++){
    int nd = (d+i)%4, ny = y + dy[nd], nx = x + dx[nd];
    while(ny>=0 && nx>=0 && ny<h && nx<w){
      if(g[ny][nx] == 'o'){
	string tmp = dfs(ny,nx,nd,rem-1,s+dir[nd]);
	if(tmp.size())return tmp;
	break;
      }
      ny += dy[nd]; nx += dx[nd];
    }
  }

  g[y][x] = tmp;
  return "";
}

int main(){
  int y,x,d,cnt = 0;
  cin >> h >> w;
  g.resize(h);
  for(int i=0;i<h;i++){
    cin >> g[i];
    for(int j=0;j<w;j++){
      if(isupper(g[i][j])){
	y = i; x = j;
	for(int k=0;k<4;k++){
	  if(dir[k] == g[i][j])d = k;
	}
      }else if(g[i][j] == 'o')cnt++;
    }
  }
  cout << dfs(y,x,d,cnt,"") << endl;
}
  

Measured memory_bytes: 1216
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ans = 0;
    for (ll i=1; 2*i<n; i++) ans++;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

bool isPrime(int n) {
    if (n == 2) return true;
    if (n < 2 || n % 2 == 0) return false;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    int x;
    cin >> x;

    while (!isPrime(x)) x++;
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e5 + 10, INF = 1e9;

long long last[2 * MAXn], cnt[2 * MAXn], n, ar[MAXn], psum[MAXn];

bool check(int a) {
	fill_n(last, 2 * MAXn, -1);
	fill_n(cnt, 2 * MAXn, 0);
	fill_n(psum, MAXn, 0);
	long long psum1 = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		if (ar[i] > a)
			psum1--;
		else
			psum1++;
		int hp = last[psum1 + MAXn] + 1;
		
		if (psum[hp] < psum1) {
			cnt[psum1 + MAXn] += (i - hp);
		}
		ans += cnt[psum1 + MAXn] + (psum1 > 0);
		last[psum1 + MAXn] = i;
		psum[i] = psum1;
	}
//	cout << ans << endl;
	long long hp2 = (n * (n + 1)) / 2;
	return hp2 / 2 < ans;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	if (n == 1)
		return cout << ar[0],0;
	
	int st = 0, en = INF + 10;
	while(st + 1 < en) {
		int med = (st + en) / 2;
		if (check(med))
			en = med;
		else
			st = med;
	}
	cout << en;
}

Measured memory_bytes: 4992
N=list(input())
if int(N[-1]) == 2 or int(N[-1]) == 4 or int(N[-1]) == 5 or int(N[-1]) == 7 or int(N[-1]) == 9:
    print("hon")
if int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8:
    print("pon")
if int(N[-1]) == 3:
    print("bon")

Measured memory_bytes: 9208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int K=scan.nextInt();
		int X=scan.nextInt();
		if(K*500>=X)
		{
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 35624
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    const auto L = S.size();
    if (L == 2) {
        if (S[0] == S[1]) {
            std::cout << "1 2" << std::endl;
        }
        else {
            std::cout << "-1 -1" << std::endl;
        }
        return 0;
    }

    for (size_t i = 0; i < S.size() - 2; ++i) {
        if (S[i] == S[i+1]) {
            std::cout << i+1 << " " << i+2 << std::endl;
            return 0;
        }
        if (S[i] == S[i+2]) {
            std::cout << i+1 << " " << i+3 << std::endl;
            return 0;
        }
    }

    std::cout << "-1 -1" << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int sum = 0;
    int abmin = min(a+b,c*2);

    if(x >= y){
        sum += y*abmin;
        if(a > c*2){
            sum += (x-y)*c*2;
        }else{
            sum += (x-y)*a;
        }
    }else{
        sum += x*abmin;
        if(b > c*2){
            sum += (y-x)*c*2;
        }else{
            sum += (y-x)*b;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;

int main(){
    int n;
	  cin >> n;
    int p[n]={};

    for(int i = 0;i<n;i++){
        cin >> p[i];
    }
    int count = 0;
    for(int j = 1;j<n-1;j++){
        if((p[j-1]<p[j])&&(p[j]<p[j+1])){
            count ++;
        }else if((p[j-1]>p[j])&&(p[j]>p[j+1])){
        	count++;
        }

    }

        cout << count;

}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split()))

B = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
    ball = 0
    base = i + 1

    for j in range(i, N + 1, i):
        ball += B[j]

    if ball % 2 != A[i]:
        B[i] = 1

print(sum(B))
print(*[i for i, b in enumerate(B) if b == 1], sep=' ')


Measured memory_bytes: 13108
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <unordered_map>

using namespace std;
using str = string;

#define rep(a,l,r) for(int a=(l);a<(r);a++)
#define get cin>>
#define put cout<<

void run() {

	long n; get n;
	vector<long> aList{};

	rep(i,0,n){
		int a; get a;
		aList.emplace_back(a);
	}

	sort(aList.begin(),aList.end());

	put abs(aList.back() - aList.front());
}

int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);run();return 0;}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int h[1600],w[1600];

long long solve(int N,int M){
    long long ans=0;
    vector<int> prep;

    for(int i=0;i<N;++i){
        cin>>h[i];
        int sum = 0;
        for(int ii=i;ii>=0;--ii){
            sum += h[ii];
            prep.push_back(sum);
        }
    }

    sort(prep.begin(),prep.end());

    //前処理。h_iのシークエンス和としてありうる値をマルチセットに格納しておく。　オーダー O(N^2logN)

    for(int j=0;j<M;++j){
        cin>>w[j];
        int sum = 0;
        for(int jj=j;jj>=0;--jj){
            sum += w[jj];
            ans += (upper_bound(prep.begin(),prep.end(),sum) - lower_bound(prep.begin(),prep.end(),sum));
        }
    }
    //w_iの各シークエンス和全てに対し、マルチセットでの登場回数
    //(正方形を成すh_iのシークエント和の個数)をカウントして答えに合算。オーダー O(M^2logN)
    return ans;
}

int main(){
    int N,M;

    ios_base::sync_with_stdio(true);
    while(true){
        cin>>N>>M;

        if(N==0 && M==0) return 0;
        cout<<solve(N,M)<<endl; //マルチセットと答え変数の初期化を簡単にするため、関数を分離した
    }
    return 0;
}



Measured memory_bytes: 15464
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

/*vector<int> p(n);
cin >> p[i]*/

int main(){

    long long int n;
    bool flag=false;
    cin >> n;

    vector<long long int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    sort(a.begin(), a.end() );

    for(int i=0; i<n; i++){
        if(a[i] == a[i+1]){
            flag = true;
            break;
        }
    }

    if(flag == true) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1792
n=int(input())
A=list(map(int,input().split()))
S=[0] #累積和
cnt=0
for i in range(n):
    cnt+=A[i]
    S.append(cnt)

ans=S[n]
d1=1 #しきり1(i個目の右で切る)
d3=2 #しきり3

for d2 in range(2,n-1): #しきり2を全探索
    L=S[d2]
    R=S[n]-S[d2]
    for i in range(d1,d2): #しきり1を右に動かす
        if S[i]>=L/2:
            break
    if abs(S[i]-L/2)>=abs(S[i-1]-L/2): #しきり1を更新
        d1=i-1
    else:
        d1=i
    for i in range(d3,n): #しきり3を右に動かす
        if S[i]-S[d2]>=R/2:
            break
    if abs(S[i]-S[d2]-R/2)>=abs(S[i-1]-S[d2]-R/2): #しきり3を更新
        d3=i-1
    else:
        d3=i
    s=[S[d1],S[d2]-S[d1],S[d3]-S[d2],S[n]-S[d3]] #4分割の結果
    ans=min(max(s)-min(s),ans) #解答の更新
    #print(d1,d2,d3,s)
print(ans)

Measured memory_bytes: 97400
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const long long N = 10000;
vector<long long> f[N];
vector<long long> pack;
long long n, l, m ,r;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> l >> m >> r;
	l *= 2; m *= 2; r *= 2;
	for (long long i = 0; i <= n; ++i)
		f[i] = vector<long long>(m + 10, 0);
	for (long long i = 0; i < n; ++i) {
		long long weight;
		cin >> weight;
		pack.push_back(weight);
	}
	f[0][0] = 1;
	f[0][1] = -1;
	for (long long i = 0; i <= n; ++i) {
		for (long long j = 1; j <= m; ++j)
			f[i][j] += f[i][j - 1];
		if (i == n) break;
		for (long long j = 0; j <= m; ++j) {
			if (!f[i][j]) continue;
			long long kl = r * pack[i], kr = l / 2 * pack[i];
			long long cl, cr;
			//part1
			if(j - kl >= 0 && j - kr >= 0) {
				cl = j - kr;
				cr = j - kl;
			} else if (j - kl <= 0 && j - kr <= 0) {
				cl = abs(j - kl);
				cr = abs(j - kr);
			} else {
				cl = 0;
				cr = max(abs(j - kr), abs(j - kl));
			}
			if(cl <= m) {
				cr = min(cr, m);
				f[i + 1][cl]++;
				f[i + 1][cr + 1]--;
			}
			//part2
			cl = j + kl, cr = j + kr;
			if(cl <= m) {
				cr = min(cr, m);
				f[i + 1][cl]++;
				f[i + 1][cr + 1]--;
			}
					
		}
	}
	for (long long i = 0; i <= m; ++i)
		if (f[n][i]) {
			cout << "Yes" << endl;
			return 0;
		}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 17388
#include <bits/stdc++.h>
using namespace std;

int n, m;
char a[50][50], b[50][50];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; ++i) 
		for (int j = 0; j < n; ++j)
			cin >> a[i][j];

	for (int i = 0; i < m; ++i)
		for (int j = 0; j < m; ++j)
			cin >> b[i][j];

	for (int i = 0; i <= n - m; ++i) {
		for (int j = 0; j <= n - m; ++j) {
			bool f = true;
			for (int k = 0; k < m; ++k) {
				for (int l = 0; l < m; ++l) {
					if (a[i + k][j + l] != b[k][l]) f = false;
				}
			}

			if (f) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int x;
    cin >> x;
    if (x <= 599) {
        cout << 8 << endl;
    }
    else if (x <= 799) {
        cout << 7 << endl;
    }
    else if (x <= 999) {
        cout << 6 << endl;
    }
    else if (x <= 1199) {
        cout << 5 << endl;
    }
    else if (x <= 1399) {
        cout << 4 << endl;
    }
    else if (x <= 1599) {
        cout << 3 << endl;
    }
    else if (x <= 1799) {
        cout << 2 << endl;
    }
    else if (x <= 1999) {
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		for(int i = 0; i < n; i++){
			int x = sc.nextInt();
			map.put(x, map.containsKey(x) ? map.get(x)+1 : 1);
		}
		int num = map.size() - k;
		int sum = 0;
		for(Entry<Integer, Integer> e : map.entrySet().stream().sorted((e1, e2) -> e1.getValue() - e2.getValue()).collect(Collectors.toList())){
			if(num-- <=0) break;
			sum += e.getValue();
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 103688
n = int(input())

sList = sorted(list(map(int,input().split())),reverse=True)
res = []
acc = False
for i in range(n-1):
  if acc:
    acc = False
  else:
      if sList[i] == sList[i+1]:
        res.append(sList[i])
        acc = True
      if len(res) == 2:
        print(res[0]*res[1])
        exit(0)

print(0)



Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
static const int MAX_N = 550;
int N, M, Q, X[509][509], cnt[509][509];
// cnt[l][r] := 左端がlで右端がr以下の列車の総数

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    rep(i, M) {
        int L, R;
        cin >> L >> R;
        cnt[L][R]++;
    }
    for (int l = 1; l <= N; l++) {
        for (int r = 2; r <= N; r++) {
            cnt[l][r] += cnt[l][r - 1];
        }
    }
    rep(i, Q)
    {
        int p, q;
        cin >> p >> q;
        int sum = 0;
        for (int l = p; l <= q; l++) {
            sum += cnt[l][q];
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll x;
    cin >> x;
    // REP1(i, 100) cout << pow(i, 5) << " "; cout << endl;
    for (ll b = -1000; b <= 1000; b++) {
        for (ll a = -1000; a <= 1000; a++) {
            if ((ll)pow(a, 5) - (ll)pow(b, 5) == x) {
                cout << a << " " << b << endl;
                return;
            }
        }
    }
}


Measured memory_bytes: 4104
#include <stdio.h>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>

using namespace std;

int main() {
    int A;
    int B;
    int C;
    int X;

    int count = 0;

    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&X);

    for(int a = 0;a <= A;a++) {
        for(int b = 0;b <= B;b++) {
            int c = (X - a*500 - b*100)/50;
            if(C < c || c < 0) {
                continue;
            }
            count++;
        }
    }

    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
if (H == 1 or W == 1):
  ans = 1
elif (H % 2 == 0 or W % 2 == 0):
  ans = (H * W) / 2
else:
  ans = (H * W) // 2 + 1
print(int(ans))

Measured memory_bytes: 3060
//
//  main.cpp
//  green_programmig
//
//  Created by 渡辺隆太郎 on 2017/10/09.
//  Copyright © 2017年 渡辺隆太郎. All rights reserved.
//

#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
using namespace std;
long long inf=100000000000007;
#define int long long
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");

signed main(){
    int a,b,c;cin>>a>>b>>c;
    if(a==b)cout<<c<<endl;
    else if(b==c)cout<<a<<endl;
    else cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
x = int(input())

if 400 <= x <= 599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 61624
#include <iostream>

using namespace std;

string s;
bool north , south , west , east;

int main()
{
    cin >> s;
    for(int i = 0 ; i < s.size() ; i++)
    {
        if(s[i] == 'E')
            east = true;
        if(s[i] == 'W')
            west = true;
        if(s[i] == 'N')
            north = true;
        if(s[i] == 'S')
            south = true;
    }
    if(south == north && east == west)
        cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll A, ll B) {
  cout << A*B << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){




    int h, w, i, j;
    while (1) {
        cin >> h >> w;
        if (!h && !w)
            break;
        for (i = 0; i < h; i++) {
            for (j = 0; j < w; j++) {
                if (i == 0 || j == 0 || i == h - 1 || j == w - 1)
                    cout << '#';
                else
                    cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}









Measured memory_bytes: 3100
#include <iostream>
#include <cstdlib>
#include<ctime>
#include<math.h>
#include<string>
using namespace std;

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(x>=r && y>=r && x<=W-r && y<=H-r){
        cout << "Yes\n";
    }
    else cout <<"No\n";
    
    return 0;
}


Measured memory_bytes: 3104
#include <cstdio>
#include <iostream>

using namespace std;

#define MAX 25
#define NIL -1
struct Node{
  int parent,left,right;
};

struct Node T[MAX];

void preParse(int u){
  if(u==NIL) return;
  cout << " " << u;
  preParse(T[u].left);
  preParse(T[u].right);
}

void inParse(int u){
  if(u==NIL) return;
  inParse(T[u].left);
  cout << " " << u;
  inParse(T[u].right);
}

void postParse(int u){
  if(u==NIL) return;
  postParse(T[u].left);
  postParse(T[u].right);
  cout << " " << u;
}

int getRoot(){
  int r=0;
  while(T[r].parent!=NIL){
    r=T[r].parent;
  }
  return r;
}

int main(){
  int n; cin >> n;
  for(int i=0;i<n;i++){
    T[i].left=NIL;
    T[i].right=NIL;
    T[i].parent=NIL;
  }
  for(int i=0;i<n;i++){
    int id,l,r;
    scanf("%d %d %d",&id,&l,&r);
    if(l!=NIL){
      T[id].left=l; T[l].parent=id;
    }
    if(r!=NIL){
      T[id].right=r; T[r].parent=id;
    }
  }
  int root=getRoot();
  cout << "Preorder" << endl;
  preParse(root);
  cout << endl;
  cout << "Inorder" << endl;
  inParse(root);
  cout << endl;
  cout << "Postorder" << endl;
  postParse(root);
  cout << endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int t;
    cin >> t;
    if(t==0) return 0;
    vector<int> s(t);
    rep(i,t) cin >> s[i];
    int n;
    cin >> n;
    vector<pair<int,int>> dm(n);
    rep(i,n){
      cin >> dm[i].first >> dm[i].second;
      dm[i].first--;
    }
    sort(all(dm));
    // rep(i,n){
    //   cout << dm[i].first SP dm[i].second << endl;
    // }
    vector<int> c(100,IINF);
    c[0]=0;
    int now=0;
    rep(i,100){
      int co=IINF;
      rep(j,i) co=min(co,c[j]);
      c[i]=min(c[i],co+1);
      while(dm[now].first==i){
        rep(j,100){
          if(s[(dm[now].first-j)%t]>dm[now].second) c[j]=IINF;
        }
        now++;
        if(now>=n) break;
      }
      // rep(j,i+1) cout << c[j] << " ";
      // cout << endl;
    }
    int ans=IINF;
    rep(i,100){
      ans=min(ans,c[i]);
      // cout << c[i] << " ";
    }
    // cout << endl;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const long double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}
int n,W;
int weight[100];
int val[100];
int minweightneeded[100001][100];
int maxvalposs=0;
int minwreq(int v , int i)
{
	//cout<<"v= "<<v <<" i=  "<<i;
	if(i==n && v!=0)
		return (int)W+1;
	else if(minweightneeded[v][i]>=0)
		return minweightneeded[v][i];
	else if(v ==0 )
	{
		if(i<n)
		{
			minweightneeded[v][i]=0;
			return minweightneeded[v][i];
		}	
		else
		return 0;	
	}
	else
	{
		int x;
		
		if(v-val[i]>=0)
		{
			 x= weight[i]+minwreq(v-val[i],i+1);
		}
		else
		 x=W+1;	
		
		int y= minwreq(v,i+1);

		if(x>W && y>W)
			{
				minweightneeded[v][i]=W+1;
				return minweightneeded[v][i];
			}
		else
		if(x<y)
		{

				minweightneeded[v][i]=x;
				return minweightneeded[v][i];
		}

		else
		{

				minweightneeded[v][i]=y;
				return minweightneeded[v][i];
		}

	}

}
int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin>>n>>W;
	for(int i=0;i< n ;i++)
	{
		cin>>weight[i];
		cin>>val[i];
	}
	for(int i=0 ; i<= 100000 ; i++)
	{
		for(int j=0 ; j<100 ; j++)
			minweightneeded[i][j]=-1;
	}
	for(int i=100000 ; i>=0 ;i--)
	{
		
			minwreq(i,0);
	}
	for(int i=100000 ; i>=0 ;i--)
	{
		
			 if(minwreq(i,0)<=W)
			 {
			 	if(i>maxvalposs)
			 		maxvalposs=i;
			 }
	}

	cout<<maxvalposs;
	// cerr<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 39424
#include "bits/stdc++.h"
using namespace std;

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 401;
int ai[N];
long long dp[N][N] , pre[N];
int main()
{
	 #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n ; cin >> n ;
	for(int i = 1 ; i <= n ; ++i)
		cin >> ai[i] , pre[i] = pre[i-1] + ai[i];
	if(n == 2) 
	{
		cout << ai[1] + ai[2];
		return 0;
	}
	long long  m , w;
	for(int i = 1 ; i <= n ; ++i)
		dp[i][i] = ai[i];
	for(int i = 1 ; i < n ;  ++i)
		dp[i][i+1] = ai[i] + ai[i+1];
	for(int dif = 2 ; dif < n  ; ++dif)
	{
		for(int i = 1 ; i <= n - dif ; ++i)
		{
			w = pre[i+dif] - pre[i-1] ;
			m = min (dp[i+1][i+dif] + w , dp[i][i+dif-1] + w) ;
			for(int j = i + 1 ; j < i + dif - 1; ++j)
			{
				m = min(m , dp[i][j] + dp[j+1][i+dif] + w);
			}
			dp[i][i+dif] = m ;
			cerr << i << " "<< i + dif << " "<< dp[i][i+dif] << endl;
		}
	}

	cout << dp[1][n];
	return 0;
}

Measured memory_bytes: 1664
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static final int MAX_HP = 6;
	public static final int MAX = 8;
		
	public static final int[][] move_dir = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
	
	public static boolean is_ok(int x, int y, int h, int w){
		if(x < 0 || x >= w || y < 0 || y >= h){
			return false;
		}else{
			return true;
		}
	}
	
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		boolean[][] can_enter = new boolean[MAX][MAX];
		boolean[][] on_food = new boolean[MAX][MAX];
		boolean[][][] visited = new boolean[MAX][MAX][MAX_HP + 1];
		
		while (true) {
			final int w = sc.nextInt();
			final int h = sc.nextInt();
			
			if(w == 0 && h == 0){
				break;
			}
			
			int sx = -1, sy = -1, gx = -1, gy = -1;
			
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					final int num = sc.nextInt();
					
					can_enter[i][j] = num != 0;
					
					if(num == 2){
						sx = j;
						sy = i;
					}else if(num == 3){
						gx = j;
						gy = i;
					}
					
					on_food[i][j] = num == 4;
					
					for(int k = 0; k <= MAX_HP; k++){
						visited[i][j][k] = false;
					}
				}
			}
			
			LinkedList<Integer> x_queue = new LinkedList<Integer>();
			LinkedList<Integer> y_queue = new LinkedList<Integer>();
			LinkedList<Integer> hp_queue = new LinkedList<Integer>();
			LinkedList<Integer> t_queue = new LinkedList<Integer>();
			
			x_queue.add(sx);
			y_queue.add(sy);
			hp_queue.add(MAX_HP);
			t_queue.add(0);
			visited[sy][sx][MAX_HP] = true;
			
			boolean flag = false;
			while(!x_queue.isEmpty()){
				final int x = x_queue.poll();
				final int y = y_queue.poll();
				final int hp = hp_queue.poll();
				final int time = t_queue.poll();
				
				if(hp <= 0){
					continue;
				}
				
				if(gx == x && gy == y){
					System.out.println(time);
					flag = true;
					break;
				}
				
				//System.out.println(x + " " + y + " " + hp + " " + time);
		
				final int next_hp = on_food[y][x] ? MAX_HP - 1 : hp - 1;
				
				if(next_hp <= 0){
					continue;
				}
				
				for(int[] move : move_dir){
					final int nx = x + move[0];
					final int ny = y + move[1];
					
					if(!is_ok(nx, ny, h, w)){
						continue;
					}else if(!can_enter[ny][nx]){
						continue;
					}else if(visited[ny][nx][next_hp]){
						continue;
					}
					
					visited[ny][nx][next_hp] = true;
					x_queue.add(nx);
					y_queue.add(ny);
					hp_queue.add(next_hp);
					t_queue.add(time + 1);
				}
			}
			
			if(!flag){
				System.out.println(-1);
			}
		}
	}

}

Measured memory_bytes: 21004