akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

type segmentTree struct {
	offset int
	data   []int
	op     func(x, y int) int
	e      int
}

func newSegmentTree(n int, op func(x, y int) int, e int) segmentTree {
	var result segmentTree
	t := 1
	for t < n {
		t *= 2
	}
	result.offset = t - 1
	result.data = make([]int, 2*t-1)
	for i := 0; i < len(result.data); i++ {
		result.data[i] = e
	}
	result.op = op
	result.e = e
	return result
}

func (st segmentTree) build(a []int) {
	for i, v := range a {
		st.data[st.offset+i] = v
	}
	for i := st.offset - 1; i > -1; i-- {
		st.data[i] = st.op(st.data[i*2+1], st.data[i*2+2])
	}
}

func (st segmentTree) get(index int) int {
	return st.data[st.offset+index]
}

func (st segmentTree) update(index, value int) {
	i := st.offset + index
	st.data[i] = value
	for i >= 1 {
		i = (i - 1) / 2
		st.data[i] = st.op(st.data[i*2+1], st.data[i*2+2])
	}
}

func (st segmentTree) query(start, stop int) int {
	result := st.e
	l := start + st.offset
	r := stop + st.offset
	for l < r {
		if l&1 == 0 {
			result = st.op(result, st.data[l])
		}
		if r&1 == 0 {
			result = st.op(result, st.data[r-1])
		}
		l = l / 2
		r = (r - 1) / 2
	}
	return result
}

