akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int n;
int a[5];
ll ans;

int s[5][4];
bool t[20][20]={};

void dfs(int d, int idx, int row, int v){
    if(d==n){
        // ok
        ll mx = 0;
        rep(i,n)rep(j,min(4,a[i])) mx = max(mx,(ll)s[i][j]);
        ++mx;
        rep(i,n){
            if(a[i]>4) mx += a[i]-4;
        }

        // if(mx == 11){
        //     rep(i,n){
        //         rep(j,min(4,a[i]))printf(" %d", s[i][j]);
        //         printf("\n");
        //     }
        // }
        ans = min(ans, mx);
        return;
    }

    int sz = min(4,a[d]);

    int nd = d;
    int nidx = idx+1;
    int nrow = row;
    if(idx == sz-1){
        nd = d+1;
        nidx = 0;
        nrow = 0;
    }

    if(row<d){
        rep(i,min(4,a[row])){
            s[d][idx] = s[row][i];

            bool ok = true;
            rep(j,idx){
                if(s[d][j] == s[d][idx] || t[s[d][j]][s[d][idx]]){
                    ok = false;
                }
            }

            if(ok){
                rep(j,idx){
                    t[s[d][j]][s[d][idx]] = t[s[d][idx]][s[d][j]] = true;
                }

                nrow = row+1;
                if(nidx == 0) nrow = 0;
                dfs(nd,nidx,nrow,v);

                rep(j,idx){
                    t[s[d][j]][s[d][idx]] = t[s[d][idx]][s[d][j]] = false;
                }
            }
            s[d][idx] = -1;
        }

        dfs(d,idx,row+1,v);
    }

    s[d][idx] = v;
    rep(i,idx) t[s[d][i]][s[d][idx]] = t[s[d][idx]][s[d][i]] = true;
    if(idx != sz-1) nrow = nd;
    dfs(nd,nidx,nrow,v+1);
    rep(i,idx) t[s[d][i]][s[d][idx]] = t[s[d][idx]][s[d][i]] = false;
    s[d][idx] = -1;
}

int main(){
    cin >>n;

    ans = 0;
    rep(i,n){
        cin >>a[i];
        ans += a[i];
    }
    sort(a,a+n);

    memset(s,-1,sizeof(s));
    dfs(0,0,0,0);

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



Measured memory_bytes: 3132
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(M)]

smallest = min(a) + min(b)

for i in range(M):
    if a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2] < smallest:
        smallest = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]

print(smallest)


Measured memory_bytes: 38560
// ~/Remember,remember the 6th of March
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-9;
const ll MOD = 100000000;
const int N = 2e6 + 10;
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
double dist(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
int dcmp(double x, double y)
{
	return abs(x - y) < EPS ? 0 : 1;
}
int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt","w",stdout);
#endif*/
	vector<int>arr(5);
	int k;
	cin >> arr[0] >> arr[1] >> arr[2] >> arr[3] >> arr[4] >> k;
	for(int i=0;i<5;i++)
		for (int j = i + 1; j < 5; j++)
		{
			if (arr[j] - arr[i] > k)
			{
				puts(":(");
				return 0;
			}
		}
	puts("Yay!");
	return 0;
}

Measured memory_bytes: 256
def main():
    x, n = map(int, input().split())
    if n != 0:
        P = list(map(int, input().split()))

        maxP = max(P)

        numList = [0 for i in range(maxP+2)]

        for num in P:
            numList[num] += 1
        
        maxRes = 101
        maxCount = 0
        minRes = 101
        minCount = 0

        for i in range(x, maxP+2):
            maxCount += 1
            if numList[i] == 0:
                maxRes = i
                break
        
        for i in range(x, -1, -1):
            minCount += 1
            if numList[i] == 0:
                minRes = i
                break

        if maxCount < minCount:
            print(maxRes)
        else:
            print(minRes)

    else:
        print(x)

    

if __name__ == '__main__':
    main()

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

int main(){
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  printf("%.9lf",w/2.0*h);
  cout << " ";
  if( x == w/2.0 && y == h/2.0 ){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}

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

int main() {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H) cout << "Yes" << endl;
    else cout  << "No" << endl;
}


