akhauriyash/Code-Regression huggingface dataset:
// B - Training Camp

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

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

	ll ans = 1;
	for (int i=1; i<=N; i++) {
		ans = (ans * i) % MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local pow2 = {1}
for i = 2, 28 do pow2[i] = pow2[i - 1] * 2 end
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = pow2[i]
    for j = 0, cnt - 1 do
      self.stage[cnt + j] = self.func(self.stage[(cnt + j) * 2], self.stage[(cnt + j) * 2 + 1])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
  end
  self.stagenum = stagenum
  for i = 1, mul * 2 - 1 do self.stage[i] = emptyvalue end
  for i = 1, n do self.stage[mul + i - 1] = i end
  self:updateAll()
end
SegTree.update = function(self, idx)
  idx = idx + pow2[self.stagenum] - 1
  for i = self.stagenum - 1, 1, -1 do
    local dst = mfl(idx / 2)
    local rem = dst * 4 + 1 - idx
    self.stage[dst] = self.func(self.stage[idx], self.stage[rem])
    idx = dst
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local h, w, k = io.read("*n", "*n", "*n")
local inf = h * w * k + 1
local x1, y1 = io.read("*n", "*n")
local sidx = (x1 - 1) * w + y1
local x2, y2 = io.read("*n", "*n", "*l")
local tidx = (x2 - 1) * w + y2
local len = {}
local asked = {}
for i = 1, h do
  local s = io.read()
  for j = 1, w do
    local idx = (i - 1) * w + j
    local f = s:sub(j, j) ~= "."
    for k = -1, 0 do
      len[idx * 2 + k] = inf
      asked[idx * 2 + k] = f
    end
  end
end
len[sidx * 2 - 1] = 0
len[sidx * 2] = 0

local n = h * w * 2
asked[n + 1] = true

local function mergefunc(x, y)
  if asked[x] then return y
  elseif asked[y] then return x
  else
    return len[x] < len[y] and x or y
  end
end

local st = SegTree.new(n, mergefunc, n + 1)

local function walk(src, dst, cost)
  if not asked[dst] and len[src] + cost < len[dst] then
    len[dst] = len[src] + cost
    st:update(dst)
  end
end

for i = 1, n do
  local src = st.stage[1]
  if asked[src] then break end
  asked[src] = true
  st:update(src)
  local idx = mce(src / 2)

  local l = len[src]
  local z = mce(l / k) * k - l
  if src % 2 == 1 then
    -- to left-right
    if 1 < w then
      if idx % w ~= 1 then walk(src, src - 2, 1) end
      if idx % w ~= 0 then walk(src, src + 2, 1) end
    end
    walk(src, src + 1, z)
  else
    -- to up-down
    if w < idx then
      walk(src, src - 2 * w, 1)
    end
    if idx <= (h - 1) * w then
      walk(src, src + 2 * w, 1)
    end
    walk(src, src - 1, z)
  end
end

local ret = mmi(len[tidx * 2 - 1], len[tidx * 2])
if inf <= ret then
  print(-1)
else
  local l = mce(ret / k)
  print(l)
end
-- print(os.clock())


Measured memory_bytes: 69860
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main()
{
	int h, w;
	string s[100];
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < w + 2; i++) {
		cout << "#";
	}
	cout << endl;
	for (int i = 0; i < h; i++) {
		cout << "#" << s[i] << "#" << endl;
	}
	for (int i = 0; i < w + 2; i++) {
		cout << "#";
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var S = cin.ReadLine.ToCharArray();

            int zero = 0;
            int one = 0;
            foreach(var elem in S)
            {
                if(elem == '0')
                {
                    zero++;
                }
                else
                {
                    one++;
                }
            }

            Console.WriteLine(2 * Min(zero, one));

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13304
#include <bits/stdc++.h>
using namespace std;
#include <stdio.h>
int main() {
  char a[4];
  for(int i; i<4; i++) cin >> a[i];
  int ans = 0;
  for (int i; i<4; i++){
  if(a[i]=='+') ans++;
  else ans--;
  }
  cout << ans << endl;
}



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

using namespace std;

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

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

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

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

	cout << dp.at(n - 1) << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
//#define int long long
#define all(x) (x).begin(), (x).end()
#define finout(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
#define X first
#define Y second

using namespace std;
const int MOD = 1e9 + 7;

typedef pair <int, int> pii;
typedef vector <int> vi;
inline int ni() {int x; cin >> x; return x;}
template <class T>
inline T nt() {T x; cin >> x; return x;}
inline void print(){}
template<typename T, typename ...TAIL>
inline void print(const T &t, TAIL... tail) {cout << t; print(tail...);}
inline void input() {return;}
template<typename T, typename ...TAIL>
inline void input(T &t, TAIL&... tail) {cin >> t; input(tail...);}

const int N = 2 * 1005001;
const int inf = 1e9 + 7;
const double PI = 3.14159265359;

signed main () {
    ios_base::sync_with_stdio(NULL);  cin.tie(0); cout.tie(0);
    int n = ni();
    vi v;
    map <int, int> mp;
    for (int i = 0; i < n; i++) {
        v.push_back(ni());
        mp[v[i]] = i % 2;
    }
    sort(all(v));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 != mp[v[i]]) ans++;
    }
    ans = (ans + 1) / 2;
    cout << ans << '\n';
}




