func main() {
	defer flush()

	N := readInt()
	K := readInt()

	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	st := newSegmentTree(300000+1, max, 0)

	t := make([]int, N)
	result := 0
	for i := 0; i < N; i++ {
		t[i] = st.query(max(A[i]-K, 0), min(A[i]+K+1, 300000+1)) + 1
		result = max(result, t[i])
		st.update(A[i], t[i])
	}
	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


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

using namespace std;

#define sz(a) ((int)a.size())

string s;

void trans() {
    cin >> s;
    long long ans = 0, cnt = 0;
    for (int i = 0; i < sz(s); i++) {
        if (s[i] == 'W') {
            ans += cnt;
        } else cnt++;
    }
    cout << ans;
}

int main() {
    trans();

    return 0;
}


Measured memory_bytes: 640
S = input().rstrip()
N = len(S)
if S == S[::-1] and \
        S[:int((N - 1) / 2)] == S[:int((N - 1) / 2)][::-1] and \
        S[int((N + 3) / 2) - 1:N] == S[int((N + 3) / 2) - 1:N][::-1]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
S = input()
if 1 <= int(S[:2]) <= 12:
    if 1 <= int(S[2:]) <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= int(S[2:]) <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

struct Heap {
    int *H;
    int size;
    Heap() {
        this->H = new int[2000000];
        this->size = 0;
    }
    int siz() {
        return this->size;
    }
    void swap(int a, int b) {
        int aux = this->H[b];
        this->H[b] = this->H[a];
        this->H[a] = aux;
    }
    void Iheapify(int i) {
        int f;
        if(i > 0) {
            f = i / 2;
            if(i%2 == 0 && f > 0) {
                f-=1;
            }
            if (this->H[i] > this->H[f]) {
                swap (i, f);
                Iheapify (f);
            }
        }
    }

    void Rheapify(int i) {
        int l,r,m;
        m = i;
        l = (2*i) + 1;
        r = (2*i) + 2;
        if(l < this->size && this->H[l] >= this->H[m]) {
            m = l;
        }
        if(r < this->size && this->H[r] >= this->H[m]) {
            m = r;
        }
        if(m != i) {
            swap (i, m);
            Rheapify (m);
        }
    }
    void insert(int k) {
        this->H[size] = k;
        Iheapify(size);
        this->size++;
    }
    int extract () {
        int temp = this->H[0];
        swap (0, size-1);
        this->size--;
        Rheapify (0);
        return temp;
    }

    void print() {
        for(int i = 1; i <= size; i++) {
            cout << H[i] << endl;
        }
    }
};

int main() {
    string s="";
    int k;
    bool b = true;
    Heap *heap = new Heap();
    while(b) {
        cin >> s;
        if(s == "end") {
            break;
        }
        if(s[0]=='i') {
            cin >> k;
            heap->insert (k);
        } else {
            if(heap->siz() > 0) {
                k = heap->extract ();
                cout << k << endl;
            }
        }
    }
    return 0;
}


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

int main(){
  int a;
  int i, j, k;
  int count;

  while(cin>>a){
    count=0;
    for(i=0; i<10; i++){
      for(j=0; j<10; j++){
        for(k=0; k<10; k++){
          if(i+j+k<=a && i+j+k>=a-9) count++;
        }
      }
    }
    printf("%d\n", count);
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	string s; cin >> s;
	const int mod = 1e9 + 7;
	int n = s.size();
	vi dp(13);
	dp[0] = 1;
	rep(i, n){
		vi next(13);
		rep(j, 10){
			if(s[i] != '?' && s[i] - '0' != j) continue;
			rep(k, 13) (next[(k * 10 + j) % 13] += dp[k]) %= mod;
		}
		dp = next;
	}
	cout << dp[5] << endl;
	return 0;
}

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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var ln = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var a = ln[0];
            var b = ln[1];

            decimal ans = 0;
            
            if (b > 1) {
                ans = 1;

                if (a < b) {
                    decimal x = b - a;
                    ans += Math.Ceiling(x / (a-1));
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28352
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
//using lli = __int128;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using vqi = vector<qi>;
using pqi = priority_queue<li>;
using pi = pair<li, li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li, li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = LLONG_MAX;
constexpr li mod = 1000000007;

void Yes(li b) {
	if (b)cout << "Yes";


	else cout << "No";
}
void yes(li b) {
	if (b)cout << "yes";
	else cout << "no";
}

/* //__int128用
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout.precision(16);

	li N,M;
	cin >>N>>M;

	if(M==0){
		cout<<1;
		return 0;
	}

	vsi friends(N+1);

	li a,b;
	Rep(i,M){
		cin>>a>>b;

		friends[a].insert(b);
		friends[b].insert(a);
	}

	si rest;
	Rep1(i,N){
		rest.insert(i);
	}

	qi next;
	vqi island(N+1);
	li j=0;
	li maxsize=0;

	while(!rest.empty()){
		j++;
		next.ef(*rest.begin());
		rest.erase(rest.begin());
		island[j].eb(next.front());

		while(!next.empty()){
			for(auto&& f:friends[next.front()]){
				if(rest.count(f)){
					next.eb(f);
					rest.erase(f);
					island[j].eb(f);
				}
			}
			next.pof;
		}
      
      
		maxsize=max(maxsize , Size(island[j]) );
	}
  

	cout<<maxsize;
  
}

Measured memory_bytes: 176328
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;

bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i*i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}


template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}
ll nCr(ll n, ll r);//コンビネーション
int permutation(int n, int r);//nPk パーミュテーション
int factorial(int k);//階乗

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	//priority_queue<int> q;
	string s = {};
	string s1 = {};
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	ll x[105][4][2] = {};
	ll y[300005] = {};
	ll z[302][302] = {};
	ll n;
	cin >> s;
	n = s.size();
	ll K;
	cin >> K;
	x[0][0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			for (int k = 0; k < 2; k++)
			{
				for (int d = 0; d < 10; d++)
				{
				ll ni=i+1, nj=j, nk=k;
				ll nd = s[i] - '0';
					if (d!=0)
					{
						nj++;
					}
					if (nj>K)
					{
						continue;
					}
					if (k==0)
					{
						if (d>nd)
						{
							continue;
						}
						if (d<nd)
						{
							nk = 1;
						}
					}
					x[ni][nj][nk] += x[i][j][k];
				}
			}
		}
	}


	cout << x[n][K][0] +x[n][K][1] << endl;



	//return 0;

	/*cout << c << endl;
	cout << b << endl;*/
	//cout << fixed << setprecision(10) <<tmp << endl;
	//cout<<factorial<10><<endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}

int permutation(int n, int r) {
	int n_sum, r_sum;
	int i;
	r = n - r;
	n_sum = factorial(n);
	r_sum = factorial(r);
	return n_sum / r_sum;
}

ll nCr(ll n, ll r) {
	ll ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int factorial(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, n;
    cin >> k >> n;
    vector<int> v(n);
    for(int i = 0;i<n;i++) cin >> v[i];
    
    vector<int> s;
    for(int i = 0;i<n;i++){
        if(i == n-1) s.emplace_back(k+v[0]-v[n-1]);
        else s.emplace_back(v[i+1]-v[i]);

    }
    sort(all(s));
    int ans = k - s.back();
    cout << ans << endl;
}

Measured memory_bytes: 2168
use proconio::input;
use proconio::marker::Usize1;

#[allow(non_snake_case)]
fn main() {
    input! {
        H: usize,
        W: usize,
        M: usize,
        T: [(Usize1, Usize1); M]
    }

    let mut count_h = vec![0; H];
    let mut count_w = vec![0; W];

    for &(y, x) in T.iter() {
        count_h[y] += 1;
        count_w[x] += 1;
    }
    let max_h = count_h.iter().max().unwrap();
    let max_w = count_w.iter().max().unwrap();

    let a = count_h.iter().filter(|y| *y == max_h).count();
    let b = count_w.iter().filter(|x| *x == max_w).count();
    let c = T
        .iter()
        .filter(|(y, x)| count_h[*y] == *max_h && count_w[*x] == *max_w)
        .count();

    println!("{}", max_h + max_w - if a * b == c { 1 } else { 0 });
}


Measured memory_bytes: 12936
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int D;
vector<LL> c(26);
vector<vector<LL>> s;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

LL solve(const vector<LL>& t) {
  LL ans = 0;
  vector<LL> last(26, 0);
  for (int d = 1; d <= D; ++d) {
    int i = d - 1;
    int j = t[i];
    last[j] = d;
    ans += s[i][j];
    for (int k = 0; k < 26; ++k) {
      ans -= c[k] * (d - last[k]);
    }
  }
  return ans;
}

int main() {
  cin >> D;
  cin >> c;
  s.resize(D, vector<LL>(26, 0));
  for (int i = 0; i < D; ++i) cin >> s[i];

  vector<LL> t(D);
  for (int d  =  0; d < D; ++d) t[d] = d % 26;

  LL prev = solve(t);
  for (int i = 0; i < 100000; ++i) {
    auto t_bk = t;
    t[i % D] = rand() % 26;

    LL score = solve(t);
    if (score < prev) t = t_bk;
  }

  for (int x : t) cout << x + 1 << endl;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,ans;
	cin>>n;
	int k=0;
	for(int i=sqrt(n);i>=1;i--)
	{
		if(n%i==0)
		{
            ans=n/i;
            break;
        }
	}
    while(ans>0)
	{ 
        ++k;
        ans/=10;
    }
    cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int m = 0;
    for(int i = 0; i < n; i++)
    {
        if(i % 2 == 1)
        {
            if(s[i] == '0') m++;
        }
        else
        {
            if(s[i] == '1') m++;
        }
    }
    int x = 0;
    for(int i = 0; i < n; i++)
    {
        if(i % 2 == 1)
        {
            if(s[i] == '1') x++;
        }
        else
        {
            if(s[i] == '0') x++;
        }
    }
    int ans = min(m, x);
    cout << ans << endl;
}


Measured memory_bytes: 512
def is_big(x = [0]*10, y = [0]*10):
    if sum(x) > sum(y):
        return True
    if sum(x) < sum(y):
        return False
    for i in range(0,10)[::-1]:
        if x[i] > y[i]:
            return True
        if y[i] > x[i]:
            return False
    return True
  
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())))
#print(a)
d = [0]*8
b = []
L1 = [1,7,4,2,3,5,6,9,8]
L2 = [2,3,4,5,5,5,6,6,7]
for i in range(9):
  if L1[i] in a:
    d[L2[i]] = L1[i]
    if L2[i] not in b:
      b.append(L2[i])
#print(d)
#print(b)
p = []
for i in range(n+1):
  p.append([-1,0,0,0,0,0,0,0,0,0])
  
p[0][0] = 0
for i in range(1,n+1):
  for t in b:
    if i-t <0 or p[i-t][0] == -1: 
      continue
    q = p[i-t][:]
    q[d[t]] += 1
    if is_big(q,p[i]):
      p[i] = q

a = ""
for i in range(10)[::-1]:
  a += str(i)*p[n][i]
print(a)

Measured memory_bytes: 4876
#include <iostream>

int main() {
  int N;
  std::cin >> N;
  int numbers[N];
  for (int i = 0; i < N; i++) {
    std::cin >> numbers[i];
  }
  unsigned long long count[102][22] = {};
  count[1][numbers[0]] = 1;
  for (int i = 1; i < N - 1; i++) {
    for (int j = 0; j <= 20; j++) {
      if (count[i][j] > 0) {
        int plus = j + numbers[i];
        int minus = j - numbers[i];
        if (0 <= plus && plus <= 20) {
          count[i + 1][plus] += count[i][j];
        }
        if (0 <= minus && minus <= 20) {
          count[i + 1][minus] += count[i][j];
        }
      }
    }
  }

  std::cout << count[N - 1][numbers[N - 1]] << std::endl;
  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;


int32_t main()
{
    fast

   int test=1;
    //cin>>test;
  
  while(test--)
  {
  int a,b,c,k,sum=0;
  cin>>a>>b>>c>>k;
  
  int x=min(k,a);
  sum=x*1;
  k-=x;
  if(k>0)
  {
    x=min(k,b);
    k-=x;
  }
  if(k>0)
  {
    x=min(k,c);
    sum+=x*(-1);
  }

  cout<<sum;

  // while loop ending
   }
  

return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <cstring>

#define nl '\n'

using namespace std;

int h, w, r, c, mx;
char G[1005][1005];

queue<pair <int, pair<int, int> > > Q; //distance, node
int dist[1005][1005];

int dr[4] = {1, -1, 0, 0}, dc[4] = {0, 0, 1, -1};

int main(){

    cin >> h >> w;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> G[i][j];
            if(G[i][j] == '#'){
                Q.push(make_pair(0, make_pair(i, j)));
            }
        }
    }

    memset(dist, -1, sizeof(dist));

    while(!Q.empty()){
        int d = Q.front().first, r = Q.front().second.first, c = Q.front().second.second;
        Q.pop();
        if(dist[r][c] != -1) continue;
        dist[r][c] = d; //the shortest distance to node u is d
        for(int i = 0; i < 4; i++){
            if((r+dr[i] > -1 && r+dr[i] < h) && (c+dc[i] > -1 && c+dc[i] < w)){
                Q.push(make_pair(d+1, make_pair(r + dr[i], c + dc[i])));
            }
        }
    }


    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(dist[i][j] > mx){
                mx = dist[i][j];
            }
        }
    }

    cout << mx;
}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

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

