akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while(cin>>n, n) {
    int w, h;
    cin >> w >> h;
    
    int ba[w][h];
    memset(ba,0,sizeof(ba));
    
    REP(i,n) {
      int x,y;
      cin >> x >> y;
      ba[x-1][y-1] = 1;
    }
    int s, t;
    cin >> s >> t;
    int ans = 0;
    REP(y,h-t+1) {
      REP(x,w-s+1) {
        int wa = 0;
        REP(i,t) {
          REP(j,s) {
            wa += ba[x+j][y+i];
          }
        }
        ans = max(ans, wa);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
w,h,x,y=n1()

ans1=w*h/2
ans2=0
if x*2==w and y*2==h:
    ans2=1
print(ans1,ans2)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		String s = sc.next();

		int[]x = new int[n];

		for (int i=0; i<n; i++){
			x[i] = s.charAt(i) - '0';
		}

		int pc =0;
		for (int i=0; i<n; i++){
			if (x[i] == 1){
				pc++;
			}
		}

		int[] ans = new int[n];
		int[] f = new int[n];
		for (int i=0; i<2; i++){


			int npc;
			if (i == 0) {
				npc = pc +1;
			} else {
				npc = pc -1;
			}
			if (npc <= 0){
				continue;
			}
			int r0=0;
			for (int k=0; k<n; k++){
				r0 = (r0*2) % npc;
				r0 += x[k];
			}
			int l = 1;
			for (int j=n-1; j>=0 ; --j){
				if (x[j] == i){
					int r = r0;
					if (i == 0) {
						r = (r + l) % npc;
					} else {
						r = (r - l + npc) % npc;
					}
					ans[j] = f(r) + 1;
				}
				l = (l*2) % npc;
			}
		}
		for (int i=0; i<n; i++){
			System.out.println(ans[i]);
		}
	}

	public static int f(int n){

		if (n == 0){
			return 0;
		}
		return f(n % pcnt(n)) + 1;

	}

	public static int pcnt(int n){
		String b = Integer.toBinaryString(n);
		int ret = 0;
		for (int i=0; i<b.length(); i++){
			if (b.charAt(i) == '1'){
				ret ++;
			}
		}
		return ret;
	}

}

Measured memory_bytes: 59732
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64));
    for i in 0..26 {
        let x = n - i * 4;
        if x >= 0 && x % 7 == 0 {
            return "Yes".to_string();
        }
    }
    return "No".to_string();
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "11" => "Yes",
    test2: "40" => "Yes",
    test3: "3" => "No",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vi d(n);
	rep(i, n)cin >> d[i];
	sort(all(d));
	cout << d[n / 2] - d[n / 2 - 1] << endl;

}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>

#include <queue>
#include <cstdio>

#include <list>

#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DIV_NUM (1000000007)

using namespace std;


bool seen[501][501];

int N,K,S;
int X, Y, Z;
int con;

char field[501][501];
int  dist[501][501];

typedef pair<int, int> P;
queue<P> que;


//typedef vector<vector<int>> v;
vector<double> A;
vector<double> v1;
vector<double> v2;


int main(){
  
  
    // input data
 
    cin >> K >> S;

    X = 0;
    Y = 0; 
    Z = 0;

    con = 0;

    for (int i = 0; i <= K; i++) {
        X = i;
        for (int j = 0; j <= K; j++) {
            Y = j;
            Z = S - (X + Y);
            if (Z>=0 && Z<=K) { con++; }

            //std::cout << X << Y << Z << "\n";

        }
    }
       
       
    
    std::cout << con << "\n";

        return 0;

}

Measured memory_bytes: 256
import sys
import math

def main():
    H, W = [int(_) for _ in input().split()]
    if H == 1 or W == 1:
        m = 1
        print(int(m))
        sys.exit()
        
    elif H % 2 == 1 and W % 2 == 1:
        m = (H * W) // 2 + 1
    else:
        m = (H * W) // 2
    print(int(m))
main()

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

string S, T;

int main() {
  cin >> S >> T;

  int res = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != T[i])
      res++;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3896
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int &i:A)
    cin>>i;
  vector<vector<vector<int>>> B(N+1,vector<vector<int>>(N+1,vector<int>(2,0)));
  for(int i=0;i<N;i++){
    for(int j=0;j<N-i;j++){
      if(j+i==0){
        B[j][j+i][0]=B[j+1][j+i][1]+A[j+i];
        B[j][j+i][1]=B[j+1][j+i][0]-A[j+i];
      }else if(j==N-1){
        B[j][j+i][0]=B[j][j+i-1][1]+A[j+i];
        B[j][j+i][1]=B[j][j+i-1][0]-A[j+i];
      }else{
        B[j][j+i][0]=max(B[j][j+i-1][1]+A[j+i],B[j+1][j+i][1]+A[j]);
        B[j][j+i][1]=min(B[j][j+i-1][0]-A[j+i],B[j+1][j+i][0]-A[j]);
      }
    }
  }
  cout<<B[0][N-1][0]<<endl;
}

