akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;


public class Main {
	
	public static final int MAX = 20;
	
	public static boolean is_ok(int x, int y, int H, int W){
		if(x < 0 || y < 0 || x >= W || y >= H){
			return false;
		}else{
			return true;
		}
	}
	
	public static final int[][] move_dir = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		boolean[][] can_enter = new boolean[MAX][MAX];
		boolean[][] visited = new boolean[MAX][MAX];
		
		while(true){
			final int W = sc.nextInt();
			final int H = sc.nextInt();
			
			if(W == 0 && H == 0){
				break;
			}
			
			int s_x = -1, s_y = -1;
			
			for(int i = 0; i < H; i++){
				char[] input = sc.next().toCharArray();
				
				for(int j = 0; j < W; j++){
					if(input[j] == '#'){
						can_enter[i][j] = false;
					}else{
						can_enter[i][j] = true;
					}
					
					if(input[j] == '@'){
						s_x = j;
						s_y = i;
					}
					
					visited[i][j] = false;
				}
			}
			
			LinkedList<Integer> x_queue = new LinkedList<Integer>();
			LinkedList<Integer> y_queue = new LinkedList<Integer>();
			visited[s_y][s_x] = true;
			x_queue.add(s_x);
			y_queue.add(s_y);
			
			int count = 0;
			while(!x_queue.isEmpty()){
				final int x = x_queue.poll();
				final int y = y_queue.poll();
				
				count++;
				
				for(int[] move : move_dir){
					final int nx = x + move[0];
					final int ny = y + move[1];
					
					if(!is_ok(nx, ny, H, W)){
						continue;
					}else if(!can_enter[ny][nx]){
						continue;
					}else if(visited[ny][nx]){
						continue;
					}
					
					visited[ny][nx] = true;
					x_queue.add(nx);
					y_queue.add(ny);
				}
			}
			
			System.out.println(count);
		}
		
	}
}

Measured memory_bytes: 33808
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000009
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    cin>>x;
    if(x==0)cout<<"1\n";
    else cout<<"0\n";
    return 0;  
}   

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
//vector<vector<long>>adj;
vector<vector<long long>> dp;
#define MOD 1000000007
int main(){
    long long m,n;
    cin>>m>>n;
    dp.resize(m+1,vector<long long>(n+1));
    // vector<vector<int>>maze(m+1,vector<int>(n+1));
    
    for(int i=0;i<=m;i++){
        for(int j=0;j<=n;j++){
            if(i==0||j==0) {dp[i][j]=0;continue;} 
            char c;
            cin>>c;
            dp[i][j]=(c=='.')?0:-1;
            // cout<<dp[i][j];
        }
    }
    dp[0][1]=1;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            dp[i][j]=(dp[i][j]>=0)?((dp[i-1][j]+dp[i][j-1])%MOD):0;
            // cout<<dp[i][j]<<dp[i-1][j]<<dp[i][j-1];
        }
        // cout<<endl;
    }
    cout<<dp[m][n]%MOD;
    return 0;
}

Measured memory_bytes: 8064
//### In The Name Of GOD ###

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

#define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())

const int MOD = 1000000007;
const int INF = 30 * 1000 + 20;
const int MAXN = 401;
const int MLOG = 18;
const int NMAX = 60;

signed main(){
  int n, m;
  cin >> n >> m;
  int hm;
  cin >> hm;
  map < pair < int, int > , int > all, ans;
  for(int i = 0; i < hm; i++){
    int a, b;
    cin >> a >> b;
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        ans[ { a - i, b - j } ]++;
      }
    }
  }
  int anss[10] = {};
  int x = (n - 2) * (m - 2);
  for(auto i : ans){
    if(i.X.X >= 1 && i.X.Y >= 1 && i.X.X <= n - 2 && i.X.Y <= m - 2){
      anss[i.Y]++;
      x--;
    }
  }
  anss[0] += x;
  for(int i = 0; i <= 9; i++){
    cout << anss[i] << endl;
  }
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;

