akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int n, m;
int cost[100][100];
bool used[100];
int d[100];
int pre[100];
map<pair<int, int>, bool> usede;

void dijkstra(int s) {
	fill(d, d + n, INF);
	fill(used, used + n, false);
	fill(pre, pre + n, -1);
	d[s] = 0;
	while (true) {
		int v = -1;
		for (int u = 0; u < n; u++) {
			if (!used[u] && (v == -1 || d[u] < d[v]))v = u;
		}
		if (v == -1)break;
		used[v] = true;
		for (int u = 0; u < n; u++) {
			if (d[u] > d[v] + cost[v][u]) {
				d[u] = d[v] + cost[v][u];
				pre[u] = v;
			}
		}
	}

	return;
}

void getpath(int t) {
	while (t != -1) {
		usede[pair<int, int>(min(t, pre[t]), max(t, pre[t]))] = true;
		t = pre[t];
	}

	return;
}

int main() {

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			cost[i][j] = cost[j][i] = INF;
		}
	}

	rep(i, m) {
		int a, b, c; cin >> a >> b >> c; a--; b--;
		cost[a][b] = cost[b][a] = c;
		usede[pair<int, int>(a, b)] = usede[pair<int, int>(b, a)] = false;
	}

	for (int i = 0; i < n; i++) {
		dijkstra(i);
		for (int j = i + 1; j < n; j++) {
			getpath(j);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (usede[pair<int, int>(i, j)])m--;
		}
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int A, B;
	cin >> A >> B;
	if(A == 1) A = 14;
	if(B == 1) B = 14;
	if(A == B)
		cout << "Draw" << endl;
	else if (A < B)
		cout << "Bob" << endl;
	else
		cout << "Alice" << endl;
	return 0;
}


Measured memory_bytes: 764
#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <cmath>

using namespace std;

#define forn(n) for (int i = 0; i < (n); ++i)

typedef long long ll;
typedef unsigned int uint;
typedef long double ld;

const int INT_INF=1e9;
const ll INF=1e18;
const double pi = acos(-1);
const int MAXN = 3e5;
const int MAXM = 1e6;


pair<ll, ll> t[4*MAXN];

void build (int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = {0, -tl};
    }
    else {
        int tm = (tl + tr) / 2;
        build(v*2, tl, tm);
        build(v*2+1, tm+1, tr);
        t[v] = min(t[v*2], t[v*2+1]);
    }
}

pair<ll, ll> get_min (int v, int tl, int tr, int l, int r) {
    if (l > r)
        return make_pair (INF, INF);
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(
        get_min (v*2, tl, tm, l, min(r,tm)),
        get_min (v*2+1, tm+1, tr, max(l,tm+1), r)
    );
}

void update (int v, int tl, int tr, int pos, pair<ll, ll> new_val) {
    if (tl == tr)
        t[v] = new_val;
    else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update (v*2, tl, tm, pos, new_val);
        else
            update (v*2+1, tm+1, tr, pos, new_val);
        t[v] = min(t[v*2], t[v*2+1]);
    }
}