Measured memory_bytes: 496048
<?php
$inputArray = array();
while (!feof(STDIN)) {
  $input = trim(fgets(STDIN));
  if (empty($input)) {
    break;
  }
  array_push($inputArray, $input);
}

$loopcount = 0;
foreach ($inputArray as $years) {
  $delimiter = ' ';
  $aryInputs = explode($delimiter, $years);
  $startYear = $aryInputs[0];
  $endYear = $aryInputs[1];

  // 0 0 ?????£????????????
  if (!$startYear || !$endYear) {
    break;
  }

  // 1????????\?????????????????????
  if ($loopcount++) {
    echo "\n";
  }

  $count = 0;
  for ($year = $startYear; $year <= $endYear; $year++) {
    if ((!($year%4) && $year%100) || !($year%400)) {
      echo $year . "\n";
      $count++;
    }
  }
  if (!$count) {
    echo 'NA' . "\n";
  }
}

Measured memory_bytes: 15236
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = vals[0];
        var x = vals[1];
        var a = Console.ReadLine().Split(' ').Select(long.Parse).OrderBy(t => t).ToArray();

        int count = 0;
        bool ng = false;
        foreach (var aa in a)
        {
            if (aa <= x)
            {
                x -= aa;
                count++;
            }
            else
            {
                ng = true;
                break;
            }
        }

        if (!ng && x > 0)
        {
            count--;
        }


        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13396
#include<iostream>
using namespace std;
int main() {
	bool a[31] = {false};
	int b;
	for (int i = 0; i < 28; ++i) {
		cin >> b;
		a[b] = true;
	}
	for (int i = 1; i <= 30; ++i) {
		if (a[i] == false) {
			cout << i << endl;
		}
	}
	return 0;
}

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

float a,b;
int ans = -1;

