akhauriyash/Code-Regression huggingface dataset:
//
// 2006 国内予選B問題
// 列車の編成パートII
//
// setとstringを用いて簡素に書いた版
// 06/21 Tsuji
//

//利用するのはsetとstringなのでinclude
#include <iostream>
#include <set>
#include <string>

//stdを省略
using namespace std;

//入力された文字列を反転する関数 引数は参照渡し
string reverseString(string &str){
	string res="";

	for(int i=str.size()-1;i>=0;i--){
		res+=str.at(i);
	}
	return res;
}

//解法関数 引数は入力された文字列
int solve(string str){
	set<string> sets;			//string型のsetを宣言
	int strsize=str.size();		//文字列の長さは頻繁にアクセスするので変数化
	string strs[4];				//分離した文字列とそれの反転したものを保持する4つの配列

	for(int i=0;i<strsize;i++){				//任意のi番目で分離することを考える
		strs[0]=str.substr(0,i);			//前半部
		strs[1]=str.substr(i,strsize-i);	//後半部

		strs[2]=reverseString(strs[0]);		//前半部の反転
		strs[3]=reverseString(strs[1]);		//後半部の反転

		//組み合わせをfor文を使って生成する
		for(int x=0;x<4;x++){
			for(int y=0;y<4;y++){
				//前半部同士や，前半部とその反転同士にならないように
				//偶数番目が前半部について，奇数番目が後半部についてなってることに着目して
				if(x%2!=y%2)	sets.insert(strs[x]+strs[y]);
			}
		}
		//直ガキした場合，前半部をstr1,後半部をstr2,前半部の反転をrev_str1,後半部の反転をrev_str2としたとき
		// sets.insert(str1+str2);
		// sets.insert(str1+rev_str2);
		// sets.insert(str2+str1);
		// sets.insert(str2+rev_str1);
		// sets.insert(rev_str1+str2);
		// sets.insert(rev_str1+rev_str2);
		// sets.insert(rev_str2+str1);
		// sets.insert(rev_str2+rev_str2);
		// と同じ事
	}
	//setは重複した場合は追加されていないのでsetsのsizeが組み合わせの数になるので出力する
	return sets.size(); 
}

//main関数
int main(void){
	int m;
	string str;

	//cinはc++での標準入力関数
	//scanf("%s",str);
	cin >> m;
	for(int i=0;i<m;i++){
		cin >> str;
		//coutはc++での標準出力関数
		//printf("%d\n",solve(str));
		cout << solve(str) << endl;
	}

	return 0;
}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
using namespace std;
int t, N, A[3][3], B[3][3];
int main()
{
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> A[i][j];
		}
	}
	cin >> N;
	while (N--)
	{
		cin >> t;
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				if (A[i][j] == t)
				{
					B[i][j]++;
				}
			}
		}
	}
	if (B[0][0] && B[0][1] && B[0][2] || B[1][0] && B[1][1] && B[1][2] || B[2][0] && B[2][1] && B[2][2] || B[0][0] && B[1][0] && B[2][0] || B[0][0] && B[1][0] && B[2][0] || B[0][1] && B[1][1] && B[2][1] || B[0][2] && B[1][2] && B[2][2] || B[0][0] && B[1][1] && B[2][2] || B[2][0] && B[1][1] && B[0][2])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long

using namespace std;

int main()
{
	int n;
	cin >> n;
	bool in = false;
	for (int i=1;i<=9;i++)
	{
		if (n % i == 0 && n/i<10)
		{
			cout << "Yes";
			in = true;
			break;
		}
	}
	if (in == false)
	cout << "No";
}




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

// ----本問について----
// 問題：観音堂
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/0168
// 所要時間：15分
// 学んだこと：DPの基礎
// ------------------

// ----ここから本問のソースコード----

const ll N_MAX = 30 + 10;

// グローバル変数（入力）
ll n, dp[N_MAX];

ll solve(ll i) {                     // メモ化再帰（？）
  if (dp[i] != -1) { return dp[i]; } // 計算済みならその値を返す

  if (i == 0) {
    dp[i] = 1;
  } else if (i == 1) {
    dp[i] = solve(i - 1);
  } else if (i == 2){
    dp[i] = solve(i - 1) + solve(i - 2);
  } else {
    dp[i] = solve(i - 1) + solve(i - 2) + solve(i - 3);
  }

  return dp[i];
}

int main() {
  // cout << fixed << setprecision(10);
  rep(i, N_MAX) { dp[i] = -1; }
  while (cin >> n && n > 0){
    cout << ceil(solve(n)/3650.0) << endl;
  }

  return 0;
}



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

const int inf = 1e9;
const ll linf = 1e18;

class UnionFind
{
public:
    UnionFind(int n = 0) : m_data(n, -1), m_count(n) {}

    int find(int x)
    {
        if (m_data[x] < 0) return x;
        else return m_data[x] = find(m_data[x]);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if (x == y) return false;

        if (m_data[x] > m_data[y]) swap(x, y);
        m_data[x] += m_data[y];
        m_data[y] = x;
        m_count--;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return -m_data[find(x)]; }