void solve() {
    int h, w;
    cin >> h >> w;
    build(1, 0, w - 1);
    for (int i = 0; i < h; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        pair<ll, ll> d = get_min(1, 0, w - 1, a, b);
        while (d.first != INF) {
            update(1, 0, w - 1, -d.second, {INF, INF});
            d.first += (b + 1 + d.second);
            if (b + 1 < w) {
                auto cur = get_min(1, 0, w - 1, b + 1, b + 1);
                if (cur.first > d.first) {
                    d.second = -(b + 1);
                    update(1, 0, w - 1, b + 1, d);
                }
            }
            d = get_min(1, 0, w - 1, a, b);
        }
        d = get_min(1, 0, w - 1, 0, w - 1);
        if (d.first == INF) {
            cout << -1 << '\n';
        } else {
            cout << d.first + i + 1 << '\n';
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(9);
#ifdef LOCAL
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif
    solve();

#ifdef LOCAL
    cout << "Time:\n";
    cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << '\n';
#endif

}


Measured memory_bytes: 11800
#include <stdio.h>
#include <string.h>

int main(){
	int a;
	scanf("%s", &a);
	char str [255];
	
	if(a>='A'&& a<= 'Z'){
		printf("A\n");
	}
	else if (a>='a'&& a<='z'){
		printf("a\n");
	}
	
	return 0;
}

Measured memory_bytes: 1660
s=gets.chomp
n=s.size
(n/2).times do |i|
  if s[i]!=s[n-1-i]
    puts "No"
    exit
  end
end
(n/4).times do |i|
  if s[i]!=s[n/2-1-i]
    puts "No"
    exit
  end
end
(n/4).times do |i|
  if s[i+n/2+1]!=s[n-1-i]
    puts "No"
    exit
  end
end
puts "Yes"



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);

int main(){
    int k,t;cin>>k>>t;
    int a[t];
    int m=0,mc=0,sum=0;
    rep(i,t)cin>>a[i];
    rep(i,t){
        m=max(m,a[i]);
        sum+=a[i];
    }
    sum-=m;
    int ans =m-sum-1;;
    cout<<max(0,ans)<<endl;

}

Measured memory_bytes: 3532
//
//  main.swift
//
//  Created by sun-yryr
//  Copyright © 2019 sun-yryr. All rights reserved.
//

import Foundation

prefix operator *
prefix func * <T> (a: [T]) -> (T, T) {return (a[0], a[1])}
prefix func * <T> (a: [T]) -> (T, T, T) {return (a[0], a[1], a[2])}


func readInt(separator s: Character = " ") -> [Int] {return readLine()!.split(separator: s).map({Int($0)!})}
func readDouble(separator s: Character = " ") -> [Double] {return readLine()!.split(separator: s).map({Double($0)!})}
func readElement(separator s: Character = " ") -> [String] {return readLine()!.split(separator: s).map({String($0)})}

extension String {
    func at(_ i: Int) -> Character {
        precondition(0 <= i && i < self.count)
        return self[self.index(self.startIndex, offsetBy: i)]
    }
}

func main() {
    let (A, B, C) = *readInt()
    if (C <= (A+B)) {
        print("Yes")
    } else {
        print("No")
    }
}
main()


Measured memory_bytes: 13660
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
    int N,M;
    cin >> N >> M;
    Graph G(N);
    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    vint dist(N,-1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto nv:G[v]){
            if(dist[nv] != -1)continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    if(dist[N-1] == 2){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

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

using namespace std;

long long gcd(long long m,long long n)
{
	long long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}


int main(){
 int n;
  cin >> n;
 
  long long res=1;
  
  long long t;
  
  for(int i=0;i<n;i++){
    cin >> t;
    res=t/gcd(res,t)*res;
  
  
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
  if xy[i][0] > xy[i][1]:
    xy[i][0],xy[i][1] = xy[i][1],xy[i][0]
if n == 1:
  print(0)
  exit()
x = list(zip(*xy))[0]
y = list(zip(*xy))[1]
xmax = max(x)
ymax = max(y)
xmin = min(x)
ymin = min(y)
ans = (xmax-xmin)*(ymax-ymin)
r = ymax-xmin
cand = []
for i in range(n):
  if xy[i] == [xmin,ymax]:
    print(ans)
    exit()
  if xy[i][0] == xmin:
    cand.append(xy[i][1])
  if xy[i][1] == ymax:
    cand.append(xy[i][0])
bmax = max(cand)
bmin = min(cand)
cons = []
for i in range(n):
  if xy[i][1] < bmin:
    bmin = xy[i][1]
  elif xy[i][0] > bmax:
    bmax = xy[i][0]
for i in range(n):
  if xy[i][0] < bmin and xy[i][1] > bmax:
    cons.append(xy[i])
if not cons:
  print(min(ans,r*(bmax-bmin)))
  exit()
cons.sort(key = lambda x:x[1])
lc = len(cons)+1
cols = [[0 for i in range(2)] for j in range(lc)]
for i in range(lc)[::-1]:
  if i >= 1:
    cols[i][1] = cons[i-1][1]
  else:
    cols[i][1] = bmax
  if i == lc-1:
    cols[i][0] = bmin
  else:
    cols[i][0] = min(cols[i+1][0],cons[i][0])
for i in range(lc):
  ans = min(ans,r*(cols[i][1]-cols[i][0]))
print(ans)

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

#define int long long
typedef pair <int, int> pii;

const int N = 2e5 +  10;
int n;
pii ar[N];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> ar[i].first >> ar[i].second;
	sort(ar, ar + n, [&] (pii p1, pii p2) { 
		return min(p1.second - p1.first, p2.second - p1.first - p2.first) > min(p2.second - p2.first, p1.second - p1.first - p2.first);
	});
	
	int now = 0;
	for (int i = 0; i < n; i++) {
		if (now + ar[i].first > ar[i].second)
			return cout << "No" << endl, 0;
		now += ar[i].first;
	}
	cout << "Yes" << endl;
}

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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(){
    int a, b;
    cin >> a >> b;
    int c = a + b;
    if(c == 3) cout << 3 << endl;
    if(c == 4) cout << 2 << endl;
    if(c == 5) cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
#include<string>
#define ll long long
#define vel vector<long long>
#define veb vector<bool>
#define vvel vector<vel>
#define pin pair<int,int>
#define ppin pair<pin,int>
#define qin pair<ll,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define V vector
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
using namespace std;
vel pa;
int INF = 1000000000 + 1;
vel hpn;
int mx1 = 0;
vel num; vel x;
signed main() {
	int n; cin >> n;
	vel v(n);
	rep(i, n) { 
		char x; cin >> x;
		if (x == '.') { v[i] = 0; }
		else { v[i] = 1; }
	}
	vel l(n+1, 0);
	l[0] = 0;
	for (int i = 1; i <= n; i++) { l[i] = l[i-1] + v[i-1]; }
	vel r(n+1, 0);
	for (int i = n - 1; i >= 0; i--) { r[i] = r[i + 1] + (1 - v[i]); }
	ll ans = n;
	rep(i, n+1) { mmin(ans, l[i] + r[i]); }
	cout << ans << endl;
	return 0;
}


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

LIST=[]

def next(L):
    if len(L)==10:
        return
    t=int(L[-1])
    for x in [t-1,t,t+1]:
        if 0<=x<=9:
            y=L+(x,)
            LIST.append(y)
            next(y)

for i in range(1,10):
    x=(i,)
    LIST.append(x)
    next(x)

        
L2=[]

for l in LIST:
    L2.append(int("".join(map(str,l))))

L2.sort()
print(L2[int(input())-1])


Measured memory_bytes: 37712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    string s;
    cin >> s;
    vector<string>d = {"maerd","remaerd","esare","resare"};
    reverse(s.begin(),s.end());
    bool ok = true;
    for(int i = 0;i < s.size();){
        bool can = false;
        rep(j,4){
            string e = d[j];
            string f = s.substr(i,e.size());
            if(e == f){
                can = true;
                i += e.size();
            }
        }
        if(can == false){
            ok = false;
            break;
        }
    }
    if(ok)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    double sum = 0;
    for(ll a : A){
        sum += a;
    }

    double mean = sum / N;

    vector<double> B(N);
    FOR(i, 0, N){
        B[i] = abs(A[i] - mean);
    }
    double min_diff = *min_element(ALL(B));

    FOR(i, 0, N){
        if(B[i]==min_diff){
            p(i);
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> P2;
typedef pair<ll,vector<ll>> pv;
vector<ll> node[1005];
bool used[1005]={false};
bool u2[1005]={true};
ll isnode[1005][1005]={0};
vector<ll> vec;
P2 mk_P(ll x,ll y,ll z){
  return P2(P(x,y),z);
}
ll dfs(ll pos){
  for(int i=0;i<node[pos].size();i++){
    int to=node[pos][i];
    if(used[to]&&u2[to]){
      return to;
    }
    else{
      used[to]=true;
      return dfs(to);
    }
  }
  u2[pos]=false;
  return -1;
}
pv solve(ll fpos){
  vector<P> vec(1005);
  for(int i=0;i<1005;i++) vec[i].first=17441744;
  priority_queue<P,vector<P>,greater<P>> pque;
  pque.push(P(0,fpos));
  vec[fpos].first=0;
  vec[fpos].second=0;
  bool kused[1005];
  for(int i=0;i<1005;i++) kused[i]=false;

  while(!pque.empty()){
    P p=pque.top();
    pque.pop();
    ll cos=p.first,pos=p.second;
    if(kused[pos]) continue;
    else kused[pos]=true;
    for(int i=0;i<node[pos].size();i++){
      int to=node[pos][i];
      if(cos+1<vec[to].first){
        vec[to]=vec[pos];
        vec[to].first++;
        vec[to].second=pos;
        pque.push(P(cos+1,to));
      }
    }
  }
  vector<ll> ansvec;
  ll cos=17441744,ansp=0;
  for(int i=0;i<1005;i++){
    if(isnode[i][fpos]>0&&cos>vec[i].first&&i!=fpos){
      cos=vec[i].first;
      ansp=i;
    }
  }
  if(ansp==0){
    return pv(0,ansvec);
  }
  if(vec[ansp].second!=0) ansvec.push_back(ansp);
  while(vec[ansp].second!=0){
    ansvec.push_back(vec[ansp].second);
    ansp=vec[ansp].second;
  }
  return pv(ansvec.size(),ansvec);
}
int main(){
  ll n,m;
  cin>>n>>m;
  for(int i=1;i<=m;i++){
    ll a,b;
    cin>>a>>b;
    node[a].push_back(b);
    isnode[a][b]=i;
  }
  ll asiz=17441744;
  vector<ll> ansvec;
  for(int i=1;i<=n;i++){
    pv p=solve(i);
    if(p.first==0) continue;
    else{
      if(p.first<asiz){
        asiz=p.first;
        ansvec=p.second;
      }
      if(asiz==3) break;
    }
  }
  if(asiz==17441744){
    cout<<-1<<endl;
  }
  else{
    cout<<ansvec.size()<<endl;
    for(int i=0;i<ansvec.size();i++) cout<<ansvec[i]<<endl;
  }
}


Measured memory_bytes: 6912
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, ll> P;
int main()
{
  int N, Q;
  while(cin>>N>>Q,N||Q) {
    map<P, string> MAP;
    FOR(i,0,N) {
      string s;
      ll a, b;
      cin >> s >> a >> b;
      MAP[P(a, b)] = s;
    }
    FOR(i,0,Q) {
      ll in; cin >> in;
      bool ok = false;
      for(auto m : MAP) {
        ll end = m.first.second;
        ll start = end - m.first.first + 1;
        if(in >= start && in <= end) {
          ok = true;
          cout << m.second << " " << in - start + 1 << endl;
        }
      }
      if(!ok) {
        puts("Unknown");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int k = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			for(int i = a ; i <= b; i++ ) {
				if ( i % k == 0 ) {
					System.out.println("OK");
					return;
				}
			}
			
			System.out.println("NG");
				
		}
	}

}

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

int main(){
	// sengen
	int x;
	int sum = 0,count = 0;
	// nyuryoku
	cin >> x;
	// keisan
	sum = x;
	count = 1;
	while(sum % 360 != 0){
		sum += x;
		count++;
	}
	// syutsuryoku
	cout << count;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  long ans = 1;
  vector<int>moji(26,0);
  for(int i=0;i<n;i++){
    moji[(int)(s[i]-'a')]++;
  }
  long const mod = 1e9+7;
  for(int i=0;i<26;i++){
    ans *= (moji[i]+1);
    ans %= mod;
  }
  ans += mod-1;
  ans %= mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

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

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

const ull MOD = 1000'000'007;

const ll NMAX = (ll)1e5 + 10;
ll dp[NMAX] = {};

int main(){
    ll N = read<ll>();
    ll K = read<ll>();
    auto h = read<ll>(N);
    
    for(auto& x: dp){ x = 1e+9; }
    
    dp[0] = 0;
    for(ll i = 0; i < N; ++i)
        for(ll k = 1; k <= K && i + k < N; ++k)
            dp[i + k] = min(dp[i + k], dp[i] + abs(h[i + k] - h[i]));
    write(dp[N-1]);
}



Measured memory_bytes: 1792
N,M=map(int,input().split())
A = [[1 for _ in range(M)]]+[[0 for _ in range(M)] for _ in range(N)]
for i in range(1,N+1):
    B=list(map(int,input().split()))
    Ai=B[1:]
    for m in Ai:
        A[i][m-1]=A[i-1][m-1]
a=sum(A[N])
print(int(a))

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

int main()
{
    int i,turn,score=0,score2=0;
	string str;
	string str2;
	cin>>turn;
	for(i=0;i<turn;i++){
		cin>>str;
		cin>>str2;
		if(str==str2){
			score+=1;
			score2+=1;
		}else if(str<str2){
			score2+=3;
		}
		else{
			score+=3;
		}
	}
	cout<<score<<" "<<score2<<endl;
    return 0;
}

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

using namespace std;
int f[100001];
bool visited[100001];
vector<int> gr[100001];
void dfs(int cur,int prev)
{
    for(auto node : gr[cur])
    {
        if(!visited[node])
        {
            dfs(node,cur);
        }
        else
        {
            f[cur]=max(f[cur],f[node]+1);
        }
    }
    if(prev!=-1)f[prev]=max(f[prev],f[cur]+1);
    visited[cur]=1;
}
int main()
{
    int n,m;
    cin >> n >> m;
    int a,b;
    for(int i=0;i<m;i++)
    {
        cin >> a >> b;
        a--;
        b--;
        gr[a].push_back(b);
    }
    for(int i=0;i<n;i++)
    {
        dfs(i,-1);
    }
    int rez=0;
    for(int i=0;i<n;i++)
    {
        rez=max(rez,f[i]);
    }
    cout << rez;
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int p = 0;
  for (int i = A; i <= B; i++) {
    int first = i % 10;
    int second = ((i % 100) - (i % 10)) / 10;
    int fourth = ((i % 10000) - (i % 1000)) / 1000;
    int fifth = ((i % 100000) - (i % 10000)) / 10000;
    
    if ((first == fifth) && (second == fourth)) { p++; }
  }
  
  cout << p << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
using namespace std;
int main(void){
    int arr[26] = {};
    char ch;
    while(scanf("%c", &ch) != EOF)
        if(isalpha(ch)) arr[tolower(ch) - 'a']++;
    for(int i = 0; i < 26; i++) printf("%c : %d\n", 'a' + i, arr[i]);

    return 0;
}



Measured memory_bytes: 2720
import java.util.Scanner;

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

        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();

            if (h + w == 0) {
                return;
            }

            for (int i=0; i<h; ++i) {
                for (int j=0; j<w; ++j) {
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 34900
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    // Your code here!
    int n, m;
    scanf("%d %d", &n, &m);
    
    int tmp;
    for(int i=0; i<m; i++){
        scanf("%d", &tmp);
        n -= tmp;
    }
    if(n<0)printf("-1");
    else printf("%d", n);
}


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

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using ll = long long;
using pii = pair<int, int>;

int main(){
  string a, b, result;
  cin >> a >> b;
  if (a.size() != b.size()) {
    result = a.size() > b.size() ? "GREATER":"LESS";
    puts(result)
    exit(0);
  }
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i]) {
      result = a[i] > b[i] ? "GREATER":"LESS";
      puts(result)
      exit(0);
    }
  }
  puts("EQUAL")
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
using namespace std;

int32_t main()
{
    IOS;
    string s;
    cin >> s;
    int n=0;
    for(int i = 0;i < s.length(); i++){
        n+= (s[i]-'0');
    }
    if(n%9==0||n==0)
        cout << "Yes \n";
    else
    {
        cout << "No \n";
    }
    
    return 0;
}

Measured memory_bytes: 3736
N, Q = map(int, input().split())
parentNodes = [1] * (N + 1)  # parentNodes[i] = i番目ノードの親番号

ans = [0] * (N + 1)
for _ in range(N - 1):
    a, b = map(int, input().split())  # 接続ノード
    parentNodes[b] = a

for _ in range(Q):
    p, x = map(int, input().split())
    ans[p] += x

for i in range(2, N + 1):
    ans[i] += ans[parentNodes[i]]

ans.pop(0)
print(" ".join(map(str, ans)))


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;n %= 10;
	if (n == 3) die("bon");
	else if (n == 0 || n == 1 || n == 6 || n == 8) die("pon");
	else die("hon");
}


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

int main() {
  int N,K;
  cin>>N>>K;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int sum=0;
  for(int i=0;i<K;i++){
    sum+=vec.at(i);
  }
  cout<<sum<<endl;
    
  
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

const ll MAX_N=(1<<19);

ll n,N,dat[2*MAX_N-1];//n...segmenttreeの葉の大きさ,N...与えられた数列等の大きさ
ll b[1000000];

ll unit(){
    return 0;//単位元
}

ll calc(ll a,ll b){
    return a+b;//演算
}

//初期化
void init(){
    n=1;
    while(n<N) n*=2;//座標とかであれば n<N ではなく n<(座標の最大値)　下も同様
    //for(int i=0;i<N;i++) dat[i+n-1]=a[i];
    //for(int i=N;i<n;i++) dat[i]=unit();//単位元で埋める
}

void update(ll k,ll s){
    k+=n-1;
    dat[k]=s;//変更する式
    while(k>0){
        k=(k-1)/2;
        dat[k]=calc(dat[2*k+1],dat[2*k+2]);//条件
    }
}

ll query(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l) return unit();//単位元
    if(a<=l&&r<=b) return dat[k];

    ll m=(l+r)/2;
    ll u=query(a,b,2*k+1,l,m);
    ll v=query(a,b,2*k+2,m,r);
    return calc(u,v);//条件
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll k;
    cin>>N>>k;
    V<ll> a(N),s(N+1),t(N+1);
    rep(i,N){
        cin>>a[i];
        s[i+1]=s[i]+a[i];
    }
    ll ans=0;
    V<P> p;
    for(ll i=1;i<=N;i++){
        t[i]=s[i]-k*i;
        p.emplace_back(t[i],i);
    }
    p.emplace_back(0LL,0LL);
    sort(all(p));
    init();
    rep(i,N) update(i,1);
    rep(i,N){
        ans+=query(p[i].sc,N,0,0,n);
        update(p[i].sc-1,0);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 15212
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int K,N; cin >> K >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    int ans = a[0]+K-a[N-1];
    rep(i,N-1){
        ans = max(ans,abs(a[i]-a[i+1]));
    }
    cout << K-ans << endl;

}

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

using i64 = int64_t;

int main(){
    int n, d;
    string x;
    cin >> n >> x >> d;
    string ans = x;
    int m = 0;
    bool ok = false;
    if(d == 0){
        cout << x << endl;
        return 0;
    }
    for(int i=0;i<n;++i){
        if(x[i] == '0'){
            ans[i] = '1';
            m++;
        }
        if(m >= d){
            ok = true;
            break;
        }
    }
    if(!ok){
        for(int i=n-1;i>=0;--i){
            if(x[i] == '1'){
                ans[i] = '0';
                m++;
            }
            if(m >= d){
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3196
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

def main():
    N, K = map(int, input().split())
    S = input()
    nums = []
    # 1の個数、0の個数を交互に記録していく
    if S[0] == '0': nums.append(0)
    i = 0
    while i < N:
        j = i
        while j < N and S[i]==S[j]:
            j += 1
        nums.append(j-i)
        i = j
    if S[-1] == '0': nums.append(0)
    # print(nums)
    nums = [0] + list(accumulate(nums))
    # print(nums)
    ans = 0
    
    for i in range(0,len(nums),2):
        # print(i)
        ans = max(ans,nums[min(i+2*K+1,len(nums)-1)]-nums[i])
    print(ans)
        

if __name__ == "__main__":
    main()


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

#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
#define OMAZINAI cin.tie(0); ios::sync_with_stdio(false);
typedef long long int ll;

int main() {
	OMAZINAI;
	int n, t;
	vector<int> v;
	cin >> n;
	loop(i, n) {
		cin >> t;
		v.push_back(t);
	}
	std::sort(begin(v), end(v));
	cout << v[n - 1] - v[0] << endl;
	
	return 0;
}

Measured memory_bytes: 896
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

int N, A[1000];

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

    cin >> N;
    REP(i, N) cin >> A[i];

    int prev = -1;
    int ans = 0;
    REP(i, N) {
        if (prev == A[i]) {
            ans++;
            prev = -1;
        } else {
            prev = A[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
using namespace std;

void solve(){
  int a, b; cin >> a >> b;
  int maxx;
  maxx = max(a + b, a - b);
  maxx = max(maxx, a * b);
  cout << maxx << endl;
  return;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int ans=0;
void dfc(int n,int i){
	if(n<=0)return;
	else
	{
		dfc(n/i,i);
		ans++;
	}
	
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	/*while(t--){
		
		
		
	}*/
	dfc(n,k);
	printf("%d",ans);




	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include <cmath>
#include <set>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define all(a) a.begin(), a.end()
#define N 5000000

const long long int  inf = 1e15 ;
const int M = 1e9+7;

typedef long long int LL;
typedef pair<LL,LL>pii;

LL arr[N],dp[N];
int n,k;

LL solve(int cur)
{
	if(cur>=n)
	{
		return 0;
	}
	if(dp[cur]==inf)
	{
		for (int i = 1; i <= k ; ++i)
		{
			dp[cur]=min( dp[cur] , solve(cur+i) + abs(arr[cur+i]-arr[cur]) );
		}
	}
	return dp[cur];
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n >>k;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		dp[i]=inf;
	}
	for (int i = 0; i < k+4; ++i)
	{
		arr[n+i]=arr[n-1];
		dp[n+i]=inf;
	}
	cout << solve(0) << endl;

	return 0;
}

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

int main()
{
    int a;
    cin >> a;
    a = a % 10;
    if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9) {
        cout << "hon" << endl;
    }
    else if (a == 0 || a == 1 || a == 6 || a == 8) {
        cout << "pon" << endl;
    }
    else {
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import itertools
n = int(input())
s = input()

memo = {}
for i in range(len(s)):
  if s[i] not in memo:
    memo[s[i]] = 1
  else:
    memo[s[i]] += 1
 
li = []
for i in memo.values() :
  li.append(i)

ans = 1
for i in li:
  ans = (ans*(i+1))%1000000007
print((ans-1)%1000000007)

Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
    int a[200];
    int m,p,i,j,n;
    long long int t,x,sum=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&t);
        a[i]=t;
    }
    scanf("%d",&m);
    for(j=1;j<=m;j++)
    {   sum=0;
        scanf("%d%lld",&p,&x);
        for(i=1;i<=n;i++)
        {
            if(i==p) {sum=sum+x;}
            else
            {
                sum=sum+a[i];
            }
        }
        printf("%lld\n",sum);
    }
    return 0;

}

Measured memory_bytes: 128
import math
a,b,h,m = map(float, input().split())

long_needle = 6*m
short_needle = 30*h + m/2
deg = abs(long_needle - short_needle)

#degreeからラジアン変換
rad = math.radians(deg)
cosA = math.cos(rad)
length = math.sqrt(a**2 + b**2 - 2*a*b*cosA)

print(length)

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll r, D, x;
    cin >> r >> D >> x;
    for(ll i = 0; i < 10; i++){
        x = r * x - D;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
// AGC033A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <utility>
#include <tuple>
#include <algorithm>

int main()
{
	using namespace std;
	using lolo=int;	
	using tup3=tuple<lolo,lolo,lolo>;
	
	
	lolo H, W;
	cin >> H >> W;

	vector< vector<lolo> > HMANY(H);

	vector< string > A(H);
	for (lolo i = 0; i < H; ++i) {
		cin >> A[i];

		HMANY[i].resize(W);
		fill(HMANY[i].begin(), HMANY[i].end(), lolo(10e9));
	}

	deque<tuple<lolo,lolo,lolo>> q;
	
	for (lolo h = 0; h < H; ++h) {
		for (lolo w = 0; w < W; ++w) {
			if (A[h][w] == '#') {
				q.push_back(
					tuple<lolo,lolo,lolo>(0, h, w)
				);
				A[h][w] = '.';
			}
		}
	}

	while (!q.empty()) {
		tup3 t = q[0];
		q.pop_front();
		lolo num, h, w;
		num = get<0>(t);
		h = get<1>(t);
		w = get<2>(t);

		if (HMANY[h][w] > num and A[h][w] == '.') {
			HMANY[h][w] = num;
			A[h][w] = '#';
			if (h + 1 < H and A[h + 1][w] == '.') {
				q.push_back(tup3(num + 1, h + 1, w));
			}
			if (w + 1 < W and A[h][w + 1] == '.') {
				q.push_back(tup3(num + 1, h, w + 1));
			}
			if (0 <= h - 1 and A[h - 1][w] == '.') {
				q.push_back(tup3(num + 1, h - 1, w));
			}
			if (0 <= w - 1 and A[h][w - 1] == '.') {
				q.push_back(tup3(num + 1, h, w - 1));
			}
		}
	}

	lolo ans = 0;
	for (auto v : HMANY) {
		ans = max(ans, *max_element(v.begin(), v.end()));
	}
	cout << ans << endl;
		


		
	
	
    //std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 29492
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int main()
{
  string S;
  cin>>S;
  int n=S.size();
  vector<ll> L(n+1,0);
  vector<ll> R(n+1,0);
  ll sum=0;
  for(int i=0;i<n;i++){if(S.at(i)=='<') L.at(i+1)=L.at(i)+1;}
  for(int i=n-1;i>=0;i--){if(S.at(i)=='>') R.at(i)=R.at(i+1)+1;}
  for(int i=0;i<n+1;i++) sum+=max(L.at(i),R.at(i));
  cout<<sum<<endl;
}

Measured memory_bytes: 8708
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	cin>>k;
	vector<int>visited(k);
	int curr=1;
	int num=7%k;
	while(true)
	{
		if(num==0){
			cout<<curr;
			break;
		}
		else if(visited[num]){
			cout<<"-1";
			break;
		}
		else{
			curr++;
			visited[num]=1;
			num=(10*num+7)%k;
		}
	}
	return 0;
}

Measured memory_bytes: 7132
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
 
#define in std::cin
#define out std::cout
 
int64_t N;
std::unordered_set<int64_t> graph[100000];//木
int64_t need[100000] = {};
int64_t use[100000] = {};
bool is_lef[100000] = {};
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
 
	in >> N;
	for (int64_t i = 0; i < N; ++i)
	{
		in >> need[i];
	}
	for (int64_t i = 0; i < N-1; ++i)
	{
		int a, b;
		in >> a >> b; --a; --b;
		graph[a].insert(b);
		graph[b].insert(a);
	}
 
	std::queue<int64_t> que;
	for (int64_t i = 0; i < N; ++i)
	{
		if (graph[i].size() == 1) {
			is_lef[i] = true;
			if (i != 0) {
				que.push(i);
			}
		}
		else {
			need[i] *= 2;
		}
	}
	while (!que.empty())
	{
		auto pos = que.front(); que.pop();
		auto p = *graph[pos].begin();
		auto add = need[pos] - use[pos];
		if (add<0 || (!is_lef[pos] && add * 2 > need[pos]) || (!is_lef[p] && add * 2 > need[p])) {
			out << "NO" << endl; return 0;
		}
		use[p] += add; use[pos] += add;
		graph[p].erase(pos);
		if (p != 0 && graph[p].size() == 1) {
			que.push(p);
		}
	}
	out << ((need[0] == use[0]) ? ("YES") : ("NO")) << endl;
	return 0;
}
#endif

Measured memory_bytes: 16256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,h,area;
    scanf("%d %d %d",&a,&b,&h);
    if(h%2==0)
    {
    area=(a+b)*(h/2);
    printf("%d",area);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;

using namespace std;

int main()
{
    int n;
    long long w;
    cin >> n >> w;
    vector<vector<long long>> dp(n + 1, vector<long long>(w + 1, 0));
    vector<long long> weight(n), value(n);
    for (int i = 0; i < n; i++)
    {
        cin >> weight[i] >> value[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            if (j >= weight[i])
            {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight[i]] + value[i]);
            }

            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
        }
    }

    long long ans = dp[n][w];

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

Measured memory_bytes: 80256
import java.util.Scanner;
import java.util.regex.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner input=new Scanner(System.in);
        String str=input.nextLine();
        String pattern="A?KIHA?BA?RA?$";
        if(Pattern.matches(pattern,str)) System.out.println("YES");
        else System.out.println("NO");
   }
}

Measured memory_bytes: 23252
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    template <bool nl>
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { final(); }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
        template <bool f = nl>
        auto final() -> std::enable_if_t<f> { cout << '\n'; }
        template <bool f = nl>
        auto final() -> std::enable_if_t<!f> {}
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy<true> operator,(T&& val)
    {
        cout << val;
        return {};
    }
    proxy<false> noreturn() { return {}; }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
            }
            cout << x;
            first = false;
        }
    }
};

void prog()
{
    input in;
    output out;

    int n, l;
    in >> n, l;

    int i = 1 - l;
    int e = 0;
    if (i < 1)
        e = l;
    else if (n < i)
        e = l + n - 1;

    out, n* l - n + n*(n + 1) / 2 - e;
}

int main()
{
    prog();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
signed main(){
	int n,k;cin >> n >> k;
	vector<int> A(n);
	rep(i,n)cin >> A[i];
	vector<int> res;
	int ans = -INF;
	rep(a,n+1)rep(b,n+1){
		if(a + b > n)continue;
		res.clear();
		
		rep(i,a)res.push_back(A[i]);
		for(int i = n-1;i >n-1-b;i--)res.push_back(A[i]);
		if(res.size() == 0)continue;
		sort(res.begin(),res.end());
		int rest = min((int)res.size(),k-a-b);
		if(rest < 0 )continue;
		int tmp = 0;
		rep(i,res.size()) tmp += res[i];
		rep(i,rest){
			if(res[i] < 0 )tmp -= res[i];
		}
		ans = max(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int x;
	cin >> x;
	int happyness = 0;
	happyness += (x / 500) * 1000;
	x = x % 500;
	happyness += (x / 5) * 5;
	x = x % 5;
	cout << happyness << endl;
	return 0;
}


Measured memory_bytes: 3568