akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element

int H, W;
bool field[21][21];

int _dx[] = {1, 0, -1, 0};
int _dy[] = {0, 1, 0, -1};

int step(int x, int y)
{
	bool flg[21][21] = {};

	queue<int> q;
	q.push(x);
	q.push(y);
	flg[x][y] = true;

	int step = 0;
	while (q.size() > 0)
	{
		int q_size = q.size();
		for (int i = 0; i < q_size / 2; i++)
		{
			int x = q.front();
			q.pop();
			int y = q.front();
			q.pop();

			for (int d = 0; d < 4; d++)
			{
				int nx = x + _dx[d];
				int ny = y + _dy[d];
				if (0 <= nx && nx < W && 0 <= ny && ny < H)
				{
					if (!flg[nx][ny] && !field[nx][ny])
					{
						flg[nx][ny] = true;
						q.push(nx);
						q.push(ny);
					}
				}
			}
		}
		step++;
	}

	return step;
}

signed main()
{
	cin >> H >> W;
	REP(y, H)
	{
		string s;
		cin >> s;
		REP(x, W)
		{
			char ch = s[x];
			field[x][y] = (ch == '#');
		}
	}


	int ans = 0;
	REP(y, H)
	{
		REP(x, W)
		{
			if (!field[x][y])
			{
				ans = max(ans, step(x, y));
			}
		}
	}
	cout << (ans - 1) << endl;
}




Measured memory_bytes: 256
N,K = list(map(int,input().split()))
P = list(map(int,input().split()))
PP = []
for p in P:
    PP.append(((p*(1+p))/2)/p)
PPP = [PP[0]]
for i in range(1,N):
    PPP.append(PP[i]+PPP[i-1])
MAX = PPP[K-1]
for i in range(N-K):
    MAX = max(MAX,PPP[i+K]-PPP[i])
print(MAX)

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

#define ll long long
#define ld long double
#define mod 1000000007LL
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define pb(x) push_back(x)
#define fo(i, a, n) for (i = (a); i < (n); i++)
#define foe(i, a, n) for (i = (a); i <= (n); i++)
// clang-format off
#define vin(a) for (ll i = 0; i < sz(a); i++) { cin >> a[i]; } 
#define vout(a) for (auto x : a) { cout << x << " "; }
#define sws                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
// clang-format on
#define pd(x) cout << x
#define sd(x) cin >> x
#define nl cout << endl
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define foreach(i, a)                                                          \
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
// int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
void solve() {
  ll m, n;
  ll i, j;
  cin >> n;
  vector<ll> dp(n + 1, 1);
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[6] = 2;

  for (i = 7; i <= n; i++) {
    for (j = i - 1; j >= 3; j--) {
      if (i - j < 3)
        continue;
      dp[i] += dp[j];
      dp[i] %= mod;
    }
  }

  cout << dp[n] << endl;
}

int main() {
  sws;
  solve();
  return 0;
}

Measured memory_bytes: 3664
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct

  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    if t.size <= 0 then failwith "out of size" else
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m = i then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(m);
        t.node.(m) <- tmp;
        max_heapify m
      end in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      let p = parent i in
      if i <= 1 || M.compare t.node.(p) t.node.(i) >= 0 then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(p);
        t.node.(p) <- tmp;
        doit p
      end in
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    doit t.size

end

module H = MakeBinaryHeap(struct type t = (int * int) let compare (_, x) (_, y) = y - x end)

let prim a n =
  let reached_p = Array.make n false in
  let d = Array.make n max_int in
  d.(0) <- 0;
  let que = H.make 500 (0, 0) in
  H.push (0, 0) que;
  while not (H.empty_p que) do
    let (u, _) = H.pop que in
    reached_p.(u) <- true;
    List.iter (fun (v, c) ->
      if not reached_p.(v) && c < d.(v) then begin
        d.(v) <- c;
        H.push (v, c) que;
      end) a.(u);
  done;
  Array.fold_left (fun sum c -> if c = max_int then sum else sum + c) 0 d

let () =
  let n = read_int () in
  let a = Array.make n [] in
  for i = 0 to n - 1 do
    for j = 0 to n - 1 do
      let x = Scanf.scanf " %d" (fun i -> i) in
      if x <> (-1) then a.(i) <- (j, x) :: a.(i);
    done
  done;
  prim a n |> Printf.printf "%d\n"

