akhauriyash/Code-Regression huggingface dataset:
use std::cmp::{max, min};
use std::collections::{HashSet, VecDeque};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {

        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };


    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        xl: [(i64, i64); n],
    }
    let mut xl = xl
        .iter()
        .map(|r| (r.0 - r.1, r.0 + r.1))
        .collect::<Vec<(i64, i64)>>();
    xl.sort_by_key(|r| r.1);
    let ans = xl
        .iter()
        .fold((0, std::i64::MIN), |s, r| {
            if s.1 <= r.0 {
                (s.0 + 1, r.1)
            } else {
                s
            }
        })
        .0;
    println!("{}", ans);
}


Measured memory_bytes: 10492
n,k,c = map(int,input().split())
s = input()
fro = []
bac = []

for i in range(n):
    if s[i] == "o" and (len(fro) == 0 or fro[-1]+c < i):
        fro.append(i)
    if s[n-i-1] == "o" and (len(bac) == 0 or bac[-1]-c > n-i-1):
        bac.append(n-i-1)

for i in range(k):
    if fro[i] == bac[k-i-1]:
        print(fro[i]+1)


Measured memory_bytes: 20568
import sys
N,M = map(int,sys.stdin.readline().split())
start = []
goal = []
for i in range(M):
    a,b = map(int,sys.stdin.readline().split())
    if a == 1:
        start.append(b)
    if b == N:
        goal.append(a)
ans = 'IMPOSSIBLE'
seta = set(start)
setg = set(goal)
for i in seta:
    if i in setg:
        ans = 'POSSIBLE'
        break
print(ans)

