akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;

    int nowx = 0;
    int nowy = 0;
    int nowt = 0;
    for(int i = 0; i < n; i++){
        int t, x, y;
        cin >> t >> x >> y;
        int dist = abs(nowx - x) + abs(nowy - y);
        int at = t - nowt;
        if(dist > t){
            cout << "No" << endl;
            return 0;
        }
        int time = t - nowt;
        int npar = (nowx + nowy) % 2;
        int tpar = (x + y) % 2;
        //cout << npar << " " << tpar << endl;
        if(time % 2 == 0){
            if(npar != tpar){
                cout << "No" << endl;
                return 0;
            }
        } else {
            if(npar == tpar){
                cout << "No" << endl;
                return 0;
            }
        }
        nowt = t;
        nowx = x;
        nowy = y;
    }
    cout << "Yes" << endl;
}   

Measured memory_bytes: 256
MOD = 1000000007
n = gets.to_i
str = gets.chomp
_ = gets.chomp
# 連続する文字数に置換、正規表現で後方置換 aab → [2, 1]
nums = str.gsub(/(.)\1{0,}/) { |x| x.size }.split("").map(&:to_i)

ans = []
prev_num = 0
if nums.shift == 1
  ans << 3
  prev_num = 1
else
  ans << 6
  prev_num = 2
end

nums.each do |num|
  if prev_num == 1
    ans << 2
  elsif prev_num == 2 && num == 1
    ans << 1
  else
    ans << 3
  end
  prev_num = num
end

puts ans.inject(1) { |res, num| res * num % MOD }


Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#define maxSize (int)(1e5 + 1)

