akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>

using namespace std;

long long a[3001],n,s[3001];
long long f[3001][3001];

int main()
{
    //freopen("INPUT.TXT","r",stdin);
    //freopen("OUTPUT.TXT","w",stdout);
    cin>>n;
    for(long long i=1; i<=n; ++i) cin>>a[i];
    s[0]=0;
    s[1]=a[1];
    for(long long i=2; i<=n; ++i) s[i]=s[i-1]+a[i];
    for(long long i=1; i<=n; ++i) f[i][i]=a[i];
    for(long long i=n-1; i>=1; --i) {
        for(long long j=i+1; j<=n; ++j)
            if (abs(i-j)==1) f[i][j]=max(a[i],a[j]);
            else f[i][j]=(s[j]-s[i-1])-min(f[i+1][j],f[i][j-1]);
    }
//    for(long long i=1; i<=n; ++i) {
//        for(long long j=1; j<=n; ++j)
//            cout<<f[i][j]<<" ";
//        cout<<"\n";
//    }
    cout<<f[1][n]*2-s[n];
    return 0;
}


Measured memory_bytes: 70016
// ------------------------------------
// Date:2018/ 3/ 7
// Problem:ABC 077 Rotation a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  char c[2][3];
  REP(hi, 2) {
    REP(wi, 3) {
      cin >> c[hi][wi];
    }
  }

  bool ok = true;
  REP(hi, 2) {
    REP(wi, 3) {
      if (c[hi][wi] != c[1 - hi][2 - wi]) ok = false;
    }
  }

  cout << (ok ? "YES" : "NO" ) << endl;
  
  return 0;
}



Measured memory_bytes: 256
N = int(input())
All = [list(map(int, input().split())) for _ in range(N)]
pre_x = 0
pre_y = 0
pre_t = 0

can = True
for n in range(N):
    can2 = False
    T = All[n][0] - pre_t
    d = abs(All[n][1] - pre_x) + abs(All[n][2] - pre_y)
    # print(T, d)
    if d <= T and T % 2 ==  d % 2:
        can2 = True

    if can2 == False:
        can = False
        break

    pre_t = All[n][0]
    pre_x = All[n][1]
    pre_y = All[n][2]

if can == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27380
#include <stdio.h>

#define NUM 3

int main(void){
	int num;
	int output;
	int i;
	
	scanf("%d", &num);
	
	output = num;
	for(i=0 ; i < NUM-1 ; i++){
		output *= num;
	}
	printf("%d\n", output);
	
	return 0;
}

Measured memory_bytes: 596
#C
import sys
input=sys.stdin.readline