Measured memory_bytes: 4660
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String astr = sc.next();
			String bstr = sc.next();
			int a = 0, b = 0;
			int l = 1;
			for (int j = 0; j < astr.length(); j++) {
				switch (astr.charAt(j)) {
				case '2':
					l = 2;
					break;
				case '3':
					l = 3;
					break;
				case '4':
					l = 4;
					break;
				case '5':
					l = 5;
					break;
				case '6':
					l = 6;
					break;
				case '7':
					l = 7;
					break;
				case '8':
					l = 8;
					break;
				case '9':
					l = 9;
					break;
				case 'm':
					a += l * 1000;
					l = 1;
					break;
				case 'c':
					a += l * 100;
					l = 1;
					break;
				case 'x':
					a += l * 10;
					l = 1;
					break;
				case 'i':
					a += l;
					l = 1;
					break;
				default:
					break;
				}
			}
			l = 1;
			for (int j = 0; j < bstr.length(); j++) {
				switch (bstr.charAt(j)) {
				case '2':
					l = 2;
					break;
				case '3':
					l = 3;
					break;
				case '4':
					l = 4;
					break;
				case '5':
					l = 5;
					break;
				case '6':
					l = 6;
					break;
				case '7':
					l = 7;
					break;
				case '8':
					l = 8;
					break;
				case '9':
					l = 9;
					break;
				case 'm':
					b += l * 1000;
					l = 1;
					break;
				case 'c':
					b += l * 100;
					l = 1;
					break;
				case 'x':
					b += l * 10;
					l = 1;
					break;
				case 'i':
					b += l;
					l = 1;
					break;
				default:
					break;
				}
			}
			int c = a + b;
			String cr = Integer.toString(c);
			String cstr = "";
			for (int j = 0; j < cr.length(); j++) {
				switch (cr.charAt(j)) {
				case '0':
					cstr += "";
					break;
				case '1':
					cstr += "";
					break;
				case '2':
					cstr += "2";
					break;
				case '3':
					cstr += "3";
					break;
				case '4':
					cstr += "4";
					break;
				case '5':
					cstr += "5";
					break;
				case '6':
					cstr += "6";
					break;
				case '7':
					cstr += "7";
					break;
				case '8':
					cstr += "8";
					break;
				case '9':
					cstr += "9";
					break;
				}
				switch (cr.length()) {
				case 1:
					if (cr.charAt(j) != '0')
						cstr += "i";
					break;
				case 2:
					if (cr.charAt(j) != '0')
						switch (j) {
						case 0:
							cstr += "x";
							break;
						case 1:
							cstr += "i";
							break;
						}
					break;
				case 3:
					if (cr.charAt(j) != '0')
						switch (j) {
						case 0:
							cstr += "c";
							break;
						case 1:
							cstr += "x";
							break;
						case 2:
							cstr += "i";
							break;
						}
					break;
				case 4:
					if (cr.charAt(j) != '0')
						switch (j) {
						case 0:
							cstr += "m";
							break;
						case 1:
							cstr += "c";
							break;
						case 2:
							cstr += "x";
							break;
						case 3:
							cstr += "i";
							break;
						}
					break;
				}
			}
			System.out.println(cstr);
		}
		sc.close();
	}
}

Measured memory_bytes: 27068
def main():
    antenna = [0] * 5
    for i in range(5):
        antenna[i] = int(input())
    k = int(input())

    for i in range(5):
        for j in range(i+1, 5):
            if antenna[j] - antenna[i] > k:
                print(':(')
                return
    
    print('Yay!')


if __name__ == '__main__':
    main()

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n;
  cin >> n;
  vi h(n);
  rep (i, n) {
    cin >> h[i];
  }
  int l = 0;
  int ans = 0;
  while (l < n) {
    if (h[l] == 0) {
      l++;
      continue;
    }
    int r = l;
    while (r < n && h[r] != 0) {
      r++;
    }
    for (int i = l; i < r; i++) {
      h[i]--;
    }
    ans++;
  }
  cout << ans << endl;
}


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

#define ALL(v) v.begin(), v.end()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

using namespace std;
int main() {

	string s;
	cin >> s;


	
	cout << s[0];
	cout << s.length() - 2;
	cout << s[s.length() - 1];


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n >> m;

    vector<int> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    long sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a.at(i);
    }
    int kazu = 0;
    double kijun = sum / (double)(4 * m);
    for (int i = 0; i < n; i++)
    {
        if (a.at(i) >= kijun)
        {
            kazu++;
        };
    }
    if (kazu >= m)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