int main() {
	int n; cin>>n;
	int ret=n;
	for(int i=0; i<=n; i++) {
		int cur=0;
		int t=i;
		while(t)
			cur+=t%6,t/=6;
		t=n-i;
		while(t)
			cur+=t%9,t/=9;
		ret=min(ret,cur);
	}
	cout<<ret<<"\n";
	return 0;
}

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

using namespace std;

int n;
double num[100],ans;

bool cmp(double a,double b)
{
	return a>b;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	    scanf("%lf",&num[i]);
	sort(num+1,num+1+n,cmp);
	double item=0.5;
	ans=0.0;
	for(int i=1;i<=n;i++)
	{
		if(i==n)
		    ans=ans+num[i]*2*item;
		else
		    ans=ans+num[i]*item;
		item=item/2;
	}
	printf("%.14lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
'use strict'

const main = arg => {
    var input = arg.trim().split("\n")[0].split(" ");
    const x1 = input[0];
    const y1 = input[1];
    const x2 = input[2];
    const y2 = input[3];
    const result = Math.sqrt( Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));

    console.log(`${result.toFixed(8)}`);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

//long long型(64bit整数)
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<pair<ll, ll> > pairs(n);
    int a, b;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        pairs[i] = make_pair(b, a);
    }
    //締め切りが早い順にソート
    sort(pairs.begin(), pairs.end());

    bool isok = true;
    ll time = 0;
    for(int i=0; i<n; i++){
        time += pairs[i].second;
        if(time > pairs[i].first){
            isok = false;
            break;
        }
    }
    if(isok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3328
import java.util.Scanner;

/**
 * A - The Number of Even Pairs
 * N+M  個のボールがあります。各ボールには整数が 1 つ書かれています。
 * これらのボールに書かれている数について、
 *  ・N 個のボールに書かれている数は偶数
 *  ・M 個のボールに書かれている数は奇数
 * であることがわかっています。
 * これらの N+M 個のボールの中から 2 つ選んで、書かれた数の和が偶数になる方法の数を求めてください。選ぶ順序は考慮しません。
 * なお、この方法の数はボールに書かれている整数の実際の値によらないことが示せます。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 偶数が書いてあるボールの数
        int n = sc.nextInt();
        // 奇数が書いてあるボールの数
        int m = sc.nextInt();
        // 偶数＆偶数または奇数＆奇数のパターンのみカウント
        int result = n * ( n - 1 ) / 2;
        result += m * ( m - 1 ) / 2;

        System.out.println( result );

        sc.close();
    }
}


Measured memory_bytes: 23764
#include<stdio.h>

int main(){
  //counter
  int i,j;

  //input
  int n;
  scanf("%2000000d",&n);
  
  int A[n];
  int k=0;  // TODO serching "k"
  for(i=0;i<n;i++){
    scanf("%10000d",&A[i]);
    if(A[i]>k){
      k = A[i];
  }
  }

  
  //Counting Sort

  int C[k+1];
  for(i=0;i<k+1;i++){
    C[i] = 0;
  }
  for(j=0;j<n;j++){
    C[A[j]]++;
  }
  for(i=1;i<k+1;i++){
    C[i] = C[i] + C[i-1];
  }
    int B[n];
    for(j=(n-1);j>=0;j--){
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
    }

  //output
  for(i=0;i<n-1;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n-1]);
  


    return 0;
}



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

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll gap = abs(a - b);
  for (int i = 0; i * 2 <= n; ++i) {
    ll mi = c * (n - 1 - i * 2) + (c - d) * i;
    ll ma = d * (n - 1 - i * 2) - (c - d) * i;
    if (mi <= gap && gap <= ma) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int i,j,m;
	string str;
	while(true){
		cin>>str;
		if(str[0]=='-')break;
		cin>>m;
		for(i=0;i<m;i++){
			cin>>j;
			str=str.substr(j)+str.substr(0,j);
		}
		cout<<str<<endl;
	}
	return 0;
}



Measured memory_bytes: 3220
using System;
using System.Collections.Generic;

namespace ABC137_B
{
    class Program
    {
        static void Main(string[] args) {
            
            string[] input = Console.ReadLine().Split();
            long k = long.Parse(input[0]);
            long x = long.Parse(input[1]);

            long minValue = x - k + 1;
            long maxValue = x + k - 1;

            if(minValue < -1000000) {
                maxValue += -1000000 - minValue;
                minValue = -1000000;
            }
            if (maxValue > 1000000) {
                minValue -= 1000000 - maxValue;
                maxValue = 1000000;
            }

            for (long i = minValue; i <= maxValue; i++) {
                Console.Write(i + " ");
            }
        }
    }
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  ll c = a+b;
  if (n <= c) {
    cout << min(n, a) << endl;
  } else {
    ll x = n / c;
    ll m = n % c;

    cout << (x*a+min(m, a)) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{  
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] str=br.readLine().split(" ");
        long N=Integer.parseInt(str[0]);
        long K=Integer.parseInt(str[1]);
        long M=1000000007;
        long count=0;
        for(long i=K;i<=N+1;i++){
            count=(count+(i*(N-i+1)+1))%M;
        }
        System.out.println(count);
    }
}


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

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

const int64_t INF = 1LL << 60;

void solve() {
    int64_t N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    vector<pair<int, int64_t>> ops;
    ops.emplace_back(2, A);
    ops.emplace_back(3, B);
    ops.emplace_back(5, C);
    map<int64_t, int64_t> mp;
    mp[0] = 0;
    mp[1] = D;
    auto dfs = [&](auto &&dfs, int64_t v) -> int64_t {
        if(mp.find(v) != mp.end()) return mp[v];
        int64_t res = INF;
        if((double)v * D < INF) {
            res = v * D;
        }
        for(auto &[x, cost] : ops) {
            for(int i = -x + 1; i <= x - 1; ++i) {
                int64_t n = v + i;
                if(n >= 0 && n % x == 0) {
                    chmin(res, dfs(dfs, n / x) + cost + abs(i) * D);
                }
            }
        }
        return mp[v] = res;
    };
    cout << dfs(dfs, N) << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while(t--) solve();
    return 0;
}


Measured memory_bytes: 4472
#include<stdio.h>
int T=1,m[101][101],d[101]={0},a[101],b[101],n;
void visit(int u){
  int v; 
  a[u]=T++;
  d[u]=1;
  for(v=0;v<n;v++){
    if(m[u][v]==1&&d[v]==0){ 
      visit(v);
    }
  }   
  b[u]=T++;  
}
#include<stdio.h>
int main(){
  int k,i,j,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      m[i][j]=0;
 for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
       m[u-1][v-1]=1;      
   }
 }
 for(i=0;i<n;i++)
   if(d[i]==0) visit(i);
 for(i=0;i<n;i++)
   printf("%d %d %d\n",i+1,a[i],b[i]);
 return 0;
}

Measured memory_bytes: 636
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def subsetall(self):
        a = []
        for i in range(len(self.table)):
            if self.table[i] < 0:
                a.append((i, -self.table[i]))
        return a

    def tall(self):
        d = collections.defaultdict(list)
        for i in range(len(self.table)):
            d[self.find(i)].append(i)
        return d

def main():
    M = 2**17
    n,m = LI()
    a = [LI() for _ in range(m)]
    e = collections.defaultdict(list)
    for p,q,c in a:
        pc = p+c*M
        qc = q+c*M
        pm = p-M
        qm = q-M
        e[pc].append(qc)
        e[qc].append(pc)
        e[pm].append(pc)
        e[qm].append(qc)
        e[pc].append(pm)
        e[qc].append(qm)

    def search():
        d = collections.defaultdict(lambda: inf)
        s = 1-M
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = set()
        while len(q):
            k, u = heapq.heappop(q)
            if u in v:
                continue
            v.add(u)
            if u < 0:
                for uv in e[u]:
                    if uv in v:
                        continue
                    vd = k + 1
                    if d[uv] > vd:
                        d[uv] = vd
                        heapq.heappush(q, (vd, uv))

            else:
                if u % M == n:
                    return k

                for uv in e[u]:
                    if uv in v:
                        continue
                    if d[uv] > k:
                        d[uv] = k
                        heapq.heappush(q, (k, uv))

        return -1

    return search()



print(main())


Measured memory_bytes: 222060
n, m, c = map(int, input().split())
apple = []
orange = list(map(int, input().split()))
for _ in range(n):
    apple.append(list(map(int, input().split())))
count = 0

def cat(b, a):
    d = 0
    for j in range(m):
        d += b[j] * a[j]
    return int(d + c)

for i in apple:
    if cat(orange, i) > 0:
        count += 1

print(count)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

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

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

// コンビネーションのmod、
// 最初にCOMinit()した後に、COM(n,k) で n_C_k が取れる。
const int MAX_N= 200000;
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll COM(int n, int k){
    if(n<k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


int main(){
    int s;
    cin >> s;
    COMinit();
    ll ans = 0;
    rep(i, s/3){
        int tmp = s - 3*(i+1);
        ans += COM(tmp+i, i);
        ans %= mod;
    }
    cout << ans << endl;
}



Measured memory_bytes: 8316
#! python3
# partition.py - 配列を特定の値で、分割するアルゴリズム

def partition(array, p, len_array):
    X = array[len_array]
    i = 0 - 1
    for j in range(p, len_array):
        if array[j] <= X:
            i += 1
            tmp = array[i]
            array[i] = array[j]
            array[j] = tmp
    tmp = array[i + 1]
    array[i + 1] = array[len_array]
    array[len_array] = tmp
    
    return i + 1, array
    
len_array = int(input()) - 1
array = [int(i) for i in input().split()]
p = 0 # 配列のスタート位置、今後別の関数で使うことも想定して、変数で渡しておく

index, array = partition(array, p, len_array)
# print(index)
# print(array)
str_array = list(map(str, array))
# print(str_array)
str_array[index] = '[{}]'.format(str_array[index])
print(' '.join(str_array))


Measured memory_bytes: 16592
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  int c = 0;
  if (s[0] == 'o')
    c++;
  if (s[1] == 'o')
    c++;
  if (s[2] == 'o')
    c++;
  cout << 700 + 100 * c << endl;
  return 0;
}


Measured memory_bytes: 3192
/*
 * author: calgagi
 *         Calvin Gagliano 
 */
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define ar array
#define f first
#define s second
#define dd long double

int main() {
    ios_base::sync_with_stdio(false);  
    cin.tie(NULL);
    srand(chrono::steady_clock::now().time_since_epoch().count()); 
    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
    
    int n, k;
    cin >> n >> k;

    vector<bool> snack(n, 0);

    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int x;
            cin >> x;
            x--;
            snack[x] = 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!snack[i]) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

int main() {
#ifdef LOCAL
  freopen("b.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  int n, i;
  string a, b;
  double ans = 0, da, x;
  cin >> n;
  cout << fixed << setprecision(9);
  while (n--) {
    cin >> a >> b;
    da = i = x = 0;
    while (a[i] != '.' && i < SZ(a)) i++;
    da = stoi(a.substr(0, i));
    if (i != SZ(a)) {
      x = stoi(a.substr(i + 1, SZ(a)));
      da += (x / pow(10, SZ(a) - i - 1));
    }
    if (b == "BTC")
      ans += (da * 380000);
    else
      ans += da;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4204
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.next().split("");
        String[] s2 = sc.next().split("");
        String[] s3 = sc.next().split("");

        System.out.println(s1[0].toUpperCase() + s2[0].toUpperCase() + s3[0].toUpperCase());
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[1010][1010];
ll h, w;
char a[1010][1010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	cin >> h >> w;
	dp[0][0] = 1;
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
			if (a[i][j] == '#')continue;
			if (i > 0 && j > 0) {
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
				dp[i][j] = dp[i][j] % MOD;
			}
			else if (i == 0 && j > 0) {
				dp[i][j] = dp[i][j - 1];
			}
			else if (j == 0 && i > 0) {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout <<dp[h-1][w-1] << endl;
	return 0;
}


Measured memory_bytes: 12316
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug puts("orzyrt")
	#define debug(a...) fprintf(stderr,a);
#else
	#define Debug ('orzyrt')
	#define debug(a...) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(a>b)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

const int maxn = 1111;
int n,m;
LL x[maxn],y[maxn],z[maxn],f[maxn];
LL ans;
int main(){
	read(n);read(m);
	for(R int i=1;i<=n;++i){
		read(x[i]);read(y[i]);read(z[i]);
	}
	for(R int i=0;i<8;++i){
		for(R int j=1;j<=n;++j){
			f[j]=((i&1)?1:-1)*x[j]+((i&2)?1:-1)*y[j]+((i&4)?1:-1)*z[j];
		}
		R LL ret=0;
		sort(f+1,f+1+n);
		for(R int j=1;j<=m;++j){
			ret-=f[j];
		}
		cmax(ans,ret);
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }
    ll res = 0;
    for(int i = 1; i < N; i++) {
        if(A[i] < A[i - 1]) {
            res += A[i - 1] - A[i];

            A[i] += A[i - 1] - A[i];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 4836
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {1,0,-1,0};

//up
//right
//down
//left
void move(int sx,int sy,int dir,
	int* dx,int* dy,int dist,int W,int H,string cmd){
		if(cmd=="forw"){
			*dx = (sx + tx[dir]*dist >= W ? W-1 : (sx + tx[dir]*dist < 0 ? 0 : sx + tx[dir]*dist));
			*dy = (sy + ty[dir]*dist >= H ? H-1 : (sy + ty[dir]*dist < 0 ? 0 : sy + ty[dir]*dist));
		}
		else{
			*dx = (sx + tx[(dir+2)%4]*dist >= W ? W-1 : (sx + tx[(dir+2)%4]*dist < 0 ? 0 : sx + tx[(dir+2)%4]*dist));
			*dy = (sy + ty[(dir+2)%4]*dist >= H ? H-1 : (sy + ty[(dir+2)%4]*dist < 0 ? 0 : sy + ty[(dir+2)%4]*dist));
		}
}

int main(){
	int W,H;
	while(cin >> W >> H){
		if(W==0 && H==0) break;
		int posX=0,posY=0;
		string cmd;
		int dir = 0;
		while(cin >> cmd){
			if(cmd == "FORWARD"){
				int dist;
				cin >> dist;
				move(posX,posY,dir,&posX,&posY,dist,W,H,"forw");
			}
			else if(cmd == "BACKWARD"){
				int dist;
				cin >> dist;
				move(posX,posY,dir,&posX,&posY,dist,W,H,"back");
			}
			else if(cmd == "RIGHT"){
				dir++;
				if(dir >= 4) dir = 0;
			}
			else if(cmd == "LEFT"){
				dir--;
				if(dir < 0) dir = 3;
			}
			else if(cmd == "STOP"){
				break;
			}
		}
		printf("%d %d\n",posX+1,posY+1);
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main implements Runnable {

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), C = sc.nextInt();
        int[] s = new int[100000], t = new int[100000], c = new int[100000];
        for (int i = 0; i < N; i++) {
            s[i] = sc.nextInt();
            t[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        int[] ss = new int[200002], tt = new int[200002];
        for (int i = 1; i <= C; i++) {
            for (int j = 0; j < 200002; j++) {
                tt[j] = 0;
            }
            for (int j = 0; j < N; j++) {
                if (c[j] == i) {
                    for (int k = s[j] * 2 - 1; k < t[j] * 2; k++) {
                        tt[k]++;
                    }
                }
            }
            for (int j = 0; j < 200002; j++) {
                if (tt[j] > 0) {
                    ss[j]++;
                }
            }
        }
        int max = 0;
        for (int i = 0; i < 200002; i++) {
            max = Math.max(max, ss[i]);
        }
        System.out.println(max);
    }
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	ll x;
	ll res = 0;
	scanf("%lld", &x);
	static ll gojo[1001] = { 0 };
	FOR(i, 1, 1000) {
		gojo[i] = i*i*i*i*i;
	}
	FOR(i, 0, 1000) {
		FOR(j, 0, 1000) {
			if (gojo[i] - gojo[j] == x) {
				printf("%lld %lld\n", i, j);
				return(0);
			}
		}
	}
	FOR(i, 0, 1000) {
		FOR(j, 0, 1000) {
			if (gojo[i] + gojo[j] == x) {
				ll temp = -1 * j;
				printf("%lld %lld\n", i, temp);
				return(0);
			}
		}
	}
	return(0);
}

Measured memory_bytes: 3240
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    int i = scan.nextInt();
    int j = scan.nextInt();
    scan.close();

    System.out.print(i*j);
    System.out.print(" ");
    System.out.println((i+j)*2);
}

}

Measured memory_bytes: 26024
// #pragma GCC optimize(“O2”)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include<bitset>
using namespace std;
#define pi 3.14159265358979323846264338327950254
 #define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);//************************************
 
#define ll long long
// #define int ll

const int mod = 100999;

int main()
{
    // STDIN
    int n, m; cin >> n >> m;
    int sum = 0;
    for (int i = 1; i <= m; i++)
    {
        int t;
        scanf("%d", &t);sum+=t;
    }
    if (sum > n) cout << -1 << endl;
    else cout << n - sum << endl;
}


Measured memory_bytes: 3688
#a=int(input())
#b,c=int(input()),int(input())
# c=[]
#  for i in b:
#     c.append(i)
H,N = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(a)]
# h = []
# for i in range(e1):
#     h.append(list(map(int,input().split())))
if sum(f)>=H:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 83076
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  int sum = 0;
  for (int i = 0; i < n; ++i) sum ^= a[i];
  for (int i = 0; i < n; ++i) a[i] ^= sum;
  for (int i = 0; i < n; ++i) cout << a[i] << endl;
}


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

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> w(N+1);
    vector<int> e(N+1);
    string s; cin >> s;
    w[0] = 0; e[0] = 0;
    for(int i=0;i<N;i++){
        w[i+1] = w[i] + (s[i] == 'W');
        e[i+1] = e[i] + (s[i] == 'E');
    }

    int ans = 1000000;
    for(int i=0;i<N;i++){
        ans = min(ans, w[i] + (e[N]-e[i+1]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3204
using System;

namespace abc097_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            bool flag = false;
            n++;
            while (!flag)
            {
                n--;
                for (int i = 1; i <= 40; i++)
                {
                    for (int j = 2; j < 20; j++)
                    {
                        if (Math.Pow(i, j) == n) flag = true;
                    }
                }
            }
            Console.WriteLine(n);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <math.h>
using namespace std;

int main(void){
	int n;
	int debt = 100;
	cin >> n;
	for(int i=0;i<n;i++){
		debt = ceil(debt*1.05);
	}
	cout << debt*1000 << endl;
	return 0;
}

Measured memory_bytes: 0