int main() {
  cin >> a >> b;
  for (float i = 1; i <= 1250; i++) {
    if (a <= 0.08 * i && 0.08 * i < a + 1 && b <= 0.1 * i && 0.1 * i < b + 1) {
      ans = (int)i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

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

bool isok(int y, int x){
    REP(i, m)REP(j, m){
        if(a[y + i][x + j] != b[i][j]){
            return false;
        }
    }
    return true;
}

int main(){
    cin >> n >> m;
    REP(i, n)REP(j, n)cin >> a[i][j];

    REP(i, m)REP(j, m)cin >> b[i][j];

    REP(i, n - m + 1)REP(j, n - m + 1){
        if(isok(i, j)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
table = []

for i, a in enumerate(A):
    table.append([a,i])
table.sort(reverse=True)

# DP[i][j] 左端に i 個, 右端に j 個貪欲に詰めたときのうれしさ
DP = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
    # i 人目 table[i-1] の幼児を移動させる
    for x in range(i+1):
        y = i - x

        #左端に置く場合と右端に置く場合でmax
        DP[x][y] = max((DP[x-1][y] + table[i-1][0] * abs(table[i-1][1]  - x+1)) * (x>0),\
                     (DP[x][y-1] + table[i-1][0] * abs(table[i-1][1] - (N - y))*(y>0)))


ans = 0
for i in range(N+1):
    for j in range(N+1):
        ans = max(ans, DP[i][j])
print(ans)


Measured memory_bytes: 102140
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
typedef long long ll;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;


int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int res = (H - h)*(W - w);
	cout << res << endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
M = 7000
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
dp = [[0] * (w + 1) for _ in range(h + 1)]
dp[0][1] = dp[1][0] = 1 << M
for i in range(h):
    for j in range(w):
        dp[i + 1][j + 1] |= dp[i][j + 1] << abs(a[i][j] - b[i][j])
        dp[i + 1][j + 1] |= dp[i][j + 1] >> abs(a[i][j] - b[i][j])
        dp[i + 1][j + 1] |= dp[i + 1][j] << abs(a[i][j] - b[i][j])
        dp[i + 1][j + 1] |= dp[i + 1][j] >> abs(a[i][j] - b[i][j])
ans = M
for b in range(2 * M + 1):
    if dp[h][w] >> b & 1:
        ans = min(ans, abs(b - M))
print(ans)


Measured memory_bytes: 15604
'''
https://atcoder.jp/contests/abc084/tasks/abc084_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    def primecheck(n):
        p = [True] * (n + 1)
        p[0] = False
        p[1] = False
        for i in range(2, int(n ** 0.5) + 1):
            if p[i]:
                for j in range(i * i, n + 1, i):
                    p[j] = False
        return p
    
    p = primecheck(10**5)
    cnt = 0
    res = [0]*(10**5)
    for i in range(10**5):
        if p[i]==p[(i+1)//2]==1:
            cnt += 1
        res[i] = cnt


    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        print(res[r]-res[l-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 5808
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

template<class T> bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}

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

	vector<int> h(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
	}

	vector<int> dp(n, INF);

	dp.at(0) = 0;

	for (int i = 1; i < n; i++)
	{
		chmin(dp.at(i), dp.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
		if (i > 1)
		{
			chmin(dp.at(i), dp.at(i - 2) + abs(h.at(i) - h.at(i - 2)));
		}
	}

	cout << dp.back() << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int a;
    cin >> a;
    cout << a + pow(a, 2) + pow(a, 3) << endl;
}

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

int main(){
  ll n,k;
  cin >> n >> k;
  if(n < k){
    cout << 1 << endl;
    return 0;
  }
  ll ans = 0;
  ll a = 1;
  while(1){
    if(n >= a){
      a *= k;
      ++ans;
    }
    else{
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e10;
const int MAX_N = 200001;

int a;
int cnt = 0;
const int max = 999999999;
int sft[3] = { 7,5,3 };
void dfs(int m,int n,int s,int f,int t) {
	if (m == 0 && n == 0) {
		dfs(sft[0], 1, 1, 0, 0);
		dfs(sft[1], 1, 0, 1, 0);
		dfs(sft[2], 1, 0, 0, 1);
	}
	else if(n < 9) {
		if (m <= a && s >= 1 && f >= 1 && t >= 1) cnt++;
		dfs(10*m+sft[0], n+1, s + 1, f, t);
		dfs(10*m+sft[1], n+1, s, f+1, t);
		dfs(10*m+sft[2], n+1, s, f, t+1);
	}
	else if (n == 9) {
		if (m <= a && s >= 1 && f >= 1 && t >= 1) cnt++;
	}
}
int main() {

	cin >> a;
	dfs(0,0,0,0,0);
	cout << cnt << endl;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int H, W;
  while (1)
{
  cin >> H >> W;
  if (H == 0 && W == 0)
    break;
  
  for (int h = 0; h < H; ++h)
  {
    for (int w = 0; w < W; ++w)
    {
      cout << ((h + w) % 2 == 0 ? '#' : '.');
    }
    cout << endl;
  }
  cout << endl ;
}
}


Measured memory_bytes: 3120
#include<stdio.h>
#define mod 1000000007ll
#define inf 2147483647ll
#define ll long long
struct edge{
    int to,nex;
}e[3000010];
int c[200010],h[200010],pos[200010],cnt[200010],tot;
ll w[200010],fac[200010],rfac[200010],min[200010];
bool v[200010];
ll pow(ll a,ll b){
    ll ans=1,base=a;
    while(b){
        if(b&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        b>>=1;
    }
    return ans;
}
ll C(ll n,ll k){
    return(((fac[n]*rfac[n-k])%mod)*rfac[k])%mod;
}
void add(int a,int b){
    tot++;
    e[tot].to=b;
    e[tot].nex=h[a];
    h[a]=tot;
}
void dfs(int x){
    v[x]=1;
    for(int i=h[x];i;i=e[i].nex){
        if(!v[e[i].to])dfs(e[i].to);
    }
}
int main(){
    int n,i,fir,sec=0;
    ll X,Y,min1,min2,tot,ans;
    scanf("%d%lld%lld",&n,&X,&Y);
    fac[0]=1;
    for(i=1;i<=n;i++){
        scanf("%d%lld",c+i,w+i);
        fac[i]=(i*fac[i-1])%mod;
        min[i]=inf;
    }
    rfac[n]=pow(fac[n],mod-2);
    for(i=n;i>0;i--)rfac[i-1]=(i*rfac[i])%mod;
    for(i=1;i<=n;i++){
        if(w[i]<min[c[i]]){
            min[c[i]]=w[i];
            pos[c[i]]=i;
        }
    }
    for(i=1;i<=n;i++){
        if(i!=pos[c[i]]&&w[i]+min[c[i]]<=X){
            add(i,pos[c[i]]);
            add(pos[c[i]],i);
        }
    }
    min1=min2=inf;
    for(i=1;i<=n;i++){
        if(w[i]<min1){
            min1=w[i];
            fir=i;
        }
    }
    for(i=1;i<=n;i++){
        if(w[i]<=min2&&c[i]!=c[fir]){
            min2=w[i];
            sec=i;
        }
    }
    for(i=1;i<=n;i++){
        if(i==fir)continue;
        if(c[i]!=c[fir]&&w[i]+w[fir]<=Y){
            add(i,fir);
            add(fir,i);
        }
        if(sec&&c[i]!=c[sec]&&w[i]+w[sec]<=Y){
            add(i,sec);
            add(sec,i);
        }
    }
    dfs(fir);
    tot=0;
    for(i=1;i<=n;i++){
        if(v[i]){
            tot++;
            cnt[c[i]]++;
        }
    }
    ans=1;
    for(i=1;i<=n;i++){
        if(cnt[i]){
            ans=(ans*C(tot,cnt[i]))%mod;
            tot-=cnt[i];
        }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 16512
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)
/**==Info==
*Program:3
*Problem:E - 木と整数 / Integers on a Tree
*Date:2018-10-20
*Algorithm:Teacher's DFS 2
*Stats:Unknown*/

bool debug=false;

bool parity[100005][2];
bool known[100005];
int l[100005],r[100005],ans[100005],val[100005];
bool used[100005];
int par[100005];
vector<int> ord;
int n,k;
vector<int> nei[100005];

void dfs(int pos){
	used[pos]=true;
	
	l[pos]=-1e9;
	r[pos]=1e9;
	
	for(int i=0;i<nei[pos].size();i++){
		int to=nei[pos][i];
		if(!used[to]){
			dfs(to);
			par[to]=pos;
			
			if(parity[to][0]){
				parity[pos][1]=true;
			}
			if(parity[to][1]){
				parity[pos][0]=true;
			}
			l[pos]=max(l[pos],l[to]-1);
			r[pos]=min(r[pos],r[to]+1);
		}
	}
	
	if(known[pos]){
		l[pos]=max(l[pos],val[pos]);
		r[pos]=min(r[pos],val[pos]);
		parity[pos][val[pos]%2]=true;
	}
	
	if(parity[pos][0] && parity[pos][1]){
		puts("No");
		exit(0);
	}
	
	if(l[pos]>r[pos]){
		puts("No");
		exit(0);
	}
	
	ord.push_back(pos);
}

int fuck(int a,int b){
	if(b==-1){
		return l[a];
	}
	
	l[a]=max(l[a],ans[b]-1);
	r[b]=min(r[b],ans[b]+1);
	
	while(l[a]%2==ans[b]%2){
		l[a]++;
	}
	
	return l[a];
}

int main(int argc,char* argv[]){
	
	memset(par,-1,sizeof(par));
	
	qi;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	
	cin>>k;
	for(int i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		a--;
		known[a]=true;
		val[a]=b;
	}
	
	
	dfs(0);
	
	reverse(ord.begin(),ord.end());
	
	for(int i=0;i<n;i++){
		ans[ord[i]]=fuck(ord[i],par[ord[i]]);
	}
	
	cout<<"Yes"<<endl;
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 13944
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
pair<int,int> X[100010], Y[100010];

double func(double t)
{
	double minx = 10000000000.0;
	double maxx = -10000000000.0;
	double miny = 10000000000.0;
	double maxy = -10000000000.0;
	rep(i, 0, N)
	{
		double tx, ty;
		if (X[i].second == 0)tx = (double)X[i].first + t;
		else if (X[i].second == 1)tx = (double)X[i].first;
		else tx = (double)X[i].first - t;
		if (Y[i].second == 0)ty = (double)Y[i].first + t;
		else if (Y[i].second == 1)ty = (double)Y[i].first;
		else ty = (double)Y[i].first - t;
		chmin(minx, tx);
		chmax(maxx, tx);
		chmin(miny, ty);
		chmax(maxy, ty);
	}
	return (maxx - minx)*(maxy - miny);
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	char d;
	cin >> N;
	rep(i, 0, N)
	{
		cin >> X[i].first >> Y[i].first >> d;
		if (d == 'R')
		{
			X[i].second = 0;
			Y[i].second = 1;
		}
		else if (d == 'L')
		{
			X[i].second = 2;
			Y[i].second = 1;
		}
		else if (d == 'U')
		{
			X[i].second = 1;
			Y[i].second = 0;
		}
		else
		{
			X[i].second = 1;
			Y[i].second = 2;
		}
	}

	vector<double> times;
	times.push_back(0.0);
	int tp[4][3];
	rep(i, 0, 4)rep(j, 0, 3)
	{
		if (i % 2 == 0)tp[i][j] = INF;
		else tp[i][j] = -INF;
	}
	rep(i, 0, N)
	{
		chmin(tp[0][X[i].second], X[i].first);
		chmax(tp[1][X[i].second], X[i].first);
		chmin(tp[2][Y[i].second], Y[i].first);
		chmax(tp[3][Y[i].second], Y[i].first);
	}
	rep(i, 0, 4)
	{
		if (abs(tp[i][0]) < INF&&abs(tp[i][2]) < INF&&tp[i][0] < tp[i][2])times.push_back((double)abs(tp[i][0] - tp[i][2]) / 2.0);
		if (abs(tp[i][0]) < INF&&abs(tp[i][1]) < INF&&tp[i][0] < tp[i][1])times.push_back((double)abs(tp[i][1] - tp[i][0]));
		if (abs(tp[i][2]) < INF&&abs(tp[i][1]) < INF&&tp[i][1] < tp[i][2])times.push_back((double)abs(tp[i][2] - tp[i][1]));
	}

	double ans = 1LL << 60;
	for (auto t : times)
	{
		chmin(ans, func(t));
	}

	printf("%.12lf\n", ans);

	return 0;
}

Measured memory_bytes: 3456
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

int main()
{
    int n, k;
    std::cin >> n >> k;
    std::vector<int> v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
    }

    long long ans = 0;
    for (int num_pop = 0; num_pop <= k; num_pop++) {
        for (int pop_from_right = 0; pop_from_right <= num_pop; pop_from_right++) {
            std::vector<int> copied_v = v;
            std::priority_queue<int, std::vector<int>, std::greater<int>> q;

            for (int i = 0; i < pop_from_right && copied_v.size(); i++) {
                q.push(copied_v.back());
                copied_v.pop_back();
            }

            std::reverse(copied_v.begin(), copied_v.end());
            for (int i = 0; i < num_pop - pop_from_right && copied_v.size(); i++) {
                q.push(copied_v.back());
                copied_v.pop_back();
            }

            int num_push = k - num_pop;
            for (int i = 0; i < num_push && q.size() && q.top() < 0; i++) {
                q.pop();
            }

            long long sum = 0;
            while (q.size()) {
                sum += q.top();
                q.pop();
            }

            if (ans < sum) {
                ans = sum;
            }
        }
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    stack<int> a;
    ll x = 0, y = 0;
    rep(i, n) {
        int s;
        cin >> s;
        if (i==n-1) y += s;
        else if (i==0) x += s;
        else {
            x += s;
            a.push(s);
        }
    }
    ll ans = abs(x-y);
    rep(i, n-2) {
        int s = a.top(); a.pop();
        y += s;
        x -= s;
        ans = min(ans, abs(x-y));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
    double d;
    cin >> d;
    double m = d * 2 / sqrt(2);
    for (int h = 1; h <= d; h++) {
        double w = sqrt(d * d - h * h);
        if(w < 1) m = max(m, (double)1 + h);
    }
    printf("%.9f\n", m);
}



Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-8;
int INF = 1e9;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int m,n;
bool fld[100][100];
bool used[100][100];
bool pos(int x,int y){return 0<=x&&x<m&&0<=y&&y<n;}
int rec(int x,int y){
	if(!pos(x,y))return 0;
	if(!fld[x][y]||used[x][y])return 0;
	used[x][y]=true;
	int res=0;
	REP(i,4){
		int nx=x+dx[i],ny=y+dy[i];
		res=max(res,rec(nx,ny)+1);
	}
	used[x][y]=false;
	return res;
}
int main(){
	while(cin>>m>>n&&(m||n)){
		REP(i,n)REP(j,m)cin>>fld[j][i];
		memset(used,false,sizeof(used));
		int res=0;
		REP(i,n)REP(j,m)if(fld[j][i])res=max(res,rec(j,i));
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1188
/*  Isn't it lovely, all alone?             */
/*  Heart made of glass, my mind of stone   */
/*  Tear me to pieces, skin to bone         */
/*  Hello, welcome home                     */

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 998244353
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);


ll t=1;
//cin>>t;
while(t--)
{

ll a,b,c,k;
cin>>a>>b>>c;
cin>>k;
ll ti=0;

while(a>=b)
{
 b*=2;
  ti++;
}

while(c<=b)
{
  c*=2;
  ti++;
}

if(ti<=k)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;

}
return 0;
}







Measured memory_bytes: 3648
function sl(n){
	if(n%2===0){
		return 2;
	}
	for(var i=3;i*i<=n;i+=2){
		if(n%i===0){
			return i;
		}
	}
	return n;
}
var a=[2,3];
for(var i=1,l=1e6;i*6+1<l;i++){
	var o=i*6-1,p=i*6+1;
	sl(o)===o&&a.push(o);
	sl(p)===p&&a.push(p);
}
process.stdin.on("data",function(c){
	(c+"").trim().split("\n").some(function(n){
		var i=0,n=+n,c=0;
		while(a[i++]<=n)c++;
		console.log(c);
	});
}).resume();

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

#define ll long long
using namespace std;

int a[10000001];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);
    ll n;
    cin>>n;
    a[1]=1;
    a[2]=2;
    for (ll i=2;i<n;i++){
        ll k=2;
        for (ll j=i*k;j<=n;j=i*k){
           a[j]++;
           k++;
        }
    }
    ll ans=0;
    for (ll i=1;i<=n;i++){

       if(i>2)a[i]+=2;
       ans=ans+a[i]*i;
    }
    cout<<ans<<endl;
}







Measured memory_bytes: 42680
X = gets.to_i
K = gets.to_i
rs = [0] + gets.split.map(&:to_i)

sat_ub = [X]
sat_lb = [0]
val_lb = [0]
(1..K).each do |k|
    rd = rs[k] - rs[k-1]
    if k % 2 == 1   # パーツA減少
        if val_lb[k-1] - rd < 0
            val_lb[k] = 0
            sat_lb[k] = sat_lb[k-1] + (rd - val_lb[k-1])
        else
            val_lb[k] = val_lb[k-1] - rd
            sat_lb[k] = sat_lb[k-1]
        end
        sat_ub[k] = sat_ub[k-1]
        sat_lb[k] = sat_ub[k] if sat_lb[k] > sat_ub[k]
    else
        val_ub = val_lb[k-1] + sat_ub[k-1] - sat_lb[k-1]
        if val_ub + rd > X
            sat_ub[k] = sat_ub[k-1] - (val_ub + rd - X)
        else
            sat_ub[k] = sat_ub[k-1]
        end
        val_lb[k] = val_lb[k-1] + rd
        val_lb[k] = X if val_lb[k] > X
        sat_lb[k] = sat_lb[k-1]
        sat_ub[k] = sat_lb[k] if sat_ub[k] < sat_lb[k]
    end
end

Q = gets.to_i
Q.times do
    t, a = gets.split.map(&:to_i)
    i = (0...K).bsearch{|k|  rs[k+1] > t} || K
    if a <= sat_lb[i]
        start = val_lb[i]
    elsif a <= sat_ub[i]
        start = val_lb[i] + a - sat_lb[i]
    else
        start = val_lb[i] + sat_ub[i] - sat_lb[i]
    end
    if i % 2 == 0 # パーツA減少
        result = start - (t - rs[i])
        result = 0 if result < 0
    else
        result = start + (t - rs[i])
        result = X if result > X
    end
    puts result
end



Measured memory_bytes: 15808
import numpy as np

DEBUG = False

def dprint(*args):
    if DEBUG:
        print(*args)

digit = 6

def to_str(x):
    if x[0] == 0:
        return str(x[1])
    else:
        return "{:d}{:06d}".format(x[0], x[1])


def add(x, y):
    carry = 0
    new1 = x[1] + y[1]
    if new1 >= 1000000:
        carry = 1
        new1 -= 1000000
    new0 = x[0] + y[0] + carry
    return [new0, new1]

def sub(x, y):
    carry = 0
    new1 = x[1] - y[1]
    if new1 < 0:
        carry = 1
        new1 += 1000000
    new0 = x[0] - y[0] - carry
    return [new0, new1]

def gt(x, y):
    if x[0] > y[0]:
        return True
    elif x[0] < y[0]:
        return False
    else:
        if x[1] > y[1]:
            return True
        else:
            return False

abk = input().split(' ')
a_s, b_s, k_s = abk

nums = []
for t_str in abk:
    if len(t_str) > 6:
        upper, lower = int(t_str[0:-6]), int(t_str[-6:])
    else:
        upper, lower = 0, int(t_str)
    nums.append([upper, lower])

a, b, k = nums
dprint(a_s, b_s, k_s)
dprint(a, b, k)
dprint(gt(a, b))
dprint(gt(b, a))
dprint(gt(a, k))
dprint(gt(k, a))

if(gt(a, k)):
    result = sub(a, k)
    print(to_str(result), b_s)
else:
    mod = sub(k, a)
    if(gt(b, mod)):
        mod2 = sub(b, mod)
        print(0, to_str(mod2))
    else:
        print(0, 0)


Measured memory_bytes: 12500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,T;
  cin>>N>>T;
  vector<int>c(N);
  vector<int>t(N);
  for(int i=0;i<N;i++){
    cin>>c.at(i)>>t.at(i);
  }
  int count=1001;
  int sum=0;
  for(int i=0;i<N;i++){
    if(t.at(i)<=T){
      if(c.at(i)<count){
        sum=sum+1;
        count=c.at(i);
      }
      else{
      }
    }
    else{
    }
  }
  if(sum==0){
    cout<<"TLE"<<endl;
  }
  else{
    cout<<count<<endl;
  }
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s; cin >> s;
    FORD(i, s.size()-1, 2) {
        if (i % 2 != 0) {
            continue;
        }
        if (s.substr(0, i/2) == s.substr(i/2, i/2)) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 384
xyzk, a, b, c = STDIN.read.lines.map { |line| line.split(/\s+/).map(&:to_i) }
k = xyzk[-1]

a.sort! { |x, y| y <=> x }
b.sort! { |x, y| y <=> x }
c.sort! { |x, y| y <=> x }

ret = []
a.size.times { |ai|
  b.size.times { |bi|
    c.size.times { |ci|
      if ((ai + 1) * (bi + 1) * (ci + 1) <= k)
        ret << (a[ai] + b[bi] + c[ci])
      else
        break
      end
    }
  }
}

ret.sort! { |x, y| y <=> x }
puts ret[0...k].join("\n")

Measured memory_bytes: 4152
import heapq
N, M = map(int, input().split())
works = sorted([list(map(int, input().split())) for i in range(N)])

ans = 0
hq = []
i = 0
for limit in range(1, M + 1):
    while (i < N) and (works[i][0] <= limit):
        cost, value = works[i]
        heapq.heappush(hq, -value)
        i += 1

    if hq:
        ans += -heapq.heappop(hq)

print(ans)


Measured memory_bytes: 31964
from heapq import heappop, heappush

n, m = map(int, input().split())
jobs = {}
for _ in range(n):
	a, b = map(int, input().split())
	if not a in jobs:
		jobs[a] = [b]
	else:
		jobs[a].append(b)

res = 0
tmp = []
for day in range(1, m + 1):
	if day in jobs:
		for b in jobs[day]:
			heappush(tmp, -b)
	else:
		if len(tmp) == 0:
			continue
	res -= heappop(tmp)

print(res)


Measured memory_bytes: 26064
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

void main() {
  long[] buf = readln.chomp.split.to!(long[]);
  long q = buf[0],
      h = buf[1],
      s = buf[2],
      d = buf[3];
  long N = readln.chomp.to!(long);

  long min_cost_per_1L = min(q * 4, h * 2, s);
  long min_cost_per_2L = min(q * 8, h * 4, s * 2, d);

  writeln(
      min((N / 2 * min_cost_per_2L + N % 2 * min_cost_per_1L), (N * min_cost_per_1L))
      );
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assart
#include <numeric>
#include <iterator>
#include <list>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(int i=(max);i>=(min);i--)
const int MOD=1e9+7;
const int MOD2=998244353;

const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}


//Eと名のつくのはデバッグ用！
int EintN(int array[],const int num){
    for(int i=0;i<num;i++){cerr<<array[i]<<" ";}
    br;
    return 0;
}
int EintNN(const int heighth,const int width,int array[heighth][width]){
    FOR(i, 0, heighth){
        FOR(k, 0, width){
            {cerr<<array[i][k]<<" ";}
        }
        br;
    }
    br;
    return 0;
}
int Eint(string str,const ll num){
    cerr<<str<<" is "<<num<<" now."<<endl;
    return 0;
}


int prob(){
    ll ans;ans=0;
    int N;cin>>N;
    
    int H;
    int height=0;
    FOR(i, 0, N){
        cin>>H;
        if(H==height)continue;
        if(H >height){height=H-1;continue;}
        if(H <height){OutputAndReturn0("No")}
    }
    OutputAndReturn0("Yes");
    return 0;
}



signed main(){
    //test();
    prob();
    return 0;
}


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

int main() {

	ll N;
	int h, n, w;
	scanf("%lld", &N);
	for (int i = 1; i <= 3500; i++) {
		for (int j = 1; j <= 3500; j++) {
			ll a = N*i*j;
			ll b = 4 * i*j -  N*i - N*j;
			if (b > 0 && a%b == 0) {
				printf("%d %d %lld\n", j, i, a / b);
				return 0;
			}
		}
	}
}

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

long long mod = 1000000007;
long long N, H, D;
long long dp[1 << 20], fact[1 << 20];

int main() {
	cin >> N >> H >> D;
	fact[0] = 1; for (int i = 1; i <= N; i++) fact[i] = (1LL * i*fact[i - 1]) % mod;
	long long s = 0; for (int i = 1; i <= N; i++) { s += fact[i]; s %= mod; }

	dp[0] = 1; long long ret = dp[0];
	for (int i = 1; i <= H; i++) {
		if (i == H) dp[i] = (ret*fact[N]) % mod;
		else dp[i] = (ret * s) % mod;
		ret += dp[i]; ret %= mod;
		if (i >= D) { ret -= dp[i - D]; ret += mod; ret %= mod; }
	}
	cout << dp[H] << endl;
	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

bool check(char a){

	bool isans = false;
	std::vector<char> v = {'1','2','3','4','5','6','7','8','9','0'};
	for (int i = 0; i < 10; ++i)
	{
		if(a == v[i]) isans= true;
	}

	return isans;
}

int main() {
	int a,b; cin >> a >> b;
	string s; cin >> s;

	bool isAns = true;

	for (int i = 0; i < a; ++i)
	{
		if(!check(s[i])) isAns = false;
	}
	if(s[a]!='-') isAns = false;
	for (int i = a+1; i < a+b+1; ++i)
	{
		if(!check(s[i])) isAns = false;
	}

	if (isAns) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
N = STDIN.gets.chomp.to_i

a = [0] * (N+1)

xb = Math.sqrt(N/6).to_i
b = Math.sqrt(N).to_i
(1..xb).each do |x|
	(x..b).each do |y|
		xy = x * x + y * y + x * y
		break if xy >= N
		(y..b).each do |z|
			c = xy + z * z + y * z + z * x
			if c <= N
				if x == y && y == z
					a[c] += 1
				elsif x == y || y == z || z == x
					a[c] += 3
				else
					a[c] += 6
				end
			elsif c > N
				break
			end
		end
	end
end

(1..N).each do |n|
	puts a[n]
end
	

Measured memory_bytes: 14272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* 基本要素 */
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double EPS = 1e-9; // 許容誤差^2
const double INF = 1e9;
#define X real()
#define Y imag()
// #define LE(n,m) ((n) < (m) + EPS)
#define LE(n,m) ((n) - (m) < EPS)
// #define GE(n,m) ((n) + EPS > (m))
#define GE(n,m) (EPS > (m) - (n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// 外積　cross(a,b) = |a||b|sinθ
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

// 点の進行方向
int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

// 点pの直線aへの射影点を返す
Point proj(Point a1, Point a2, Point p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

double distLP(Point a1, Point a2, Point p) {
  return abs(proj(a1, a2, p) - p);
}

// 2円の共通接線。返される各直線に含まれる頂点は円との接点となる
vector<Line> tangentLines(Point a, double ar, Point b, double br) {
  vector<Line> ls;
  double d = abs(b-a);
  rep (i,2) {
    double sin = (ar - (1-i*2)*br) / d;
    if (!LE(sin*sin, 1)) break;
    double cos = sqrt(max(1 - sin*sin, 0.0));
    rep (j,2) {
      Point n = (b-a) * Point(sin, (1-j*2)*cos) / d;
      ls.push_back(Line(a + ar*n, b + (1-i*2)*br*n));
      if (cos < EPS) break;  // 重複する接線を無視（重複していいならこの行不要）
    }
  }
  return ls;
}

int main(){
    int n;
    while(cin >>n,n){
        vector<Point> c(n);
        vector<int> r(n),m(n);
        rep(i,n){
            int x,y;
            cin >>x >>y >>r[i] >>m[i];
            c[i] = Point(x,y);
        }

        int ans = 1;
        rep(i,n)rep(j,n)if(i!=j){
            rep(ii,2)rep(jj,2){
                vector<Line> ls = tangentLines(c[i],r[i]+ii*m[i],c[j],r[j]+jj*m[j]);
                for(const auto &l:ls){
                    int tt = 0;
                    rep(k,n){
                        double d = distLP(l.fi,l.se,c[k]);
                        if(LE(0,d-r[k]) && LE(d-r[k],m[k])) ++tt;
                    }
                    ans = max(ans,tt);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3132
#include<cstdio>
#include<algorithm>
using namespace std;
int n, K, D1[5010][5010], D2[5010][5010];
int w[5010], cnt;
bool Exist(int a, int b, int e){
    if(b <= 0){
        return D2[a][e] >= 1;
    }
    return D2[a][e] - D2[a][b-1] >= 1;
}
int main(){
    int i, j;
    scanf("%d%d",&n,&K);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
    }
    D1[0][0]=D2[n+1][0]=1;
    for(i=1;i<=n;i++){
        for(j=0;j<=K;j++){
            D1[i][j] = D1[i-1][j];
            if(j>=w[i] && D1[i-1][j-w[i]])D1[i][j] = 1;
        }
    }
    for(i=n;i>=1;i--){
        for(j=0;j<=K;j++){
            D2[i][j] = D2[i+1][j];
            if(j>=w[i] && D2[i+1][j-w[i]])D2[i][j] = 1;
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=K;j++)D2[i+1][j] += D2[i+1][j-1];
        if(w[i] > K){
            cnt++;
            continue;
        }
        for(j=0;j<K;j++){
            if(D1[i-1][j] && Exist(i+1,K-w[i]-j, K-j-1)){
                cnt++;
                break;
            }
        }
    }
    printf("%d\n",n-cnt);
}

Measured memory_bytes: 196096
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string s;
	cin >> s;

	int count1 = 0;
	char c='\0';
	for (size_t i = 0; i < 4; ++i) {
		if (s[i] == s[0]) {
			++count1;
		}
		else{
			c = s[i];
		}
	}

	int count2 = 0;
	for (size_t i = 0; i < 4; ++i) {
		if (s[i] == c) {
			++count2;
		}
	}

	if (count1 == 2 && count2 == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
a,b = gets.split.map(&:to_i)
kazu = 0

if b <= 9
  kazu = 10*a+b
 elsif 10 <= b && b <= 99
  kazu = 100*a+b
 else kazu = 1000*a+b
end

m = Array.new
for i in 0..317
 m[i] = i*i
end

switch = 0
for i in 0..317
 if m[i] == kazu
  switch = 1
 end
end

if switch == 1
 puts("Yes")
 else puts("No")
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       int[] nums = new int[n];

       for (int i = 0; i < n; i++){
           nums[i] = sc.nextInt();
       }

       int count = 0;
       boolean continueCheck = true;
       while(continueCheck){
           for (int j = 0; j < n; j++){
               if(nums[j] % 2 == 0 ){
                   nums[j] = nums[j] / 2;
               } else {
                   continueCheck = false;
                   break;
               }
           }
           if(continueCheck){
               count++;
           }
       }

       System.out.println(count);

       sc.close();

    }

}


Measured memory_bytes: 22996