int main(){
	int i, gnum = 0, pnum = 0;
	char *s = (char *)malloc(sizeof(char) * maxSize);
	scanf("%s", s);
	for(i = 0; s[i] != '\0'; i++){
		if(s[i] == 'g'){
			gnum++;
		}
		else{
			pnum++;
		}
	}
	printf("%d\n", (gnum + pnum)/2 - pnum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int a = 0;
  string s;
  cin >> s;
  for(int i = 0; i <(s.size() + (s.size()%2))/2; i++){
    if(s.at(i*2)=='L'){
      a = 1;
      break;
    }
  }
  for(int i = 0; i <(s.size()- (s.size()%2))/2; i++){
    if(s.at(i*2+1)=='R'){
      a = 1;
      break;
    }
  }
  if(a ==1){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <map>
#include <utility>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int a[n];
    map<int, int> cnt;
    repi(i, n, 0)
    {
        cin >> a[i];
    }
    repi(i, n, 0)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > 2)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    if (n % 2 && cnt[0] > 1 || (n + 1) / 2 != cnt.size())
    {
        cout << 0 << endl;
    }
    else
    {
        ll ans = 1;
        repi(i, n / 2, 0)
        {
            ans *= 2;
            ans %= MOD;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
import java.awt.Point;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author kumar1
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		InputStream in = System.in;
		Scanner scanner = new Scanner(in);
		LinkedList<Integer> ans = new LinkedList<Integer>();
		while(true) {
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			if(w == 0 && h == 0)
				break;
			ArrayList<ArrayList<Boolean> > board = new ArrayList<ArrayList<Boolean> >();
			//ArrayList<ArrayList<Boolean> > r_walls = new ArrayList<ArrayList<Boolean> >();
			//ArrayList<ArrayList<Boolean> > b_walls = new ArrayList<ArrayList<Boolean> >();
			ArrayList<Boolean> wallrow = new ArrayList<Boolean>();
			for(int i=0; i < w * 2 + 1; i++)
				wallrow.add(false);
			board.add(wallrow);
			for(int i=0; i < h; i++) {
				ArrayList<Boolean> row = new ArrayList<Boolean>();
				row.add(false);
				for(int j=0; j < w - 1; j++) {
					row.add(true);
					if(scanner.nextInt() == 0)
						row.add(true);
					else
						row.add(false);
				}
				row.add(true);
				row.add(false);
				board.add(row);
				if(i >= h - 1)
					break;
				row = new ArrayList<Boolean>();
				for(int j=0; j < w * 2 + 1; j++) {
					row.add(false);
				}
				for(int j=0; j < w; j++) {
					if(scanner.nextInt() == 0)
						row.set(1 + 2 * j, true);
				}
				board.add(row);
			}
			board.add(wallrow);
			// ここまで入力
			
			Point start = new Point(1, 1);
			Point goal = new Point(w * 2 - 1, h * 2 - 1);
			// 左, 右, 上, 下
			int[] dx = {-1, 1, 0, 0};
			int[] dy = {0, 0, -1, 1};
			int[][] fp = new int[board.size()][board.get(0).size()];
			fp[1][1] = 1;
			Deque<Point> deque = new LinkedList<Point>();
			deque.offer(start);
			while(true) {
				if(deque.isEmpty()) {
					ans.add(0);
					break;
				}
				Point crt = deque.poll();
				if(crt.equals(goal)) {
					ans.add(fp[goal.y][goal.x] / 2 + 1);
					break;
				}
				for(int i=0; i < 4; i++) {
					int nx = crt.x + dx[i];
					int ny = crt.y + dy[i];
					if(board.get(ny).get(nx) == true && fp[ny][nx] == 0) {
						deque.add(new Point(nx, ny));
						fp[ny][nx] = fp[crt.y][crt.x] + 1;
					}
				}
			}
			
		}
		scanner.close();
		
		for(Iterator<Integer> it = ans.iterator(); it.hasNext();)
			System.out.println(it.next());
	}

}

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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    rep(i,m) cin >> a[i];
    int cost0 = 0;
    rep(i,n){
        if(a[i] > x){
            break;
        }
        cost0++;
    }
    int costn = m-cost0;
    int ans = min(cost0,costn);
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
    string s , t ; 
    cin>>s >> t ;
    int n = s.size() ;
    int m = t.size() ;
    int dp[n+1][m+1] ;
    repu(i , 0 , n){
    	dp[i][0] = 0 ;
    }
    repu(j , 0 , m){
    	dp[0][j] = 0 ;
    }
    repu(i , 1 , n){
    	repu(j , 1 , m){
    		dp[i][j] = max(dp[i-1][j],dp[i][j-1]) ;
    		if(s[i-1]==t[j-1]){
    			dp[i][j] = max(dp[i][j] , dp[i-1][j-1]+1) ;
    		}
    	}
    }
    string ans = "" ;
    int i = n , j = m ;
    int maxlen = dp[n][m] ;
    while(maxlen){
    	if(dp[i][j]>dp[i-1][j] && dp[i][j]>dp[i][j-1]){
    		ans += s[i-1] ;
    		i--;j--;
    		maxlen--;
    	}
    	else if(dp[i-1][j]>dp[i][j-1]){
    		i--;
    	}
    	else{
    		j--;
    	}
    }
    reverse(ans.begin()  , ans.end());
    cout<<ans<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 38996
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
diff_po = [0]*n
diff_ne = 0
ans = 0
for i in range(n):
    num = a[i]-b[i]
    if num >= 0:
        diff_po[i] = num
    else:
        diff_ne += num
        ans += 1
diff_ne = -diff_ne
if sum(diff_po) < diff_ne:
    print(-1)
    exit()

if diff_ne == 0:
    print(0)
    exit()

diff_po.sort(reverse=1)
for i in diff_po:
    ans += 1
    diff_ne -= i
    if diff_ne <= 0:
        print(ans)
        break

Measured memory_bytes: 24204
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <climits>
#include <iomanip>

using namespace std;

const int N = 2e6 + 9;
const int INF = 2e9 + 2;
const int mod = 1e9 + 7;
const int K = 25;
const int P = 51;
const long long LONG_INF = LONG_MAX;
const int SZ = (1 << 18) - 1;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define mkp make_pair
#define all(s) s.begin(), s.end()

#define ll long long

#define int ll

void solve() {
	int n, m;
	cin >> n >> m;
	cout << ((n * (n - 1)) / 2) + ((m * (m - 1)) / 2);
}

signed main() {
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n=0,m=0,sum=0;
    cin >> n>> m;
    for(int i=0;i<m;i++){
        int j=0;
        cin >> j;
        sum=sum +j;
    }
    if(sum>n){
      cout<<-1<<"\n";
    }else{
      cout <<n-sum<<"\n";
    }

}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=15;
int vis[maxn];
int dig[maxn],cn;
int n,k;
int ans;
int dfs(int sum,int large,int id)
{
    if(id==-1)
    {
        ans=sum;
        return 1;
    }
    for(int i=0;i<10;i++)
    {
        if(vis[i]) continue;
        if(large)
        {
            if(dfs(sum*10+i,large,id-1)) return 1;
        }
        else
        {
            if(i>=dig[id]&&dfs(sum*10+i,i>dig[id],id-1)) return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    int x;
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&x);
        vis[x]=1;
    }
    int t=n;cn=0;
    while(t)
    {
        dig[cn++]=t%10;
        t/=10;
    }
    if(!dfs(0,0,cn-1))
    {
        ans=0;
        for(int i=1;i<10;i++)
        {
            if(vis[i]==0)
            {
                ans=i;
                break;
            }
        }
        int mnnum=0;
        for(int i=0;i<10;i++)
        {
            if(vis[i]==0)
            {
                mnnum=i;
                break;
            }
        }
        for(int i=1;i<=cn;i++)
        {
            ans=ans*10+mnnum;
        }
    }
    printf("%d\n",ans);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

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

const int N = 1e3 + 5;
const int mod = 1e9 + 7;
int used[N][N];
int val[N][N];

int h, w;

char grid[N][N];

int check(int row, int col)
{
    if (row >= h || row < 0 || col >= w || col < 0 || grid[row][col] == '#')
        return 0;
    else
        return 1;
}

void dfs(int row, int col)
{
    used[row][col] = 1;
    if (check(row + 1, col) && !used[row + 1][col])
        dfs(row + 1, col);
    if (check(row, col + 1) && !used[row][col + 1])
        dfs(row, col + 1);
}

void solve()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
            cin >> grid[i][j];
    }
    mem0(used);
    mem0(val);
    dfs(0, 0);
    if (!used[h - 1][w - 1])
    {
        cout << "0" << endl;
        return;
    }
    val[0][0] = 1;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (!used[i][j])continue;
            if (used[i - 1][j])val[i][j] += 1 * val[i - 1][j];
            val[i][j] %= mod;
            if (used[i][j - 1])val[i][j] += 1 * val[i][j - 1];
            val[i][j] %= mod;
        }
    }
    cout << val[h - 1][w - 1];

}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

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