Measured memory_bytes: 21824
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
#include<math.h> 
#include<stdlib.h>
#include<map>
#include<set>
#include<time.h>
#include<bitset>
#include<list>
const double inf=1e20;
const int md=1e9+7;
const int MX=1e5+10;
using namespace std;
int mx=0,a[MX],nm[MX];
int main(){
	int N;scanf("%d",&N);
	for (int i=0;i<N;i++)
	{
		scanf("%d",&a[i]);
		a[i]++;
		nm[a[i]]++;
	}
	for (int i=0;i<N;i++)
	{
		mx=max(mx,nm[a[i]+1]+nm[a[i]-1]+nm[a[i]]);
	}
	printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 1024
#include <cassert>
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

typedef long long ll;
ll dp[200010];
int main() {
  string a;
  cin >> a;
  vector<ll> count(26);
  dp[0] = 1;
  int n = a.size();
  for (ll i = 0; i < n; ++i) {
    dp[i+1] = dp[i]+i-count[a[i]-'a'];
    ++count[a[i]-'a'];
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 2180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		int[] list = new int[n];
		int all = 0;
		for(int i = 0;i < n; i++) {
			int a = sc.nextInt();
			list[i] = a;
			all += a;
		}
		Arrays.sort(list);
		double ch = list[n-m], c = 4*m;
		if(ch*c - all >= 0 ) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 23124
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

class LazySegmentTree{
public:
  int N;
  vector<ll> node, lazy;
  ll INF = 1LL << 40;

  //コンストラクタ
  LazySegmentTree(vector<ll> v){
    int sz = v.size();
    N = 1;
    while(N < sz) N *= 2;
    node.resize(2 * N - 1, INF);
    lazy.resize(2 * N - 1, INF);

    for(int i = 0; i < sz; i++){
      int k = i + N - 1;
      node[k] = v[i];
      while(k > 0){
        k = (k - 1) / 2;
        node[k] = min(node[k * 2 + 1], node[k * 2 + 2]);
      }
    }
  }

  // [a, b)をcに変更
  void update(int a, int b, ll c){
    Update(a, b, c, 0, 0, N);
  }

  void Update(int a, int b, ll c, int k, int l, int r){
    eval(k, l, r);
    if(r <= a || b <= l) return;
    if(a <= l && r <= b){
      lazy[k] = c;
      eval(k, l, r);
    }
    else {
      Update(a, b, c, 2 * k + 1, l, (l + r) / 2);
      Update(a, b, c, 2 * k + 2, (l + r) / 2, r);
      node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }

  //[a,b)の最小値
  ll query(int a, int b){
    return Query(a, b, 0, 0, N);
  }

  ll Query(int a, int b, int k, int l, int r){
    eval(k, l, r);
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return node[k];
    else{
      ll v1 = Query(a, b, k * 2 + 1, l, (l + r) / 2);
      ll v2 = Query(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(v1, v2);
    }
  }

  //k番目のノードに遅延評価
  void eval(int k, int l, int r){
    if(lazy[k] != INF){
      node[k] = lazy[k];

      //最下段でないなら
      if(r - l > 1){
        lazy[2 * k + 1] = lazy[k];
        lazy[2 * k + 2] = lazy[k];
      }

      //自ノードの遅延配列を0に
      lazy[k] = INF;
    }
  }

  void print(){
    for(int i = 0; i < 2 * N - 1; i++){
      cout << "node[" << i << "] " << node[i] << "  " << lazy[i] << endl;
    }
  }
};

int main(){
  int N, Q;
  cin >> N >> Q;

  vector<ll> a(N, (1LL << 31) - 1);
  LazySegmentTree sg = LazySegmentTree(a);

  vector<ll> ans;

  for(int i = 0; i < Q; i++){
    int j, s, t;
    ll x;
    cin >> j;
    if(j == 0){
      cin >> s >> t >> x;
      sg.update(s, t + 1, x);
    }
    if(j == 1){
      cin >> s >> t;
      ans.push_back(sg.query(s, t + 1));
    }

    //sg.print();
    //cout << endl;
  }

  for(auto it = ans.begin(); it != ans.end(); it++){
    cout << *it << endl;
  }

  return 0;
}


Measured memory_bytes: 9472
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			Map<Integer, Integer> map = new HashMap<Integer, Integer>();
			while (sc.hasNextLine()) {
				String[] s = sc.nextLine().split(",");
				if (s.length > 1) {
					map.put(Integer.parseInt(s[0]), Integer.parseInt(s[1]));
				}
			}

			int totalPrice = 0;
			int totalQuantity = 0;

			for (int unitPrice : map.keySet()) {
				int quantity = map.get(unitPrice);
				totalPrice += unitPrice * quantity;
				totalQuantity += quantity;
			}

			int quantityAve = new BigDecimal(totalQuantity).divide(
					new BigDecimal(map.size()), RoundingMode.HALF_UP)
					.intValue();

			System.out.println(totalPrice);
			System.out.println(quantityAve);

		} finally {
			sc.close();
		}
	}
}

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

vector<vector<ll>> dp(100010,vector<ll>(3));

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

    int n;
    cin >> n;
    
    vector<vector<ll>> arr(n,vector<ll>(3));
    
    rep(i,n){
        rep(j,3){
            cin >> arr[i][j];
        }
    }
    
    for(int i = 0; i < 3; i++){
        dp[0][i] = arr[0][i];
    }
    
    for(int i = 0; i < n - 1; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j != k) dp[i+1][j] = max(dp[i+1][j],dp[i][k] + arr[i+1][j]);
            }
        }
    }
    
    
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
}



Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
double a[1000];
int main(){
    double n, m, sum = 0, pop = 0;
    cin >> n >> m;
    for(int i = 0;i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    for(int i = 0; i < n; i++){
        if(!(a[i] < sum / (4 * m))){
            pop++;
        }
    }
    if(pop >= m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
 
using namespace std;
 
int main(){
 long N,K;
  cin>>N>>K;
  vector<long> v(N);
  for(auto &x:v){
    cin>>x;
  }
  sort(v.begin(),v.end());
  long ans=0;
  for(int i=N-1;i>=0;i--){
    if(K>0){
      K--;
    }else{
      ans+=v[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define N 200005
int n, m, i, j, k;
char a[N], b[N];
int main(){
	scanf("%s%s", a, b);
	for(i=0; a[i]; i++){
		n += a[i] != b[i];
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        int id = 0; map<string, int> M;
        vector<int> dp(n), dp2(n, INF<int>);
        for (int i = 0; i < n; ++i) {
            string s; int x;
            cin >> s >> x;
            dp[id] = x;
            M[s] = id++;
        }
        int m;
        cin >> m;
        vector<int> deg(n);
        vector<vector<int>> G(n);
        for (int i = 0; i < m; ++i) {
            string s; int a;
            cin >> s >> a;
            for (int j = 0; j < a; ++j) {
                string t; cin >> t;
                G[M[t]].emplace_back(M[s]);
                deg[M[s]]++;
            }
        }
        queue<int> Q;
        for (int i = 0; i < n; ++i) {
            if(!deg[i]) Q.emplace(i);
        }
        while(!Q.empty()){
            int i = Q.front(); Q.pop();
            for (auto &&j : G[i]) {
                if(dp2[j] == INF<int>) dp2[j] = min(dp[i], dp2[i]);
                else dp2[j] += min(dp[i], dp2[i]);
                deg[j]--;
                if(!deg[j]) Q.emplace(j);
            }
        }
        string s;
        cin >> s;
        cout << min(dp[M[s]], dp2[M[s]]) << "\n";
    }
    return 0;
}


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


public class Test
{	

    public static int ans = 0;
    public static int n;

  
    public static void Main()
	{
        n = int.Parse(Console.ReadLine());
        int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        
        int f = 0;
        for(int i = 0 ; i < n ; i++){
            f += nums[i]-1;
        }
        Console.WriteLine(f);
 
        
    }
}

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

int main() {
    ll n,x,m;cin>>n>>x>>m;
    ll ans = 0;
    ll tmp = x;
    
    if(x==0){
        cout<<0<<endl;
        return 0;
    }
    if(x==1){
        cout<<n<<endl;
        return 0;
    }
    
    vector<bool>seen(m+1,false);
    
    ll s[m+1];
    s[0]=0;
    s[1]=x;
  ll a[m+1];
    a[0]=x;

    seen[x]=true;
    
    for(ll i=1;i<n;++i){
        tmp*=tmp;
        tmp%=m;
//          cout<<s[i]<<endl;
       if(seen[tmp]==true){
//          cout<<tmp<<endl;
            for(int j=0;j<i;++j){
                if(a[j]==tmp){
                ans=((n-j)/(i-j))*(s[i]-s[j]) + s[j];
                ll n2 = (n-j)%(i-j);
                rep(i2,n2){
                    ans+=tmp;
                    tmp*=tmp;
                    tmp%=m;
                }
//              cout<<i<<" "<<j<<endl;
              cout<<ans<<endl;
                return 0;
            }
        }
       }
        else{
            seen[tmp]=true;
            a[i]=tmp;
            s[i+1]=s[i]+tmp;
        }
    }
//  rep(i,n+1)cout<<s[i]<<endl;
    cout<<s[n]<<endl;
	return 0;
}

Measured memory_bytes: 4380
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int N,K;
	cin >> N >> K;
	vector<int> l(N);
	int t = 0;
	for (int i = 0; i < N; ++i) {
		cin >> l[i];
	}
	sort(l.begin(),l.end());
	int sum = 0;
	for (int i = 0; i < K; ++i) {
		sum += l[N-1-i];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

vector<int> prime,flag;

void list_prime(int N){
	flag.resize(N + 1);
	flag[0] = 1;
	flag[1] = 1;
	for(int i = 4;i <= N;i += 2) flag[i] = 1;
	for(int i = 3;i * i <= N;i += 2){
		if(flag[i]) continue;
		for(int j = i * 2;j <= N;j += i) flag[j] = 1;
	}
	for(int i = 0;i <= N;i++) if(!flag[i]) prime.push_back(i);
	for(int i = 0;i <= N;i++) flag[i] = !flag[i];
}

signed main(){
	int n,ind = 0,ans[55];
	cin >> n;
	list_prime(60000);
	for(int v : prime){
		if(ind >= n) break;
		if(v % 5 == 1) ans[ind++] = v;
	}
	for(int i = 0;i < n;i++) cout << (i ? " " : "") << ans[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;





int main() {
	//cout << fixed << setprecision(10);
	
	
	long long int n, m, a, b, c, d,k,cou=1,one=0,zero=0;
	string str;
	cin >> str;
	n = str.length();
	for (int i = 0; i <n; i++) {
		if (str[i]=='0'){
			zero++;
		}else  {
			one++;
		}
	}
	cout << 2 * min(zero, one);
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int a, b;
    string s;
    cin >> a >> b >> s;
    string ans = "Yes";
    if (s[a] != '-')
        ans = "No";
    rep(i, a)
    {
        if ('0' <= s[i] && s[i] <= '9')
            continue;
        else
            ans = "No";
    }
    for (int i = b + 1; i <= a + b; ++i)
    {
        if ('0' <= s[i] && s[i] <= '9')
            continue;
        else
            ans = "No";
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
using namespace std;
long long INF = 1e10;
int main(){
  int n,i,j;
  cin >> n;
  long long h[n+1],dp[n+1];
  for(i=1;i<=n;i++)cin >> h[i];
  for(i=0;i<=n;i++)dp[i]=INF;
  dp[1]=0;
  for(i=1;i<n;i++){
    dp[i+1]=min(dp[i]+abs(h[i]-h[i+1]),dp[i+1]);
    if(i!=n-1)dp[i+2]=min(dp[i]+abs(h[i]-h[i+2]),dp[i+2]);
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;

    REP(i, dy) {
        cout << 'U';
    }
    REP(i, dx) {
        cout << 'R';
    }
    REP(i, dy) {
        cout << 'D';
    }
    REP(i, dx) {
        cout << 'L';
    }

    cout << 'L';
    REP(i, dy+1) {
        cout << 'U';
    }
    REP(i, dx+1) {
        cout << 'R';
    }
    cout << 'D';

    cout << 'R';
    REP(i, dy+1) {
        cout << 'D';
    }
    REP(i, dx+1) {
        cout << 'L';
    }
    cout << 'U';


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <bits/stdc++.h>
#include <iostream>
//#include <cfloat>
//#include <climits>
#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
#define LL long long

using namespace std;

int main()
{
	string s;
	int k;
	vector<string> buf;
	
	cin>>s;
	cin>>k;
	int len=s.size();
	for(int i=0;i<len;i++) {
		for(int j=1;j<=5;j++) {
			if(i+j>len) break;
			string temp=s.substr(i,j);
			buf.push_back(temp);
		}
	}
	sort(buf.begin(),buf.end());
	
	int count=1;
	if(k==1){
		cout<<buf[0];
		rt0;
	}
	for(int j=1;j<buf.size();j++){
		if(buf[j]==buf[j-1]) continue;
		if(++count==k){
			cout<<buf[j];
			rt0;
		}		
	}
	
	
    rt0;
}


Measured memory_bytes: 1660
n = int(input())
x = list(map(int, input().split()))

sx = sorted(x)
m = (n+1)//2
med1 = sx[m - 1]
med2 = sx[m]

for _x in x:
    if _x <= med1:
        print(med2)
    else:
        print(med1)

Measured memory_bytes: 93780
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, h[100005], i, ruimax[100005];
    cin >> n;
    for(i=0;i<n;i++){
        cin >> h[i];
    }
    if(n==1){
        cout << "Yes" <<endl;
        return 0;
    }

    ruimax[0]=h[0];
    for(i=0;i<n;i++){
        ruimax[i]=max(ruimax[i-1], h[i]);
    }

    for(i=0;i<n;i++){
        if(ruimax[i]-h[i]>=2){
            cout << "No" <<endl;
            return 0;
        }
    }
        
    cout << "Yes" <<endl; 

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
data = input().split(" ")
for i in range (len(data)):
    data[i] = int(data[i])
arr = sorted(data)
ctr = 0
for j in range (len(data)):
    if arr[j] != data[j]:
        ctr += 1
if ctr == 0 or ctr == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;
ll dp[1000100];
ll pr[1000100];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,d,h; cin >> n >> h >> d;
	ll p=1;
	ll s=0;
	for(ll i=1;i<=n;i++){
		(p*=i)%=mod;
		(s+=p)%=mod;
	}
	for(int i=1;i<=h;i++){
		pr[i]=pr[i-1];
		ll sum=(pr[i-1]-pr[max(0,i-d-1)])%mod;
		if(sum<0)sum+=mod;
		(dp[i]+=sum*s%mod)%=mod;
		if(i<=d)(dp[i]+=p)%=mod;
		(pr[i]+=dp[i])%=mod;
	}
	cout << dp[h] << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    ll m = 1, c = 0;
    while (n - m >= 0) {
        n -= m;
        m *= 26;
        c++;
    }
    vector<char> res(c);
    for (int i = 0; i < c; i++) {
        res[i] = 'a' + n % 26;
        n /= 26;
    }
    reverse(res.begin(), res.end());
    for (auto e : res) cout << e;
    cout << "\n";
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

struct Operation{
	int x, y, nx, ny;
	Operation(int ix = 0, int iy = 0, int inx = 0, int iny = 0){
		x = ix; y = iy; nx = inx; ny = iny;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int h, w;
	cin>>h>>w;
	int a[h][w];
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin>>a[i][j];
		}
	}
	vector<Operation> op;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(a[i][j]&1){
				if(i + 1 < h){
					op.push_back(Operation(i + 1, j + 1, i + 2, j + 1));
					a[i + 1][j]++;
				}else if(j + 1 < w){
					op.push_back(Operation(i + 1, j + 1, i + 1, j + 2));
					a[i][j + 1]++;
				}
			}
		}
	}
	cout<<op.size()<<'\n';
	for(auto x : op){
		cout<<x.x<<" "<<x.y<<" "<<x.nx<<" "<<x.ny<<'\n';
	}

	return 0;
}

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

int main() {
    int n, x;
  
    while (1) {
        cin >> n >> x;
        
        if (n == 0 && x == 0) {
            return 0;
        }

        int c = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i+1; j <= n; j++) {
                if ((x-i-j <= n) && (j < x-i-j)) {
                    c++;
                }
            }
        }
        cout << c << endl;
    }  
}

Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int main()
{
	int N;
	int pow=1;
	int i;
	cin >> N;
	for (i = 1; i <= N; ++i) {
		if ((N - pow) < 0) break; 
		pow *= 2;
	}
	pow /= 2;
	cout << pow<< endl;
	return 0;
}

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

using namespace std;


int main()

{

    int n,l;
    vector<string> v;

    cin >> n >>l;
    for(int i =0;i<n;i++)
    {
        string a;
        cin >> a;
        v.push_back(a);
    }

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

    for(int i =0;i<n;++i)
        cout << v[i];

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

vector<bool> seen;
vector<vector<ll>> g;

void dfs(ll x){

    seen[x] = 1;

    ll L = g[x].size();

    rep(i, 0, L){

        if(seen[g[x][i]])continue;

        dfs(g[x][i]);

    }

}

int main(){
ll N, M, Ans = 0;cin >> N >> M;
vector<pair<ll, ll>> A(M);
seen.resize(N + 1);
g.resize(N  + 1);

rep(i, 0, M){

    ll a, b;cin >> a >> b;

    A[i].first = a;A[i].second = b;

    g[a].push_back(b);g[b].push_back(a);

}

rep(i, 0, M){

    rep(i, 1, N + 1)seen[i] = 0;

    ll a = A[i].first, b = A[i].second;

    g[a].erase(remove(g[a].begin(), g[a].end(), b), g[a].end());
    g[b].erase(remove(g[b].begin(), g[b].end(), a), g[b].end());

    dfs(1);

    rep(i, 1, N + 1){

        if(!seen[i]){Ans++;break;}

    }

    g[a].push_back(b);g[b].push_back(a);
    
}

cout << Ans;

}

Measured memory_bytes: 3596
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>


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

using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;

  int count = 0;
  for (int i = 0; i < N; ++i)
  {
    int h;
    cin >> h;
    if (K <= h) ++count;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;

ll mod = 1000000007 ;

ll modpow(ll x,ll n){
	ll res  = 1 ;
	while(n>0){
		if(n&1) res = res*x%mod ;
		x = x*x%mod ;
		n >>= 1 ;
	}
	return res ;
}

int main(){
	ll n,a,b ;
	cin >> n >> a >> b ;
	vll inv(2*100000+10,1) ;
    vll finv(2*100000+10,1) ;
	for(int i=2;i<2*100000+10;i++){
		inv.at(i) = mod-inv.at(mod%i)*(mod/i)%mod ;
        finv.at(i) = finv.at(i-1)*inv.at(i)%mod ;
	}
	vll nfac(2*100000+10,n) ;
	for(int i=1;i<2*100000+10;i++){
		nfac.at(i) = nfac.at(i-1)*(n-i)%mod ;
	}
	ll ans = modpow(2,n)-1 ;
	ans -= nfac.at(a-1)*finv.at(a)%mod ;
	ans -= nfac.at(b-1)*finv.at(b)%mod ;
	cout << (ans+mod+mod)%mod << endl ;
}

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

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

    int n = 2;
    vector<int> numbers;
    while (100 >= n) {
        numbers.push_back(n);
        n *= 2;
    }

    int maxNumber = 1;
    for (int number : numbers) {
        if (N >= number) {
            maxNumber = number;
        }
    }

    cout << maxNumber << endl;

    return 0;
}

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


int check(char c){
  if(c == 'I') return 1;
  else if(c == 'V') return 5;
  else if(c == 'X') return 10;
  else if(c == 'L') return 50;
  else if(c == 'C') return 100;
  else if(c == 'D') return 500;
  else if(c == 'M') return 1000;
}

int main(void){
  string str;
  while(cin >> str){
    int ans = 0;
    for(int i = 0; i < str.size() - 1; i++){
      if(check(str[i]) >= check(str[i+1])) ans += check(str[i]);
      else ans -= check(str[i]);
    }
    ans += check(str[str.size() - 1]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#ABC 174 C
k = int(input())

sevens = [0] * k

sevens[0] = 7 % k

if k == 7 or k == 1:
    print(1)
    
else:
    for i in range(1, k):
        new = (sevens[i - 1] * 10 + 7) % k
        sevens[i] = new

        if new == 0:
            print(i + 1)
            break
    else:
        print(-1)

Measured memory_bytes: 48352
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int a,b;
	cin>>a>>b;
	if(a>8||b>8)
	cout<<":(";
	else
	cout<<"Yay!";
	
}

Measured memory_bytes: 3620
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 = Integer.toString(n);
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            sum += Integer.parseInt(s.substring(i, i + 1));
        }
        if(n % sum == 0)System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 35844
n = int(input())
nn = n
ans = ''
a = 2
while True:
	if n == 0:
		break
	if n % a == 0:
		ans += '0'
	else:
		ans += '1'
		n -= (a//2)

	n = n//2
	if a == 2:
		a = -2
	else:
		a = 2


ans = ans[::-1]
if nn == 0:
	print(0)
else:
	print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll h, w;
  cin >> h >> w;
  int c[10][10];
  fi(0, 10)
    fj(0, 10)
      cin >> c[i][j];

  fi(0, 10)
    fj(0, 10)
    fk(0, 10) {
      if(c[j][i] + c[i][k] < c[j][k])
        c[j][k] = c[j][i] + c[i][k];
    }

  fi(0, h)
    fj(0, w) {
      int x;
      cin >> x;
      if(x == -1)
        continue;
      ans += c[x][1];
    }
    
  
  cout << ans << endl;
  return 0;
}



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int l;
    cin >> l;
    double ans = pow(l/3.0, 3);
    printf("%.10f", ans);
    return 0;
}



Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int n;
    long long int cnt=0;
    cin>>n;
    while(n>=500){
        cnt+=1000;
        n-=500;
    }
    while(n>=5){
        cnt+=5;
        n-=5;
    }
    cout<<cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){
  int A, B;
  int ans;
  cin >> A;
  cin >> B;

  if ( (A != 1) && (B != 1) ) {
    ans = 1;
  }
  else if ( (A != 2) && (B != 2) ) {
    ans = 2;
  }
  else {
    ans = 3;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define debug4(n, m, x, y) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << ' ' << y << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#define upzero(n) rrn < 0) n = 0
#define alive(n) cout << "Alive here: checkpoint " << n << endl
#pragma GCC optimize("Ofast")
using namespace std;
void yes() {
    cout << "Yes\n";
    return;
}
void no() {
    cout << "No\n";
    return;
}
void solve(int case_no) {
    // implementation
    string str;
    cin >> str;
    int strl = str.length();
    int cnt = 0;
    for (int i = 0;i < strl;i++) {
    	cnt += str[i] - 48;
	}
	if (cnt % 9 == 0) return yes();
	else return no();
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(NULL));
    int t = 1;
//    cin >> t;
    for (int i = 1;i <= t;i++) solve(i);
}
/*

*/

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N,M; cin >> N >> M;
    int ans=0;
    // 前処理
    COMinit();

    // 計算例
    ans=COM(N,2)+COM(M,2);
    cout << ans<< endl;
}

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

int main() {
  
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  
  int i=0,k=1;
  while(k!=2){
    k=a.at(k-1);
    i++;
    if(i>N){
      cout << -1 << endl;
      break;
    }
  }
  
  if(k==2){
    cout << i << endl;
  }
  
}

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

int main() {
  int a, b, c, x, i, j, k, count = 0;
  cin >> a >> b >> c >> x;
  
  for(i = 0; i <= a; i++){
    for(j = 0; j <= b; j++){
      for(k = 0; k <= c; k++){
        if(500 * i + 100 * j + 50 * k == x){
        count++;
        }
      }
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n) cin >> a[i];
    ll ans = LLINF;
    {
        ll t = 0;
        ll now = 0;
        bool f = true;
        REP(i,n){
            now += a[i];
            if(f&&now<=0){
                t += 1 - now;
                now = 1;
            }else if((!f)&&now>=0){
                t += now + 1;
                now = -1;
            }
            f = (!f);
        }
        ans = min(ans, t);
    }
    {
        ll t = 0;
        ll now = 0;
        bool f = false;
        REP(i,n){
            now += a[i];
            if(f&&now<=0){
                t += 1 - now;
                now = 1;
            }else if((!f)&&now>=0){
                t += now + 1;
                now = -1;
            }
            f = (!f);
        }
        ans = min(ans, t);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j >= w[i]) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
    }
  }
  cout << dp[N][W] << endl;
}


Measured memory_bytes: 80256
k =int(input())

if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  if k % 7 == 0:
    k //= 7
  if k == 1:
    print(1)
  else:
    k *= 9
    i = 1
    num = 10
    while num % k != 1:
      num %= k
      num *= 10
      i += 1
    print(i)

Measured memory_bytes: 9220
n = int(input())
t = [int(s) for s in input().split()]
m = int(input())
total = sum(t)
ans = []
for i in range(m):
    p, x = map(int, input().split())
    ans.append(total - t[p - 1] + x)

for a in ans:
    print(a)

Measured memory_bytes: 9124
n, m = gets.split.map(&:to_i)
hs = gets.split.map(&:to_i)
arr = Array.new(n, 1)

m.times do
  a, b = gets.split.map(&:to_i)

  arr[a - 1] = 0 if hs[a - 1] <= hs[b - 1]
  arr[b - 1] = 0 if hs[b - 1] <= hs[a - 1]
end

puts arr.count(1)


Measured memory_bytes: 22700
#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;
typedef tuple<int, int, string, long, string> _t;

int main() {
  int n;
  cin >> n;
  vector<_t> A;
  int v, w;
  long d;
  string t;
  string s;
  while (cin >> v >> w >> t >> d >> s)
    A.push_back(make_tuple(v, w, t, d, s));
  sort(A.begin(), A.end());
  for (auto &tup : A) {
    tie(v, w, t, d, s) = tup;
    cout << v << " " << w << " " << t << " " << d << " " << s << endl;
  }
}


Measured memory_bytes: 16920
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	var N = parseInt(input[0][0], 10);
	var H = parseInt(input[1][0], 10);
	var W = parseInt(input[2][0], 10);
	console.log((N - H + 1) * (N - W + 1));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 29504
def div2 h,w
 
  return [h*w/2, h*w/2] if h % 2 == 0 or w % 2 == 0
  h,w = [h, w].sort
  return [w/2*h, (w+1)/2*h]
end
  
def f h,w
  
  return 0 if h % 3 == 0 or w % 3 == 0
  
  res = h*w
  
  0.upto h%3 do |i|
    
    s = w*(h/3 + i)
    ss =div2(h-h/3-i, w).push(s)
    res = [res, ss.max - ss.min].min
  end
  
  0.upto w%3 do |i|
    
    s = h*(w/3 + i)
    ss =div2(w-w/3-i, h).push(s)
    res = [res, ss.max - ss.min].min 
  end
  
  res
end  
 
H, W = gets.split.map(&:to_i).sort
puts [f(H,W), f(W,H)].min
 

Measured memory_bytes: 1916
#include <stdio.h>

int main(){
  int H, W, a, b, c, d, e, f, h, w;
  for(a=0;;a++){
      scanf("%d%d",&H,&W);
      if(H==0&&W==0)break;
  w=(W-2);
  h=(H-2);
  for(b=0;b<W;b++){
      printf("#");
  }
  printf("\n");
  if(H>1){
  for(c=0;c<h;c++){
      printf("#");
      for(e=0;e<w;e++){
          printf(".");
      }
      printf("#");
      printf("\n");
  }
  for(b=0;b<W;b++){
      printf("#");
  }
  printf("\n\n");
  }
  else printf("\n");
  }
    return 0;
}

Measured memory_bytes: 1796
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
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...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll sum=0;
    ll ans=0;
    REP(i,n) cin>>a[i];
    //偶数+
    REP(i,n){
        sum+=a[i];
        if(i%2==0&&sum<0){
            ans+=abs(sum)+1;
            sum=1;
        }else if(i%2==1&&sum>0){
            ans+=abs(sum)+1;
            sum=-1;
        }else if(sum==0){
            ans++;
            if(i%2==0){
                sum++;
            }else{
                sum--;
            }
        }
    }

    sum=0;
    ll ans2=0;
    //偶数-
    REP(i,n){
        sum+=a[i];
        if(i%2==1&&sum<0){
            ans2+=abs(sum)+1;
            sum=1;
        }else if(i%2==0&&sum>0){
            ans2+=abs(sum)+1;
            sum=-1;
        }else if(sum==0){
            ans2++;
            if(i%2==1){
                sum++;
            }else{
                sum--;
            }
        }
    }
    ans=min(ans,ans2);
    cout<<ans<<endl;
}

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

int main() {
	long long a, b, x, ans;
	cin >> a >> b >> x;

	if (a != 0) {
		ans = (b / x) - ((a - 1) / x);
	}
	if (a == 0) {
		ans = b / x + 1;
	}
	
	cout << ans << endl;

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; i++){
        cin >> T[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += T[i];
    }
    int M;
    cin >> M;
    int P, X;
    for (int i = 0; i < M; i++){
        cin >> P >> X;
        cout << ans - T[P-1] + X<< endl;
    }
}


Measured memory_bytes: 256
require 'set'

n, k = gets.chomp.split.map(&:to_s)
ds = gets.chomp.split.map(&:to_i).sort
arrow_numbers = (Set.new((0..9)) - Set.new(ds)).to_a

result = arrow_numbers.repeated_permutation(n.length).map { |s| s.join("").to_i }.sort.select { |s| s >= n.to_i }.first

if result.nil? 
    result = arrow_numbers.repeated_permutation(n.length+1).map { |s| s.join("").to_i }.sort.select { |s| s >= n.to_i }.first
end

print result

Measured memory_bytes: 2168
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;

int main() 
{
    ll a,b; cin >> a >> b;
    double d = 1.0 * a / b;
    cout << a/b << ' ' << a%b << ' ';
    printf("%.5lf\n",d);
}


Measured memory_bytes: 3232
h, w = map(int, input().split())

ls = [list(input()) for i in range(h)]
ls1 = [i for i in ls if '#' in i]
ls2 = [i for i in zip(*ls1) if '#' in i]
ls3 = [i for i in zip(*ls2)]

for i in ls3:
    print(''.join(i))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll n,k,s;
int main()
{
    FASTINOUT

    cin>>n>>k>>s;
    
   for(int i=0;i<k;i++){
         cout<<s<<" "; 
   }
   for(int i=k;i<n;i++){
        cout<<(21353142)<<" ";
   }

    return 0;
}

Measured memory_bytes: 1280
using System;
using System.Linq;

namespace d
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var wr = Console.ReadLine();
            var cnt_r = wr.Count(c => c == 'R');
            var swr = wr.Substring(0, cnt_r);
            int ans = swr.Count(c => c == 'W');
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28940
#include<bits/stdc++.h>
using namespace::std;
using lint=long long;
constexpr lint INF=1LL<<60;

struct subsequence{
    struct node;
    using np=node*;
    struct node{
        np ch[26]={};
        int idx;
        char c;
        node(int idx,char c):idx(idx),c(c){}
    };
    string s;int n;
    vector<vector<int>>m;
    vector<np>v;
    np root=0;
    subsequence(string s):s(s),n(s.size()),m(n+1,vector<int>(26,-1)),v(n+1){
        for(int i=n-1;i>=0;--i){
            m[i]=m[i+1];
            m[i][s[i]-'a']=i;
        }
        for(int i=0;i<n+1;++i)v[i]=new node(i,(i?s[i-1]:'#'));
        for(int i=0;i<n;++i){
            for(int j=0;j<26;++j){
                if(~m[i][j])v[i]->ch[j]=v[m[i][j]+1];
            }
        }
        root=v[0];
    }
    //ここから問題ごとに書く
    vector<lint>dp;
    void dp2(){
        dp.resize(n+1);
        for(int i=n;i>=0;--i){
            np t=v[i];
            dp[i]=INF;
            for(int j=0;j<26;++j){
                if(!t->ch[j])dp[i]=1;
                else dp[i]=min(dp[i],dp[t->ch[j]->idx]+1);
            }
        }
    }
    string ans;
    void dfs(np t){
        for(int i=0;i<26;i++){
            if(!t->ch[i]){
                if(t!=root)ans+=t->c;
                ans+=char(i+'a');
                return;
            }
            if(dp[t->ch[i]->idx]==dp[t->idx]-1){
                if(t!=root)ans+=t->c;
                dfs(t->ch[i]);
                return;
            }
        }
    }
    string solve(){
        dp2();
        dfs(root);
        return ans;
    }
};

int main(){
    string s;
    cin>>s;
    cout<<subsequence(s).solve()<<endl;
}

Measured memory_bytes: 77320
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
string convertToTitle(LL n) {
        string ans="";
        while(n){
            n-=1;
            ans+='a'+n%26;
            n/=26;
        }
        reverse(ans.begin(),ans.end());
        return ans;
    }
int main(){
  LL n;
  cin>>n;
  cout<<convertToTitle(n);
}
  

Measured memory_bytes: 3628
a,b,c,d = map(int,input().split())
def gcd(x,y):
    while y:
        x, y = y, x%y
    return x
cd = int(c*d/gcd(c,d))
l = [c,d,cd]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    e = a+l[i]-a%l[i]
    if e <= b:
      if i < 2:
        count += (1+len(range(e+1,b+1))//l[i])
      else:
        count -= (1+len(range(e+1,b+1))//l[i])
    
print(len(range(a,b+1))-count)

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

int main () {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> h.at(i);
  sort (h.begin(),h.end());
  
  int ans = 0;
  for (int i = 0; i <= N-K; i++){   
    int dh = h.at(K-1+i) - h.at(i);
    if (i == 0) ans = dh;
    else if (ans > dh) ans = dh;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640