int main()
{
	int n , m;
	cin >> n >> m;
	vector< int > ans(n , -1);
	for(int i = 0 ; i < m ; i++){
			int s , c;
			cin >> s >> c;
			s--;
			if(ans[s] == -1)
				ans[s] = c;
			if(ans[s] != c)
				return cout << -1 , 0;
	}
	for(int i = 0 ; i < n ; i++){
		if(ans[i] == -1){
			if(i != 0 || n == 1)
				ans[i] = 0;
			else 
				ans[i] = 1;
		}
	}
	if(n > 1 && ans[0] == 0)
		return cout << -1 , 0;
	for(int i = 0 ; i < n ; i++)
		cout << ans[i];
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool mem[2005][2005][2][2];
int dp[2005][2005][2][2];
vector<int> t;
int N,Z,W;

int solve(int a,int b,int f,int f2){
  int c=max(a,b)+1;
  if(c==N){
    return abs(t[a]-t[b]);
  }
  
  if(mem[a][b][f][f2])return dp[a][b][f][f2];
  
  mem[a][b][f][f2]=1;
  int res;
  
  if(f==0){
    res=solve(c,b,1-f,0);
    res=max(res, solve(c,b,f,1) );
  }else{
    res=solve(a,c,1-f,0);
    res=min(res, solve(a,c,f,1) );
  }

  //  cout<<a<<' '<<b<<' '<<f<<' '<<f2<<endl;
  return dp[a][b][f][f2]=res;
}

int main(){

  cin>>N>>Z>>W;
  t.push_back(Z);
  t.push_back(W);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    t.push_back(a);
  }
  
  N=t.size();
  cout<< solve(0,1,0,0) <<endl;
  return 0;
}


Measured memory_bytes: 78848
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
// long long -> lint
using lint = long long;
// fast cin and cout from hitonanode-san's code
// w/o 71 ms -> w/ 18 ms (tested on ABC148-D with C++14(GCC 5.4.1))
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


int main(){
    // input
    double R;
    cin >> R;

    cout << 2.0*R*M_PI << endl;
} 

Measured memory_bytes: 3800
#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = read!(u64);

    let v: Vec<char> = n.to_string().chars().collect();
    let s = v.iter().fold(0, |acc, &i| acc + i as u64 - 48);
    println!("{}", if n % s == 0 { "Yes" } else { "No" });
}


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

int main(void) {
  int a, b;
  cin >> a >> b;

  cout << (a+b+1)/2 << endl;
  return 0;
}


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

using namespace std;

int N, L;
vector<tuple<int, int, int>> g;

void solve(int L) {
  if (L == 1) {
    N = 1;
    return;
  }
  if (L % 2) {
    solve(L - 1);
    g.emplace_back(1, N, L - 1);
  } else {
    solve(L / 2);
    g.emplace_back(N, N + 1, 0);
    g.emplace_back(N, N + 1, L / 2);
    ++N;
  }
}

int main() {
  cin >> L;
  solve(L);
  printf("%d %d\n", N, (int)g.size());
  for (const auto &p : g) {
    cout << get<0>(p) << ' ' << get<1>(p) << ' ' << get<2>(p) << '\n';
  }
}


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

int main() {
  int K;
  string S,ans;
  cin >> K >> S;
  if (S.size() <= K){
    ans = S;
  }
  else{
    ans = "";
    for (int i = 0; i < K; i++){
      ans = ans + S.at(i);
    }
    ans = ans + "...";
  }
  cout << ans << endl;
}

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