Measured memory_bytes: 3092
import java.util.*;
import java.math.*;
import java.io.*;


public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();

        int num = 0;
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == t.charAt(i)) num++;
        }
        System.out.println(num);


    } 
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	int N;	cin>>N;
	vector<vector<int> > cnt(N, vector<int>(26, 0));
	for (int n = 0; n < N; ++n) {
		string s;	cin>>s;
		int len = s.length();
		for (int i = 0; i < len; ++i) {
			cnt[n][s[i]-'a']++;
		}
	}
	
	for (int i = 0; i < 26; ++i) {
		int shor = 100;
		for (int j = 0; j < N; ++j) {
			shor = min(shor, cnt[j][i]);
		}
		if (shor == 100)
			continue;
		for (int j = 0; j < shor; ++j)
			cout<<(char)(i+'a');
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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; }



void solve(long long N, std::vector<long long> A, std::vector<long long> B){
	ll sum = 0;
	REP(i, N) {
		ll atk = B[i];
		ll damage = A[i] - atk;
		if (damage < 0) {
			sum += A[i];
			atk -= A[i];
			damage = A[i+1] - atk;
			if (damage < 0) {
				sum += A[i+1];
				A[i+1] = 0;
			} else {
				sum += atk;
				A[i+1] -= atk;
			}
		} else {
			sum += atk;
		}
	}
	cout << sum << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N+1);
    for(int i = 0 ; i < N+1 ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <algorithm>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
int main () {
  int n,a,b;
  int planA,planB;
  cin >> n >> a >> b;
  planA = a * n;
  planB = b;
  int plan = planA < planB ? planA :planB;
  cout << plan << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
//QAQ

//   ^--^
//  (*-_-)
//   --~-	
//  / ":"\
// /  ":"\

int main()
{
	//freopen("tt.txt","r",stdin);
	string a;
	cin>>a;
	int b,m=0;
	b=a.length();
	for(int i=0;i<b;i++)
	{
		if(a[i]=='1')
		{
			m++;
		}
	}
	cout<<m;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;

void main() {
  string[] input = split(readln());
  int a = to!int(input[0])-1;
  int b = to!int(input[1]);
  int ans = 0;
  int tap = 1;


  while (tap < b) {
    tap += a;
    ans++;
  }

  writeln(ans);
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

struct Line { int L, R; };

int N;
Line A[MAXN+10];
int ans;
Line val1[MAXN+10], val2[MAXN+10];

int main()
{
    int i, j;

    scanf("%d", &N);
    for(i=1; i<=N; i++) scanf("%d%d", &A[i].L, &A[i].R);

    int l=-1, r=1e9+1;
    for(i=1; i<=N; i++) l=max(l, A[i].L), r=min(r, A[i].R);

    if(l<=r)
    {
        int flag=-1;
        for(i=1; i<=N; i++) if(A[i].L==l && A[i].R==r) flag=i;
        if(flag!=-1) for(i=1; i<=N; i++) if(i!=flag) ans=max(ans, A[i].R-A[i].L+r-l+2);
        else
        {
            pii pl={-1, 0}, pr={1e9+1, 0};
            for(i=1; i<=N; i++)
            {
                if(A[i].R==r) pl=max(pl, pii(A[i].L, i));
                if(A[i].L==l) pr=min(pr, pii(A[i].R, i));
            }
            for(i=1; i<=N; i++)
            {
                if(i==pl.second || i==pr.second) continue;
                ans=max(ans, A[i].R-A[i].L+r-l+2);
            }
        }
    }

    sort(A+1, A+N+1, [&](const Line &p, const Line &q)
         {
             if(p.R==q.R) return p.L<q.L;
             return p.R>q.R;
         });

    int nl=-1, nr=1e9+1;
    val1[0]={nl, nr};
    for(i=1; i<=N; i++)
    {
        nl=max(nl, A[i].L);
        nr=min(nr, A[i].R);
        val1[i]={nl, nr};
    }

    nl=-1, nr=1e9+1;
    val2[N+1]={nl, nr};
    for(i=N; i>=1; i--)
    {
        nl=max(nl, A[i].L);
        nr=min(nr, A[i].R);
        val2[i]={nl, nr};
    }

    for(i=1; i<N; i++) ans=max(ans, max(0, val1[i].R-val1[i].L+1)+max(0, val2[i+1].R-val2[i+1].L+1));
    for(i=1; i<=N; i++) ans=max(ans, A[i].R-A[i].L+1+max(0, min(val1[i-1].R, val2[i+1].R)-max(val1[i-1].L, val2[i+1].L)+1));
    printf("%d", ans);
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	string s;
	cin >> s;
	int cnt[3] = {0};
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i]=='a') cnt[0]++;
		if(s[i]=='b') cnt[1]++;
		if(s[i]=='c') cnt[2]++;
	}

	sort(cnt,cnt+3);
	int x = cnt[0];
	for(int i = 0; i < 3; i++)
	{
		cnt[i] -= x;
		//cout << cnt[i] << endl;
	}

	if (cnt[2]<=1)
	{
		cout << "YES" << endl;
	}else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define inf 2000000000
using namespace std;
// 0-indexed
struct Dinic {
  struct edge {
    int to;
    int cap;
    int rev;
  };
  vector<vector<edge>> lst;
  vector<int> completed;
  vector<int> dist;
  Dinic(int n = 1) {
    // if 1-indexed
    //++n;
    lst.resize(n);
    completed.resize(n);
    dist.resize(n);
  }
  bool add(int start, int goal, int capacity) {
    lst[start].push_back(
        (edge){goal, capacity, (int)lst[goal].size()});
    lst[goal].push_back(
        (edge){start, 0, (int)lst[start].size() - 1});
    return 1;
  }
  // dist = time from start to now number
  void distbfs(int start) {
    fill(dist.begin(), dist.end(), -1);
    queue<int> bfsqu;
    dist[start] = 0;
    bfsqu.push(start);
    while(bfsqu.size() > 0) {
      int now = bfsqu.front();
      bfsqu.pop();
      for(int i = 0; i < lst[now].size(); ++i) {
        edge* nowe = &lst[now][i];
        if(nowe->cap > 0 && dist[nowe->to] < 0) {
          dist[nowe->to] = dist[now] + 1;
          bfsqu.push(nowe->to);
        }
      }
    }
  }
  int pathdfs(int now, int goal, int nf) {
    if(now == goal) return nf;
    for(int& i = completed[now]; i < lst[now].size(); ++i) {
      edge* e = &lst[now][i];
      if(e->cap > 0 && dist[now] < dist[e->to]) {
        int ans = pathdfs(e->to, goal, min(nf, e->cap));
        if(ans > 0) {
          e->cap -= ans;
          lst[e->to][e->rev].cap += ans;
          return ans;
        }
      }
    }
    return 0;
  }
  int solve(int start, int goal) {
    int ans = 0, nf = 0;
    while(1) {
      // bfs
      distbfs(start);
      // cannnot go to goal from start
      if(dist[goal] < 0) return ans;
      // reset
      fill(completed.begin(), completed.end(), 0);
      while((nf = pathdfs(start, goal, inf)) > 0) ans += nf;
    }
    return -1;
  }
};

int cnt[26] = {0};
int memo[26][26] = {0};
bool ch[26] = {0};
int n;
Dinic dn;

void solve();

int main() {
  cin >> n;
  dn = Dinic(52);
  for(int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    ch[s[s.size() - 1] - 'a'] = 1;
    ++cnt[s[0] - 'a'];
    ++memo[s[0] - 'a'][s[s.size() - 1] - 'a'];
  }
  for(int i = 0; i < 26; ++i)
    for(int j = 0; j < 26; ++j) {
      if(i == j) dn.add(i + 26, j, 1000000);
      if(memo[i][j] != 0) dn.add(i, j + 26, memo[i][j]);
    }

  solve();
  return 0;
}

void solve() {
  for(int i = 0; i < 26; ++i) {
    if(ch[i] && cnt[i] == dn.solve(i, i + 26))
      cout << (char)(i + 'a') << endl;
  }
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int i, j, k;
    char data = s.at(0);
    int ans = 1;
    for(i = 0; i < n; i++){
        if(s.at(i) != data){
            ans++;
            data = s.at(i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(1,N-1):
	if max(L[i-1],L[i],L[i+1])!=L[i] and min(L[i-1],L[i],L[i+1])!=L[i]:
		ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
source:
    int a, b;
    cin >> a >> b;
    if (a + b == 15) {
        cout << "+" << endl;
    } else if (a * b == 15) {
        cout << "*" << endl;
    } else {
        cout << "x" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> h(n);
    tuple<ll, ll, ll> h_exp_set;
    vector<tuple<ll, ll, ll>> ans;
    rep(i, n) {
        cin >> x[i] >> y[i] >> h[i];
        if ( h[i] >= 1 ) {
            h_exp_set = make_tuple(x[i], y[i], h[i]);
        }
    }
    rep(i, 101) rep(j, 101) {
        ll h_exp = get<2>(h_exp_set) + abs(get<0>(h_exp_set) - i) + abs(get<1>(h_exp_set) - j);
        h_exp = max(0LL, h_exp);
        bool ok = true;
        rep(k, n) {
            ll tmp_h = h_exp - abs(x[k] - i) - abs(y[k] - j);
            tmp_h = max(0LL, tmp_h);
            if ( h[k] !=  tmp_h ) {
                ok = false;
            }
        }
        if ( ok ) {
            ans.emplace_back(i, j, h_exp);
        }
    }
    if ( ans.size() == 1 ) {
        cout << get<0>(ans[0]) << " " << get<1>(ans[0]) << " " << get<2>(ans[0]) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
<?php

$dirs = array(
	array(1, 0),
	array(-1, 0),
	array(0, 1),
	array(0, -1)
);

while(TRUE) {
	$map = array();
	for ($i = 0; $i < 12; $i++) {
		$line = trim(fgets(STDIN));
		$map[] = $line;
	}
	// マップのロード完了
	$count = 0;
	for ($i = 0; $i < 12; $i++) {
		for ($j = 0; $j < 12; $j++) {
			if ($map[$i][$j] == 1) {
				$count++;
				bfs($i, $j);
			}
		}
	}
	echo $count . "\n";
	$line = fgets(STDIN);
	if ($line === false) {
		break;
	}
}

function bfs($i, $j) {
	global $map, $dirs;
	$que = array(array($i, $j));
	while (!empty($que)) {
		$point = array_shift($que);
		$x = $point[0];
		$y = $point[1];
		// 探索済み
		$map[$x][$y] = 0;
		foreach ($dirs as $d) {
			$dx = $d[0];
			$dy = $d[1];
			if (isset($map[$x + $dy][$y + $dx]) && $map[$x + $dy][$y + $dx] == 1) {
				$map[$x + $dy][$y + $dx] = 0;
				$que[] = array($x + $dy, $y + $dx);
			}
		}
	}
}

Measured memory_bytes: 6688
#include <stdio.h>

int main(void)
{
	double x[4], y[4];
	int n;
	
	scanf("%d", &n);
	
	while (n){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]);
		
		if (((y[1] - y[0]) / (x[1] - x[0])) == ((y[3] - y[2]) / (x[3] - x[2]))){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		n--;
	}
	
	return (0);
}

		

Measured memory_bytes: 620
#include<stdio.h>
using namespace std;

	
	int main() {
	int n;
	scanf("%d", &n);
	int p[100010];
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	int k = 0;
	for (int i = 0; i < n; i++){
		if (p[i] != i + 1)
			k++;
	}
	if (k <= 2) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>

using namespace std;

#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define INF 1 << 30

int P, N[6], p[6] = {1, 5, 10, 50, 100, 500};

int change(int m){
  int c = m-P, res = 0, use;
  for(int i = 5; i >= 0; i--){
    if(c/p[i]){
      use = c/p[i];
      res += use;
      c -= use*p[i];
    }
  }
  return res;
}

int pay(int m){
  int res = 0, use;
  for(int i = 5; i >= 0; i--){
    if(m/p[i]){
      use = min(m/p[i], N[i]);
      res += use;
      m -= use*p[i];
    }
  }
  if(m) return INF;
  else return res;
}

int main(){
  while(scanf("%d%d%d%d%d%d%d", &P, &N[0], &N[1], &N[2], &N[3], &N[4], &N[5]) && P){
    int res = INF, sum = 0;
    REP(i, 0, 6) sum += N[i]*p[i];
    REP(i, P, sum+1) res = min(res, change(i)+pay(i));
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1032
n = int(input())

nums = [0]*n
a = int(n**0.5)+1
for x in range(1,a):
  for y in range(1,a):
    if x**2 + y**2 + x*y > n: break
    for z in range(1,a):
      s = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if s <= n: nums[s-1] += 1
print(*nums, sep="\n")

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

int main() {
  int n;

  cin >> n;

  vector<long> h(n), ans(n);

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

  ans[1] = abs(h[0] - h[1]);
  for (int i = 2; i < n; i++) {
    ans[i] = 1e9;
    for (int j = 1; j < 2 + 1; j++) {
      ans[i] = min(ans[i], abs(h[i] - h[i - j]) + ans[i - j]);

    }
  }

  cout << ans[n - 1];

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  string s;
  cin>>k;
  cin>>s;
  if(k>=s.size()) cout<<s;
  else {
    for(int i=0;i<k;i++)
    cout<<s[i];
    cout<<"..."<<endl;
  }
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int n;
int y, m, d;

int main()
{
  cin >> n;
  while(n--){
    cin >> y >> m >> d;
    int res = 0;

    rrep(i, y, 1000) erep(j, 1, 10) erep(k, 1, 20){
      if(i == y){
        if(j < m) continue;
        if(j == m && k < d) continue;
      }

      if(i % 3){
        if(j % 2 == 0 && k == 20) continue;
      }
      res += 1;
    }

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import bisect
A,B,Q=map(int,input().split())
INF=10**18
S=[-INF]+[int(input()) for i in range(A)]+[INF]
T=[-INF]+[int(input()) for i in range(B)]+[INF]
for q in range(Q):
    x=int(input())
    i=bisect.bisect_right(S,x)
    j=bisect.bisect_right(T,x)
    d=INF
    for s in [S[i-1],S[i]]:
        for t in [T[j-1],T[j]]:
            d1=abs(s-x)+abs(s-t)
            d2=abs(t-x)+abs(s-t)
            d=min(d,d1,d2)
    print(d)

Measured memory_bytes: 13844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  string upper;
  for (int i = 0;i<w+2;i++) upper += "#";
  cout << upper << endl;
  for (int i = 0;i<h;i++){
    string loc;
    cin >> loc;
    cout << "#" << loc << "#" << endl;
  }
  cout << upper << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<ll> Vec;
typedef vector<pair<ll, ll>> Pair;
#define rep(i, n) for(ll i=0;i<n;i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359


int main() {
    // input
    ll N, K;
    cin >> N >> K;
    Vec A(N);
    rep(i, N) {
        cin >> A[i];
        --A[i];
    }

    // process
    Vec is_visited(N, 0);
    ll now = 0, loop = 0, remaining_K = 0;
    rep(i, K) {
        if (is_visited[now] != 0) {
            loop = i - is_visited[now];
            remaining_K = K - i;
            break;
        }
        is_visited[now] = i;
        now = A[now];
    }

    if (remaining_K != 0) {
        remaining_K %= loop;
        rep(i, remaining_K) {
            now = A[now];
        }
    }

    cout << now + 1 << endl;

    return 0;
}



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

int N,i,out_point;
double x,H[1100],T,A;        

int main() {
    cin >> N;
    cin >> T >> A;
    for (int i = 0; i < N; ++i) cin >> H[i];
 
    double min;
    
    // 操作が行える限り操作を繰り返す
        for (int i = 0; i < N; ++i) {
        //cout <<  H[i] << endl;
 
         x = T - H[i] * 0.006;
        //cout << x << endl;
         
        if (x < A) x = A - x;
        else x = x - A;
          
         //cout << x << endl;

         if (x <= min || i == 0) {
           min = x; 
           out_point = i;
           }
            // 奇数があったらフラグを立てる
        
        
        }

    // cout << max << endl;
   //  cout << min << endl;
   // max = max - min;
    cout << out_point +1 << endl;
}

Measured memory_bytes: 3740
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main()
{
    int a;
    long long x=0,y=0,mi=0,sum=0;
    int s[200005];
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>s[i];
    }
    for(int i=0;i<a;i++)
    {
        sum+=s[i];
        mi+=abs(s[i]);
    }
    for(int i=0;i<a-1;i++)
    {
        x+=s[i];
        y=sum-x;
       if(x-y<0)
       {
           if(mi>y-x) mi = y-x;
       }
       if(x-y>=0)
       {
           if(mi>x-y) mi = x-y;
       }
    }
    cout<<mi<<endl;
}

Measured memory_bytes: 1024
x, K, D = [int(i) for i in input().split()]
x = abs(x)

if K * D < x:
  print(x - K * D)
  exit(0)

v = x // D # ここまでの移動回数
x = x % D  # 現時点でのx

nokori = (K - v) % 2
if nokori:
  print(abs(x - D))
else:
  print(x)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))  
#define lli long long int
#define ll long long 
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define BS binary_search
#define pii pair<lli,lli>
const long long int mod=1000000009;
//const long long int mod=998244353;
const long double PI=3.141592653589793;
const long long int inf=1e18;
const long long int inf2=LLONG_MAX;
#define setBitCount(x) __builtin_popcountll(x)
#define all(a) (a).begin(), (a).end()
#define all_r(a) (a).rbegin(), (a).rend()
lli gcd(lli a,lli b)
{
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
}
// calculating (x^y)%p
lli power(lli x,lli y,lli p)
{
    lli res = 1;      
    x = x % p;  
    while (y > 0)
    {
        if (y & 1) //y is odd  
        res = (res*x) % p;
        y = y>>1; 
        x = ( (x%p)*(x%p) )% p;  
    }
    return res%p;
}
// calculating modular inverse using fermat little theorem
lli modInverse(lli n,lli p) 
{
    return power(n, p-2, p)%p;
}

// policy based data structures !!
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
// s.order_of_key (k) : Number of items strictly smaller than k
// *(s.find_by_order(k)) : K-th element in a set (counting from zero)
lli pre[500];
lli a[500];
void solve()
{
   lli n;
   cin>>n;
   
   for(lli i=1;i<=n;i++)
   {
      cin>>a[i];
      pre[i]=pre[i-1]+a[i];
   }
   
   lli dp[n+5][n+5];
   for(lli i=1;i<=n;i++)
   for(lli j=1;j<=n;j++)
   dp[i][j]=inf;
   
   for(lli i=1;i<=n;i++)
   dp[i][i]=0;
   
   for(lli i=1;i<n;i++)
   dp[i][i+1]=a[i]+a[i+1];
   
   for(lli len=3;len<=n;len++)
   {
      for(lli i=1;i<=n-len+1;i++)
      {
         lli j=len+i-1;
         for(lli k=i;k<j;k++)
         {
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+pre[j]-pre[i-1]);
         }
      }
   }
   cout<<dp[1][n];
}
int main()
{
   
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    lli T;
    //cin>>T;
    T=1;
    while(T--)
    {
        solve();
    }




    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> p(n), d(n);
    rep(i, n){
        cin >> p.at(i);
        d.at(i) = i+1;
    }

    int count = 0;
    rep(i, n){
        if(p.at(i) != d.at(i)) count++;
    }
    
    string s = "NO";
    if(count <= 2) s = "YES";

    cout << s << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, D, X; scanf("%d %d %d", &N, &D, &X);
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  int ans = X;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j * A[i] + 1 <= D; ++j) {
      ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g $PROGRAM -o $OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d, string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while (getline(ss, t, d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;
    if(s=="ARC")
        cout << "ABC";
    else
        cout << "ARC";

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


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

int main()
{
  int x, y;
  while (true)
  {
    cin >> x >> y;
    if (!x && !y)
    {
      break;
    }
    if (x > y)
    {
      cout << y << " " << x << endl;
    }
    else
    {
      cout << x << " " << y << endl;
    }
  }
}


Measured memory_bytes: 3036
import sys

input = sys.stdin.readline


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def iml(N: int, t: type = int):
    return [t(input()) for _ in range(N)]


N = ii()
D = iml(N)

print(len(set(D)))

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<lint> div(n);
    for (int i = 1; i <= n; ++i) {
    	for (int j = i; j <= n; j += i) {
    		div[j] += 1;
    	}
    }
    lint res = 0;
    for (int i = 1; i <= n; ++i) {
    	res += i * div[i];
    }
    cout << res << '\n';
}

Measured memory_bytes: 81324
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
ll t[20][20];

ll dp[20][(1 << 17)];
ll mincost[20][(1 << 17)];

int main() {
	while (cin >> n&&n) {
		REP(i, n)REP(j, n + 1)cin >> t[i][j];
		REP(i, 20)REP(j, (1 << 17)) {
			dp[i][j] = INF;
			mincost[i][j] = t[i][0];
		}
		dp[0][0] = 0;
		REP(i, n) {
			REP(j, (1 << n)) {
				FOR(k, 1, n + 1) {
					if ((1 << (k - 1))&j)mincost[i][j] = min(mincost[i][j], t[i][k]);
				}
			}
		}
		//REP(i, n) {
		//	REP(j, (1 << n)) {
		//		cout << j << "!" << mincost[i][j] << " ";
		//	}
		//	cout << endl;
		//}
		REP(i, n) {
			REP(now, (1 << n) + 1) {
				REP(k, n) {
					ll nxt = now | (1 << k);
					dp[i + 1][nxt] = min(dp[i][now] + mincost[k][now], dp[i + 1][nxt]);
				}
			}
		}
		cout << dp[n][(1 << n) - 1] << endl;
	}

}

Measured memory_bytes: 44016
#include<iostream>
#include<stdio.h>

using namespace std;

int N,k,a,result,tate,yoko;

int main()
{
    cin >> N >> k;
    if(N % 2 == 1)
    {
        a = N / 2 + 1;
        for(int i = 0; i < k; i++)
        {
            cin >> yoko >> tate;
            if(yoko > a)
            {
                yoko = N - yoko + 1;
            }
            else if(tate > a)
            {
                tate = N - tate + 1;
            }
            //printf("[%d][%d]\n",yoko,tate);
            if(yoko < tate)
            {
                result = (yoko + 3) % 3;
                if(result  == 0)result = 3;
                cout << result << endl;
            }
            else if(tate < yoko)
            {
                result = (tate + 3) % 3;
                if(result == 0)result = 3;
                cout << result << endl;
            }
            else if(yoko == tate)
            {
                result = (yoko + 3) % 3;
                if(result == 0)result = 3;
                cout << result << endl;
            }
        }
    }
    else if(N % 2 == 0)
    {
        a = N / 2;
        for(int i = 0; i < k; i++)
        {
            cin >> yoko >> tate;
            if(yoko > a)
            {
                yoko = N - yoko + 1;
            }
            if(tate > a)
            {
                tate = N - tate + 1;
            }
            //printf("[%d][%d]\n",yoko,tate);
             if(yoko < tate)
            {
                result = (yoko + 3) % 3;
                if(result  == 0)result = 3;
                cout << result << endl;
            }
            else if(tate < yoko)
            {
                result = (tate + 3) % 3;
                if(result == 0)result = 3;
                cout << result << endl;
            }
            else if(yoko == tate)
            {
                result = (yoko + 3) % 3;
                if(result == 0)result = 3;
                cout << result << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
    vector<int> par; // uf(x,y)->y
    UnionFind() {}
    UnionFind(int NV) { init(NV); }
    void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); }
    void reset() { rep(i, 0, par.size()) par[i] = i; }
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) par[x] = y; }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/







int E[4][4];
//---------------------------------------------------------------------------------------------------
void _main() {
    rep(i, 0, 3) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a][b] = E[b][a] = 1;
    }

    vector<int> ord;
    rep(i, 0, 4) ord.push_back(i);
    do {
        int ng = 0;
        rep(j, 0, 3) if (!E[ord[j]][ord[j + 1]]) ng = 1;
        if(!ng) {
            printf("YES\n");
            return;
        }
    } while(next_permutation(all(ord)));

    printf("NO\n");
}

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

typedef long long ll;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){

    int A,B,C;
    cin >> A >> B >> C;
    cout << C << " " <<  A << " " <<  B << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long int n,i,j,k,sum=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			long int m=__gcd(i,j);
			for(k=1;k<=n;k++)
			{
				sum=sum+__gcd(m,k);
			}
		}
	}
	cout<<sum;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  
  for (int i=0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
  
  vector<string> pixel(H);
  for (int i=0; i<H; i++){
    cin >> pixel.at(i);
    cout << "#" << pixel.at(i) << "#" << endl;
  }
  
    for (int i=0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int N, K; cin >> N >> K;
    vector<ll> h(N+1, 0);
    repr(i, 1, N+1) cin >> h[i];

    ll const inf = 1LL<<60;
    vector<vector<ll>> dp(N+1, vector<ll>(N+1, inf));
    dp[0][0] = 0;

    repr(i, 1, N+1) repr(j, 1, i+1){
        rep(k, i) chmin(dp[i][j], dp[k][j-1]+max(0LL, h[i]-h[k]));
    }

    ll ans = inf;
    repr(i, N-K, N+1) chmin(ans, dp[i][N-K]);
    cout << ans << endl;

    
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x>>y;
	if(x>8 || y>8) cout<<":("<<endl;
	else cout<<"Yay!"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define PAIN___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < int , int >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 1000005

    ll mat[100005][3];
    ll dp[1000005][3];
    ll n;


    int main()
    {

      // unordered_map< pair<char,int> ,ll> :: iterator itr;
      ll t;
      t=1;
      while(t--)
      {
        PAIN___;
     // unordered_map< char ,ll >um1,um2;

        cin>>n;
        mat[n][3];
        ll j1,j2;
        forl(i,1,n,n+1)
        {

            forl(j,1,n,4)
            {

                cin>>mat[i][j];
                dp[i][j]=mat[i][j];

            }
        }

        for(ll i=n-1;i>=1;i--)
        {
            forl(j,1,n,4)
            {
                if(j==1){j1=2,j2=3;}if(j==2){j1=1;j2=3;}if(j==3){j1=1;j2=2;}

                dp[i][j]=mat[i][j]+max(dp[i+1][j1],dp[i+1][j2]);


            }
        }
       cout<<max(max(dp[1][1],dp[1][2]),dp[1][3])<<endl;
      }}



Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int>adj[200005];
main()
{
    int n;
    cin>>n;
    map<int,int>cnt;
    for(int i=1;i<n;i++){
        int x;
        cin>>x;
        cnt[x]++;
    }
    for(int i=1;i<=n;i++) cout<<cnt[i]<<endl;

}


Measured memory_bytes: 20720
a,b = (int(x) for x in input().split())

ans_a = ""
ans_b =""
for i in range(a):
    ans_a += str(b)
for j in range(b):
    ans_b += str(a)
    
ans_list = [ans_a,ans_b]
ans_list.sort()

print(ans_list[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll a = 0;
  string s; cin >> s;
  rep(i,s.size()){
    if(s[i] == '+'){
      a++;
    }
    else{
      a--;
    }
  }
  cout << a;
}
  

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    string s;
    int a,b; cin >> a >> b;
    if(a>b) {
        rep(i,a) cout << b;
        cout << '\n';
    }else {
        rep(i,b) cout << a ;
        cout << '\n';
    }

}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = []

for i in range(m):
    s = input().split()
    l.append(list(map(int, s[1:])))

pl = list(map(int, input().split()))

ans = 0

for i in range(2**n): #電源on/offの全パターン
    for sw, p in zip(l, pl):
        odd = False
        for a in sw:
            if i & 1 << (a - 1): #onになっているswと連動しているか
                odd = not odd #True/Falseを切り替えている。
        if int(odd) != p: #Trueは1, Falseは0になる。
            break
    else: #breakでループを抜けなかった時だけ実行される
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    var(int, N);
    priority_queue<double, vector<double>, greater<>> maxValue;

    rep(i, N) {
        var(int, v);
        maxValue.emplace(v);
    }

    while(maxValue.size() > 1) {
        const double a = maxValue.top(); maxValue.pop();
        const double b = maxValue.top(); maxValue.pop();
        maxValue.emplace((a + b) / 2.0);
    }

    cout << fixed << setprecision(9);
    print(maxValue.top());

    return 0;
}


Measured memory_bytes: 256