    int count(void) const { return m_count; }

private:
    vector<int> m_data;
    int m_count;
};

int main()
{
    int n, q; cin >> n >> q;
    UnionFind uf(n);

    for (int i = 0; i < q; i++) {
        int com, x, y; cin >> com >> x >> y;
        if (!com) uf.unite(x, y);
        else cout << uf.same(x, y) << endl;
    }
    return 0;
}



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

// B - Comparing Strings 
int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        for (int i = 0; i < a; i++) cout << b;
        return 0;
    } else {
        for (int i = 0; i < b; i++) cout << a;
        return 0;
    }
}


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

using namespace std;

int main(){
    int k;
    string s;

    cin >> k;
    cin >> s;

    if(s.length() <= k){
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll dp[N+5][5];
ll n;
ll A[N+5];

int main()
{
  finp;
  cin>>n;
  ll ans=0;
  afor(i,1,n)
  {
    cin>>A[i];
    if(A[i] & 1)
    {
      ans+=(A[i]-1)/2;
      A[i]=1;
    }
    else if(A[i]>0)
    {
      ans+=(A[i]-2)/2;
      A[i]=2;
    }
  }

  afor(i,0,n)afor(j,0,2)dp[i][j]=-1;

  dp[0][0]=0;

  afor(i,1,n)
  {
    if(dp[i-1][0]!=-1)
    {
      dp[i][0] = max(dp[i][0],dp[i-1][0] + A[i]/2);
      if(A[i]>=1)dp[i][1] = max(dp[i][1],dp[i-1][0]);
      if(A[i]>=2)dp[i][2] = max(dp[i][2],dp[i-1][0]);
    }

    if(dp[i-1][1]!=-1)
    {
      dp[i][0] = max(dp[i][0],dp[i-1][1] + (A[i]+1)/2);
      if(A[i]>=1)dp[i][1] = max(dp[i][1],dp[i-1][1] + A[i]/2);
      if(A[i]>=2)dp[i][2] = max(dp[i][2],dp[i-1][1]);
    }

    if(dp[i-1][2]!=-1)
    {
      dp[i][0] = max(dp[i][0],dp[i-1][2] + (A[i]+2)/2);
      if(A[i]>=1)dp[i][1] = max(dp[i][1],dp[i-1][2] + (A[i]+1)/2);
      if(A[i]>=2)dp[i][2] = max(dp[i][2],dp[i-1][2] + A[i]/2);
    }
  }
 

  ll curr=0;
  afor(i,0,2)curr=max(curr,dp[n][i]);
  
  cout<<ans+curr;
return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>



int main()
{
  long  a;
  scanf("%ld",&a);

  getchar();
  if(a==1){
    printf("0\n");
  }else
  {
       long rn=0;
       while (rn*rn<=a) rn++;
       long re = a-1;
       for(long  i=2;i<=rn;i++){
        if(!(a%i)){
            long  temp = i+a/i-2;
            if(temp<re){
                re = temp;
            }
        }
       }
       printf("%ld\n",re);
  }
  return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int64, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}

	r := 1
	for i := 1; i < N; i++ {
		b := true
		for j := i - 1; j >= 0; j-- {
			if A[i] < A[j] {
				b = false
				break
			}
		}
		if b {
			r++
		}
	}
	fmt.Println(r)
}

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

//関数
//main関数
int main() {
    
    
    
    //入力
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    
    
    
    //計算
    
    //出力
    if(e-a<=k){
        cout<<"Yay!"<<endl;
    }else{
        cout<<":("<<endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;
const int INF = 3e18;
const double PI = acos(-1);
const int MOD = 1e9 + 7;

int n, m;
int x[100010], y[100010];

bool possible[100010];
int many[100010];
int ans = 0;
signed main()
{
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    cin >> x[i] >> y[i];
  }

  for(int i = 1; i <= n; i++){
    many[i] = 1;
  }
  possible[1] = true;

  for(int i = 0; i < m; i++){
    if(possible[x[i]]){
      possible[y[i]] = true;
    }
    many[x[i]]--;
    many[y[i]]++;
    if(many[x[i]] == 0){
      possible[x[i]] = false;
    }
  }

  for(int i = 1; i <= n; i++){
    if(possible[i]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2688
#include <iostream>

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr int N_MAX = 1000;

ll fact[N_MAX+1], rfact[N_MAX+1];

ll perm(ll n, ll k) {
    if(n-k < 0LL) return 0LL;
    return (fact[n] * rfact[n-k]) % MOD;
}

ll comb(ll n, ll k) {
    if(n-k < 0LL) return 0LL;
    return (perm(n, k) * rfact[k]) % MOD;
}

ll modpow(ll a, ll p) {
    ll ret = 1LL;
    while(p) {
        if(p & 1) {
            ret = (ret * a) % MOD;
        }
        a = (a * a) % MOD;
        p >>= 1;
    }
    return ret;
}

void init_fact(ll n) {
    fact[0] = fact[1] = 1;
    rfact[0] = rfact[1] = 1;
    for(ll i=2;i<=n;++i) {
        fact[i] = (fact[i-1] * i) % MOD;
        rfact[i] = modpow(fact[i], MOD-2);
    }
}

int main() {
    ll n, k;
    cin >> n >> k;
    init_fact(k);
    cout << comb(k, n) << endl;
}


Measured memory_bytes: 3112
//  IT'S NEVER TOO LATE...

		    #include <bits/stdc++.h>
			#include <complex>
		    #define ll long long

			#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
			#define forn(i, n) fore(i, 0, n)
			#define fori(i, l, r) fore(i, l, (r) + 1)
			#define sz(v) int((v).size())
			#define all(v) (v).begin(), (v).end()
			#define pb push_back
			#define mp make_pair
		    #define ff first
		    #define ss second
		    
			//#define C complex<int>
			#define X real()
			#define Y imag()

		    using namespace std; 

		    const double PI = atan(1)*4;
		    #define inf 1e9
		    const int mod=1e9+7;


		    /*struct matrix
		    {
		    	int k;
		    	vector<vector<ll>> data;
		    	matrix(int x)
		    	{
		    		k=x;
		    		data.resize(x);
		    		forn(i,x)
		    		data[i].resize(x);
		    	}

		    	matrix operator *(matrix m1)
		    	{
		    		int n=m1.data.size();
		    		matrix m2(n);

		    		forn(i,n)
		    		{
		    			forn(j,n)
		    			{
		    				forn(k,n)
		    				{
		    					m2.data[i][k]+=((m1.data[i][j]%1000000007)*(data[j][k]%1000000007))%1000000007;
		    					m2.data[i][k]%=1000000007;
		    				}
		    			}
		    		}


		    		return m2;
		    	}
		    };*/

		    /*bool comp(pair<int,int> a,pair<int,int> b)
		    {
		    	return ((double)a.ff/a.ss) < ((double)b.ff/b.ss) ;
		    }

		    int dp[100][100],val[100],wt[100];
		    int knapsack(int n,int cap)
		    {
		    	if(n==0 || cap==0)
		    		return 0;
		    	if(dp[n][cap])
		    		return dp[n][cap];
		    	if(wt[n-1]<=cap)
		    	{
		    		return dp[n][cap]=max(knapsack(n,cap-wt[n-1]) + val[n-1], knapsack(n-1,cap));
		    	}
		    	else
		    		return dp[n][cap]= knapsack(n-1,cap);
		    }*/

		    int main()
		    {
		    	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		     
		    	#ifndef ONLINE_JUDGE
		        freopen("input.txt","r", stdin);
		        freopen("output.txt", "w", stdout);
		        #endif
		     
		    	int tt=1;
		    	//cin>>tt;
		    	
		    	while(tt--)
		    	{
		    		//matrix mat(n),m2(n);
		    		
		    		int n;
		    		cin>>n;
		    		int a[n];
		    		forn(i,n)
		    		cin>>a[i];

		    		int mn=0;
		    		ll sum=0;
		    		forn(i,n)
		    		{
		    			sum+=max(0,mn-a[i]);
		    			mn=max(mn,a[i]);
		    		}

		    		cout<<sum;
		    	}
		    	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

		    	return 0;
		    }
		    				//              NOW IT'S TIME TO WAKE UP... 

Measured memory_bytes: 4588
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

int main() {
    ll x,y;
    cin>>x>>y;

    ll ans=0;
    while(x<=y){
        ans++;
        x*=2;
    }
    cout<<ans<<endl;





    return 0;
}


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

int main() {
	ll n;
	cin >> n;
	vector<ll>a(n+1);
	for (int i = 0; i < n+1; i++)cin >> a.at(i);
	if (n == 0) {
		if (a.at(0) == 1)cout << 1 << endl;
		else cout << -1 << endl;
		return 0;
	}
	if (n >= 1 && a.at(0) != 0) {
		cout << -1 << endl;
		return 0;
	}
	vector<ll>sig;
	for (int i = n; i >= 0; i--) {
		if (i == n)sig.push_back(a.at(i));
		else {
			sig.push_back(sig.at(sig.size() - 1) + a.at(i));
		}
	}
	reverse(sig.begin(), sig.end());
	ll ans = 1;
	ll cur = 1;
	for (int i = 1; i <= n; i++) {
		if (cur * 2 < sig.at(i)) {
			cur *= 2;
			ans += cur;
			cur -= a.at(i);
			if (cur < 0) {
				cout << -1 << endl;
				return 0;
			}
		}
		else {
			cur = sig.at(i);
			ans += cur;
			cur -= a.at(i);
			if (cur < 0) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5052
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < c&&c < b || b < c&&c < a) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
//om namah shivaaay//
#include <bits/stdc++.h>
#define input int t;cin>>t;while(t--)
#define Om_namah_Shivaay ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout.precision(10)
 #define ll long long
 #define vi  vector<int>
 #define pb push_back
 #define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
 #define f(i, a, b) for (int i = 0; i < (b); i++)
 #define w(t) int t;cin>>t;while(t --)
#define fr(i, a, b) for (int i = (a); i >= (b); i--)
 const int N=1e5 +5;
 using namespace std;
 int main()
 {
    Om_namah_Shivaay;
    string s,t;
   cin>>s>>t;
   int ans=INT_MAX;
for(int i=0;i<=(int)s.size()-(int)t.size();i++){
	   int diff=0;
	   for(int j=0;j<(int)t.size();j++){
	   if(t[j]!=s[i+j])
	     diff+=1;
	   }
    ans=min(ans,diff);
}
cout<<ans<<endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <string>
#include <typeinfo>

using namespace std;

void xyz(int x[], int n)
{
	if(x[n] == 1)
	{
		x[n] = 0;
		xyz(x, n + 1);
	}
	else if(x[n] == 0)
	{
		x[n] = 1;
	}
}

bool check(int x[], int n)
{
	bool flag = true;
	for(int i = 0; i < n; i++)
	{
		if(x[i] != 1)
		{
			flag = false;
			break;
		}
	}
	return flag;
}

int main()
{
	string s;
	cin >> s;
	
	long ans = stol(s);
	
	if(s.size() > 1)
	{
		int x[s.size() - 1] = {0};
		while(!check(x, s.size() - 1))
		{
			xyz(x, 0);
			string tmp;
			for(int j = 0; j < s.size(); j++)
			{
				tmp.push_back(s[j]);
				if(j != s.size() - 1)
				{
					if(x[j] == 1)
					{
						ans += stol(tmp);
						tmp.clear();
					}
				}
			}
			ans += stol(tmp);
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n,m;

vector<int>G[100010];
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  cin >> n >> m;
  
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int>ans(n,-1);
  queue<int>que;
  que.push(0);
  while(!que.empty()){
    int t=que.front();
    que.pop();
    for(auto nt:G[t]){
      if(ans[nt]!=-1)continue;
      if(ans[nt]==-1){
        ans[nt]=t+1;
        que.push(nt);
      }
    }
  }
     
  cout << "Yes" << endl;
  rep(i,n-1){
    cout << ans[i+1] << endl;
  }
    
  return 0;     
}


Measured memory_bytes: 10060
#include <iostream>
#define INF  1000000

int main()
{
	int N;
	std::cin >> N;
	int h[100010];
	int costs[100010] ;
	for (int i = 0; i < 100010; i++) { costs[i] = INF; }
	for (int i = 0; i < N; i++) {
		std::cin >> h[i];
	}
	costs[0] = 0;
	costs[1] = abs(h[0] - h[1]);
	for (int i = 2; i < N; i++) {
		int a, b;
		a = abs(h[i] - h[i - 1]) + costs[i-1];
		b = abs(h[i] - h[i - 2]) + costs[i-2];
		costs[i] = (a > b) ? b : a;
	}
	std::cout << costs[N - 1];
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdint.h>

#ifdef DEBUG
#define DEBUG_LOG(fmt, ...)   printf(fmt, ##__VA_ARGS__)
#else
#define DEBUG_LOG(fmt, ...)
#endif

using namespace std;

int main()
{
    uint32_t n, c[3], a, ans;
    ans = 1;
    c[0] = c[1] = c[2] = 0;
    scanf(" %u", &n);
    for (uint32_t i = 0; i<n; i++) {
        scanf(" %u", &a);
        bool found = false;
        uint32_t p = 0;
        for (int ci=0; ci<3; ci++) {
            if (c[ci] == a) {
                p++;
                if (found == false) {
                    found = true;
                    c[ci]++;
                }
            }
        }
        ans *= p;
        ans %= 1000000007;
    }
    printf("%u\n", ans);
    return 0;
}


Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import Data.Map ((!))
import qualified Data.Map as M
-- import Data.IntMap ((!))
-- import qualified Data.IntMap as M
import qualified Data.List as L
import Data.Maybe (catMaybes)
-- import qualified Data.Char as C
-- import qualified Data.IntSet as I
import Debug.Trace
import Text.Regex.Posix ((=~))
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------

main :: IO ()
main = do
  [a, b, c] <- getIntList
  let ab = a + b
  putStrLn $ if ab >= c then "Yes" else "No"


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

string s;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> s;
  int n = SZ(s);
  reverse(ALL(s));
  int res = 0;
  R(mb,1 << (n-1)){
    int p10 = 1;
    int pom = mb;
    R(i,n){
      res += p10 * (s[i]-'0'); 
      p10 *= 10;
      if(pom&1)p10=1;
      pom/=2;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 764
def main():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]
    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in ab]
    [g[b-1].append(a-1) for a, b in ab]
    root = 0  # 根
    d = [-1]*n  # 根からの距離
    d[root] = 0
    q = [root]
    cnt = 0
    while q:  # BFS
        cnt += 1
        qq = []
        while q:
            i = q.pop()
            for j in g[i]:
                if d[j] == -1:
                    d[j] = cnt
                    qq.append(j)
        q = qq
    grundy = [0]*n

    dd = [j for i, j in sorted([(j, i) for i, j in enumerate(d)])[::-1]]

    for i in dd:
        dist = d[i]
        xorlist = []
        xor = 0
        for j in g[i]:
            if d[j] > dist:
                xorlist.append(grundy[j]+1)
        for j in xorlist:
            xor ^= j
        grundy[i] = xor

    if grundy[0]:
        print("Alice")
    else:
        print("Bob")


main()


Measured memory_bytes: 58372
#include<stdio.h>
int main(){
int a;
scanf("%d", &a);
  
  if(a%10==3){
    printf("bon\n");
    return 0;
  }
  
  if(a%10==0||a%10==1||a%10==6||a%10==8){
    printf("pon\n");
    return 0;
  }

printf("hon\n");
return 0;
}


Measured memory_bytes: 1656
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define MOD 1000000007;

int main() {

    long long N, M;
    cin >> N >> M;
    priority_queue<long long>que;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        que.push(A);
    }

    for (int i = 0; i < M; i++) {
        if (que.empty())break;
        que.push(que.top() / 2);
        que.pop();
    }

    long long ans = 0;
    while (!que.empty())
    {
        ans += que.top();
        que.pop();
    }
    cout << ans;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int H, W; in(H); in(W);
  int N; in(N);

  int board[H][W];
  int x = 0, y = 0;
  rep(i, N) {
    int a; in(a);
    rep(j, a) {
      board[x][y] = i+1;
      y += 1 - (x % 2) * 2;
      if (y < 0) {
        ++x; ++y;
      }
      if (y >= W) {
        ++x; --y;
      }
    }
  }
  rep(i, H) {
    rep(j, W-1) {
      cout << board[i][j] << " ";
    }
    cout << board[i][W-1] << "\n";
  }

  return 0;
}


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

using namespace std;

#define ll long long
typedef complex<double> P;

struct Node {
  Node *parent;
  vector<Node*> childs;
  int num;
};

Node *root;

int main() {
  root = new Node;
  root->parent = root;
  int n;
  cin >> n;
  Node *nodes[n];
  for (int i = 0; i < n; i++) {
    nodes[i] = new Node;
    nodes[i]->parent = root;
    nodes[i]->num = i;
  }

  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;

    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      nodes[id]->childs.push_back(nodes[c]);
      nodes[c]->parent = nodes[id];
    }
  }

  for (int i = 0; i < n; i++) {
    int parent = nodes[i]->parent == root ? -1 : nodes[i]->parent->num;
    int depth = 0;
    Node *p = nodes[i]->parent;
    while(p != root) {
      depth++;
      p = p->parent;
    }
    string type;
    if(nodes[i]->parent == root) type = "root";
    else if(nodes[i]->childs.size() == 0) type = "leaf";
    else type = "internal node";

    cout << "node " << i << ": ";
    cout << "parent = " << parent << ", ";
    cout << "depth = " << depth << ", ";
    cout << type << ", ";
    cout << "[";
    for (int j = 0; j < nodes[i]->childs.size(); j++) {
      cout << nodes[i]->childs[j]->num << (j+1 == nodes[i]->childs.size() ? "" : ", ");
    }
    cout << "]" << endl;
  }

  delete root;
  for (int i = 0; i < n; i++) {
    delete nodes[i];
  }
}

Measured memory_bytes: 9564
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [0]*n
num = 0
count = 0
for i in range(n):
    a[i] = list(map(int,input().split()))
    for j in range(m):
        num += a[i][j]*b[j]
    if num + c > 0:
        count += 1
    num = 0
print(count)

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

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

    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << "\n";

    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    withdraws = []
    for i in range(N):
        if N < 9**i:
            break
        withdraws.append(9**i)
    for i in range(1, N):
        if N < 6**i:
            break
        withdraws.append(6**i)
    withdraws.sort(reverse=True)
    W = len(withdraws)

    dp = [[10**9 for i in range(N + 1)] for j in range(W + 1)]
    dp[0][0] = 0
    for i in range(1, W+1):
        for n in range(N + 1):
            if n - withdraws[i-1] >= 0:
                dp[i][n] = min(dp[i-1][n], dp[i][n],
                               dp[i][n - withdraws[i-1]] + 1)
            else:
                dp[i][n] = min(dp[i-1][n], dp[i][n])
    print(dp[W][N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 107756
#include<stdio.h>

#define MAX 8

int r[MAX],c[MAX],p[2*MAX-1],n[2*MAX-1],m[MAX][MAX];

void unit(){
  int i;
  for(i=0;i<MAX;i++){r[i]=-1;c[i]=-1;}
  for(i=0;i<2*MAX-1;i++){p[i]=-1;n[i]=-1;}
}

void board(){
  int i,j;
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
      if(m[i][j]){if(r[i]!=j) return;}
    }
  }for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
      if(r[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void Queen(int i){
  int j;
  
  if(i==MAX){board();return;}

  for(j=0;j<MAX;j++){
    if(1==c[j]||1==p[i+j]||1==n[i-j+MAX-1]) continue;
    r[i]=j; c[j]=p[i+j]=n[i-j+MAX-1]=1;
    Queen(i+1);
    r[i]=c[j]=p[i+j]=n[i-j+MAX-1]=-1;
  }
}

int main(){
  int i,j,k;
  int row,st;
  
  unit();

  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++) m[i][j]=0;
  }

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&row,&st);
    m[row][st]=1;
  }

  Queen(0);

  return 0;
}




Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
using namespace std;
long long dp[6000],n,a[6000],i,maxm;
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[1]=maxm=a[1];
    for(int i=2;i<=n;i++){
      if(dp[i-1]>=0)dp[i]=dp[i-1]+a[i];
      else dp[i]=a[i];
      
      maxm=max(dp[i],maxm);
    }
    cout<<maxm<<endl;
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int a, b;
	cin >> a >> b;

	cout << (a - 1) * (b - 1) << endl;

}

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

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  string s,t;
  cin >> s >> t;
  for(int i = s.size() - t.size(); i >= 0; i--){
    bool flag = true;
    for(int j = 0; j < t.size(); j++){
      if(t[j] == s[j+i] || s[j+i] == '?') continue;
      else flag = false;
    }
    if(flag){
      for(int j = 0; j < t.size(); j++){
        s[j+i] = t[j];
      }
      for(int j = 0; j < s.size(); j++){
        if(s[j] == '?') s[j] = 'a';
      }
      cout << s << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


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

int main() {
	int h[10];
	int max[3];
	int tmp, maxj;

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

	for (int i = 0; i < 3; ++i) {
		tmp = 0;
		for (int j = 0; j < 10; ++j) {
			if (h[j] > tmp) {
				tmp = h[j];
				maxj = j;
			}
		}
		max[i] = tmp; h[maxj] = 0;
	}

	for (int i = 0; i < 3; ++i) {
		cout << max[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int x = (a + d - 1) / d;
        int y = (c + b - 1) / b;
        if (x >= y) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        } 
    }
}

Measured memory_bytes: 35832
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    double a;
    cin>>a;
    cout<<2*a*3.1415<<endl;
}

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

using namespace std;

template <typename T>std::string NumberToString ( T Number ){std::ostringstream ss; ss << Number;return ss.str(); } // Usages NumberToString(3)
template <typename T>T StringToNumber ( const string &Text ){istringstream ss(Text);T result;return ss >> result ? result : 0;} // StringToNumber<int>("3")

int main(){

   ios::sync_with_stdio(0);
   cin.tie(0);

   string str;
   string rev_str;
   string f_str = "";
   string frev_str = "";
   string l_str = "";
   string lrev_str = "";

   cin >> str;

   rev_str = str;
   reverse(rev_str.begin(), rev_str.end());

   if(str == rev_str){

      for(int i=0; i<str.length()/2; i++){
         f_str += str[i];
      }
      for(int i=(str.length() + 3/2) - 1; i<str.length(); i++){
         l_str += str[i];
      }

      frev_str = f_str;
      lrev_str = l_str;

      reverse(frev_str.begin(), frev_str.end());
      reverse(lrev_str.begin(), lrev_str.end());

      if(frev_str == f_str){
         if(lrev_str == l_str){
            cout << "Yes" << endl;
            return 0;
         }
      }

   }

   cout << "No" << endl;





   return 0;
}

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

main()
{
        int n; cin>>n;
        vector<int> v(n);
        for(int i=0;i<n;i++)cin>>v[i];
        int ans=0;
        for(int i=0;i<n-2;i++)
        {
                vector<int> a={v[i],v[i+1],v[i+2]};
                sort(a.begin(),a.end());
                if(a[1]==v[i+1])ans++;
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const int INF = 1 << 30;
const int MOD = 1e9 + 7;

vector<int> memo1;
vector<int> memo2;
vector<vector<int>> g;

void dfs(int v, vector<int>& memo, int d=0,int p=-1){
    memo[v] = d;
    for (int nv: g[v]) {
        if (nv == p) continue;
        dfs(nv, memo, d+1, v);
    }
}

int main() {
    int n; cin >> n;
    memo1.assign(n, INF);
    memo2.assign(n, INF);
    g.resize(n);
    rep(i, n-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, memo1);
    dfs(n-1, memo2);

    int count1 = 0;
    int count2 = 0;
    rep(i, n) {
        if (memo1[i] <= memo2[i]) count1++;
        else count2++;
    }

    if (count1 > count2) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;




    return 0;
}

Measured memory_bytes: 12800
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
int main() {
	ll n,v[100010];
	cin >> n;
	rep(i, n)cin >> v[i];
	sort(v, v+n);
	ll mx=0, mx2=0,ct=1,last;
	rep(i, n) {
		if (i == 0) { last = v[i]; continue; }
		if (last == v[i])++ct;
		if (ct == 2) {
			ct = 0;
			if (mx == 0)mx = v[i];
			else { mx2 = mx; mx = v[i]; }
		}
		if (last != v[i])ct = 1;
		last = v[i];
	}
	cout << mx * mx2 << endl;
	return 0;
}

Measured memory_bytes: 1024
n = input()
arr = [0]+map(int,raw_input().split())+[0]
dis = []
for i in range(1,n+2):
	dis.append(abs(arr[i-1]-arr[i]))
s = sum(dis)
for i in range(1,n+1):
	print s-dis[i]-dis[i-1]+abs(arr[i-1]-arr[i+1])


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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    scanf("%d", &n);
    printf("%.12Lf", (long double)((n + 1) / 2) / n);
    return 0;
}


Measured memory_bytes: 3784
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

lld max(lld a, lld b, lld c){
    if(b <= a && c <= a){
        return a;
    }
    if(a <= b && c <= b){
        return b;
    }
    return c;
}

lld min(lld a, lld b, lld c){
    if(b >= a && c >= a){
        return a;
    }
    if(a >= b && c >= b){
        return b;
    }
    return c;
}

int main(){
    lld h, w;
    scanf("%lld %lld", &h, &w);
    lld ans = 10000000000;
    lld buf;
    lld a, b, c;
    buf = (h - ((h - (h/3))/2 + (h/3))) * w - (h/3) * w;
    if(buf < ans){
        ans = buf;
    }
    buf = h * (w - ((w - (w/3))/2 + (w/3))) - h * (w/3);
    if(buf < ans){
        ans = buf;
    }
    rep(i, 1, (int)h){
        a = (lld)i * w;
        b = (h - (lld)i) * (w/2);
        c = (h - (lld)i) * (w - w/2);
        buf = max(a, b, c) - min(a, b, c);
        if(buf < ans){
            ans = buf;
        }
    }
    rep(i, 1, (int)w){
        a = h * (lld)i;
        b = (h/2) * (w - (lld)i);
        c = (h - h/2) * (w - (lld)i);
        buf = max(a, b, c) - min(a, b, c);
        if(buf < ans){
            ans = buf;
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 128
using System;

class MyClass
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 1; i <= n; i++)
        {
            if (i % 3 == 0 || i.ToString().Contains("3"))
            {
                Console.Write(" {0}", i);
            }
        }
        Console.WriteLine();
    }
}


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

int main()
{
   int a,b,c,d,t,ao;
   cin >> a >> b >> c >> d;
   t=(a+d-1)/d;
   ao=(c+b-1)/b;
   if(t>=ao)
       cout << "Yes" << endl;
   else if(t<ao)
       cout << "No" << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(){
		row = col = move_cost = sum_cost = 0;
	}

	Info(int arg_row,int arg_col,int arg_move_cost,int arg_sum_cost){
		row = arg_row;
		col = arg_col;
		move_cost = arg_move_cost;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct Info &arg) const{
		return sum_cost > arg.sum_cost;
	}
	int row,col,move_cost,sum_cost;
};

int H,W;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
int min_cost[30][30][901],base_map[30][30];


bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1){
		return true;
	}else{
		return false;
	}
}


int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++)scanf("%d",&base_map[row][col]);
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			for(int i = 0; i <= H*W; i++)min_cost[row][col][i] = BIG_NUM;
		}
	}

	priority_queue<Info> Q;
	min_cost[0][0][0] = 0;
	Q.push(Info(0,0,0,0));

	int adj_row,adj_col,next_move_cost,next_sum_cost;
	int ans = BIG_NUM;

	Info info;

	while(!Q.empty()){

		if(Q.top().row == H-1 && Q.top().col == W-1){
			ans = min(ans,Q.top().sum_cost);
			Q.pop();
		}else if(Q.top().sum_cost > min_cost[Q.top().row][Q.top().col][Q.top().move_cost]){
			Q.pop();
		}else if(Q.top().move_cost == H*W+1){
			Q.pop();
		}else{

			info = Q.top();
			Q.pop();

			for(int i = 0; i < 4; i++){
				adj_row = info.row+diff_row[i];
				adj_col = info.col+diff_col[i];

				if(!rangeCheck(adj_row,adj_col))continue;

				next_move_cost = info.move_cost+1;
				next_sum_cost = info.sum_cost+(base_map[adj_row][adj_col]*(2*info.move_cost+1))+1;

				if(adj_row == H-1 && adj_col == W-1){
					next_sum_cost -= info.move_cost+1;
				}

				if(min_cost[adj_row][adj_col][next_move_cost] > next_sum_cost){
					min_cost[adj_row][adj_col][next_move_cost] = next_sum_cost;
					Q.push(Info(adj_row,adj_col,next_move_cost,next_sum_cost));
				}
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 10112
import heapq
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ans = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
heapq.heapify(ans)
added = {"0 0 0"}
for _ in range(k):
    w = heapq.heappop(ans)
    print(-w[0])
    i, j, m = w[1:]
    dx = [1, 0, 0]
    dy = [0, 1, 0]
    dz = [0, 0, 1]
    for r in range(3):
        ni, nj, nm = i + dx[r], j + dy[r], m + dz[r]
        if not (ni < x and nj < y and nm < z):
            continue
        g = " ".join(map(str, (ni, nj, nm)))
        if g not in added:
            added.add(g)
            heapq.heappush(ans, (-(a[ni] + b[nj] + c[nm]), ni, nj, nm))


Measured memory_bytes: 4972
#include <stdio.h>

int main() {
    int n, m;
    int p[100001] = {0};
    char s[100001][2] = {0};
    
    scanf("%d %d", &n, &m);
    for(int cnt = 0; cnt < m; cnt++)
        scanf("%d %s", &p[cnt], s[cnt]);
    
    int c[100001][3] = {0};
    
    for(int cnt = 0; cnt < m; cnt++) {
        c[p[cnt]][0]++;
        if((s[cnt][0] == 'W') && (c[p[cnt]][2] == 0))
            c[p[cnt]][1]++;
        else if(s[cnt][0] == 'A')
            c[p[cnt]][2] = 1;
    }
        
    int ok = 0;
    int pena = 0;
    
    for(int cnt = 1; cnt <= n; cnt++) {
        if(c[cnt][2]) {
            ok++;
            pena += c[cnt][1];
        }
    }
    
    printf("%d %d", ok, pena);
    
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
using namespace std;
int main()
{
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int xx,yy;
    for(int i=0;i<n;i++)
    {
        cin>>xx;
        if(xx>x) x=xx;
    }
    for(int i=0;i<m;i++)
    {
        cin>>yy;
        if(yy<y) y=yy;
    }
    if(x<y) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}

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

using namespace std;
int n, x, a[105], sum;

int t(int i, int j){
    if(j < i){
        return j;
    }
    if(i <= j){
        return i;
    }
}

int main()
{
    cin >> n;
    for(int i = 0; i < n-1; i++){
        cin >> x;
        a[i]=x;
    }
    for(int i = 0; i < n; i++){
        sum+=t(a[i], a[i+1]);
    }
    sum+=a[n-2];
    sum+=a[0];
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto C = RD!string;

	writeln(cast(string)[C[0]+1]);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		boolean flag = false;


		if(N >=1 && N<=81)
		{
			for(int i = 1; i<=9; i++)
			{
				if( ((N%i) == 0) && ((N/i) <= 9) )
					flag = true;
			}
		}

		if(flag == true)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 23380
#include<iostream>

using namespace std;

int main(){
  while(1){
    int N,M,P;
    cin >> N >> M >> P;
    if(N==0&&M==0&&P==0)break;
    int sum=0;
    int mem;
    for(int i=1;i<=N;i++){
      int input;
      cin >> input;
      sum+=input;
      if(i==M)mem=input;
    }
    sum=sum*(100-P);
    cout << (mem?sum/mem:0) << endl;
  }
}



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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int M,K;

int mypow(int n,int d) {
    d--;
    while(d > 0) {
        n *= 2;
        d--;
    }

    return n;
}

int main(void) {
    cin>>M>>K;

    if(K >= mypow(2,M)) {
        cout<<-1<<endl;

        return 0;
    }

    if(M == 0) {
        if(K == 0) {
            cout<<0<<" "<<0<<endl;
        } else {
            cout<<-1<<endl;
        }

        return 0;
    }

    if(M == 1) {
        if(K == 0) {
            cout<<1<<" "<<1<<" "<<0<<" "<<0<<endl;
        } else {
            cout<<-1<<endl;
        }

        return 0;
    }

    int r = mypow(2,M);
    vector<int> b;
    for(int i = 0;i < r;i++) {
        if(K == i)
            continue;
        b.push_back(i);
    }

    vector<int> c;
    for(int i = b.size()-1;i >= 0;i--) {
        c.push_back(b[i]);
    }

    for(int i = 0;i < b.size();i++) {
        cout<<b[i]<<" ";
    }
    cout<<K<<" ";
    for(int i = 0;i < c.size();i++) {
        cout<<c[i]<<" ";
    }
    cout<<K<<endl;

    return 0;
}




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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }
  int cnt = 0;
  for(int i = 0; i < n; i++){
    if(p[i] != i+1) cnt++;
  }
  if(cnt == 2 || cnt == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
typedef long long i64;
const i64 MOD(1e9 + 7);
inline i64 Powlog(i64 a, i64 b) {
    i64 res(1);
    while (b) {
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
i64 n, a, b, kf, res;
i64 CNK(i64 n, i64 k) {
    i64 r(1), kf(1);
    for (int i = 0; i < k; ++i)
        r = (r * (n - i)) % MOD;
    kf = 1;
    for (int i = 1; i <= k; ++i)
        kf = (kf * i) % MOD;
    kf = Powlog(kf, MOD - 2);
    r = (r * kf) % MOD;
    return r;
}
int main() {
    DAU
    cin >> n >> a >> b;
    res = Powlog(2, n) - 1 - CNK(n, a) - CNK(n, b);
    while (res < 0)
        res += MOD;
    cout << res;
    PLEC
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#define mod 1000000007
#define pb push_back
using namespace std;
int main(){
	int k;
	string s;
	vector<string> str;
	map<string,int> mp;
	cin>>s;
	cin>>k;
	for(int i=0;i<s.size();i++){
		int t=s.size()-i;
		for(int j=1;j<=min(t,5);j++){
			if(mp[s.substr(i,j)]==0){
				str.pb(s.substr(i,j));
				mp[s.substr(i,j)]++;
			}
		}
	}
	sort(str.begin(),str.end());
	cout<<str[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 2688