int main() {
    string S;
    cin >> S;
    int index_a = 0, index_z = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'A') {
            index_a = i;
            break;
        }
    }
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'Z') {
            index_z = i;
        }
    }

    cout << index_z - index_a + 1;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	vpint a;
	while (1) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		a.push_back({ x,y });
	}
	rep(i, a.size()) {
		rep(j, a[i].first) {
			rep(k, a[i].second) {
				if (j == 0 || j == a[i].first - 1 || k == 0 || k == a[i].second - 1) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


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

//?????????
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //???????????????????????????????????????????????????
std::ifstream ifs("data.txt");
#define put ifs >>
#else //?????£????????????????????§?????????????????????
#define put cin >>
#endif
#pragma endregion
//???????????°??????????????´
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef????????????????????????????¶????????????§?????????
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
#pragma endregion
//??????????????°(???????????????????????§??????)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion

const static int MAX_V = 10000;
const static int MAX_E = 30000;
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];

void add_edge(int from, int to) {
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v) {
	used[v] = true;
	rep(i, G[v].size()) {
		if (!used[G[v][i]]) dfs(G[v][i]);
	}
	vs.push_back(v);
}

void rdfs(int v, int k) {
	used[v] = true;
	cmp[v] = k;
	rep(i, rG[v].size()) {
		if (!used[rG[v][i]]) rdfs(rG[v][i],k);
	}
}

int scc() {
	fill(used, used + MAX_V, 0);
	vs.clear();
	rep(v, V) {
		if (!used[v])dfs(v);
	}
	fill(used, used + MAX_V, 0);
	int k = 0;
	rrep(i, vs.size()) {
		if (!used[vs[i]]) rdfs(vs[i],k++);
	}
	return k;
}

//AOJ 
int main() {
	int v, e; put v >> e;
	V = v;
	rep(i, e) {
		int s, t; put s >> t;
		add_edge(s,t);
	}
	int q; put q;
	scc();
	//cout << scc() << endl;
	rep(i, q) {
		int u, v; put u >> v;
		if (cmp[u] == cmp[v])cout << 1 << endl;
		else cout << 0 << endl;
	}
END:

	return 0;
}

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

using namespace std;

const int N = 1e5+5;
const int MaxN = 2e5+5;
typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    int temp  = y/2;
    if (y & 1) cout << "No";
    else{
        if (temp == x)cout << "Yes";
        else if (temp > x){
            if (temp-x > x)cout << "No";
            else cout << "Yes";
        }else cout << "No";
    }
}


Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a+b>=a-b&&a+b>=a*b){
  printf("%d",a+b);
  }
  else if(a-b>=a+b&&a-b>=a*b){
  printf("%d",a-b);
  }
    else{
  printf("%d",a*b);
  }
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    ll N; cin >> N;
    ll V=0, E=0;
    REP(i,N-1){
        ll u,v; cin >> u >> v;
        E += min(u,v) * (N - max(u,v) + 1);
    }

    FOR(v,1,N+1){
        V += ll(v)*(ll(v)+1)/2;
    }

    cout << V - E << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n";
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int a[N];
 
int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
 
int modinv(int k)
{
	return pow(k, MOD-2, MOD);
}
int ans[N];
int32_t main()
{
	IOS;
	int n,k;
	cin>>n>>k;
	for(int i=k;i>=1;i--)
	{
		int ans1=pow(k/i,n,MOD);
		for(int j=2*i;j<=k;j+=i)
		{
			ans1-=ans[j];
			ans1+=MOD;
			ans1%=MOD;
		}
		ans[i]=ans1;
	}
	int sum=0;
	for(int i=1;i<=k;i++)
	{
		sum+=(ans[i]*i)%MOD;
		sum%=MOD;
	}
	cout<<sum<<endl;
	
	
}

Measured memory_bytes: 4420
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

num = 1
ans = 0

(0..n-1).each do |i|
  if a[i] != num
    ans += 1
  else
    num = a[i] + 1 
  end
end
ans = -1 if ans == n

puts ans

Measured memory_bytes: 16772
A = list(map(int,input().split()))
def abs_A(A1,A2,A3):
    return abs(A1-A2)+abs(A2-A3)
minA = min(abs_A(A[0],A[1],A[2]),abs_A(A[0],A[2],A[1]),abs_A(A[1],A[0],A[2]),abs_A(A[1],A[2],A[0]),abs_A(A[2],A[0],A[1]),abs_A(A[2],A[1],A[0]))
print(minA)

Measured memory_bytes: 3064
#include <stdio.h>
#include <ctype.h>

int main()
{
    char firstLetter;
    char secondLetter;

    firstLetter = getc( stdin );
    if ( isalpha(firstLetter) && tolower(firstLetter) != 'z' ) {
        secondLetter = firstLetter + 1;
        printf( "%c", secondLetter );
    } else { 
        printf( "Invalid letter\n" );
    }

    return 0;
}


Measured memory_bytes: 2024
#include <stdio.h>