def main():
    h,w,k=map(int,input().split())
    Ss=[input().strip() for _ in range(h)]
    Ans=[[0]*w for _ in range(h)]
    num=0
    flag1=False
    for i,S in enumerate(Ss):
        if set(S)=={'.'}:
            if i==0:
                flag1=True
            else:
                for j,s in enumerate(S):
                    Ans[i][j]=Ans[i-1][j]
        else:
            flag2=False
            num+=1
            for j,s in enumerate(S):
                if not flag2:
                    Ans[i][j]=num
                    if s=='#':
                        flag2=True
                else:
                    if s=='#':
                        num+=1
                    Ans[i][j]=num
        Ans2=[[0]*w for _ in range(h)]
        tmp=[]
        for i in reversed(range(h)):
            ans=Ans[i]
            if set(ans)=={0}:
                Ans2[i]=tmp[:]
            else:
                Ans2[i]=ans[:]
                tmp=ans[:]
            
    for ans in Ans2:
        print(*ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 124888
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define Cerr(x) cerr << (x) << endl
#define fi first
#define se second

ll n, cnt, ans, a, b, c[ohara], d, tmp, tmpp, m, h, w, x, y, sum, pos, k, s[ohara], t[ohara], C, imo[ohara];
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
bool fl;
struct edge
{
    int to, cost;
};
pair<ll, pair<ll, ll>> p[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> C;
    rep(i, n) cin >> s[i] >> t[i] >> c[i], s[i] *= 2, t[i] *= 2, s[i]--;
    rep(i, n)
    {
        p[i] = make_pair(c[i], make_pair(s[i], t[i]));
    }
    sort(p, p + n);
    ll now = 0;
    rep(i, n)
    {
        now = i;
        ll from, to;
        from = p[i].se.fi;
        to = p[i].se.se;
        while (1)
        {
            if (p[now].fi != p[now + 1].fi)
                break;
            ll ffrom, tto;
            ffrom = p[now + 1].se.fi;
            tto = p[now + 1].se.se;
            if (to >= ffrom)
            {
                to = tto;
                now++;
            }
            else
                break;
        }
        i = now;
        imo[from]++;
        imo[to]--;
    }
    rrep(i, 1, ohara)
    {
        imo[i] += imo[i - 1];
    }
    rep(i, ohara)
    {
        ans = max(ans, imo[i]);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 20736
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(A+B > C+D) cout << "Left" << endl;
    else if(A+B < C+D) cout << "Right" << endl;
    else cout << "Balanced" << endl;
    
    return 0;
}

Measured memory_bytes: 256
///"    "\\\

# include <bits/stdc++.h>

# define pb push_back

using namespace std;

int k , z = 0 , o , p = 0 ;

	
int main() {

	int a , b ;
	cin >> a >> b ;
	cout << max(max((a-b),(a+b)),(a*b));

}

///"    "\\\

Measured memory_bytes: 256
import Data.Bool
main = interact $ bool "Alice" "Brown" . sol . map read . words
sol [a,b] = abs (a-b)<2
{-
import Data.List
sol [a,b] = grundy (a,b)==0
grundy = mex . fmap grundy . move
mex = head . ([0..] \\)
move (a,b)
  | max a b<2 = []
  | otherwise = [(a-2*i,b+i) | i <- [1..a `div` 2]] ++ [(a+j,b-2*j) | j <- [1..b `div` 2]]
-}

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#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++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int main()
{
    int D,T,S;
    cin >> D >> T >> S;
    if(D<=T*S)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

void test_case() {
	//int a[100], n;
	//cin >> n;
	//for(int i = 0; i < n; ++i) {
		//cin >> a[i];
	//}
	int n;
	cin >> n;
	cout << n + (n * n) + (n * n * n) << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//int T;
	//cin >> T;
	//while(T--) {
		//test_case();
	//}
	test_case();
}


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

int main() {
	int N, d[100], count = 1;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	sort(d, d + N);
	for (int i = 0; i < N - 1; i++) {
		if (d[i] != d[i + 1]) count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	string s;
	cin>>n>>s;
	int ans=1;
	for(int i=1; i<n; i++){
		if(s[i]==s[i-1]){
			continue;
		}
		else{
			ans++;
		}
	}
	cout<<ans;
	return 0;

}

Measured memory_bytes: 3664
#include <iostream>
#include <string.h>
using namespace std;

int n;
int a[9][9];
bool b[9][9], c[9];

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		memset(b, 0, sizeof(b));

		for (int j = 0; j < 9; j++)
			for (int k = 0; k < 9; k++)
				cin >> a[j][k];

		for (int j = 0; j < 9; j++) {
			memset(c, 0, sizeof(c));
			for (int k = 0; k < 9; k++) {
				if (c[a[j][k] - 1]) {
					b[j][k] = 1;
					int u = k - 1;
					while (u > 0 && a[j][u] != a[j][k])
						u--;
					b[j][u] = 1;
				}
				else
					c[a[j][k] - 1] = 1;
			}
		}

		for (int k = 0; k < 9; k++) {
			memset(c, 0, sizeof(c));
			for (int j = 0; j < 9; j++) {
				if (c[a[j][k] - 1]) {
					b[j][k] = 1;
					int u = j - 1;
					while (u > 0 && a[u][k] != a[j][k])
						u--;
					b[u][k] = 1;
				}
				else
					c[a[j][k] - 1] = 1;
			}
		}

		for (int s = 0; s < 9; s++) {
			memset(c, 0, sizeof(c));
			for (int t = 0; t < 9; t++) {
				int j = t / 3 + (s / 3) * 3, k = t % 3 + (s % 3) * 3;

				if (c[a[j][k] - 1]) {
					b[j][k] = 1;
					int u = t - 1, v = u / 3 + (s / 3) * 3, w = u % 3 + (s % 3) * 3;
					while (u > 0 && a[v][w] != a[j][k]) {
						u--;
						v = u / 3 + (s / 3) * 3;
						w = u % 3 + (s % 3) * 3;
					}
					b[v][w] = 1;
				}
				else
					c[a[j][k] - 1] = 1;
			}
		}

		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				if (b[j][k])
					cout << "*";
				else
					cout << " ";

				cout << a[j][k];
			}
			cout << endl;
		}

		if (i != n - 1)
			cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3052
import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))

already = [False] * N
step = 0
now = 1
count = 0
while(already[now-1] != True):
    already[now - 1] = True
    now = A[now - 1]
    count += 1
    if count == K:
      print(now)
      exit(0)
loop = 0
cycle = 0
if(now == 1):
    step = 0
    cycle = count
    loop = K % cycle
else:
    step = 0
    temp = 1
    while(temp != now):
        temp = A[temp - 1]
        step += 1
    cycle = count - step
    loop= (K - step) % cycle

temp = 1
for i in range(step + loop):
    temp = A[temp - 1]
print(temp)