int main() {
  int n;cin>>n;
  vector<tuple<string,int,int>> vec(n+1);
  for(int i=1;i<=n;i++){
    string s;cin>>s;
    int a;cin>>a;
    a=-a;
    vec[i]=make_tuple(s,a,i);
  }
  sort(all(vec));
  for(int i=1;i<=n;i++){
    string s;
    int a;
    int b;
    tie(s,a,b)=vec[i];
    cout<<b<<endl;
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define int long long
using namespace std;

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

  map<int, int> num;
  for( int i = 0; i < N; i++ ){
    int A;
    cin >> A;

    if( num.count(A) ) num.at(A)++;
    else num[A] = 1;
  }
  
  int total = (int)num.size();
  if( total%2 == 0 ) cout << total-1 << endl;
  else cout << total << endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    char op;
    cin >> A >> op >> B;
    if (op == '+') cout << A + B << endl;
    else cout << A - B << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<int,int>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n,k;cin>>n>>k;

  int ans=0;
  rep(i,0,n){
    int x;cin>>x;

    ans+=2*min(x,abs(x-k));
  }
  out(ans);

  return 0;
}


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

int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    ans += 2 * (ll)(N/11);
    if(N % 11 != 0){
        if(N % 11 <= 6) ans++;
        else ans += 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

even = []
odd = []
for i in range(0,n):
	if i % 2 == 0:
		odd.append(a[i])
	else:
		even.append(a[i])

res = []
if n % 2 == 0:
	even = reversed(even)
	res.extend(even)
	res.extend(odd)
else:
	odd = reversed(odd)
	res.extend(odd)
	res.extend(even)

print(" ".join(map(str,res)))

Measured memory_bytes: 30404
#include<stdio.h>

typedef struct{
  int id;
  int left;
  int right;
}Tree;

void preParse(int);
void inParse(int);
void postParse(int);

int n;
Tree T[100];

int main()
{
  int i, v, l, r, root;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    T[i].id = -1;
  }

  for(i = 0; i < n; i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if(l != -1) T[l].id = v;
    if(r != -1) T[r].id = v;
  }

  for(i = 0; i < n; i++) if(T[i].id == -1) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

void preParse(int u)
{

  int i=0;

  if(u != -1){
    printf(" %d", u);
    preParse(T[u].left);
    preParse(T[u].right);
  }
}

void inParse(int u)
{

  if(u != -1){
    inParse(T[u].left);
    printf(" %d", u);
    inParse(T[u].right);
  }
}

void postParse(int u)
{

  if(u != -1){
    postParse(T[u].left);
    postParse(T[u].right);
    printf(" %d", u);
  }
}

Measured memory_bytes: 616
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int line =scn.nextInt();
        int row=scn.nextInt();
        int[][] bw = new int[line][row+1];
        for(int i=0;i<line;i++){
            String b=scn.next();
            int total=0;
            for(int j= 0;j<row+1;j++){
                if(j!=row){
                    if(b.charAt(j)=='.'){
                        bw[i][j]=0;
                    }else{
                        bw[i][j]=1;
                    }
                    total+=bw[i][j];
                }else{
                    bw[i][j]=total;
                }
            }
        }
        int[] cnt = new int[row];
        for(int i=0;i<row;i++){
            cnt[i]=0;
            int total=0;
            for(int j=0;j<line;j++){
                total+=bw[j][i];
            }
            cnt[i]=total;
        }
        for(int i=0;i<line;i++){
            if(bw[i][row]==0){
                continue;
            }else{
                for(int j=0;j<row;j++){
                    if(cnt[j]==0){
                        continue;
                    }else{
                        if(bw[i][j]==0){
                            System.out.print('.');
                        }else{
                            System.out.print('#');
                        }
                    }
                }
                System.out.println();
            }
        }
    }
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int h,w; cin >> h >> w;
	int c[10][10];
	rep(i,10){
		rep(j,10){
			cin >> c[i][j];
		}
	}
	rep(i,10){
		rep(j,10){
			rep(k,10){
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
			}
		}
	}
	int ans = 0;
	Rep(h*w){
		int a; cin >> a;
		if(a > -1){
			ans += c[a][1];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3564
#include <iostream>
using namespace std;
 
int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  int sum;
  int nokori;
  
  if (A >= K) {
  	sum = K;
  } else {
    sum = A;
    nokori = K - A;
    if (B < nokori) {
      nokori -= B;
      if (C < nokori) {
        sum -= C;
      } else {
        sum -= nokori;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3580
///
// File:  main.rs
// Author: ymiyamoto
//
// Created on Tue Feb 12 14:27:05 2019
//
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let input = scan!();
    let mut a = [0i64; 4];
    for (i, c) in input.char_indices() {
        if i < a.len() {
            a[i] = c.to_digit(10).unwrap() as i64
        }
    }

    let (a, b, c, d) = (a[0], a[1], a[2], a[3]);
    if a + b + c + d == 7 {
        println!("{}+{}+{}+{}={}", a, b, c, d, 7)
    } else if a + b + c - d == 7 {
        println!("{}+{}+{}-{}={}", a, b, c, d, 7)
    } else if a + b - c + d == 7 {
        println!("{}+{}-{}+{}={}", a, b, c, d, 7)
    } else if a + b - c - d == 7 {
        println!("{}+{}-{}-{}={}", a, b, c, d, 7)
    } else if a - b + c + d == 7 {
        println!("{}-{}+{}+{}={}", a, b, c, d, 7)
    } else if a - b + c - d == 7 {
        println!("{}-{}+{}-{}={}", a, b, c, d, 7)
    } else if a - b - c + d == 7 {
        println!("{}-{}-{}+{}={}", a, b, c, d, 7)
    } else {
        println!("{}-{}-{}-{}={}", a, b, c, d, 7)
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
  int N,Q;cin>>N>>Q;
	string S;cin>>S;
  vi z(N);

  rep(i,N){
    if(i==0){
      z[i] = 0;
    }else{
      if(S[i-1]=='A' && S[i]=='C'){
        z[i] = z[i-1]+1;
      }else{
        z[i] = z[i-1];
      }
    }
  }

  //DEBUG(z);

  rep(i,Q){
    int a,b;cin>>a>>b;
    a--;b--;
    cout<<z[b]-z[a]<<endl;
  }
}

Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>

using namespace std;
using ll = long long;


int main(){
    int H,W; cin >> H >> W;
    int sx,sy;
    int gx,gy;
    cin >> sy >> sx;
    cin >> gy >> gx;
    sy--; sx--; gy--; gx--;
    string S;
    int iii=10101010;
    vector<vector<int> > c(H,vector<int>(W,iii));
    bool f=false;
    for(int i=0;i<H;i++){
        cin >> S;
        for(int j=0;j<W;j++){
            if(S[j]=='#') c[i][j]=-1;
        }
    }
    queue<pair<int,int>> q;
    q.push(make_pair(sy,sx));
    c[sy][sx]=0;
    while(!q.empty()){
        pair<int,int> now = q.front(); q.pop();
        int y=now.first;
        int x=now.second;
        int n=c[y][x];
        for(int i=-2;i<=2;i++){
            for(int j=-2;j<=2;j++){
                int dy = y+i;
                int dx = x+j;
                int ttt=0;
                if(dy<0 || dy>=H) continue;
                if(dx<0 || dx>=W) continue;
                int nn=n;
                int dd=c[dy][dx];
                if(abs(i)>1 || abs(j)>1){
                    nn++;
                }else if(abs(i)==1 && abs(j)==1){
                    nn++;
                }
                if(dd==-1){
                    continue;
                }else if(dd>nn){
                    c[dy][dx] = nn;
                    q.push(make_pair(dy,dx));
                }else{
                    continue;
                }   
            }
        }
        
    }
    if(c[gy][gx]!=iii){
        cout << c[gy][gx] << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 7680
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

const inf = 10^^9;

void main()
{
  int n; readV(n);
  int[] p; readA(n-1, p); p[] -= 1;
  int[] x; readA(n, x);

  auto c = new int[][](n);
  foreach (i; 1..n) c[p[i-1]] ~= i;
  auto nc = new int[](n);
  foreach (i; 0..n) nc[i] = c[i].length.to!int;

  auto y = new int[](n);
  foreach_reverse (i; 0..n) {
    auto dp = new int[][](nc[i]+1, x[i]+1);
    foreach (ref dpi; dp) dpi[] = inf;
    dp[0][0] = 0;

    foreach (j; 0..nc[i]) {
      auto xj = x[c[i][j]], yj = y[c[i][j]];
      foreach (k; 0..x[i]+1) {
        if (k >= xj) dp[j+1][k] = min(dp[j+1][k], dp[j][k-xj]+yj);
        if (k >= yj) dp[j+1][k] = min(dp[j+1][k], dp[j][k-yj]+xj);
      }
    }

    y[i] = dp[$-1].reduce!min;
    if (y[i] >= inf) {
      writeln("IMPOSSIBLE");
      return;
    }
  }

  writeln("POSSIBLE");
}


Measured memory_bytes: 4860
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int N;
int a[510][510];

void dfs(const vector<int> &vec, int d = 1) {
  int n = vec.size();

  if (n == 1) return;

  vector<int> vec1, vec2;

  for(int i=0; i<n; i++){
    if (i%2) vec1.push_back(vec[i]);
    else vec2.push_back(vec[i]);
  }

  for(int i=0; i<n; i++) {
    for(int j=i+1; j<n; j++) {
      a[vec[i]][vec[j]] = a[vec[j]][vec[i]] = d;
    }
  }

  dfs(vec1, d+1);
  dfs(vec2, d+1);
}

int main(){

  cin >> N;

  vector<int> vec(N);
  iota(vec.begin(), vec.end(), 0);

  dfs(vec);

  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      printf("%d%c", a[i][j], " \n"[j+1 == N]);
    }
  }

  return 0;
}


Measured memory_bytes: 1536
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        String s = fs.next();

        int ans = 0;
        for (int i = 0; i <= s.length()/2-1; ++i) {
            if (s.charAt(i) != s.charAt(s.length()-1-i))
                ++ans;
        }

        System.out.println(ans);

    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

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




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

using namespace std;

void cut(int *a, int p, int c)
{
    for(int i=0; i<c; i++)
    {
        int t = a[p+i];
        for(int j=p+i; j>i; j--)
        {
            a[j] = a[j-1];
        }
        a[i] = t;
    }
}

int main()
{
    int n, r;
    while(cin >> n >> r, n|r)
    {
        int a[n];
        for(int i=0; i<n; i++) a[i] = n - i;
        while(r--)
        {
            int p, c;
            cin >> p >> c;
            cut(a, p-1, c);
        }
        cout << a[0] << endl;
    }
}

Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
//cerr
using namespace std;
int n, a[123];
int f(int k) {
	int r = 0;
	for1(i, n)r += (a[i] - k)*(a[i] - k);
	return r;
}
signed main() {
	cin >> n; for1(i, n)cin >> a[i]; int ans = mod; for1(i, 100)ans = min(ans, f(i)); cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{	
	
	static void run(){
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = 0;
			
			for(int a=0;a<10;a++){
			for(int b=0;b<10;b++){
			for(int c=0;c<10;c++){
			for(int d=0;d<10;d++){
				if(a+b+c+d==n) m++;
			}
			}
			}
			}
			System.out.println(m);
		}
		
	
	}
	
	public static void main (String[] args){
		run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


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

  rep(i, 102) {
    c -= b;
    if (c <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if (a <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  return 0;
}


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

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

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    int d,n;
    cin>>d>>n;
    int counter=0;
    for(int i=1;i<=INF;i++){
        int c=0;
        int now=i;
        while(now%100==0){
            c++;
            now/=100;
        }
        if(c==d)counter++;
        if(counter==n){
            cout<<i<<endl;
            return 0;
        }
    }

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  string s;
  int k;
  cin >> s >> k;
  vector<string> ans;

  rep(i, s.length()) {
    for(int j = 1; i+j <= s.length() && j <= k; ++j) {
      ans.push_back(s.substr(i, j));
    }
  }
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());

  cout << ans[k-1] << '\n';
  return 0;
}


Measured memory_bytes: 1660
N = int(input())
a = list(map(int,input().split()))
ans = 0
x = dict()
for i in range(N):
    if a[i] in x:
        x[a[i]] += 1
    else:
        x[a[i]] = 1
for idx in x:
    b = x[idx] - idx
    if b<0:
        ans += x[idx]
    else:
        ans += b 
print(ans)

Measured memory_bytes: 17780
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

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

	for(int i=1;i*i<=n;i++) {
		total = i*i;
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

class UnionFind {
  std::vector<ll> p;  // parent??

public:
  UnionFind(int n) : p(n, -1) {}

  // find: x を含む集合の代表元を返す
  int root(int x) { return (p[x] < 0) ? x : (p[x] = root(p[x])); }

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

  // union:
  // 既に x を含む集合と y を含む集合が同じ集合である場合は false を返し，
  // そうでない場合は true を返す．
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    // if (p[x] == p[y]) --p[x];
    // p[y] = x;
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  ll size(int x) { return -p[root(x)]; }
};

ll N,M;
vector<int> A,B;
vector<ll> ans;

int main()
{
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  ans.resize(M);

  REP(i,0,M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    // int A,B;
    // cin >> A >> B;
  }

  ans[M-1] = N * (N-1) / 2;  // どの橋も行き来できない

  // 橋が0個の状態から増えていく
  UnionFind uf(N);
  for(int i = M-2; i >= 0; --i) {
    if (uf.same(A[i+1], B[i+1])) {
      ans[i] = ans[i+1];
    } else {
      ans[i] = ans[i+1] - uf.size(A[i+1]) * uf.size(B[i+1]);
      uf.unite(A[i+1], B[i+1]);
    }
  }

  REP(i,0,M) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
#include <math.h>
double a, b, C;
double PI = acos(-1);

int main()
{
    scanf("%lf %lf %lf", &a, &b, &C);
    double rad = C * PI / 180;
    double S = a * b * sin(rad) / 2.00000000;
    double L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(rad));
    double h = b * sin(rad);
    printf("%.8f %.8f %.8f\n", S, L, h);
}


Measured memory_bytes: 2976
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

point = [K-Q] * N

for i in range(len(A)):
    point[A[i]-1] += 1

for i in range(N):
    if point[i] <= 0:
        print('No')
    else:
        print('Yes')   


Measured memory_bytes: 10452
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 

const int MOD = 1000000007;

int dp[100005];

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

    vector<int> h(N);
    rep(i, N) {
        cin >> h[i];
        dp[i] = INT_MAX;
    }

    dp[0] = 0;
    for (int i = 0; i < N-1; ++i) {
        for (int s = 1; s <= K; ++s) {
            if (N <= i+s) break;
            dp[i+s] = min(dp[i+s], dp[i] + abs(h[i+s]-h[i]));
        }
    }

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

    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int a,b,c;
int t[8];
int main()
{
  scanf("%d %d %d",&a,&b,&c);
  t[a]++;
  t[b]++;
  t[c]++;
  if(t[5]==2&&t[7]==1)
   puts("YES");
  else
   puts("NO"); 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define oprecision                                                             \
  cout.precision(30);                                                          \
  cerr.precision(7);
#define bb bool
#define ii int
#define ll long long
#define ff float
#define dd double
#define cc char
#define ss string
#define forn(sz) for (int i = 1; i <= sz; i++)
#define forni(i, sz) for (int i = 1; i <= sz; i++)
#define fornid(i, m, sz) for (int i = m; i <= sz; i++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vii vector<ii>
#define vii64 vector<ll>
#define vb vector<bb>
using namespace std;
ll n;
ii main() {
  speed;
  oprecision;
  /*#ifndef ONLINE_JUDGE
    freopen("outd.txt", "rt", stdin);
  #endif*/
  // code
  cin >> n;
  cout << (((n - 1) * n) >> 1);
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define inrange(a, x, b) (a <= x && x <= b)
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print(T x,bool cl=1){cout<<(cl?"\x1b[36m":"")<<x<<(cl?"\x1b[39m":"")<<'\n';}
template<class T> void print1d(T x,ll n=-1,bool cl=true){if(n==-1)n=x.size();rep(i,0,n){cout<<(cl?"\x1b[36m":"")<<x[i]<<(i==n-1?'\n':' ');}cout<<(cl?"\x1b[39m":"");}
template<class T> void print2d(T x,ll r=-1,ll c=-1,bool cl=1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c,cl);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        string S;
        cin >> S;
        if (S.back() != 's') {
                string x(S.begin(), S.end());
                cout << x + 's' << endl;
        } else {
                string x(S.begin(), S.end());
                x += 'e';
                x += 's';
                cout << x << endl;                
        }
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H, vector<char>(W, '-'));

    rep(i, H) {
        rep(j, W) {
            cin >> a.at(i).at(j);
        }
    }

    vector<bool> row(H, false);
    vector<bool> col(W, false);

    rep(i, H) {
        rep(j, W) {
            if (a.at(i).at(j) == '#') {
                row.at(i) = true;
                col.at(j) = true;
            }
        }
    }

    rep(i, H) {
        if (row.at(i)) {
            rep(j, W) {
                if (col.at(j)) {
                    cout << a.at(i).at(j);
                }
            }
            cout << endl;
        }
    }
}


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


int main() {
	int i = 0;
	long long int num = 7;
	int k;

	scanf("%d", &k);

	while (1) {
		if (k % 2 == 0) {
			i = -2;
			break;
		}
		if (num % k == 0) {
			break;
		}
		else {
			num = (num % k) * 10 + 7;
		}

		if (i > 1000000) {
			i = -2;
			break;
		}
		i++;
	}

	printf("%d\n", i+1);
	return 0;
}

Measured memory_bytes: 1736
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >> s >> t;
  int a[30]={},b[30]={};
  for(int i=0; i<s.size(); i++) {
    a[s[i]-'a']++,b[t[i]-'a']++;
  }
  sort(a,a+26),sort(b,b+26);
  for(int i=0; i<26; i++) {
    if(a[i]!=b[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 916