int main() {
	int n, k, sum;

	scanf("%d%d", &n, &k);
	sum = 0;
	while (n--) {
		int x;

		scanf("%d", &x);
		sum += (x < k - x ? x : k - x) * 2;
	}
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	vector<int> h(N,0);
	REP(i,N){
		cin >> h[i];
	}
	vector<int> dp(N+1, 0);

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);

	FOR(i,2,N+1){
		int a = dp[i-1] + abs(h[i-1] - h[i]);
		int b = dp[i-2] + abs(h[i-2] - h[i]);
		dp[i] = min(a, b);
	}

	cout << dp[N-1] << endl;

	return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
 
int main() {

    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll ma = a*c;
    if(ma<a*d)  ma = a*d;
    if(ma<b*c)  ma = b*c;
    if(ma<b*d)  ma = b*d;

    cout << ma << endl;
    

 return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

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

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MOD = 1000000007;

struct Pony
{
    long a, b;
 
    Pony(long a_, long b_)
    {
        a = a_;
        b = b_;
    }
 
    bool operator<(const Pony &another) const
    {
        return b < another.b;
    };
};

int fac(int k){
    int sum = 0;
    for (int i = 1; i <= k; ++i)
    {
        sum += i;
    }
    return sum;
}

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

  ll l, r;
  cin >> l >> r;

  ll res = INF*INF;
  for (ll i = l; i < min(l+10010, r); i++) {
    for(ll j = i+1; j < min(l+10011, r+1); j++) {
      res = min(res, (i*j)%2019);
    }
  }

  cout << res << endl;

}


Measured memory_bytes: 888
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))

w = int(input())
h = int(input())
t = int(input())

print(1+(t-1)//max(w,h))

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int M, D;
    cin>>M>>D;
    int res=0;
    for (int m=1; m<=M; m++) {
	for (int d=1; d<=D; d++) {
	    if (d%10>=2 && d/10>=2 && (d%10)*(d/10)==m) {
		res++;
	    }
	}
    }
    cout<<res<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main()
{
    fast;
    ll n;
    cin>>n;
    ll a[n], b[n];
    bool flag=false;
    for(int i=0;i<2;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(int i=2;i<n;i++)
    {
        cin>>a[i]>>b[i];
        if(flag==false)
        {
           if(a[i]==b[i])
        {
            if(a[i-1]==b[i-1])
            {
                if(a[i-2]==b[i-2])
                    flag=true;
            }
        }
        }


    }

    if(flag)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

using iPair = pair<int, int>;

vector<vector<pair<int, int> > > graph;
vector<int> dist;

void add_edge(int u, int v, int wt) {
	graph[u].push_back({v, wt});
	graph[v].push_back({u, wt});
}

int get_shortest_path(int V, int src) {
	priority_queue<iPair, vector<iPair>, greater<iPair> > pq;
	pq.push({0, src});

	dist = vector<int> (V, INT_MAX);
	dist[src] = 0;

	while (!pq.empty()) {
		int u = pq.top().second;
		pq.pop();

		for (auto x : graph[u]) {
			int v = x.first;
			int weight = x.second;

			if (dist[v] > dist[u] + weight) {
				dist[v] = dist[u] + weight;
				pq.push({dist[v], v});
			}
		}
	}

	return dist[V - 1];
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int h, w;
	cin >> h >> w;

	vector<string> grid(h);
	for (int i = 0; i < h; ++i) {
		cin >> grid[i];
	}

	graph = vector<vector<pair<int, int> > > (h * w, vector<pair<int, int> > ());
	int black = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (grid[i][j] == '.') {
				if (i > 0 && grid[i - 1][j] == '.') {
					add_edge(i * w + j, (i - 1) * w + j, 1);
				}
				if (i < h - 1 && grid[i + 1][j] == '.') {
					add_edge(i * w + j, (i + 1) * w + j, 1);
				}
				if (j > 0 && grid[i][j - 1] == '.') {
					add_edge(i * w + j, i * w + j - 1, 1);
				}
				if (j < w - 1 && grid[i][j + 1] == '.') {
					add_edge(i * w + j, i * w + j + 1, 1);
				}
			} else {
				++black;
			}
		}
	}

	int shortest = get_shortest_path(h * w, 0);
	if (shortest == INT_MAX) {
		cout << "-1\n";
	} else {
		cout << h * w - black - shortest - 1 << "\n";
	}

	return 0;

}

Measured memory_bytes: 3940
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int key;
  struct Node *next,*prev;
};