Measured memory_bytes: 8296
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define getindi(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)x.size()

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;
        ll k,n;
        cin>>k>>n;
        vi v(n);
        rep(i,n){
           cin>>v[i];
        }
        vll vv;
        rep1(i,1,n-1){
             vv.push_back(v[i]-v[i-1]);
        }
        vv.push_back(k-v[n-1]+v[0]);
        sort(all(vv));

        ll sum=0;
        rep(i, n-1){
            sum+=vv[i];
        }
        cout<<sum<<endl;




return 0;
}


Measured memory_bytes: 3188
S=input()
K=int(input())
notoneposition=[S.find(str(i)) for i in range(2,10) if S.find(str(i))!=-1]
if notoneposition==[]:
	print(1)
else:
	notonehead=min(notoneposition)
	notone=S[notonehead]
	print(1) if K-1<notonehead else print(str(notone))

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

a = list(map(int, input().split()))
if(a[4] <= a[2]) & (a[4] <= a[3]) & (a[2] <= a[0] - a[4]) & (a[3] <= a[1] - a[4]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5600
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define FILE_NAME "a"

int n, m;
vector<vii> g;

bool read() {
	if  (scanf("%d%d", &n, &m) < 2) {
		return 0;
	}
	g.clear();
	g.resize(n);
	forn(i, m) {
		int l, r, d;
		scanf("%d%d%d", &l, &r, &d);
		--l;
		--r;
		g[l].pb(mp(r, d));
		g[r].pb(mp(l, -d));
	}
	return 1;
}

bool dfs(int v, vi& was, vi& x) {
	assert(!was[v]);
	was[v] = 1;
	for (const auto& e : g[v]) {
		int to, d;
		tie(to, d) = e;
		if  (!was[to]) {
			x[to] = x[v] + d;
			if  (!dfs(to, was, x)) {
				return 0;
			}
		} else {
			if (x[to] != x[v] + d) {
				return 0;
			}
		}
	}
	return 1;
}

bool check(int v, vi& was, vi& x) {
	assert(!was[v]);
	return dfs(v, was, x);
}

bool solve() {
	vi was(n, 0);
	vi x(n, 0);
	forn(v, n) {
		if  (!was[v]) {
			if  (!check(v, was, x)) {
				return 0;
			}
		}
	}
	return 1;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		puts(solve() ? "Yes" : "No");
	}

#ifdef LOCAL
	eprintf("Time: %.10f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}


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

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

using namespace std;

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> p(n);
	rep(i,n) scanf("%d",&p[i]);

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

	printf("%d\n",accumulate(p.begin(),p.begin()+k,0));

	return 0;
}


Measured memory_bytes: 3724
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		String[] a = new String[n];
		String[] b = new String[m];
		String x = "";
		String y = "";
		for (int i = 0; i < n; i++) {
			a[i] = scan.next();
			x = x + a[i];
		}
		for (int i = 0; i < m; i++) {
			b[i] = scan.next();
			y = y + b[i];
		}
		//System.out.println(x);
		List<Integer> index = new ArrayList<Integer>();

		for (int i = 0,l=0; i < m; i++) {

				if(a[i].contains(b[l])) {
					index.add(i);
					l++;
			}

			}




		//System.out.println(index);
//indexの中身が連番になっていればOK
		boolean hyozi =false;
		for(int i=0, l=index.size()-1;i<index.size()-1;i++,l--) {
			if(index.get(i)+1==index.get(i+1)) {
				hyozi =true;

				//降順になってるとき
			}else if(index.get(l)+1==index.get(l-1)){
				hyozi = true;
			}else {
				hyozi = false;
			}
		}

		if(m==n) {
		int count=0;
		for (int i = 0; i < n; i++) {
			if(a[i].equals(b[i])) {
				count++;
			}
			}

		if(count == a.length) {
			hyozi = true;
		}else {
			hyozi=false;
		}
		}

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


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
int K;
void DFS(string ANS,int P,int& NOW){
	if(P==0){
		NOW++;
		if(NOW==K) cout <<ANS <<endl;
		return;
	}
	int X=ANS[ANS.size()-1]-'0';
	for(int i=X-1;i<=X+1;i++){
		if(i<0||9<i) continue;
		DFS(ANS+(char)(i+'0'),P-1,NOW);
	}
}
int main(){
	cin >>K;
	int NOW=0;
	for(int i=1;;i++){
		for(int j=1;j<=9;j++){
			string S;
			S+=j+'0';
			DFS(S,i-1,NOW);
			if(NOW>K) return 0;
		}
	}
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  vector<int> time(25);
  bool end = false;
  for(int i=0; i<N; i++){
    time.at(vec.at(i))++;
    if(time.at(vec.at(i)) > 2){
      end = true;
    } 
  }
  
  int ans = 0;
  
  for(int i=1; i<=24; i++){
    if(end){
      break;
    }
    vector<int> X(25);
    for(int j=0; j<25; j++){
      X.at(j) = time.at(j);
    }
    int T = 0;
    for(int j=0; j<25; j++){
      if(j < T+i && X.at(j) > 0){
        if(X.at(j) > 1 || j >= 12){
          end = true;
        }
        else{
          X.at(24-j)++;
          X.at(j)--;
        }
      }
      if(j >= T+i && X.at(j) > 0){
        if(X.at(j) > 1){
          X.at(24-j)++;
          X.at(j)--;
          if(j >= 12){
            end = true;
          }
        }
        T = j;
      }
    }
    /*for(int n=0; n<24; n++){
      cout << X.at(n) << " ";
    }
    cout << endl;*/
    if(24-T < i){
      end = true;
    }
    if(!end){
      ans = i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

int main() {
	int x=read();
	puts(x<30?"No":"Yes"); 
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

long long INF=LLONG_MAX;

ll dp[102][10][10];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s; 
	int K; 
	cin >> s >> K;
	memset(dp,0,sizeof(dp));
	int n = s.length();
	dp[0][0][0] = 1;
	ll sum = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= K; j++){
			for(int k = 0; k < 2; k++){
				if(dp[i][j][k]==0)continue;
				for(int num = 0; num < 10; num++){
					int cur = s[i]-'0';
					if(k==0&&num>cur)continue;
					dp[i+1][j+(num>0)][k|(num<cur)] += dp[i][j][k];
					//cout << i << ' ' << j << ' ' << k << " | "<< num << ' ' <<  i+1 << ' ' << int(j+(num>0?1:0)) << ' ' << int(k|(num<cur?1:0)) << ' ' <<dp[i+1][int(j+(num>0?1:0))][int(k|(num<cur?1:0))] << endl;
				}
			}
		}
	}
	//cout << dp[n][K][0] << ' ' << dp[n][K][1] << endl;
	sum += dp[n][K][0] + dp[n][K][1];
	cout << sum << endl;
}	


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

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

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

    vector<vector<int>> path(100005);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        path.at(a - 1).push_back(b - 1);
        path.at(b - 1).push_back(a - 1);
    }

    int ans = 0;
    for (int i = 0; i < n; i++){
        bool ret = true;
        for (int j = 0; j < path.at(i).size(); j++){
            if (height.at(i) <= height.at(path.at(i).at(j))){
                ret = false;
                break;
            }
        }

        if (ret){
            ans++;
        }
    }

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


Measured memory_bytes: 8804
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
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;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int k[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int tmp;
    cin>>tmp;
    tmp--;
    cout<<k[tmp]<<endl;
    return 0;
}




Measured memory_bytes: 256
def main():
    tmp = list(map(int, input().split(" ")))
    w = tmp[0]
    h = tmp[1]
    x = tmp[2]
    y = tmp[3]
    p = (x, y)
    if is_gusu(w) and is_gusu(h):
        center = (w // 2, h // 2)
    else:
        center = (-1, -1)

    if is_equal(p, center):
        print("{} 1".format(w*h / 2))
        return
    else:
        print("{} 0".format(w*h/2))


def is_equal(p, center):
    return p[0] == center[0] and p[1] == center[1]


def is_gusu(a):
    return a % 2 == 0


main()

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

int maxConsuming(int x){
    return (x + 9) / 10 * 10;
    }
int remTime(int x){
    return maxConsuming(x) - x;
}
int main(){
    int t[5], sum = 0;
    for(int i=0;i<5;i++){
        cin >> t[i];
        sum += maxConsuming(t[i]);
    }
    int maxPlus=0;
    for(int i=0;i<5;i++){
        maxPlus = max(maxPlus, remTime(t[i]));
    }
    cout << sum - maxPlus << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
  int n;
  int A[MAX+1];

  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }

  for (int i = 1; i <=n; i++) {
    printf("node %d: key = %d, ", i, A[i]);
    if (parent(i) >= 1) {
      printf("parent key = %d, ", A[parent(i)]);
    }
    if (left(i) <= n) {
      printf("left key = %d, ", A[left(i)]);
    }
    if (right(i) <= n) {
      printf("right key = %d, ", A[right(i)]);
    }
    printf("\n");
  }

  return 0;
}



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

using namespace std;

int main()
{
    int N,k;
    cin>>N>>k;
    long long arr[N];
    for(int i=0;i<N;i++)
    {
        cin>>arr[i];
    }
    long long ans[N]={0};
    for(int i=1;i<min(k,N);i++)
    {
        ans[i] = ans[i-1]+abs(arr[i]-arr[i-1]);
        for(int j=i-2;j>=0;j--)
        {
            ans[i] = min(ans[i],ans[j]+abs(arr[i]-arr[j]));
        }
    }
    for(int i=k;i<N;i++)
    {
        ans[i] = ans[i-1]+abs(arr[i]-arr[i-1]);
        for(int j=i-2;j>=i-k;j--)
        {
            ans[i] = min(ans[i],ans[j]+abs(arr[i]-arr[j]));
        }
    }
    cout<<ans[N-1];
  return 0;
}



Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
int main() {
	int x, max = 0, num5 = 0, num500 = 0;
	cin >> x;
	num500 = x / 500;
	x = x - num500 * 500;
	num5 = x / 5;
	max = num500 * 1000 + num5 * 5;

	cout << max << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = 1000010, MOD = 1000000007;
int64_t DP[MAXN]; // 人数iを取りうる色の数を記録

void init()
{
  for (int i = 0; i < MAXN; i++)
    DP[i] = 0;
}

int main()
{
  int64_t N, a, ans = 1;
  cin >> N;
  init();
  DP[0] = 3;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    ans = (ans * DP[a]) % MOD;
    DP[a]--;
    DP[a + 1]++;
  }
  cout << ans % MOD << endl;
}

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

using namespace std;

int main() {
	int s, hitung = 1;
	map<int, int> id;
	scanf("%d", &s);
	while (id.count(s) < 1) {
		id[s] = hitung++;
		if (s & 1)
			s = (3 * s) + 1;
		else
			s /= 2;
	}
	printf("%d\n", hitung);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	int n;
	int[] num;
	Scanner stdin =new Scanner(System.in);
	
	void Solve(){
		num=new int[21000000];
		while(true){
			n=stdin.nextInt();
			if(n==0) break;
			System.out.println(findPrime(n+1,2*n));
		}
		
	}
	int findPrime(int a,int b){
		int count=0;
		for(int i=a;i<=b;i++){
			if(judgePrime(i)) count++;
		}
		
		return count;
	}
	
	boolean judgePrime(int p){
		if(num[p]==1) return true;
		if(num[p]==-1) return false;
		
		if(p<4){
			num[p]=1;
			return true;
		}
		else{
			if(p%2==0){
				num[p]=-1;
				return false; 
			}
			
			for(int i=3;i<p;i++){
				if(p%i==0){
					num[p]=-1;
					return false;
				}
				i++;
			}
			num[p]=1;
			return true;
		}
	}
	
	
	
	public static void main(String args[]){
		Main m=new Main();
		m.Solve();
	}
	
}

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

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	 printf
#define sf			 scanf
#define pb(a)        push_back(a)
#define mp			 make_pair
#define ff			 first
#define ss			 second
#define for0(i,n)    for(int i=0;i<n;i++)
#define for1(i,n)    for(int i=1;i<=n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define lcm(a, b)    ((a)*((b)/gcd(a,b)))
#define sq(a)		 (a)*(a)
#define endl		     "\n"
#define abs(x)		 fabs(x)
#define all(v) 		 v.begin(),v.end()
#define pcase(z,x)   cout<<"Case "<<z<<": "<<x<<"\n"
#define mod 1000000007
#define WakandaForever     ios_base::sync_with_stdio(0); cin.tie(0);

int main()
{
    WakandaForever
    string s,t;
    cin>>s;
    cin>>t;
    int ans=t.size();
    for(int i=0 ; i<=(s.size()-t.size()) ; i++){
        int cnt=0;
        for(int j=0 ; j<t.size() ; j++){
            if(t[j]!=s[i+j]) cnt++;
        }
        ans = min(ans,cnt);
    }
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

int main(void){
  string s;
  int count = 0;
  
  cin >> s;
  
  for(int i = 0 ; i < 3 ; i++){
    if(s[i] == '1') count++;
  }
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <set>
 
using namespace std;
 
struct po
{
	int x,y;
	bool operator < (const po &a) const
	{
		return x == a.x ? y > a.y : x < a.x; 
	}
	bool operator == (const po &a) const
	{
		return x == a.x && y == a.y;
	}
}P[100050];
 
int lis[100050],lcnt;
const int mod = 1000000007;
 
struct BIT
{
	int val[100050];
	void add(int pos,int vl)
	{
		for(int i = pos;i <= lcnt;i += i & -i)
			val[i] = (val[i] + vl) % mod;
	}
	int query(int pos)
	{
		int ans = 0;
		for(int i = pos;i;i -= i & -i)
			ans = (ans + val[i]) % mod;
		return ans;
	}
}tree;
 
int n,m;
int minn,maxn;
int seq[100050];
int as = 0;
int f[100050];
set<int> st;
 
int main()
{
	minn = 2e9;
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n; ++ i) scanf("%d",&seq[i]);
	for(int i = 1;i <= m; ++ i)
	{
		int vl2; scanf("%d",&vl2);
		st.insert(vl2);
		minn = min(minn,vl2); maxn = max(maxn,vl2);
	}
	int c = 0;
	for(int i = 1;i <= n; ++ i)
	{
		if(seq[i] < minn || seq[i] > maxn) continue;
		P[++ c].x = *st.lower_bound(seq[i]) - seq[i];
		P[c].y = seq[i] - *(--st.lower_bound(seq[i]));
		lis[++ lcnt] = P[c].y;
	}
	lis[++ lcnt] = 0;as = 1;
	sort(lis + 1,lis + 1 + lcnt);
	lcnt = unique(lis + 1,lis + 1 + lcnt) - lis - 1;
	for(int i = 1;i <= c; ++ i)
		P[i].y = lower_bound(lis + 1,lis + 1 + lcnt,P[i].y) - lis;
	sort(P + 1,P + 1 + c);
	c = unique(P + 1,P + 1 + c) - P - 1;
	for(int i = 1;i <= c; ++ i)
	{
		f[i] = tree.query(P[i].y - 1) + 1;
		f[i] %= mod;
		as = (as + f[i]) % mod;
		tree.add(P[i].y,f[i]);
	}
	printf("%d\n",as);
}

Measured memory_bytes: 7040
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class BFoodsLovedByEveryone {
public:
	void solve(istream& in, ostream& out) {
        int n,m; in >> n >> m;
        vector<int> shu(m);
        rep(i,n){
            int k; in >> k;
            rep(j,k){
                int a; in >> a;
                a--;
                shu[a]++;
            }
        }
        int ans = 0;
        rep(i,m){
            if(shu[i] == n) ans++;
        }
        out << ans << endl;
	}
};

int main() {
	BFoodsLovedByEveryone solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

typedef pair<int,int> ii;
vector <ii> su,r;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	string s;
	int n;
	ii p;
	cin>>n;
	while(n--){
		cin>>s;
		p.first = p.second =0;
		for(int i=0;i<s.length();i++){
			if(s[i]=='(')p.second++;
			else{
				if(p.second)p.second--;
				else p.first++;
			}
		}
		if(p.second>p.first)su.push_back(p);
		else r.push_back(ii(p.second,p.first));
	}
	sort(su.begin(),su.end());
	sort(r.begin(),r.end());
	int o = 0;
	for(int i=0;i<su.size();i++){
		if(su[i].first>o){
			cout<<"No\n";
			return 0;
		}
		o+=su[i].second-su[i].first;
	}
	int o2 =0;
	for(int i=0;i<r.size();i++){
		if(r[i].first>o2){
			cout<<"No\n";
			return 0;
		}
		o2+=r[i].second-r[i].first;
	}
	if(o!=o2){
		cout<<"No\n";
		return 0;
	}
	cout<<"Yes\n";
	
	return 0;
}

Measured memory_bytes: 10780
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int N;
  sc.scan(N);
  int[] A = new int[N];

  foreach (i; 0 .. N)
    sc.scan(A[i]);

  sort(A);

  while (A.length > 1) {
    int zeroNum = 0;
    foreach (i; 1 .. N) {
      A[i] %= A[0];
      if (A[i] == 0)
        zeroNum++;
    }

    sort(A);

    foreach (i; 0 .. zeroNum) {
      A.popFront;
      N--;
    }
  }

  writeln(A[0]);
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);


int gcd(int a, int b) {
   if (a%b == 0) {
       return(b);
   }
   else {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b) {
   return a * b / gcd(a, b);
}

int main() {
   int N;
   cin >> N;
   int A[N];
   rep(i,N) {
       cin >> A[i];
   }

   int R[N],L[N];

   L[0] = A[0];
   R[N-1] = A[N-1];

   rep(i,N-1) {
       L[i+1] = gcd(L[i],A[i+1]);
       R[N-1-i-1] = gcd(R[N-1-i],A[N-1-i-1]);
   }
   
   int ans = 1;
   ans = max(L[N-2],R[1]);
   for (int i=1; i<=N-2; i++) {
       ans = max(gcd(L[i-1],R[i+1]),ans);
   }
   cout << ans << endl;
}

Measured memory_bytes: 1408
// Problem : C - Vacation
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define MM			1000000007
#define N			100005
#define pb 			push_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define Endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for(int i=begin;i<end;i++)
#define repr(i,begin,end) for(int i=end-1;i>=begin;i--)
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define re 			resize
 
 
 
signed main(void)
{ios
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		int n;
		cin>>n;
		int a[n],b[n],c[n];
		rep(i,0,n)
		{
		    int x,y,z;
		    cin>>x>>y>>z;
		    a[i]=x;
		    b[i]=y;
		    c[i]=z;
		}
		int dp[n][3];
		memset(dp,0,sizeof(dp));
		dp[0][0]=a[0];
		dp[0][1]=b[0];
		dp[0][2]=c[0];
		rep(i,1,n)
		{
		    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		    dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
		}
		int ans=0;
		rep(i,0,3) ans=max(ans,dp[n-1][i]);
		cout<<ans;
	}
}

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

typedef long long LL;

const int N=8;

struct point{
  int x,y;
  point(int X=0,int Y=0){x=X;y=Y;}
};

int n;
char a[(1<<N)+9];

void into(){
  scanf("%d%s",&n,a);
}

bool Check_a(){
  for (int u=1;u<1<<n;++u){
	if (a[u]=='0') continue;
	for (int v=u-1&u;v;v=v-1&u)
	  if (a[v]=='0') return 0;
  }
  return 1;
}

vector<point>Dfs_ans(int s,int last){
  int p=0;
  for (;s>>p&1^1;++p);
  vector<point>res;
  if (s==1<<p){
	for (int i=last;i<p;++i) res.push_back(point(i,1));
	res.push_back(point(p,1));
	res.push_back(point(p,0));
	for (int i=p-1;i>=last;--i) res.push_back(point(i,1));
	return res;
  }
  vector<point>t=Dfs_ans(s^1<<p,p+1);
  for (int i=last;i<p;++i) res.push_back(point(i,1));
  res.push_back(point(p,1));
  for (int vs=t.size(),i=0;i<vs;++i) res.push_back(t[i]);
  res.push_back(point(p,1));
  res.push_back(point(p,0));
  for (int vs=t.size(),i=vs-1;i>=0;--i) res.push_back(t[i]);
  res.push_back(point(p,0));
  for (int i=p-1;i>=last;--i) res.push_back(point(i,1));
  return res;
}

int ans0;
vector<point>ans;

void Get_ans(){
  if (!(ans0=Check_a())) return;
  vector<point>tmp;
  for (int u=1;u<1<<n;++u){
	if (a[u]=='1') continue;
	int flag=1;
	for (int v=u-1&u;v;v=v-1&u)
      if (a[v]=='0') {flag=0;break;}
    if (!flag) continue;
	vector<point>t=Dfs_ans(u,0);
	for (int vs=t.size(),i=0;i<vs;++i) tmp.push_back(t[i]);
  }
  int x=0,y=0;
  ans.push_back(point(0,0));
  for (int vs=tmp.size(),i=0;i<vs;++i){
	if (y^tmp[i].y) ans.push_back(point(x,y=tmp[i].y));
	ans.push_back(point(x==tmp[i].x?++x:--x,y));
  }
  if (y) ans.push_back(point(x,y=0));
}

void work(){
  Get_ans();
}

void outo(){
  puts(ans0?"Possible":"Impossible");
  if (!ans0) return;
  int vs=ans.size();
  printf("%d\n",vs-1);
  for (int i=0;i<vs;++i)
	printf("%d %d\n",ans[i].x,ans[i].y);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3800
n,m = map(int,input().split())
f_lis = []
for i in range(n):
    f_lis.append(list(str(input())))

ans_lis = []

W_num = []
W_cou = 0
B_num = []
B_cou = 0
R_num = []
R_cou = 0

for k in range(0,n):
    W_cou += f_lis[k].count('B') + f_lis[k].count('R')
    W_num.append(W_cou)
for k in range(0,n):
    B_cou += f_lis[k].count('W') + f_lis[k].count('R')
    B_num.append(B_cou)
for k in range(0,n):
    R_cou += f_lis[k].count('B') + f_lis[k].count('W')
    R_num.append(R_cou)

for i in range(1,n - 1):
    for j in range(i + 1,n):
        ans_lis.append(W_num[i - 1] + B_num[j - 1] - B_num[i - 1] + R_num[n - 1] - R_num[j - 1])
        
            
print(min(ans_lis))

Measured memory_bytes: 7716
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
from itertools import permutations

A = [i for i in range(1, N+1)]
lis = [l for l in permutations(A, N)]

print(abs(lis.index(Q)- lis.index(P)))

Measured memory_bytes: 44656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author liymsheep
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n, k;
            n = in.nextInt();
            k = in.nextInt();

            int gcd = 0, max = 0;
            for (int i = 0; i < n; ++i) {
                int a = in.nextInt();
                max = Math.max(max, a);
                gcd = BigInteger.valueOf(gcd).gcd(BigInteger.valueOf(a)).intValue();
            }

            if (k % gcd == 0 && k <= max) {
                out.println("POSSIBLE");
            } else {
                out.println("IMPOSSIBLE");
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

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

    }
}



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

int main() {
  int N;
  std::cin >> N;
  int res{0};
  std::string A, B, C;
  std::cin >> A >> B >> C;
  for (int i = 0; i < N; i++) {
    char a{A[i]}, b{B[i]}, c{C[i]};
    if (a == b && b == c)
      continue;
    else if (a != b && b != c && c != a)
      res += 2;
    else
      res++;
  }
  std::cout << res << std::endl;
}

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

int main() {
  int a;
  cin>>a;
  int b,c;
  c=0;
  for(int i=0;i<a;i++){
    cin>>b;
    if(b%2==0){
      if(!(b%3==0||b%5==0)){
        c++;
      }
    }
  }
  if(c==0){
    cout<<"APPROVED"<<endl;
  }
  else{
    cout<<"DENIED"<<endl;
  }
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))