Measured memory_bytes: 32284
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val d = sc.nextInt()
    val c = (0 until 26).map { sc.next().toInt() }
    val s = (0 until d).map {
        (0 until 26).map { sc.next().toInt() }
    }
    println(problemintroduction_to_heuristics_contest(d, c, s))
}

fun problemintroduction_to_heuristics_contest(
    d: Int,
    c: List<Int>,
    s: List<List<Int>>
): String {
    val last = LongArray(26) { 0 }
    val satisfactions = LongArray(26) { 0 }
    val ans = IntArray(d) { 1 }
    for (i in 0 until d) {
        val contest = s[i].indexOf(s[i].max()) + 1
        ans[i] = contest
        satisfactions[contest - 1] += s[i][contest - 1].toLong()
        last[contest - 1] = i + 1L
        for (j in 0 until 26) {
            satisfactions[j] -= c[j] * 26 * (d - last[j])
        }
//        debugLog(last.toList())
//        debugLog(satisfactions.toList())
    }
    return ans.joinToString("\n")
}

Measured memory_bytes: 47824
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n, a, b, ans;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> a >> b;
    while (n > 0) {
        int t = n, sum = 0;
        while (t > 0) {
            sum += (t%10);
            t /= 10;
        }
        if (a <= sum && sum <= b) {
            ans += n;
        }
        n--;
    }
    printf("%d\n", ans);
    return 0;
}


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

from math import ceil
def comb(n,r):
    ans = 1
    for i in range(r):
        ans *= n-i
    for i in range(1,r+1):
        ans //= i
    return ans

odd,even = 0,0
for a in A:
    if a%2==0:
        even += 1
    else:
        odd += 1

if P%2==0:
    ans = 0
    for i in range(int(odd/2)+1):
        ans += comb(odd,2*i)
else:
    ans = 0
    for i in range(1,ceil(odd/2)+1):
        ans += comb(odd,2*i-1)
ans *= 2**even
print(ans)

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


int N;
map<long, bool> m;


int main() {
    cin >> N;
    for(int i = 0; i < N; i++) {
        long tmp;
        cin >> tmp;
        m[tmp] = !m[tmp];
    }

    int count = 0;
    for(auto i = m.begin(); i != m.end(); i++) {
        if(i->second)
            count++;
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;
#define m 1000000007

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

    int a, b, k; cin>>a>>b>>k;
    vector<int> x;
    for(int i = min(a, b); i>=1; i--){
        if(a%i==0 && b%i==0) x.push_back(i);
    }
    cout<<x[k-1]<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end() 

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    int H,A;
    cin>>H>>A;
    if(H%A==0){
        cout<<H/A<<endl;
    }else{
        cout<<H/A+1<<endl;
    }
    return 0;
}


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

vector<ll> people;
vector<ll> combination;
ll min1, n, m, x, matrix[20][20];
void verif(vector<ll> v, ll& min1, ll x, ll m)
{
    int Verif=0, rez[20]= {0};
    for (int i = 0; i < v.size(); ++i)
    {
        for(int j=1; j<=m+1; j++)
            rez[j]=rez[j]+matrix[v[i]][j];
    }
    for(int j=2; j<=m+1; j++)
    {
        if(rez[j]<x)
        {
            Verif=1;
            break;
        }
    }
    if(Verif==0 && min1>rez[1])
    {
        min1=rez[1];
        // cout<<min1<<' '<<x<<' '<<m<<'\n';
    }

}
void go(ll offset, ll k, ll& min1, ll x, ll m)
{
    if (k == 0)
    {
        verif(combination, min1, x, m);
        return;
    }
    for (int i = offset; i <= people.size() - k; ++i)
    {
        combination.push_back(people[i]);
        go(i+1, k-1, min1, x, m);
        combination.pop_back();
    }
}

int main()
{
    cin>>n>>m>>x;
    min1=NMAX;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m+1; j++)
            cin>>matrix[i][j];
    }
    for (int i = 1; i <= n; ++i)
        people.push_back(i);

    for(int i=1; i<=n; i++)
        go(0, i, min1, x, m);
    if(min1!=NMAX)
        cout<<min1;
    else
        cout<<"-1";
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int M = 1 << sc.nextInt();
		int K = sc.nextInt();
		if(M == 2 && K == 0)
			System.out.println("0 0 1 1");
		else if(K >= M || M == 2)
			System.out.println(-1);
		else {
			StringBuilder ans = new StringBuilder();
			StringBuilder b = new StringBuilder();
			for(int i = 0; i < M; i++)
				if(i != K)
					b.append(i+" ");
			StringBuilder c = new StringBuilder();
			for(int i = M-1; i >= 0; i--)
				if(i != K)
					c.append(i+" ");
			ans.append(b).append(K + " ").append(c).append(K);
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 58340
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
int main() {
	// your code goes here
	int n,a,k;
	cin>>n>>k;
	int d[k];
	set<int >s;
	for(int i=0;i<k;i++){
		cin>>d[i];
	for(int j=0;j<d[i];j++){
		cin>>a;
		s.insert(a);
	}
	}
	cout<<n-s.size()<<endl;
	return 0;
}

Measured memory_bytes: 3592
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val allP = mutableSetOf<Int>()
    val chkP = mutableSetOf<Int>()
    var pc = true

    fun sb(inp :Int): Set<Int> {
        var n = inp
        val s = Math.floor(Math.sqrt(n.toDouble())).toInt()
        val ret = mutableSetOf<Int>()
        if (!pc) {
            chkP.forEach {
                if (n % it == 0) {
                    ret.add(it)
                }
            }
        } else {
            if (n % 2 == 0) {
                ret.add(2)
                while (n % 2 == 0) {
                    n /= 2
                }            }
            var i = 3
            while (i <= s) {
                if (n % i == 0) {
                    ret.add(i)
                    while (n % i == 0) {
                        n /= i
                    }
                }
                i += 2
            }
            if (n > s) ret.add(n)
        }
        return ret
    }
    fun gcd(a: Int, b: Int): Int {
        return if (a==1 || b== 1) 1
        else if (b == 0) a
        else if (a < b) gcd(a, b % a)
        else gcd(b, a % b)
    }

    var allGCD = -1
    readLine()!!.split(' ').map { s->
        if (pc) {
            val p = sb(s.toInt())
            p.forEach {
                if (it in allP) {
                    pc = false
                    chkP.add(it)
                }
                allP.add(it)
            }
        }
        allGCD = if (allGCD != -1) gcd(allGCD, s.toInt())
        else s.toInt()
    }

    println(
        when {
            pc -> "pairwise coprime"
            allGCD == 1 -> "setwise coprime"
            else -> "not coprime"
        }
    )
}