struct Node *nil;

struct Node* List(int key){
  struct Node *cur=nil->next;
  while(cur!=nil && cur->key!=key){
    cur=cur->next;
  }
return cur;
}

void in(){
  nil=(struct Node*)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void pL(){
  struct Node *cur=nil->next;
  int isf=0;
  while(1){
    if(cur==nil)break;
    if(isf++>0)printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
printf("\n");
}

void dNode(struct Node *t){
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void First(){
  dNode(nil->next);
}

void Last(){
  dNode(nil->prev);
}

void Key(int key){
  dNode(List(key));
}

void insert(int key){
  struct Node *x=(struct Node*)malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int np=0,nd=0;
  scanf("%d",&n);
  in();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0]=='d'){
      if(strlen(com)>6){
      if(com[6]=='F')First();
      else if(com[6]=='L')Last();
    }
    else{
    Key(key);
    nd++;
  }
  size--;
  }
}
pL();
return 0;
}


Measured memory_bytes: 32936
program C
    implicit none
    integer::N,i,j,kk
    real(8)::k,tmp
    read*,n
    do i = 1,3500
        do j = 1,3500
            tmp = 4*i*j - N*i - N*j
            if (tmp == 0.0d0 .OR. tmp < 0) then
                continue
            else
                k = real(i,8)*real(j,8)*real(N,8) / tmp
                kk = int(k)
                if (k == kk) then
                    print*,i,j,kk
                    stop
                else

                end if
            end if
        end do
    end do
end program C

Measured memory_bytes: 256
import math
n = int(input())
a = []
b = n
for i in range(2,int(math.sqrt(n+1))+10):
    while b % i == 0:
        b //= i
        a.append(i)
    
if b != 0 and b != 1:
    a.append(b)

    
print(n,end='')
print(': ',end='')
print(*a)


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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << ' ' <<  a << ' ' << b;
    return 0;
}

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

using namespace std;