//小さい順にソート
int c[1002];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]<s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}

int main(){
  int n,k,i,count=0;
  scanf("%d%d",&n,&k);
  int p[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);
  merge(0,n-1,p);
  for(i=0;i<k;i++)
    count+=p[i];
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 1732
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll a, b, c;
	string s;
	cin>>a;
	cout<<24+24-a<<endl;
	return 0;
}


Measured memory_bytes: 764
def gcd(a,b):
	return gcd(b,a%b) if b else a

a,b=map(int,input().split())
c=gcd(a,b)
ans=1
cnt=2
while(cnt*cnt<=c):
	bo=False
	while(c%cnt==0):
		if not bo:
			ans+=1
			bo=True
		c//=cnt
	cnt+=1
if c!=1:
	ans+=1

print(ans)

Measured memory_bytes: 40044
hel=["A","C","G","T"]

a = []
a = gets.split.map(&:to_i)
#p hel

n = gets.chomp
x = n.chars
#p x

c = []
while s = gets
  c.push(s.split.map(&:to_i))
end

cnt = [0]
t = 0
for i in 1..a[0]-1
    if x[i]=="C"
        if x[i-1]=="A"
            t+=1
        end
    end
cnt.push(t)
end

for i in 0..a[1]-1
    puts cnt[c[i][1]-1]-cnt[c[i][0]-1]
end
#puts c[2][0]




#p a
#p x
#p c
#p cnt

Measured memory_bytes: 25724
from collections import deque

h, w = map(int, input().split())
sx, sy = map(int, input().split())
gx, gy = map(int, input().split())
M = [[] for _ in range(h)]
for i in range(h):
    M[i] = input()

D = [(-1, 0), (0, -1), (1, 0), (0, 1)]
dist = [[float("inf")] * w for _ in range(h)]
dist[sx - 1][sy - 1] = 0
q = deque()
q.append((sx - 1, sy - 1))
while q:
    X, Y = q.popleft()
    d = dist[X][Y]
    for dx, dy in D:
        nx, ny = X + dx, Y + dy
        if nx < 0 or ny < 0 or nx >= h or ny >= w:
            continue
        if M[nx][ny] == "#":
            continue
        if dist[nx][ny] <= d:
            continue
        dist[nx][ny] = d
        q.appendleft((nx, ny))
    for c in range(-2, 3):
        for r in range(-2, 3):
            nx, ny = X + c, Y + r
            if nx < 0 or ny < 0 or nx >= h or ny >= w:
                continue
            if M[nx][ny] == "#":
                continue
            if dist[nx][ny] <= d + 1:
                continue
            dist[nx][ny] = d + 1
            q.append((nx, ny))

ans = dist[gx - 1][gy - 1]
if ans == float("inf"):
    ans = -1

print(ans)


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

namespace ProgramingStydying
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = input[0];
            var b = input[1];
            var c = input[2];
            var d = input[3];
            var e = input[4];
            var f = input[5];

            var maxSugerWater = 0;
            var maxSuger = 0;
            var maxConcentration = 0.0;

            for(int i = 0; 100 * a * i <= f; i++)
            {
                for (int j = 0; 100 * (a * i + b * j) <= f; j++)
                {
                    var water = 100 * (a * i + b * j);
                    var sugerLimit = (a * i + b * j) * e;

                    for(int k = 0; c * k <= sugerLimit && water + c * k <= f; k++)
                    {
                        for(int l = 0; c * k + d * l <= sugerLimit && water + c * k + d * l <= f; l++)
                        {
                            var suger = c * k + d * l;
                            var concentration = (double)100 * (suger) / (water + suger);
                            
                            if(maxConcentration == 0 && concentration == 0)
                            {
                                maxSugerWater = water + suger;
                                maxSuger = suger;
                            }

                            if(concentration > maxConcentration)
                            {
                                maxConcentration = concentration;
                                maxSugerWater = water + suger;
                                maxSuger = suger;
                            }
                        }
                    }
                }
            }
            Console.WriteLine(maxSugerWater + " " + maxSuger);
        }
    }
}

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