i_list = [0] * N
for i in range(N):
  if i == 0:
    continue
  if i == 1:
    i_list[1] = abs(h[1] - h[0])
  else:
    a = abs(h[i] - h[i-1]) + i_list[i-1]
    b = abs(h[i] - h[i-2]) + i_list[i-2]
    i_list[i] = min(a, b)
print(i_list[N - 1])
    

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define INF 1e8

using namespace std;
typedef long long int ll;


int main()
{
    int H,W; cin >> H >> W;
    vector<vector<char>>G(H,vector<char>(W));
    int white = 0;
    int black = 0;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            cin >> G[i][j];
            if(G[i][j] == '.') white++;
            else black++;
        }
    }
    queue<pair<int,int>>que;
    que.push(pair(0,0));
    vector<vector<int>>dist(H,vector<int>(W,-1));
    dist[0][0] = 0;
    int dh[4] = {1,0,-1,0};
    int dw[4] = {0,1,0,-1};
    while(!que.empty())
    {
        auto p = que.front();
        int h = p.first;
        int w = p.second;
        que.pop();
        for(int i = 0; i < 4; i++)
        {
            int nh = h + dh[i];
            int nw = w + dw[i];
            if(nh < 0 || nw < 0 || nh >= H || nw >= W) continue;
            if(dist[nh][nw] != -1) continue;
            if(G[nh][nw] == '#') continue;
            dist[nh][nw] = dist[h][w] + 1;
            que.push(pair(nh,nw));
        }
    }
    if(dist[H-1][W-1] == -1)
    {
        cout << -1 << endl;
        return 0;
    }
    int ans = H*W - (dist[H-1][W-1]+1) - black;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int n, m, k;