Measured memory_bytes: 131944
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,k,ans=-LINF;
int p[5555],c[5555];
signed main(){
	cin>>n>>k;
	rep(i,n)cin>>p[i];
	rep(i,n)cin>>c[i];
	int mem[5555];
	rep(i,n){
		int score=0,score2=0,pos=i,cnt=0,sans=-LINF;
		do{
			//cout<<pos<<endl;
			pos=p[pos]-1;
			score+=c[pos];
			cnt++;
			sans=max(sans,score);
			mem[cnt]=sans;
			//cout<<i<<";";DEB(score)END
		}while(pos!=i);
		if(0<=mem[cnt]){
			if(k%cnt==0)ans=max(ans,sans+score*(k/cnt-1));
			score=score*(k/cnt);
			score+=mem[k%cnt];
			ans=max(ans,score);
			//cout<<score<<endl;
		}
		if(k/cnt>0)ans=max(ans,sans);
		else ans=max(ans,mem[k%cnt]);
		
		
		//rep(i,cnt+1)cout<<mem[i]<<" ";
		//cout<<endl;
		//cout<<i<<";";DEB(score)END
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3744
#include <stdio.h>
int main(void){
    char a;
    
    while(1){
    scanf("%c",&a);
    if(a=='\n') {
        printf("\n");
        break;
    }
    if('A'<=a&&a<='Z') printf("%c",a+32);
    else if('a'<=a&&a<='z') printf("%c",a-32);
    else printf("%c",a);
    }
    
    return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#define  si(a)       scanf("%d",&a)
#define  sl(a)       scanf("%lld",&a)
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b)
#define  queues      priority_queue
#define mod  1000000007
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
#define fi  first
#define se  second
#define mp  make_pair
#define  pb push_back
#define mem(a,b) memset(a,b,sizeof(a));
typedef long long ll;
const ll maxn=10000006;
//priority_queue<ll,vector<ll >,greater<ll > >q;
const ll INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
//__builtin_popcount
//priority_queue
inline char nc()   //快的一批的fread快读
{
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline ll read()
{
    char ch=nc();
    ll sum=0;
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum;
}
bool cmp(ll a,ll b)
{
    return a>b;
}
ll pri[100003];
ll sum1[100003];
int b[maxn];
ll sum;
void so()
{
  for(ll i=2;i<=100003;i++)
  {
      if(!b[i])pri[++sum]=i;
      for(ll j=1;j<=sum;j++)
      {
          if(i*pri[j]>100000)break;
          b[i*pri[j]]=1;
           if(i%pri[j]==0)break;
      }
  }
  cout<<sum<<endl;
}
int main()
{
   int a,b;
   cin>>a>>b;
   cout<<max(a+b,max(a*b,a-b));
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Edge{
	Edge(int arg_to,int arg_dist){
		to = arg_to;
		dist = arg_dist;
	}
	int to,dist;
};

struct Info{
	Info(int arg_node_id,int arg_sum_dist){
		node_id = arg_node_id;
		sum_dist = arg_sum_dist;
	}
	bool operator<(const struct Info &arg) const{

		return sum_dist > arg.sum_dist; //総距離の昇順(PQ)
	}

	int node_id,sum_dist;
};

int V,E,start;
int min_dist[SIZE];
vector<Edge> G[SIZE];

int main(){

	scanf("%d %d %d",&V,&E,&start);

	int from,to,dist;

	for(int i = 0; i < E; i++){

		scanf("%d %d %d",&from,&to,&dist);
		G[from].push_back(Edge(to,dist));
	}

	for(int i = 0; i < V; i++){

		min_dist[i] = BIG_NUM;
	}

	priority_queue<Info> Q;
	min_dist[start] = 0;

	Q.push(Info(start,0));

	while(!Q.empty()){

		if(Q.top().sum_dist > min_dist[Q.top().node_id]){

			Q.pop();

		}else{

			for(int i = 0; i < G[Q.top().node_id].size(); i++){

				int next_node = G[Q.top().node_id][i].to;
				int next_dist = Q.top().sum_dist+G[Q.top().node_id][i].dist;

				if(min_dist[next_node] > next_dist){
					min_dist[next_node] = next_dist;
					Q.push(Info(next_node,next_dist));
				}
			}
			Q.pop();
		}
	}

	for(int i = 0; i < V; i++){

		if(min_dist[i] == BIG_NUM){

			printf("INF\n");

		}else{

			printf("%d\n",min_dist[i]);
		}
	}

	return 0;
}




Measured memory_bytes: 13056
package main

import (
        "fmt"
)

func solution(n int, s string) int {
        out := 0

        for i := 0; i < 1000; i++ {
                b := [3]byte{byte(i / 100), byte((i / 10) % 10), byte(i % 10)}
                f := 0
                for j := 0; j < n; j++ {
                        if s[j] == ('0' + b[f]) {
                                f++
                        }
                        if f == 3 {
                                break
                        }
                }
                if f == 3 {
                        out++
                }
        }
        return out
}

func main() {
        var n int
        var s string
        fmt.Scan(&n, &s)
        fmt.Println(solution(n, s))
}

Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;

int main() {
  int N; cin >> N;
  int M = N / 2;

  /* <数列の数字, それが数列の（奇・偶）数番目に出てきた回数 */
  map<int, int> odd, even;
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    odd[a]++;
    even[b]++;
  }

  /* 奇数番目に一番・二番目に多く出てきた数字、偶数（略） */
  int odd1 = 0, odd2 = 0, even1 = 0, even2 = 0;
  for (int i = 1; i < MAX; i++) {
    if (odd[odd1] < odd[i]) {
      odd2 = odd1;
      odd1 = i;
    } else if (odd[odd2] < odd[i]) {
      odd2 = i;
    }
    if (even[even1] < even[i]) {
      even2 = even1;
      even1 = i;
    } else if (even[even2] < even[i]) {
      even2 = i;
    }
  }

  int ans;
  if (odd1 != even1) {
    ans = M - odd[odd1] + M - even[even1];
  } else {
    ans = min(M - odd[odd1] + M - even[even2], M - odd[odd2] + M - even[even1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9600
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
ans = (pow(10,N)-2*pow(9,N)+pow(8,N))%p
print(ans)

Measured memory_bytes: 61972
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in).useDelimiter("[,\n]");
		
		int a = 0;
		int b = 0;
		int o = 0;
		int ab = 0;
		
		while (sc.hasNext())
		{
			sc.nextInt();
			String str = sc.next();
			if (str.equals("A"))
			{
				a++;
			}
			else if (str.equals("B"))
			{
				b++;
			}
			else if (str.equals("O"))
			{
				o++;
			}
			else if (str.equals("AB"))
			{
				ab++;
			}
		}
		System.out.println(a);
		System.out.println(b);
		System.out.println(ab);
		System.out.println(o);
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <algorithm>
#include <functional>

int N,M;
//(+,+,+),(+,+,-),(+,-,+),(+,-,-)
//(-,+,+),(-,+,-),(-,-,+),(-,-,-)
long long x[100000];
long long y[100000];
long long z[100000];

long long sum[100000];
int main(){
        long long cnt = 0;
        scanf("%d %d",&N,&M);

        for(int i = 0; i < N; i++){
                scanf("%lld %lld %lld", x+i, y+i, z+i);
        }
        long long maxtotal = 0;
        for(int d = 0; d < 8; d++){
                char dx=(d&4)?1:-1;
                char dy=(d&2)?1:-1;
                char dz=(d&1)?1:-1;
                for(int i = 0; i < N; i++){
                        sum[i] = dx*x[i]+dy*y[i]+dz*z[i];
                }
                std::sort(sum,sum+N,std::greater<long long>());
                long long total = 0;
                for(int i = 0; i < M; i++){
                        total += sum[i];
                }
                if(maxtotal < total) maxtotal = total;
        }

        printf("%lld\n",maxtotal);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String t = sc.next();
		HashMap<String, Integer>sMap = new HashMap<String, Integer>();
		HashMap<String, Integer>tMap = new HashMap<String, Integer>();

		for (int i=0; i<s.length(); i++){
			String sSub = s.substring(i, i+1);
			if (sMap.containsKey(sSub)){
				sMap.put(sSub, sMap.get(sSub) + 1);
			} else {
				sMap.put(sSub, 1);
			}
			String tSub = t.substring(i, i+1);
			if (tMap.containsKey(tSub)){
				tMap.put(tSub, tMap.get(tSub) + 1);
			} else {
				tMap.put(tSub, 1);
			}
		}
		int sCount[] = new int[sMap.size()];
		int tCount[] = new int[tMap.size()];
		java.util.Iterator<String> it = sMap.keySet().iterator();
		int j = 0;
		while (it.hasNext()){
			String key = it.next();
			sCount[j] = sMap.get(key);
			j++;
		}
		it = tMap.keySet().iterator();
		j = 0;
		while (it.hasNext()){
			String key = it.next();
			tCount[j] = tMap.get(key);
			j++;
		}
		Arrays.sort(sCount);
		Arrays.sort(tCount);
		if (Arrays.equals(sCount, tCount)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 46384
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

int cnt1[300000]{}, cnt2[300000]{};
bool isok[300000];

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

    ll N, K, C;
    cin >> N >> K >> C;
    string s;
    cin >> s;

    FOR(i, 1, N + 1) {
        if(s[i - 1] == 'x')
            cnt1[i] = cnt1[i - 1];
        else {
            if(i > C)
                cnt1[i] = cnt1[i - C - 1] + 1;
            else
                cnt1[i] = 1;
            if(cnt1[i] == cnt1[i - 1]) isok[i] = 1;
        }
    }
    for(int i = N; i > 0; i--) {
        if(s[i - 1] == 'x')
            cnt2[i] = cnt2[i + 1];
        else {
            cnt2[i] = cnt2[i + C + 1] + 1;
            if(cnt2[i] == cnt2[i + 1]) isok[i] = 1;
        }
    }

    FOR(i, 1, N + 1) {
        if(s[i - 1] == 'x') continue;
        if(!isok[i] && cnt1[i] + cnt2[i] <= K + 1) cout << i << endl;
    }

    return 0;
}

Measured memory_bytes: 3348
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int main() {
	int n,a[110][2]={},u[110]={},d[110]={},dsum=0;
	cin>>n;
	rep(j,0,2)rep(i,0,n){
		cin>>a[i][j];
		if(j==1)dsum+=a[i][j];
	}
	u[0]=a[0][0],d[0]=dsum;
	int ans=u[0]+d[0];
	rep(j,0,2){
		rep(i,1,n){
			if(j==0)u[i]=u[i-1]+a[i][j];
			else d[i]=d[i-1]-a[i-1][j];
			ans=max(ans,u[i]+d[i]);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

vector<bool> eratosmake(int n,vector<bool> num){
    //整数を列挙して素数の候補とする
    for(int i = 0; i < n; i++) num[i] = true;
    //0と1を消す
    num[0] = num[1] = false;
    //iを残してiの倍数を消していく
    for(int i = 2; i < n; i++){
        if(num[i]){
            for(int j = i + i; j < n; j += i){
                num[j] = false;
            }
        }
    }
    return num;
}

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    int n;
    cin>>n;
    vector<bool> v(55560);
    v=eratosmake(55560,v);
    int ans=0;
    int i=1;
    while(n>0){
        if(v[i]&&i%5==1){
            cout<<i<<endl;
            n--;
        }
        i++;
    }
    
//////////////////////////////////////////////////////
return 0;}


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

int main() {
    string s;cin>>s;
    for(int i=0;i<s.size();++i){
        if(i%2==0 && s[i]=='L'){
            cout<<"No"<<endl;
            return 0;
        }
        if(i%2==1 && s[i]=='R'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x, y;std::cin >> x >> y;
  vll num(13, 0);
  num[1]=num[3]=num[5]=num[7]=num[8]=num[10]=num[12]=1;
  num[4]=num[6]=num[9]=num[11]=2;
  num[2] = 3;
  if(num[x]==num[y]) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for (int i=0;i<N;i++) {
    cin>>vec.at(i);
  }
  
  int sum=0;
  for (int i=0;i<N;i++) {
    sum+=vec.at(i);
  }
  
  double q = sum/2;
  int p=0;
  int i=0;
  while (p<=q) {
  p+=vec.at(i);
  i++;
  }
  
  int a=0;
  for (int j=0;j<i;j++) {
    a+=vec.at(j);
  }
  int b=0;
  for (int j=0;j<i-1;j++) {
    b+=vec.at(j);
  }
  int x=a-(sum-a),y=b-(sum-b);
  if (x<0) {
    x*=-1;
  }
  if (y<0) {
    y*=-1;
  } 
  if (x<y) {
  cout<<x<<endl;
  }
  else {
    cout<<y<<endl;
  }
  
  
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	ll n,x;cin >> n >> x;
	
	vector<ll> v(n);
	
	REP(i,n)cin >> v[i];
	
	sort(ALL(v));
	
	int ans = 0;
	
	REP(i,n){
		if(x >= v[i])ans++;
		x -= v[i];
	}
	
	if(x > 0)ans--;
	
	cout << ans << endl;
	
	return 0;
}

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

    A = [0]
    for i in range(N):
        A.append(int(input()))

    A_stopped = [False for i in range(N+1)]

    b = 1
    count = 0
    while(True):
        A_stopped[b] = True
        b = A[b]
        count += 1
        #print("{} Now_point: {}".format(count,b))
        if b==2:
            print(count)
            return 0
        elif A_stopped[b]:
            print("-1")
            return -1
            
game()

Measured memory_bytes: 7880
#include <iostream>
#include <vector>
#include <cstring>
#include <climits>
using namespace std;

int n, m;
int dp[402];
bool used[402];
vector<int> to[402], cost[402];

int solve(int id){
  if(id == n - 1) return 0;
  int &res = dp[id];
  if(res != -1) return res;

  used[id] = true;
  for(int i = 0; i < to[id].size(); i++){
    if(used[to[id][i]]) continue;
    res = max(res, solve(to[id][i]) + cost[id][i]);
  }
  used[id] = false;

  return res;
}

int main(){
  while(cin >> n >> m){
    for(int i = 0; i < n; i++){
      to[i].clear();
      cost[i].clear();
    }

    for(int i = 0; i < m; i++){
      int a, b, c;
      cin >> a >> b >> c;

      to[a].push_back(b);
      cost[a].push_back(c);
    }

    memset(dp, -1, sizeof(dp));
    memset(used, 0, sizeof(used));
    cout << solve(0) << endl;
  }
}

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

int main() {
  string s, t;
  cin >> s >> t;
  
  int sn = s.size();
  int tn = t.size();
  int ans = 0;
  for (int i = 0; i <= (sn - tn); ++i) {
    int temp_max = 0;
    for (int j = 0; j < tn; ++j) {
      if (s[i + j] == t[j]) ++temp_max;
    }
    ans = max(temp_max, ans);
  }
  cout << tn - ans << endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
const ll mod = 1e9+7;
const ll cfmod = 998244353;
const int MAXN = 1e5+5;

int a, b, c, n, m, k;
string s, s1, s2, t;

int32_t main() {
	cin >> n;
	vector<int> v(n);
	for(int &i : v)
		cin >> i;
	int i = 1;
	int j = 0, ans = 0;
	while(j < n) {
		if(v[j] != i) 
			ans++;
		else i++;
		j++;
	}
	if(i == 1) cout << -1 << endl;
	else cout << ans << endl;
}
		
			




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace std;
#define int long long int
#define double long double
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> new_data_set;
bool isprime(int n)
	{
    	if(n==1) return true;
    	for(int i = 2;i*i<=n;i++){
    		if(n%i==0) return false;
		}
		return true;
	}
int lcm(int a,int b){
	return (a*b)/__gcd(a,b);
}
int gcd(int a, int b) 
{ 
    if (b == 0){
    	return a;
	} 
    return gcd(b, a % b);  
      
} 
unsigned int factorial(unsigned int n) 
{ 
    if (n == 0) 
    return 1; 
    return n * factorial(n - 1); 
} 
const int inf=1e17+7;
int dsu[1000001],s[100005];
pair<int,int>pz[100001],po[100001];
void init(int n,int m){
	for(int i=1;i<=n;i++){
		dsu[i]=i;
		s[i]=1;
	}
}
int root(int x){
	while(dsu[x]!=x){
		x = dsu[x];
	}
	return x;
}
void uni(int x,int y){
	int p = root(x);
	int q = root(y);
	if(p==q){
		return;
	}
	else{
		if(s[p]<s[q]){
			s[q]+=s[p];
			dsu[p] = q;
		}
		else{
			s[p]+=s[q];
			dsu[q] = p;
		}
	}
}
int power(int x, unsigned int y)  
{  
    int res = 1;
    x = x ; 
    if (x == 0) return 0;  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x);   
        y = y>>1;  
        x = (x*x);  
    }  
    return res;  
}
bool visited[100001]={false};

//void dfs(int x){
//	visited[x]=true;
//	//ans.push_back(x);
//	//c[x]=1;
//	for(auto &child:graph[x]){
//		if(!visited[child]){
//			dfs(child);	
//			//c[x]+=c[child];
//		}
//	}
//}
signed main(){
	FAST
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	int dp[n];
	dp[0]=0;
	for(int i=1;i<n;i++){
		int temp = INT_MAX;
		for(int j=i-1;j>=max((int)0,i-k);j--){
			temp=min(temp,dp[j]+abs(arr[i]-arr[j]));
		}
		dp[i]=temp;
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1792
a,b,x = gets.split.map(&:to_f)

include Math

rad = (0.0..(PI/2)).bsearch do |rad|
  h = a * tan(rad)
  v =  h < b ? a * b - a * h / 2 : b * b / tan(rad) / 2
  v < (x / a)
end

puts rad / PI * 180


Measured memory_bytes: 1788
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        int K = in.nextInt();
        int[] p = new int[N];
        for (int n = 0; n < N; n++)
            p[n] = in.nextInt();
        Arrays.sort(p);
        int ans = 0;
        for (int i = 0; i < K; i++)
            ans += p[i];
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 32996
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int e;
  while(cin >> e,e){
    int mn = 1000000;
    for(int z = 0 ; z*z*z <= e ; z++ ){
      for(int y = 0 ; y*y + z*z*z <= e ; y++ ){
	int x = e - (z*z*z + y*y);
	int m = x + y + z;
	mn = min(m,mn);
      }
    }
    cout << mn << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))


;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))

;;本体
(defun main ()
  (let ((a (read)))
    (println (+ 24 (- 24 a)))))

#-swank(main)


Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
signed main(){
	int n;cin>>n;int anx=n;string s="";
	while(1){
		if(anx!=0)s+='a';else break;if(anx%26==0)anx=anx/26-1;
		else anx=anx/26;
	}
	int sum=0;
	while(n!=0){
	if(n%26==0)s[s.size()-1-sum]+=25;
	else s[s.size()-1-sum]+=n%26-1;
	sum++;	if(n%26==0)n=n/26-1;else n=n/26;
	}
	cout<<s<<"\n";
	}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
typedef long long ll;

int main() {
	ll N, K;
	cin >> N >> K;
	ll t = N % K;
	cout << min(t, K - t) << endl;
}


Measured memory_bytes: 3588
N, Q = map(int, input().split())

Tree = []
for _ in range(1, N):
    a, b = map(int, input().split())
    Tree.append([a, b])

Tree_sorted = sorted(Tree, key=lambda x:x[0])

P = []
X = []
for _ in range(Q):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

scores = [0 for _ in range(N + 1)]
for i in range(Q):
    scores[P[i]] += X[i]

for tree in Tree_sorted:
    scores[tree[1]] += scores[tree[0]]

for i, score in enumerate(scores):
    if i == 0:
        continue
    print(score, end=' ')


Measured memory_bytes: 64924
N = int(input())

if N % 2 == 1:
  print(0)
else:
  fives = 0
  twos = 0
  f = 10
  while (N // f != 0):
    fives += N // f
    f = f * 5
  t = 2
  while (N // t != 0):
    twos += N // t
    t = t * 2
  print(min(fives, twos))


Measured memory_bytes: 3060
// https://atcoder.jp/contests/abc082/tasks/arc087_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int gx, gy;
    cin >> gx >> gy;
    int cnt = 0;
    vector<int> vx, vy;
    s += 'T';
    bool bt = false;
    int fv = -1;
    for (auto &x : s) {
        if (x == 'T') {
            if (bt) {
                vy.push_back(cnt);
            } else {
                if (fv == -1) {
                    fv = cnt;
                } else {
                    vx.push_back(cnt);
                }
            }
            cnt = 0;
            bt = 1 - bt;
        } else {
            cnt++;
        }
    }
    unordered_set<int> px, py;
    px.insert(fv);
    py.insert(0);
    for (auto &a : vx) {
        unordered_set<int> tt;
        for (auto &x : px) {
            tt.insert(x + a);
            tt.insert(x - a);
        }
        px = tt;
    }
    for (auto &a : vy) {
        unordered_set<int> tt;
        for (auto &x : py) {
            tt.insert(x + a);
            tt.insert(x - a);
        }
        py = tt;
    }

    if (find(ALL(px), gx) != px.end() && find(ALL(py), gy) != py.end()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 896
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        java.util.Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = input.nextInt();
        Arrays.sort(h);
        long r = 0;
        for (int i = 0; i < n - k; i++) r += h[i];
        System.out.println(r);
    }
}


Measured memory_bytes: 64436