int main()
{
	int i,j,w,h,dp[100][100],dp2[100][100],total;
	
	while(1)
	{
		cin >> w;
		cin >> h;
		if(w==0) break;
		for(i=0;i<=w-2;i++)
		{
			dp[0][i]=1;
			dp2[0][i]=1;
		}
		dp[0][w-1]=0;
		dp2[0][w-1]=1;
		for(i=0;i<=h-2;i++)
		{
			dp[i][0]=1;
			dp2[i][0]=1;
		}
		dp[h-1][0]=1;
		dp2[h-1][0]=0;
		for(i=1;i<=h-1;i++)
		{
			for(j=1;j<=w-1;j++)
			{
				if(i==h-1 && j==w-1)
				{
					total=(dp[i][j-1]+dp2[i-1][j])%100000;
				}
				else
				{
					dp[i][j]=dp[i][j-1];
					dp2[i][j]=dp2[i-1][j];
					if(i>=2) dp[i][j]+=dp2[i-2][j];
					if(j>=2) dp2[i][j]+=dp[i][j-2];
					dp[i][j]%=100000;
					dp2[i][j]%=100000;
				}
			}
		}
		cout << total << endl;
	}
	return 0;
}

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

#define pb         push_back

const int INF = 100000000;

int main(void) {
	while(1){
		int n, q;
		vector<int> sche(200, 0);
		cin >> n >> q;
		if(n == 0 && q == 0) break;

		for(int i=0; i<n; i++){
			int m;
			cin >> m;
			for(int j=0; j<m; j++){
				int date;
				cin >> date;
				sche[date]++;
			}
		}
		int i;
		int ma = INT_MIN;
		int early = 0;
		for(i=0; i<=100; i++){
			if(sche[i] > ma && sche[i] >= q){
				ma = sche[i];
				early = i;
			}
		}

		cout << early << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int x = n;
    int ans1 = 0;
    int head;
    int c = 0;
    while(x != 0){
        ans1 += x % 10;
        if(x < 10){
            head = x;
        }
        c++;
        x /= 10;
    }
    int tmp = head + 9 * (c-1) - 1;
    if(tmp > ans1){
        ans1 = tmp;
    }
    cout << ans1 << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=200005;

int n,a[MAXN],b[MAXN],f[MAXN];

int main()
{
	#ifndef ONLINE_JUDGE
//	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	readint(n);
	for(int i=1;i<=n;++i)
	{
		readint(a[i]);
		b[a[i]]=i;
	}
	int ans=0;
	for(int i=n;i;--i)
	{
		if(b[i+1]>b[i])f[i]=f[i+1]+1;
		else f[i]=1;
		chkmax(ans,f[i]);
	}
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long

const int N=(int)1e5+5;

int dp[N];
int a[N];

int n,k;
int solve(int idx)
{

    if(idx==n)return 0;
    
    int &ans=dp[idx];
    if(ans!=-1)return ans;
    ans=INT_MAX;
    int op1=INT_MAX,op2=INT_MAX;
   
   
    for(int i=idx+1;i<=min(idx+k,n);i++)
    {
        op1=min(op1,abs(a[i]-a[idx])+solve(i));
    }
   
    return ans=min(op1,op2);
}
	
void solve()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    memset(dp,-1,sizeof dp);
    int ans=solve(1);
    cout<<ans;
}

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
	//cin>>t;
	while(t--)solve();
	    
   
}

Measured memory_bytes: 11456
def warshall_floyd(c, d):
    for i in range(10):
        for j in range(10):
            for k in range(10):
                c[j][k] = min(c[j][k],c[j][i] + c[i][k])
                if k == 1:
                    d[j] = c[j][k]
    return d

h, w = map(int, input().split())
c = [[int(i) for i in input().split()] for j in range(10)]
a = [[int(i) for i in input().split()] for j in range(h)]
dist = [0] * 10
ans = 0
warshall_floyd(c, dist)

for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += dist[a[i][j]]

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int MAXN = 10000001;
const int INF = 1e9;
#define ll long long 

class TaskD {
private:
	Debugger debugger;
	vector<vector<int>> graph;
	vector<bool> vis;
	int dfs(int u) {
		vis[u] = true;
		int ans = 1;
		for(int nxt : graph[u]) {
			if(!vis[nxt]) {
				ans += dfs(nxt);
			}
		}
		return ans;
	}

public:
	void solveOne(int it){
		int n;
		cin >> n;
		string s;
		cin >> s;
		vector<int> sum(n);
		for(int i = 0; i < n; i++) {
			sum[i] = s[i] == 'R' ? 1 : 0;
			if(i > 0) {
				sum[i] += sum[i-1];
			}
		}
		int ans = n;
		int whites = 0;
		for(int i = 0; i <= n; i++) {
			int reds = sum[n-1] - (i > 0 ? sum[i-1]:0);
			ans = min(ans, reds + whites - min(reds, whites));
			if(i < n && s[i] == 'W') {
				whites++;
			}
		}
		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 4400
h,w = map(int, input().strip().split())
F = []
for _ in range(h):
  F.append(list(input()))
 
for i in range(h):
  for j in range(w):
    if F[i][j] == ".":
      u = max(i-1,0)
      d = min(i+2,h)
      l = max(j-1,0)
      r = min(j+2,w)
      n = 0
      for line in F[u:d]:
          n += line[l:r].count("#")
      F[i][j] = str(n)

for line in F:
    print("".join(line))

Measured memory_bytes: 3188
def inpl():
    return list(map(int, input().split()))


def gcd(a, b):
    # greatest common divisor
    while b > 0:
        a, b = b, a % b

    return a


N = int(input())
V = inpl()
C = inpl()

print(sum(V[i] - C[i] for i in range(N) if V[i] > C[i]))


Measured memory_bytes: 2940
N = int(input())
S = input()
R = 0
G = 0
B = 0
for i in range(N):
    s = S[i]
    if s == "R":
        R += 1
    elif s == "G":
        G += 1
    elif s == "B":
        B += 1
ans = R * G * B
for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2*j - i
        if k <= N-1 and (S[i] != S[j] and S[j] != S[k] and S[k] != S[i]):
            ans -= 1

print(ans)

Measured memory_bytes: 68112
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def check(self, x, y):
        return self.find(x) == self.find(y)

N,M = map(int,input().split())
XYZ = list()
for i in range(M):
    x,y,z = map(int,input().split())
    XYZ.append((x,y,z))

uf = UnionFind(N)
for xyz in XYZ:
    x,y,z = xyz
    uf.unite(x-1,y-1)

ans = set()
for i in range(N):
    ans.add(uf.find(i))

print(len(ans))


Measured memory_bytes: 30956
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K, d; //d:displayed number
  cin >> N >> K; //def
  d = 1;
  
  for ( int i = 0; i < N; i++){
    int a,b;
    a = 2*d;
    b = d + K;
    if (a < b) {
      d = a;
    }
    else {
      d = b;
    }
  }
  cout << d << endl;
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

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

void solve(){
    int n,m;
    cin >> n >> m;
    map<int,int> count;
    rep(i,0,n){
        int x;
        cin >> x;
        ++count[x];
    }

    vector<int> s(m),a(m);
    for(auto &p:count){
        s[p.first%m]+=p.second;
        a[p.first%m]+=p.second/2;
    }

    int ans=0;
    vector<bool> done(m);
    rep(i,0,m){
        if(done[i]) continue;

        int j=(m-i)%m,ma=0;
        if(i==j){
            ans+=s[i]/2;
            done[i]=true;
            continue;
        }
        rep(x,0,a[i]+1){
            rep(y,0,a[j]+1){
                ma=max(ma,min(s[i]-2*x,s[j]-2*y)+x+y);
            }
        }
        ans+=ma;
        done[i]=done[j]=true;
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 5760
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;

const int MAX_V = 5000;

class UnionFind {
public:
    // コンストラクタ
    explicit UnionFind(int N) : V_NUM(N) {
        for (int i = 0; i < V_NUM; ++i) {
            par[i] = i;
        }
        fill(rank, rank + V_NUM, 0);
    }

    // xの親を返す+更新
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    // xとyを含むグループを統合する
    void unite(int x, int y) {
        x = find(x);
        y = find(y);

        if (x == y) return;

        // rank[x] >= rank[y]にする
        if (rank[x] < rank[y]) swap(x, y);
        par[y] = x;
        if (rank[x] == rank[y]) ++rank[x];
    }

    // xとyが同じグループに属するか判定
    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int V_NUM;
    int par[MAX_V], rank[MAX_V];
};

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

    tuple<ll, int, int> edges[M];
    for (int i = 0; i < M; ++i) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        edges[i] = make_tuple(c, --a, --b);
    }

    sort(edges, edges + M);
    UnionFind uf(N);

    // 最小全域木の辺とコスト
    vector<pair<int, ll>> path[N];
    ll total = 0;

    // Kruskalで最小全域木を構築
    for (int i = 0; i < M; ++i) {
        int a, b;
        ll c;
        tie(c, a, b) = edges[i];

        if (uf.same(a, b)) continue;
        uf.unite(a, b);
        total += c;
        path[a].push_back(make_pair(b, c));
        path[b].push_back(make_pair(a, c));
    }

    ll emax[N][N];
    // emax[i][j] = iからjのパス上で最大コストの辺のコスト

    // 各頂点始点のBFS
    for (int r = 0; r < N; ++r) {
        fill(emax[r], emax[r] + N, -1);
        emax[r][r] = 0;
        queue<int> que;
        que.push(r);

        while (!que.empty()) {
            int v = que.front();
            que.pop();

            for (auto p : path[v]) {
                int sv;
                ll cost;
                tie(sv, cost) = p;

                if (emax[r][sv] >= 0) continue;
                emax[r][sv] = max(emax[r][v], cost);
                que.push(sv);
            }
        }
    }

    // クエリ処理
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int s, t;
        cin >> s >> t;
        cout << total - emax[--s][--t] << endl;
    }
    return 0;
}


Measured memory_bytes: 132992
#n = int(input())
#m = int(input())
#k = int(input())
n, x = map(int, input().split())
#n, m, k = map(int, input().split())
l = list(map(int, input().split()))
#table = []
'''
for i in range h:
    temp = list(map(int, input().split()))
    table.append(temp)
'''
d = 0
count = 1
for i in range(n):
    d += l[i]
    if d <= x:
        count += 1
    else:
        break
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int  MAX  = 5;
int main(){
	ll  N;
	
	cin >> N;
	ll A[MAX];
	
	REP(i,MAX){
		cin >> A[i];
	}
	
	
	
	
    sort(A, A + 5);   
	ll ans = N/ A[0]  + 4;
	if(N % A[0] != 0) ++ans;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
int main(){
    int n; cin >> n;
    string s[n+1];
    for(int i=0; i<n; ++i){cin >> s[i];}
    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i=0; i<n; ++i){
        if(s[i]=="AC"){ac++;}
        else if(s[i]=="WA"){wa++;}
        else if(s[i]=="TLE"){tle++;}
        else{re++;}
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main () {
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll T = N;
    for(int i = 0; i < N - 1; i++){
        if(S.at(i) == S.at(i + 1)){
            T--;
        }
    }
    cout << T << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

// 素数判定
// から派生して、最初の約数を返す
int nextPrime(ll a)
{
    if (a == 1) return 1;
    for (ll i = 2; i * i <= a; i++)
	{
        if(a % i == 0) return i;
    }
    return -1;
}

void solve()
{
	ll n;
	cin >> n;

	ll first_prime = nextPrime(n);
	if (first_prime <= 0)
	{
		cout << 1;
		return;
	}
	if (first_prime == 1)
	{
		cout << 0;
		return;
	}

	map<ll, ll> mp;

	int ans = 0;
	for (int i = first_prime; i <= n; i = nextPrime(n)) 
	{
		if (i == 1) // nが割り切れた
		{
			break;
		}
		if (i == -1) // nが素数の時も割り切れた
		{
			mp[n]++;
			break;
		}
		while (n % i == 0)
		{
			mp[i]++;
			n /= i;
		}
	}

	// 素因数分解ができている
	for(auto& m : mp)
	{
		int i = 1;
		while(m.second >= i)
		{
			// n*(n+1)/2 
			m.second -= i;
			++i;
			++ans;
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  int n,cnt=0;
  cin >> n;
  vector<int> p=input(n);
  int x=p[0];
  for(int i=0;i<n;i++){
    if(p[i]<=x){
      cnt++;
    }
    x=min(x,p[i]);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}


int main(){
    int n; cin >> n;
    vector<int> v;
    for(int i = 0;i < n;i++){
        int x; cin >> x;v.push_back(x);
    }
    sort(v.begin(),v.end());
    int ans  = 0;
    for(int i = 0;i < n-1;i++){
        for(int j = i+1;j < n;j++){
            int c = lower_bound(v.begin(),v.end(),v[i]+v[j])-v.begin();
            ans += max(c-(j+1),0);
        }
    }
    cout << ans;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	int n,m,c=0,t=1,i,j,k,sum=0,ans,f=0,x,y;
	//cin>>t;
	while(t--){
		
		//vector<int> v;map<int,int> mp;set<int> st;
		cin>>s;
		if(s=="ABC") cout<<"ARC";
		else cout<<"ABC";
		//int a[n];rep(i,n) cin>>a[i];

	}
	return 0;
}




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

int main() {
  int n, m, a;
  long long int ans = 0;
  cin >> n >> m;
  priority_queue<int> que;
  for(int i = 0; i < n; ++i) {
    cin >> a;
    que.push(a);
  }
  for(int i = 0; i < m; ++i) {
    a = que.top();
    que.pop();
    que.push(a/2);
  }
  for(int i = 0; i < n; ++i) {
    ans += que.top();
    que.pop();
  }
  cout << ans << '\n';
}

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

int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  
  int x; scanf("%d",&x);
  map<int,int> event;
  for(int i=1;i<m;i++){
    int y; scanf("%d",&y);
    if(x<y){
      event[x]++; event[y]--;
    }else{
      event[x]--; event[y]++;
    }
    x = y;
  }

  ll ans = 0, num = 0;
  for(int i=1;i<n;i++){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(event.count(i))num += event[i];
    ans += min(num*a, num*b+c);
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 4144
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>
#include <climits>
#include <cmath>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

int main()
{
    ll a, b;
    cin >> a >> b;
    cout << ((b % a) == 0 ? (a + b) : (b - a));
    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	int ans = 700;
	for (int i = 0; i < 3; ++i)
		if (s[i] == 'o')
			ans += 100;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
// 2013/07/05 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n, p;
		cin >> n >> p;

		if(n==0 && p==0)
			break;

		int B = p;
		int C[50] = {0};

		for(int i=0; ; i=(i+1)%n){
			if(B>0){
				C[i]++;
				B--;
			}
			else{
				B = C[i];
				C[i] = 0;
			}

			if(C[i]==p){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

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

int main()
{
    long long int n,i,j,k;
    cin>>n>>k;

    long long int h[n];

    for(i=0;i<n;i++)
        cin>>h[i];

    long long int dp[n];

    for(i=0;i<n;i++)
        dp[i]=1e14;
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=1;j+i<n&&j<=k;j++)
            dp[i+j]=min(dp[i+j],dp[i]+(long long int)abs(h[i]-h[i+j]));
    }

    cout<<dp[n-1];
}


Measured memory_bytes: 1792
import heapq
n,m=map(int,input().split())
a=[0]*n
b=[]
c=[]

#
def make_num_str_pair(s):
    return str(s[0]).zfill(6)+str(s[1]).zfill(6)
#heapqで年の順番にして突っ込んで、その順で取り出して該当のaの要素を+して、strでzfill使いながらくっつける

for i in range(m):
    p,y=map(int,input().split())
    b.append([p,y,i])
b.sort(key=lambda x: x[1])
for i in range(m):
    a[b[i][0]-1]+=1
    b[i][1]=a[b[i][0]-1]
b.sort(key=lambda x: x[2])
for i in range(m):
    print(make_num_str_pair(b[i]))


Measured memory_bytes: 26664
#include<iostream>
using namespace std;
int main(){
	int a[3];
	while(cin>>a[0]>>a[1]>>a[2]){
		for(int i=0;i<3;i++){
			for(int j=i+1;j<3;j++){
				if(a[i]>a[j]){
					int temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}
		cout<<a[0];
		for(int i=1;i<3;i++)
			cout<<" "<<a[i];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
signed main() {
	string s;
	cin >> s;
	int ans = (int)s.size();
	rep(i, s.size()-1) {
		if(s[i]!=s[i+1])ans = min(ans, max(i+1, (int)s.size() - i - 1));
	}
	cout << ans << endl;
	END;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
using namespace std;
using namespace __gnu_pbds;
using ll = long long;

#define     _test int _TC; cin >> _TC; while(_TC--)
#define     CS(x) cout << "Case " << x << ": ";
#define     precision(n) cout << fixed << setprecision(n);
#define     Clear(a, b) memset(a, b, sizeof(a))
#define     sq(x) ((x) * 1LL * (x))
#define     eb emplace_back
#define     all(_n) _n.begin(), _n.end()
#define     rall(_n) _n.rbegin(), _n.rend()
#define     endl "\n"
#define     show(x) cout << x << endl
#define     nl cout << endl
#define     sz(x) int(x.size())
#define     gcd(a, b) __gcd(a, b)
#define     lcm(a, b) (abs((a) * (b)) / gcd(a, b))
#define     parity(a, b) ((a&1) ^ (b&1))
#define     make_unique(x) sort(all((x))); (x).erase(unique(all((x))), (x).end())
#define     IN(a) for(auto &it : a) cin >> it

template <typename T> void print (T t){ for(const auto &it : t) cout << it << ' '; nl; }
template <typename T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key find_by_order

const    double Pi = acos(-1.0);
const    int Mod = 1e9 + 7;
const    int Inf = 1 << 30; // INT_MAX = (1LL << 31) -1 // Inf -> 1e9
const    int Maxx = 1e6 + 10;

/************************************[Code Starts Here]************************************/


void _case()
{
    string s, l, r; cin >> s;
    int q; cin >> q;
    int t, f; char c; bool rev = 0;
     
    while (q--) {
        cin >> t;
        if (t == 1) {
            rev ^= 1;
        } else {
            if (rev) {
                cin >> f >> c;
                if (f == 1) r.push_back(c);
                else l.push_back(c);
            } else {
                cin >> f >> c;
                if (f == 2) r.push_back(c);
                else l.push_back(c);
            }
        }
    }
    reverse(all(l));
    string ans = l + s + r;
    if (rev) reverse(all(ans));
    show(ans);
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    _case();
    return 0;
}




Measured memory_bytes: 1300
//解説AC
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main(){
  int H,W; cin >> H >> W;
  int dx[4] = {1,0,-1,0};
  int dy[4] = {0,1,0,-1};
  
   vector<string> A(H);
   vector<vector<int>> dist(H,vector<int>(W,-1));
  // -1 は未到達を表す
  
  for(int i = 0; i < H; i++){ cin >> A[i];}
  
  queue<pair<int,int>> Q;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if( A[i][j] == '#'){ Q.push(make_pair(i,j)); dist[i][j] = 0;}
                                  }}
                                  
    while(!Q.empty()){
      pair<int,int> p = Q.front();
      Q.pop();
      int s = p.first;
      int t = p.second;
      for(int k = 0; k < 4; k++){
        if( s + dx[k] < 0 || s + dx[k] >= H || t + dy[k] < 0 || t + dy[k] >= W){
          continue;}
        if( dist[ s + dx[k]][ t + dy[k] ] == -1){
          dist[ s + dx[k]][t + dy[k]] = dist[s][t] + 1;
         Q.push(make_pair( s+dx[k] ,t + dy[k]));}}}
                
                int M = 0;
     for(int i = 0; i < H; i++){
       for(int j = 0; j < W; j++){
         M = max( M, dist[i][j]);}}
                
                cout << M << endl;
                return 0;}


Measured memory_bytes: 13456
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll u,a,b,c,d,t,ans,MAX=1LL<<60;
vector<ll>v;

int main(void){
    cin>>u>>a>>b>>c;
    for(int i=0;i<u;i++){
        cin>>d;
        v.push_back(d);
    }
    for(int i=0;i<(1<<(2*u));i++){
        ll uu=u;
        ans=0;
        vector<ll> vv={0,0,0};
        t=i;
        while(t){
            if(t>=(1<<(2*uu-2))){
                if(t!=0){
                    if(vv[t/(1<<(2*uu-2))-1]>0)ans+=10;
                    vv[t/(1<<(2*uu-2))-1]+=v[uu-1];
                }
                t%=(1<<(2*uu-2));
            }
            uu-=1;
        }
        if(vv[0]*vv[1]*vv[2]==0)continue;
        ans+=abs(vv[0]-a)+abs(vv[1]-b)+abs(vv[2]-c);
        if(MAX>ans){
            MAX=ans;
        }
        //cout<<vv[0]<<" "<<vv[1]<<" "<<vv[2]<<endl;
    }
    cout<<MAX<<endl;
}


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

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;

	if (y + r <= h && x + r <= w && y - r >= 0 && x- r >= 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bs binary_search
#define pb push_back
#define pp pair<int,int>
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
int main()
{
    fastio
    ll n,i,s=0; cin>>n; ll a[n];
    for(i=0;i<n;i++) cin>>a[i], s^=a[i];
    for(i=0;i<n;i++) cout<<(s^a[i])<<" ";
    return 0;
}

Measured memory_bytes: 5112