int main() {

	FAST;

	cin >> n >> m >> k;
	vector <int> a(n + 1), b(m + 1);
	vector <intt> prefa(n + 1), prefb(m + 1);
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		prefa[i] = prefa[i - 1] + a[i];
	}
	for (int i = 1; i <= m; i ++) {
		cin >> b[i];
		prefb[i] = prefb[i - 1] + b[i];
	}
	int ans = 0, j = m;
	for (int i = 0; i <= n; i ++) {
		if (prefa[i] > k) break;
		while (prefb[j] > k - prefa[i]) {
			j --;
		}
		ans = max(ans, i + j);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 7948
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  rep(i, 3) {
    int tmp = 2*a[i] - a[0] - a[1] - a[2];
    if(tmp == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final long MOD = 1000000007;
	public static void main(String[] args) {
		int i=0,j=0,k=0;
		Scanner sc = new Scanner(in);
		int sx = parseInt(sc.next());
		int sy = parseInt(sc.next());
		int tx = parseInt(sc.next());
		int ty = parseInt(sc.next());
		sc.close();
		PrintWriter pw = new PrintWriter(out);
		for(i=sy;i<ty;i++) {
			pw.print('U');
		}
		for(i=sx;i<tx;i++) {
			pw.print('R');
		}
		for(i=sy;i<ty;i++) {
			pw.print('D');
		}
		for(i=sx;i<tx;i++) {
			pw.print('L');
		}
		pw.print('L');
		for(i=sy;i<=ty;i++) {
			pw.print('U');
		}
		for(i=sx;i<=tx;i++) {
			pw.print('R');
		}
		pw.print('D');
		pw.print('R');
		for(i=sy;i<=ty;i++) {
			pw.print('D');
		}
		for(i=sx;i<=tx;i++) {
			pw.print('L');
		}
		pw.println('U');
		pw.flush();
	}
}


Measured memory_bytes: 23124
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,M,Y;
vi a,b;
void input(){
	cin>>N>>Y;
}

/*bool dfs(int q,int w,int e){
	if(dp[q][w][e]!=-1)return dp[q][w][e];
	if(q+w+e==N){
		if(q*10000+w*5000+e*1000==Y){
			x=q;y=w;z=e;
			return true;
		}
	}
	bool t=false;
	t=t|dfs(q+1,w,e);
	t=t|dfs(q,w+1,e);
	t=t|dfs(q,w,e+1);
	return t;
}*/
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	rep(i,N+1){
		rep(j,N+1){
			if(i+j>N)continue;
			if(i*10000+j*5000+(N-i-j)*1000==Y){
				PP(i)PP(j)P(N-i-j)
				return 0;
			}
		}
	}
	PP(-1)PP(-1)P(-1)
	return 0;
}



Measured memory_bytes: 256
class UnionFindTree():
    
    def __init__(self, N):
        self.parent = [-1]*(N+1)
        self.rank = [1]*(N+1)
        self.size = [1]*(N+1)
  
    def find(self, i):
        if self.parent[i] == -1:
            group = i
        else:
            group = self.find(self.parent[i]) 
            self.parent[i] = group
        return group
      
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] == self.rank[py]: # rank is same
                self.rank[px] += 1
            elif self.rank[px] < self.rank[py]:
                px, py = py, px
                
            self.parent[py] = px
            self.size[px] += self.size[py]
    
    def getsize(self, x):
        return self.size[self.find(x)]
    
    def groups(self, index1=True):
        return set([self.find(i) for i in range(0+index1, N+index1)])
      