int main() {
  int n;
  int a,b,c,d;
  cin >> n;
  d = n % 10;
  n /= 10;
  c = n % 10;
  n /= 10;
  b = n % 10;
  a = n / 10;
 
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < 2; j++) {
      for(int k = 0; k < 2; k++) {
	int sum = a;
	if(i == 0) sum += b;
	else sum -= b;
	if(j == 0) sum += c;
	else sum -= c;
	if(k == 0) sum += d;
	else sum -= d;
	if(sum == 7) {
	  cout << a;
	  cout << (i ? '-':'+');
	  cout << b;
	  cout << (j ? '-':'+');
	  cout << c;
	  cout << (k ? '-':'+');
	  cout << d <<"=7"<<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)
typedef long long ll;
#define bit(k) (1LL<<(k))

int main(void){
    int n;
    ll K;
    cin >> n >> K;
    ll sum[60] = {};
    rep(i,n) {
        ll a;
        cin >> a;
        rep(j,60) if(bit(j) & a) {
            sum[j]++;
        }
    }

    ll res = 0;
    ll x = 0;
    rep(i,60){
        int j = 60-1-i;
        if ((x|bit(j)) > K) {
            res += bit(j) * sum[j];
        } else if (sum[j] < n-sum[j]) { // 0が多い
            x |= bit(j);
            res += bit(j) * (n-sum[j]);
        } else {
            res += bit(j) * sum[j];
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect
import math

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

XH_array = [list(map(int, input().split())) for _ in range(N)]

XH_array = sorted(XH_array, key=lambda x: x[0])

X_array = [xh[0] for xh in XH_array]

# print(X_array)

ans = 0
bomb_count = [0] * N
now_bomb = 0

for i, xh in enumerate(XH_array):
    # print(now_bomb, bomb_count)
    x, h = xh
    remain = h - A * now_bomb
    if remain <= 0:
        now_bomb += bomb_count[i]
        continue
    bomb_add = math.ceil(remain / A)
    ans += bomb_add
    bomb_count[i] += bomb_add
    bomb_end = bisect.bisect_right(X_array, x + 2 * D)
    bomb_count[bomb_end - 1] -= bomb_add
    now_bomb += bomb_count[i]


print(ans)


Measured memory_bytes: 108936
import sys
import math
input = sys.stdin.readline


def main():
    A, B, H, M = map(int, input().split())
    x = abs(H * 30+M*0.5-M*6)
    theta = min(x, 360-x)
    rad = math.radians(theta)
    if theta == 180:
        print(A+B)
    elif theta == 0:
        print(abs(A-B))
    else:
        print(math.sqrt(A**2+B**2-2*A*B*math.cos(rad)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9332
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

typedef long long ll;
typedef pair<int, int> P;


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

    ll a[101000];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    ll dp[101000][2];
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[1][0] = a[0];
    dp[1][1] = -a[0];

    for(int i = 1; i < N-1; i++){
        dp[i+1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i+1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
    }

    cout << max(dp[N-1][0] + a[N-1], dp[N-1][1] - a[N-1]) << endl;


    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

long long POW(long long x,long long n,long long mod){
  long long ans = 1;
  while(n){
    if(n%2)ans *= x;
    x *= x;
    x %= mod;
    ans %= mod;
    n >>= 1;
  }
  return ans;
}
vector<long long> factorial(2,1);
long long nckmodp(long long n,long long k,long long p){
  if(n < k || n <= 0 || k < 0)return 0;
  while(factorial.size() <= n){
    long long i = factorial.size();
    factorial.push_back(i*factorial[i-1]%p);
  }
  return ((factorial[n]*POW(factorial[k],p-2,p))%p)*POW(factorial[n-k],p-2,p)%p;
}
long long TwelvefoldWay3(long long n,long long k,long long MOD){
  long long ans = 0;
  for(long long i = 1;i <= k;i++){
    ans += ((k-i)%2 ? -1 : 1)*nckmodp(k,i,MOD)*POW(i,n,MOD);
    ans = (ans%MOD+MOD)%MOD;
  }
  return ans;
}

signed main(){
  ll n,k;
  cin >> n >> k;
  cout << TwelvefoldWay3(n,k,INF) << endl;
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

//         18
//     17      15
// 16      14      11
//     13      10
// 12       9       6
//      8       5
//  7       4       2
//      3       1
//          0
int f(const string& s,int b,const int* a)
{
	int x=0;
	rep(i,7) x|=(b>>a[i]&1)<<i;
	return s[x]-'0';
}

int main()
{
	int a[][7]={
		{0, 1, 3, 4, 5, 8, 9},
		{1, 2, 4, 5, 6, 9,10},
		{3, 4, 7, 8, 9,12,13},
		{4, 5, 8, 9,10,13,14},
		{5, 6, 9,10,11,14,15},
		{8, 9,12,13,14,16,17},
		{9,10,13,14,15,17,18},
		{0, 1, 2, 3, 4, 5, 6},
	};
	for(string s;cin>>s && s!="#";){
		bool res=true;
		rep(i,1<<19){
			int x=0;
			rep(j,7) x|=f(s,i,a[j])<<j;
			int y=f(s,x,a[7]);
			res&=y==(x>>3&1);
		}
		cout<<(res?"yes":"no")<<endl;
	}
}

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

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int N;
    cin >> N;
    vector<int> D(N + 1, 0);
    for(int n = 1; n <= N; ++n) {
        for(int j = n; j <= N; j += n) {
            ++D[j];
        }
    }
    LL ans = 0;
    for(LL n = 1; n <= N; ++n) {
        ans += n * D[n];
    }
    cout << ans << "\n";
    
    
    return 0;
}


Measured memory_bytes: 42264
import sys

def ceaser_decode(text):
    d={}
    line=""
    for n in range(26):
        for c in (65,97):
            for i in range(26):
                d[chr(i+c)] = chr((i+n)%26+c)

        line = "".join([d.get(c,c) for c in text])
        if line.find("the")!=-1 or line.find("this")!=-1 or line.find("that")!=-1:
            break
    return line

for i in sys.stdin.readlines():
    print ceaser_decode(i),

Measured memory_bytes: 4236
def solve(n, s):
    l, r = 0, n // 2 + 1
    while l < r:
        m = (l + r + 1) // 2
        if search(m, s):
            l = m
        else:
            r = m - 1
    return l


def search(w, s):
    appeared = []
    comparing = set()
    w2 = w * 2

    for i in range(w, n + 1):
        t = hash(s[i - w:i])
        if i >= w2:
            comparing.add(appeared[i - w2])
            if t in comparing:
                return True
        appeared.append(t)

    return False


n = int(input())
s = input()
print(solve(n, s))


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



int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  rep(i, n-1) {
    int x;
    cin >> x;
    x--;
    a[x]++;
  }
  rep(i, n) {
    cout << a[i] << endl;
  }
}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, black = 0;
  cin >> H >> W;
  string s[H];
  vector<int> d(H*W);
  queue<int> q;
  vector<int> G[H*W];
  vector<bool> visited(H*W);
  for (int i = 0; i < H; i++) {
    cin >> s[i];
    for (char c : s[i]) {
      black += c == '#';
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i && s[i-1][j] != '#' && s[i][j] != '#') {
        G[i*W+j].push_back((i-1)*W+j);
      }
      if (i+1 < H && s[i+1][j] != '#' && s[i][j] != '#') {
        G[i*W+j].push_back((i+1)*W+j);
      }
      if (j && s[i][j-1] != '#' && s[i][j] != '#') {
        G[i*W+j].push_back(i*W+j-1);
      }
      if (j+1 < W && s[i][j+1] != '#' && s[i][j] != '#') {
        G[i*W+j].push_back(i*W+j+1);
      }
    }
  }
  for (q.push(0), visited[0] = true, d[0] = 1; !q.empty(); q.pop()) {
    for (int v : G[q.front()]) {
      if (!visited[v]) {
        d[v] = d[q.front()]+1;
        q.push(v);
        visited[v] = true;
      }
    }
  }
  if (d.back()) {
    cout << H*W-black-d.back();
  } else {
    cout << -1;
  }
}

Measured memory_bytes: 3584
#include <stdio.h>
#include <map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STRS(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define MED(a,b,c) ((a)<(b)?(a)>(c)?(a):(b)<(c)?(b):(c):(a)>(c)?(b)<(c)?(c):(b):(a))
#define RNG(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RNG3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXI(a,b) {if((a)<(b))(a)=(b);}
#define MINI(a,b) {if((a)>(b))(a)=(b);}
#define BEGINFOR(a,b,c,d,e,f,g,h,i) a;goto i##_6;i##_2:c;goto i##_6;i##_3:h;goto i##_7;i##_4:d;goto i##_8;i##_5:f;goto i##_8;i##_6:if(b)goto i##_4;else goto i##_9;i##_7:if(g)goto i##_5;else goto i##_1;i##_8:if(e)goto i##_2;else goto i##_3;i##_9:
#define CONTINUE(i) goto i##_3
#define BREAK(i) goto i##_1
#define ENDFOR(i) goto i##_3;i##_1:

int main(){
	std::map<int, int> data;
	int n;
	int ans = 0;
	scanf("%d", &n);
	REP(i, n){
		int a;
		scanf("%d", &a);
		data[a]++;
	}
	for(std::map<int, int>::iterator it = data.begin(); it != data.end(); it++){
		ans += it->second;
		if(it->first <= it->second) ans -= it->first;
	}
	printf("%d\n", ans);
}

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

int main(){
  ll n,t;
  cin>>n>>t;
  vector<ll> T(n);
  rep(i,n){
    cin>>T[i];
  }
  ll ans=0;
  rep(i,n-1){
    ans+=min(T[i+1]-T[i],t);
  }
  ans+=t;
  cout<<ans<<endl;
}

Measured memory_bytes: 4680
#include<iostream>
using namespace std;
const int N=502;
int ar[N];
int main(){
	int n,m,a,b,i,j;
	cin>>n>>m>>a>>b;
	if(n%a==0&&m%b==0){
		cout<<"No";
		return 0;
	}
	cout<<"Yes\n";
	if(n%a!=0){
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				if(i%a==1){
					cout<<69696*(a-1)-1<<' ';
				}
				else{
					cout<<-69696<<' ';
				}
			}
			cout<<"\n";
		}
	}
	else{
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				if(j%b==1){
					cout<<69696*(b-1)-1<<' ';
				}
				else{
					cout<<-69696<<' ';
				}
			}
			cout<<'\n';	
		}
	}
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll N,W,w,v;

int main(){
    cin>>N>>W;
    ll dp[N+1][W+1];
    rep(i,N+1){
        if(i)cin>>w>>v;
        rep(j,W+1){
            if(i==0||j==0){
                dp[i][j]=0;
                continue;
            }
            if(j<w) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v);
        }
    }
    out(dp[N][W]);
}


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

using namespace std;

int main()
{
	int l, r, d;
	cin>>l>>r>>d;
	int ans = 0;
	for(int i=l; i<=r; i++)
	{
		if(i%d == 0)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
////#include<bits/stdc++.h>
//#include<algorithm>
//#include<stdio.h>
//#include<math.h>
//using namespace std;
//#define pi acos(-1.0)
//double r,R,h,v,hh;
//int panduan(double h1)
//{
//    double rr=((hh-h1)/hh)*R;
//    double V=pi*(rr*rr+R*R+rr*R)*h1/3.0;
//    if(V>=v)
//        return 0;
//    else
//        return 1;
//}
//int main()
//{
//    int t;
//    scanf("%d",&t);
//    while(t--)
//    {
//        scanf("%lf %lf %lf %lf",&r,&R,&h,&v);
//        if(r-R<1e-5)
//        {
////            printf("%.6lf\n",pi);
////            printf("%.6lf\n",r*r);
//            printf("%.6lf\n",v/(pi*r*r));
////            printf("1\n");
//            continue;
//        }
//        hh=h+(h*r)/(R-r);
//        double l=1,r=100,mid;
//        while(r-l>1e-9)
//        {
//            mid=(r+l)/2.0;
//            if(panduan(mid))
//            {
//                l=mid;
//            }
//            else
//                r=mid;
//        }
//        printf("%.6lf\n",l);
//    }
//}
#include<stdio.h>
#include<algorithm>
using namespace std;
long long  q[100010],q1[100010];
int main()
{
    int n;
    scanf("%d",&n);
    q1[0]=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&q[i]);
//        q1[i]=q1[i-1]+q[i];
    }
    sort(q+1,q+n+1);
    for(int i=1; i<=n; i++)
    {
//        scanf("%d",&q[i]);
        q1[i]=q1[i-1]+q[i];
    }
    int sum=1;
    for(int i=1; i<=n-1; i++)
    {
        if(q1[i]*2>=q[i+1])
            sum++;
        else
            sum=1;
    }
    printf("%d\n",sum);
}


Measured memory_bytes: 1664
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  REP(i,26){
    bool make = true;
    REP(j,s.length()){
      if(s[j] == 'a' + i){
        make = false;
        break;
      }
    }
    if(make == true){
      printf("%c\n", 'a' + i);
      return 0;
    }
  }
  printf("None\n");
  return 0;
}



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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  string S;
  cin >> S;
  int red = 0, blue = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] == '0'){
      red++;
    } else{
      blue++;
    }
  }
  cout << min(red, blue) * 2<<endl;
}


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

static const int NMAX = 100100;

int main(){
  int n, m;
  int h[NMAX], ma[NMAX];  //ma[i]: 展望台 i から一本で行ける山の標高の最大値
  cin >> n >> m;
  REP(i,n) cin >> h[i];
  REP(i,n) ma[i] = 0; //初期化
  REP(i,m){
    int a, b;
    cin >> a >> b;
    --a; --b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }

  int cnt = 0;

  REP(i,n){
    if(h[i] > ma[i]) ++cnt;
  }

  cout << cnt << endl;
  return 0;
}

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

using namespace std;

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

int main(){
  int n;
  string a, b;
  cin >> n >> a >> b;
  REP(i, n){
    cout << a[i];
    cout << b[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256