N,M = map(int,input().split())
List=list(map(int,input().split()))

List2=[list(map(int,input().split())) for i in range(M)]
uf = UnionFindTree(N+1)

for i in range(M):
  a = List2[i][0]
  b = List2[i][1]  
  uf.unite(a, b)
  
cnt = 0
for i,w in enumerate(List):
  if uf.find(i+1) == uf.find(w):
    cnt += 1
  
print(cnt)

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

int main()
{
	int a, b, k,i,j;
	cin >> a >> b >> k;
	for (i=0;i<k;i++)
	{
		if (a + i > b)
			break;
		cout << a+i<<"\n";

	}
	for (j = k-1; j >= 0;j = j - 1)
	{
		if (b - j >= a + i)
		{
			cout << b - j << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, t, e;

int main(){
	cin >> n >> t >> e;
	REP(i, n){
		int x;
		cin >> x;
		for (int j = t - e; j <= t + e; j++){
			if (j > 0 && j%x == 0){
				cout << i+1 << endl;
				x = -1;
				break;
			}
		}
		if (x == -1)break;
		if (i == n - 1)cout << -1 << endl;
	}
}

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

using namespace std;

const int INF = 100100100;
int dp[101000];

int main(){
    int N;
    cin >> N;
    vector<int> hight(N);
    //init
    for(int i=0; i<N; ++i) cin >> hight[i];
    for(int i=0; i<N; ++i) dp[i] = INF;


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

    if(N <= 2){
        cout << dp[1] << endl;
    }else{
        for(int i=2; i<N; ++i){
            dp[i] = min( dp[i-2] + abs(hight[i]- hight[i-2]), dp[i-1] + abs(hight[i] - hight[i-1]));
        }
        cout << dp[N-1] << endl;
    }
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

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

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

double dp[510][510];
double sum[510];

double c(int L,int R) { // [L,R]
  assert( L <= R );
  double ret = sum[R];
  if( L-1 >= 0 ) ret -= sum[L-1];
  //cout << L << "," << R << " ret = " << ret << " L " << sum[L] << " " << sum[R] << endl;
  return ret;
}

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) {
    cin >> a[i];
    sum[i] += a[i];
    if( i-1 >= 0 ) sum[i] += sum[i-1];
  }
  rep(i,n+1) rep(j,m+1) dp[i][j] = -1;
  dp[0][0] = 0;
  double maxi = 0;
  rep(cur,n) {
    rep(i,m+1) {
      if( LT(dp[cur][i],0) ) continue;
      REP(nex,cur,n) {
	int coef = 1;
	dp[nex+1][i+coef] = max(dp[nex+1][i+coef],dp[cur][i]+c(cur,nex)/(double)(nex-cur+1));
      }
    }
  }
  rep(j,m+1) 
    if( j <= m ) {
      maxi = max(maxi,dp[n][j]);
    }
  printf("%.10f\n",maxi);
  compute();
  return 0;
}



Measured memory_bytes: 5224