akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

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

int main() 
{
    string s;
    cin >> s;

    int y = atoi(s.substr(0,4).c_str());
    int m = atoi(s.substr(5,2).c_str());
    int d = atoi(s.substr(8,2).c_str());
    
    if(y > 2019) {
        cout << "TBD" << endl;
    } else {
        if(m > 4) { 
            cout << "TBD" << endl;
        } else {
            cout << "Heisei" << endl;
        }
    }
    //cout << y << endl; cout << m << endl; cout << d << endl; 
    return 0;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	string T;
	cin >> T;
	REP(mask, 1<<4){
		string S = "";
		REP(j, 4){
			if(mask>>j & 1){
				S += "A";
			}
			if(j==0) S += "KIH";
			if(j==1) S += "B";
			if(j==2) S += "R";
		}
		if(S==T){
			cout << "YES" << endl;
			return 0; 
		}
		//dump(S)
	}
	cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))

s=0
for i in range(n):
    idxa=bisect.bisect_left(a,b[i])
    idxb=bisect.bisect_right(c,b[i])
    s+=idxa*(n-idxb)
print(s)

Measured memory_bytes: 107108
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


import numpy as np
from numba import njit

N, W_max = ints()
W, V = read_col(N)
W = np.array(W, dtype=np.int64)
V = np.array(V, dtype=np.int64)

'''
dp[i,j] ... 重さの最小 (:iまで考慮したとき、価値がちょうどjのとき)
答えはW以下の数字が入ってるマスの一番左側

更新則
chmin(dp[i+1,j+V[i]] , dp[i, j]+W[i]) #ナップサックに入れた場合
chmin(dp[i+1,j] , dp[i, j]) # ナップサックに入れなかった場合
'''


@njit('(i8, i8, i8[:], i8[:])', cache=True)
def solve(N, W_max, W, V):
    V_max = np.sum(V) + 1
    dp = np.full((N + 1, V_max), 10**12, dtype=np.int64)
    # 初期化
    dp[0][0] = 0  # 一個も選ばず価値が0なら必ず重さも0

    # 更新
    for i in range(N):
        for j in range(V_max):
            jv = j + V[i]
            if jv < V_max:
                dp[i + 1, jv] = min(dp[i + 1, jv], dp[i, j] + W[i])
            dp[i + 1, j] = min(dp[i + 1, j], dp[i, j])

    # 左から見てく
    for j in range(V_max - 1, -1, -1):
        if np.any(dp[:, j] <= W_max):
            print(j)
            return


solve(N, W_max, W, V)


Measured memory_bytes: 194048
#include <iostream>

using namespace std;

long min(long n, long k, long now) {
	if (n == 0) {
		return now;
	}

	long d = now * 2;
	long add = now + k;

	long ret = 0;

	if (d > add) {
		ret = min(n-1, k, add);
	} else {
		ret = min(n-1, k, d);
	}

	return ret;
}

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

	long result = min(n, k, 1l);
	cout << result << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353

ll n, a, b;
vector<vector<ll>> l(1000000);
vector<ll> dist(1000000, 0);
vector<bool> searched(1000000, false);
vector<ll> ans(1000000);

void dfs(ll k){
	searched.at(k) = true;
	REP(i,l.at(k).size()) if (searched.at(l.at(k).at(i)) == false){
		dist.at(l.at(k).at(i)) = dist.at(k) + 1;
		dfs(l.at(k).at(i));
	}
	return;
}

int main(){
	cin >> n;
	REP(i,n-1){
		cin >> a >> b;
		l.at(a-1).pb(b-1);
		l.at(b-1).pb(a-1);
	}
	dfs(0);
	ll cnteven = 0;
	REP(i,n) if (dist.at(i) % 2 == 0) cnteven++;

	ll m = n/3;
	ll cnter1 = 0;
	ll cnter2 = 0;
	ll cnter3 = 0;
	vector<ll> anslb;
	vector<ll> anslc;

	if (cnteven <= m){
		REPS(i,n) if (!(i % 3 == 0 && i <= 3*cnteven)) anslb.pb(i);
		REP(i,n){
			if (dist.at(i) % 2 == 0){
				ans.at(i) = 3*cnter1+3;
				cnter1++;
			}
			else{
				ans.at(i) = anslb.at(cnter2);
				cnter2++;
			}
		}
	}
	else if (cnteven >= n-m){
		REPS(i,n) if (!(i % 3 == 0 && i <= 3*(n-cnteven))) anslb.pb(i);
		REP(i,n){
			if (dist.at(i) % 2 == 1){
				ans.at(i) = 3*cnter1+3;
				cnter1++;
			}
			else{
				ans.at(i) = anslb.at(cnter2);
				cnter2++;
			}
		}
	}
	else{
		REP(i,n){
			if ((dist.at(i) % 2 == 0) && (3*cnter1+1 <= n)){
				ans.at(i) = 3*cnter1+1;
				cnter1++;
			}
			else if ((dist.at(i) % 2 == 1) && (3*cnter2+2 <= n)){
				ans.at(i) = 3*cnter2+2;
				cnter2++;
			}
			else{
				ans.at(i) = 3*cnter3+3;
				cnter3++;
			}
		}
	}
	REP(i,n){
		cout << ans.at(i) << ' ';
	}
	cout << endl;
}

Measured memory_bytes: 54656
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = [0 for i in range(n+1)]

def lb(x):
    l, r = 0, n
    while l < r:
        m = (l+r)//2
        if a[m] < x:
            l = m + 1
        else:
            r = m
    return l

def ub(x):
    l, r = 0, n
    while l < r:
        m = (l+r)//2
        if a[m] <= x:
            l = m + 1
        else:
            r = m
    return l

for i in range(n):
    l = lb(b[i])
    r = ub(b[i])-1
    if l > r:
        continue
    if l < i and i <= r:
        cnt[l+n-i]+=1
        cnt[0]+=1
        cnt[r-i+1]-=1
    elif i <= l:
        cnt[l-i]+=1
        cnt[r-i+1]-=1
    elif i > r:
        cnt[l+n-i]+=1
        cnt[r+n+1-i]-=1

res = 0
ans = -1
for i in range(n):
    res += cnt[i]
    if(res == 0):
        ans = i
if ans == -1:
    print("No")
else:
    print("Yes")
    for i in range(n):
        print(b[(i-ans+n)%n],end=' ')

Measured memory_bytes: 40416
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
	/*static double res=0;
	 static void help(int p,int r,int n){
		double tmp=p;
		for(int i=1;i<=n;i++){
			double x=1+(double)r/1200 ;
			tmp*=x;
		}
		res+=tmp;
		int k=100000,m=360;
		for(int i=m;i>0;i--){
			help(k,5,i);
		}
		System.out.println("paid amount "+k*m+" ");
		System.out.println((long)res);
	}*/
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
	    int n=s.nextInt();
	int x=1000000;int res=0;
		for(int i=1;i<=n-1;i++){
			int y=s.nextInt();
			res+=Math.min(x,y); x=y;
		}
		System.out.println(res+x);
	}
}			
	













Measured memory_bytes: 23892
// Problem : F - Knapsack for All Segments
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

typedef long long   ll;
const ll mod = 998244353;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << " | ";
	err(++it, args...);
}

const ll inf = 1e18;
const int nax = 1e5 + 5;

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		ll n,s;
		cin>>n>>s;
		
		ll a[n+1];
		forn(i,1,n+1)
		{
			cin>>a[i];
		}
		
		ll dp[n+1][3001];
		ll pref[n+1][3001];
		reset(pref,0);
		reset(dp,0);
		
		forn(i,1,n+1)
		{
			dp[i][a[i]] = i;
		}
		
		forn(i,1,n+1)
		{
			forn(j,0,s+1)
			{
				if(j-a[i] > 0)
				{
					dp[i][j] = pref[i-1][j-a[i]];
				}
				pref[i][j] = add(pref[i-1][j],dp[i][j]);
			}	 
		}
		
		// forn(i,1,n+1)
		// {
			// forn(j,0,s+1)
			// {
				// dbg(i,j,dp[i][j]);
			// }
		// }
		
		ll ans = 0;
		forn(i,1,n+1)
		{
			ans = add(ans,mult(n-i+1,dp[i][s]));
		}
		cout<<ans;
	}

	return 0;
}


Measured memory_bytes: 141056
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
	static double s;
	
    public static void main(String[] args)   throws Exception, IOException{        
//        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int x=sc.nextInt();
        int y=sc.nextInt();
        int a=0,d[]= {3,2,1};
        if(x<4)a+=d[x-1];
        if(y<4)a+=d[y-1];
        if(a==6)a+=4;
        a*=100000;
        out.println(a);
     	out.flush();
    }


    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//
//class P {
//	int x, y, d;
//	P(int  x, int y, int d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}

class P implements Comparable<P>{
    int a,b;
    P(int a, int b) {
    	this.b=b;
    	this.a=a;
    }

    public int compareTo(P p){
        return -p.a+a;//as
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 22356
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k;
string s;
int main() {
  cin >> n >> k >> s;
  string t = s;
  reverse(begin(t), end(t));
  string u = s + t;
  vector<string> ss;
  for (i64 i = 0; i <= n; ++i) {
    string v = u.substr(i, n);
    reverse(begin(v), end(v));
    ss.push_back(v);
  }
  string w = *min_element(begin(ss), end(ss));
  i64 head_cnt = 1;
  for (i64 i = 1; i < n && w[i - 1] == w[i]; ++i) ++head_cnt;
  string tail = w.substr(head_cnt, n);
  i64 head_num = head_cnt;
  for (i64 i = 1; i < k && head_num <= n; ++i) head_num *= 2;
  string ans = (string(head_num, w[0]) + tail).substr(0, n);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 24960
#include <cstdio>
#include <cstring>
#define N 200005
char a[N], ch[N];
int n, sz[N], jm[N], nx[30];
int main() {
	int i, j;
	scanf("%s", &a[1]);
	n = strlen(a+1);
	for(i=0; i<26; i++) nx[i]=-1;
	sz[n+1] = 1;
	for(i=n; i; i--) {
		nx[a[i]-'a'] = i;
		sz[i] = N;
		for(j=0; j<26; j++) {
			if(sz[nx[j]+1] + 1 < sz[i]) {
				sz[i] = sz[nx[j]+1] + 1;
				jm[i] = nx[j] + 1;
				ch[i] = j+'a';
			}
		}
	}
	for(i=1; sz[i]; i=jm[i]) {
		putchar(ch[i]);
	}
	return 0;
}

Measured memory_bytes: 2176
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var l, r [100000]int
	for i:=0;i<m;i++ {
		fmt.Scan(&l[i], &r[i])
		if i>0 {
			l[0] = int(math.Max(float64(l[0]), float64(l[i])))
			r[0] = int(math.Min(float64(r[0]), float64(r[i])))
		}
	}
	count := 0
	if l[0] <= r[0] {
		count = r[0] - l[0] + 1
	}
	fmt.Println(count)
}

Measured memory_bytes: 5504
n,m,l = map(int,input().split())
A=[]
B=[]
for i in range(n):
    a = input().split()
    a_int= [int(s) for s in a ]
    A.append(a_int)
for j in range(m):
    b = input().split()
    b_int= [int(t) for t in b ]
    B.append(b_int)
i = 0
j = 0
Z = [[0 for q in range(l)] for p in range(n)]
for i in range(n):
    for t in range(l):
        z = 0
        for j in range(m):
            z += int(A[i][j])*int(B[j][t])
        Z[i][t]=z
i = 0
for i in range(n):
        print(' '.join(map(str,Z[i])))


Measured memory_bytes: 6884
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  ll N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  --N;
  ll T = B + D * N - A;
  ll delta = D - C;
  ll wari = 2 * D - delta;
  // cerr << T << " " << delta << " " << wari << endl;
  assert(wari >= 0);
  ll sup = T / wari;
  sup = min(sup, N);
  ll inf = (T - N * delta + wari - 1) / wari;
  inf = max(inf, (ll)0);
  for (auto i = inf; i <= sup; ++i) {
    // cerr << i << endl;
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

int main(){
	int a, b, c;

	cin >> a;
	cin >> b;
	cin >> c;
	
	int ret;

	if (a - b <= c) {
		ret = c - (a-b) ;
	} else {
		ret = 0;
	}

	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s1,s2;
    cin>>s1;
    cin>>s2;
    if (s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0])
        cout<<"YES\n";
    else
        cout<<"NO\n";
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e12
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

void solve() {
	int N, K;
	cin >> N >> K;
	vl h(N), dp(N, inf);
	rep(i, N) cin >> h[i];
	if (N == 1) {cout << 0 << endl; return;}

	dp[0] = 0;
	FOR(i, 1, N - 1)
		FOR(j, 1, min(1LL*K, i))
			dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));

	// pr(dp);
	cout << dp[N-1] << endl;
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>

typedef long long ll;

int main(int argc, char* argv[])
{
  int n = 2;
  int m = 3;
  std::vector< std::string > vs(n, std::string(""));
  std::vector< std::string >::iterator it;

  for (int i = 0; i < n; i++) {
    std::cin >> vs[i];
  }

  std::string judge = "YES";
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vs[i][j] != vs[n-i-1][m-j-1]) {
	judge = "NO";
      }
    }
  }

  std::cout << judge << std::endl;

  return 0;
}


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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
vector<int> A;

int main()
{
	scanf("%d",&N);
	A.assign(N,0);
	map<int,int> mp;
	FOR(i,0,N){
		scanf("%d",&A [i]);
		mp [A [i]]++;
	}

	int ans = 0;
	for(const auto& it : mp){
		if(it.first <= it.second){
			ans += it.second - it.first;
		}
		else{
			ans += it.second;
		}
	}
	printf("%d\n",ans);

	return 0;
}


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

int main () {
    string s;
    cin >> s;
    if (s == "Sunny") {
        cout << "Cloudy";
    } else if (s == "Cloudy") {
        cout << "Rainy";
    } else if (s == "Rainy") {
        cout << "Sunny";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;


int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int P, Q, R;
  scanf("%d%d%d",&P,&Q,&R);
  if((P+Q <= Q+R) && (P+Q <= R+P))
  {
    printf("%d\n",P+Q);
  }
  else if((Q+R <= P+Q) && (Q+R <= R+P))
  {
    printf("%d\n",Q+R);
  }
  else if((R+P <= P+Q) && (R+P <= Q+R))
  {
    printf("%d\n",R+P);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define MAX 40

int n,pre[MAX],in[MAX];

void Retree(int,int);

int main()
{
  int i;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d",&pre[i]);
    }
  for(i=0;i<n;i++)
    {
      scanf("%d",&in[i]);
    }
  
  Retree(0,n);

  return 0;
}

void Retree(int L,int R)
{
  static int i,k;
  int c,m,j;
  
  if(L>=R)return;

  c=pre[i++];

  for(j=L;j<R;j++)
    {
      if(c==in[j])break;
    }

  Retree(L,j);
  Retree(j+1,R);
  
  if(k==n-1)printf("%d\n",c);
  else printf("%d ",c);
  k++;
}



  
  

  



Measured memory_bytes: 2112
from math import factorial
n,m = map(int,input().split())
if abs(n-m) > 1:
  print(0)
elif n == m:
  ans = 2*(factorial(n)%(10**9+7))**2%(10**9+7)
  print(ans)
else:
  ans = (factorial(n)%(10**9+7))*(factorial(m)%(10**9+7))%(10**9+7)
  print(ans)


Measured memory_bytes: 4104
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

string S,T,ans;

int main(){
    cin>>S>>T;
    ans=S;
    int found=0;
    for(int i=S.length()-T.length()+1;i>=0;i--){
        if(S[i]==T[0]){
            int flag=true;
            repi(j,1,T.length()){
                if(S[i+j]==T[j])continue;
                else {
                    flag=false;
                    break;
                }
            }
            if(flag&&found==0){
                rep(j,T.length()){
                    found=1;
                }
            }
        }
    }
    for(int i=S.length()-T.length()+1;i>=0;i--){
        if(S[i]==T[0]||S[i]=='?'){
            int flag=true;
            repi(j,1,T.length()){
                if(S[i+j]==T[j]||S[i+j]=='?')continue;
                else {
                    flag=false;
                    break;
                }
            }
            if(flag&&found==0){
                rep(j,T.length()){
                    ans[i+j]=T[j];
                    found=1;
                }
            }
        }
    }
    if(found){
        rep(i,ans.length()){
            if(ans[i]=='?')ans[i]='a';
        }
        out(ans);
    }
    else{
        out("UNRESTORABLE");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    vi L(N);
    in(N,L);
    
    vi s(1010,0);
    sort(all(L));
    rep(i,N) s[L[i]]++;
    reps(i,1,1010) s[i] += s[i-1];
    //outve(L);
    ll ans = 0;
    reps(i,1,N-1){
        int b = L[i];
        reps(j,i+1,N){
            int c = L[j];
            //cout << c-b << endl;
            int tt = upper_bound(L.begin(),L.begin()+i,c-b)-L.begin();
            //cout << tt-i << endl;
            if(tt < i) ans += (ll)(i-tt);
        }
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
int main(void){
int k,a,b;
  scanf("%d%d%d",&k,&a,&b);
  for(int i=a;i<=b;i++){
	if(i%k==0){printf("OK");
               return 0;
              }
  }
  printf("NG");
  return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int min_comp(int min, int a)
{

}
int max_comp(int max, int a)
{
  if(max>a)    return max;
  else    return a;
}


int main()
{
  int N,M,X;
  int A[101]={};
  int cost_0 = 0;
  int cost_N = 0;
  int number;
  int debug_cnt;
//  long long N[101]={};
  int i;
  int cont;
//    int k=0;

  scanf("%d %d %d", &N, &M,&X);

  for(i=0;i<M;i++){
    scanf("%d ", &A[i]);
    if(A[i]<X) cost_0++;
    if(A[i]>X) cost_N++;
  }

  if(cost_0<=cost_N) printf("%d", cost_0);
  else printf("%d", cost_N);
  
  //  else printf("No\n"); 
return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	int N=sc.nextInt();
    	int A=sc.nextInt();
    	int B=sc.nextInt();
    	
    	int result=Math.min(N*A,B);
    	
    	System.out.println(result);

    }
}



Measured memory_bytes: 20948
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, A, B = (int(i) for i in input().split())
    H = [int(input()) for i in range(N)]

    def is_ok(x):
        need = 0
        cur = [0]*N
        for i, h in enumerate(H):
            cur.append(max(0, h - B*x))
        for i, less in enumerate(cur):
            need += (less+(A-B)-1)//(A-B)
        if need <= x:
            return True
        else:
            return False

    def binary_search_meguru():
        ng = -1
        ok = 10**9 + 1
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(binary_search_meguru())


if __name__ == '__main__':
    main()


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

int main(){
  int l,r,d;
  cin >> l >> r >> d;
  int res=0;
  for(int i=l;i<=r;i++){
    if(i%d==0){
      res++;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3588
import java.util.*;
class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        for(;;) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a == 0 && b == 0) break;
            System.out.println("" + Math.min(a, b) + " " + Math.max(a,b));
        }
    }
}

Measured memory_bytes: 25400
fun main() {
    val n = nextInt()
    val l = nextIntList().sorted()
    var cnt = 0

    for (b in 0 until n) {
        for (a in 0 until b) {
            var idx = l.binarySearch(element = l[a] + l[b], comparator = Comparator { a, b -> if (a >= b) 1 else -1 }).inv()
            cnt += Math.max(0, idx-b-1)
        }
    }

    println(cnt)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map { it.toInt() }
fun nextLongList() = nextList().map { it.toLong() }
fun nextDoubleList() = nextList().map { it.toDouble() }


Measured memory_bytes: 55008
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let x: i64 = input();
    let a: i64 = input();
    let b: i64 = input();
    println!("{}", (x - a) % b);
}


Measured memory_bytes: 4352
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second 
#define mod 1000000007

using namespace std;

ll n, a[410], dp[410][410], sum[410];

int main() {
    // ifstream cin("tst.in");
    // ofstream cout("tst.out");
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i], sum[i] = a[i] + sum[i - 1];

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            dp[i][j] = LLONG_MAX;

    for (int i = 1; i <= n; i++)
        dp[i][i] = 0;

    for (int len = 2; len <= n; len++) {
        for (int i = 1; i + len - 1 <= n; i++) {
            int st = i;
            int dr = i + len - 1;
            for (int k = st; k < dr; k++) {
                dp[st][dr] = min(dp[st][dr], dp[st][k] + dp[k + 1][dr] + sum[dr] - sum[st - 1]);
            }
        }
    }

    cout << dp[1][n];

    return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

struct SegTree {
	std::vector<int> data;
	int n;
	SegTree(int n_) {
		for (n = 1; n < n_; n *= 2);
		data.resize(2 * n);
	}
	void set(int i, int val) {
		for (data[i += n] = val; i >>= 1; ) data[i] = std::max(data[i << 1], data[i << 1 | 1]);
	}
	int max(int l, int r) {
		int res = 0;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) {
				r--;
				res = std::max(res, data[r]);
			}
			if (l & 1) {
				res = std::max(res, data[l]);
				l++;
			}
		}
		return res;
	}
};

int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	std::set<int> all;
	for (int i = 0; i < n; i++) all.insert(a[i]);
	std::map<int, int> comp;
	std::vector<int> decomp;
	int cnt = 0;
	for (auto i : all) comp[i] = cnt++, decomp.push_back(i);
	SegTree tree(all.size());
	for (int i = 0; i < n; i++) {
		tree.set(comp[a[i]], std::max(tree.data[tree.n + comp[a[i]]], tree.max(comp[a[i]], tree.n) + 1));
	}
	std::cout << tree.max(0, tree.n) << std::endl;
	
	return 0;
}


Measured memory_bytes: 11256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

int main() {
    string S;
    cin >> S;
    
    if (S == "Sunny") cout << "Cloudy" << endl;
    else if (S == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}


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

using namespace std;

int main()
{
  string a;
  cin>>a;
  if(a[0]=='R'&&a[1]=='R'&&a[2]=='R')
    cout<<3<<endl;
  else if(a[0]=='R'&&a[1]=='R'||a[1]=='R'&&a[2]=='R')
    cout<<2<<endl;
  else if(a[0]=='R'||a[1]=='R'||a[2]=='R')
    cout<<1<<endl;
  else
    cout<<0<<endl;
}

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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b;
	cin >> a >> b;
	if(b >= a){
		cout << a << endl;
	}else{
		cout << a-1 << endl;
	}
}

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

LL gcd(LL a, LL b){
    if(a < b){
        return gcd(b,a);
    }
    else if(b == 0){
        return a;
    }
    else{
        return gcd(b, a%b);
    }

}


int main()
{
    LL T,A,B,C,D;
    cin>>T;
    for(int i=0; i<T; i++){
        cin>>A>>B>>C>>D;
        LL g = gcd(B,D);
        bool check = true;
        if(A < B){
            check = false;
        }
        if(D < B){
            check = false;
        }
        if(C < (A-B)%g + (B-g)){
            check = false;
        }
        if(check)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 1050

int N, M, L[MAX], P[MAX];

bool recursive( int pos, int value){
    if ( pos == M ){
	int j = 0;
	if ( value != L[j++] ) return false;
	for ( int i = pos; i < N + M - 1; i++ ){
	    value -= P[i-M];
	    if ( L[j] == value + 1 ) { value++; P[i] = 1;}
	    else if ( L[j] == value + 0 ) {P[i] = 0;}
	    else {return false;}
	    j++;
	}
	return true;
    } else {
	P[pos] = 1;
	if (recursive(pos+1, value+1)) return true;
	P[pos] = 0;
	if (recursive(pos+1, value)) return true;

    }
    return false;
}

int main(){
    while( cin >> N >> M ){
	if ( N == 0 && M == 0 ) break;
	for ( int i = 0; i < N; i++ ) cin >> L[i];
	if (recursive(0, 0)){
	    for ( int i = 0; i < N+M-1; i++ ) cout << P[i];
	    cout << endl;
	} else {
	    cout << "Goofy" << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 1168
x[]={1,2,1,2,1,4,1,4},o[]={0,2,6,4,1,3,7,5},a[8];
main(i,j,v,V,m,t){for(;;){
for(i=0;i<8;i++)if(scanf("%d",a+i)==-1)exit(0);
for(v=99999,V=0,i=0;i<8;i++){for(m=j=0;j<8;j++)t=a[j]-x[(o[i]+j)%8],m+=t<0?0:t;if(m<v)v=m,V=o[i];}
for(j=0;j<8;j++)printf(j<7?"%d ":"%d\n",x[(V+j)%8]);
}}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long

struct C {
  ll x, y, z;
  C(ll x, ll y ,ll z) : x(x), y(y), z(z) {}
};

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

  vector<C> cakes;
  for(ll i=0; i<N; ++i) {
    ll x, y, z;
    cin >> x >> y >> z;
    cakes.emplace_back(x,y,z);
  }

  ll ans=0;
  vector<ll> v(N);

  for(ll sx=-1; sx<=1; sx+=2)
  for(ll sy=-1; sy<=1; sy+=2)
  for(ll sz=-1; sz<=1; sz+=2) {
    for(ll i=0; i<N; ++i) {
      C& c = cakes[i];
      v[i] = c.x*sx + c.y*sy + c.z*sz;
    }
    sort(v.begin(), v.end());
    ll sum = 0;
    for(ll i=0; i<M; ++i) sum += v[N-1-i];
    if(ans<sum) ans = sum;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	long long N, D;
	scanf("%lld %lld", &N, &D);
	int ans;
	ans = 0;
	for (int i = 0; i<N; i++) {
		long long x, y;
		scanf("%lld %lld", &x, &y);
		if (D*D >= x*x + y*y) {
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;






int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w,n;
    cin>>h>>w>>n;
    map <int,int> m;
    int arr[h][w];
    for(int i =0;i <n;i++){
        int no;
        cin>>no;
        m[i+1] = no;
    }
    int j =0;
    auto it = m.begin();
    for(int i = 0;i < h;i++){
        if(i%2==0){
            j=0;
            for(;j <w;j++){
                arr[i][j] = it->first;
                it->second --;
                if(it->second==0){
                    it++;
                }
            }
        }
        else{
            j=w-1;
            for(;j >=0;j--){
                arr[i][j] = it->first;
                it->second --;
                if(it->second==0){
                    it++;
                }
            }
        }


    }
    for(int i =0;i < h;i++){
        for(int j =0;j <w;j++){
            cout<<arr[i][j]<<" ";
        }
        cout<<endl;
    }










    }















































Measured memory_bytes: 1024
n = int(input())
a = [[0]*3 for i in range(n+1)]

for i in range(1,n+1) :
    a[i] = list(map(int,input().split()))

# dp[i][j] = i日目にjの活動を行なった場合の幸福度の最大値
dp = [[0]*3 for i in range(n+1)]
dp[1] = a[1]

for i in range(2,n+1) :
    for j in range(3) :
        for k in range(3) :
            if j == k :
                continue
            dp[i][j] = max(dp[i-1][k]+a[i][j],dp[i][j])

print(max(dp[n]))

Measured memory_bytes: 78060
mod = 10 ** 9 + 7

n, k = map(int, input().split())
edge = [[] for _ in range(n)]
parent = [0] * n
permutation_k2 = [1] * n
for i in range(n-1):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
  permutation_k2[i+1] = permutation_k2[i] * (k - 2 - i) % mod
count = k * (k - 1) * permutation_k2[len(edge[0]) - 1] % mod
queue = edge[0]
while queue:
  vertex = queue.pop()
  count = count * permutation_k2[len(edge[vertex]) - 1] % mod
  p = parent[vertex]
  for v in edge[vertex]:
    if v == p:
      continue
    queue.append(v)
    parent[v] = vertex
if n == 1:
  print(k)
else:
  print(count)

Measured memory_bytes: 27588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
int dp[50][500][500]; 

void init() {
  rep(i,50) rep(j,500) rep(k,500) dp[i][j][k] = INF;
}
 
int main(){
  init();
  int n, Ma, Mb;
  cin >> n >> Ma >> Mb;
  vector<int> a(n), b(n), c(n);

  rep(i,n) cin >> a[i] >> b[i] >> c[i];

  dp[0][0][0] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0 ; j < 400; j++) {
      for (int k = 0; k < 400; k++) {
        dp[i+1][j + a[i]][k + b[i]] = min(dp[i+1][j + a[i]][k + b[i]],dp[i][j][k] + c[i]);
        dp[i+1][j][k] = min(dp[i][j][k],dp[i+1][j][k]);
      }
    }
  }

  int res = INF;
  for (int j = 1; j < 400; j++) {
    for (int k = 1; k < 400; k++) {
      if (Ma * k == Mb * j) res = min(res,dp[n][j][k]);
    }
  }
  if (res == INF) puts("-1");
  else cout << res << endl;
  return 0;
}

Measured memory_bytes: 49024
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  string s;
  cin >> s;
  vector<int> cnt(2019,0);
  cnt.at(0)++;
  long res = 0;
  long keta = 1;
  for(int i=s.size()-1;i>=0;i--){
    long p = s.at(i) - '0';
    long a = p * keta + res;
    res = a%2019;
    cnt.at(res)++;
    keta *= 10;
    keta %= 2019;
  }
  long ans = 0;
  rep(i,2019){
    long t = cnt.at(i);
    ans += t*(t-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3744
# -*- coding: utf-8 -*-
N = int(input())
tree = {n:{"height":0} for n in range(N)}
parent = set([n for n in range(N)])

for n in range(N):
    inp = [int(n) for n in input().split()]
    tree[inp[0]]["children"] = [m for m in inp[1:] if m!=-1]
    parent = parent.difference(inp[1:])

generation = [parent.pop()]
tree[generation[0]]["parent"] = -1
tree[generation[0]]["depth"] = 0
tree[generation[0]]["sibling"] = -1
tree[generation[0]]["type"] = "root"
tree[generation[0]]["degree"] = len(tree[generation[0]]["children"])

checked = set(generation)
leaves = set()

depth = 1
while len(checked) < N:
    new_generation = []
    for g in generation:
        for c in tree[g]["children"]:
            tree[c]["parent"] = g
            tree[c]["sibling"] = set(tree[g]["children"]).difference([c]).pop() if len(tree[g]["children"]) == 2 else -1
            tree[c]["depth"] = depth
            tree[c]["type"] = "leaf" if len(tree[c]["children"]) == 0 else "internal node"
            if not len(tree[c]["children"]):
                leaves.add(c)            
            tree[c]["degree"] = len(tree[c]["children"])
            new_generation.append(c)
            
            
    checked.update(generation)
    last_generation = generation
    generation = new_generation
    depth += 1

checked = set()            
parents = set()
height = 0
while len(leaves):
    old_leaves = set()
    for l in leaves:
        tree[l]["height"] = max(height, tree[l]["height"])
        if tree[l]["parent"] != -1:
            old_leaves.add(tree[l]["parent"])
    checked.update(leaves)
    leaves = old_leaves
    height += 1
    
for n in range(N):
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"\
          .format(n, tree[n]["parent"], tree[n]["sibling"], tree[n]["degree"], tree[n]["depth"], tree[n]["height"], tree[n]["type"]))
    

Measured memory_bytes: 7848
#include <stdio.h>

int main(void){

    int N = 0;

    scanf("%d", &N);

    int count = N;
    int min = 9999999;

    int P[N];
    int check[N];

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

        int flag = 0;
        check[i] = 0;

        scanf("%d", &P[i]);

        for (int j = i; j >= 0; j--){

            if(min > P[i]){

                min = P[i];
                break;
            }

            if(min < P[i]){
                
                count--;
                break;
            }
/*
            if (P[j] == P[i] + 1 && check == 1){

                count--;
                break;
            }
*/
            if (P[i] > P[j]){

                count--;
                //check[i] = 1;
                break;
            }
        } 
    }

    printf("%d", count);

    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		long row = stdin.nextLong() - 2;
		long column = stdin.nextLong() - 2;

		System.out.println(Math.abs(row * column));
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll n;
ll a[100010];

void input(){
    cin >> n;
    for(int i=0;i<n;++i) cin >> a[i];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    ll cost1 = 0;
    ll cost2 = 0;
    ll s1 = 0;
    ll s2 = 0;
    //偶数番目が正、奇数番目が負になるようにコスト計算
    for(int i=0;i<n;++i){
        //cout << s1 << endl;
        s1 += a[i];
        if(i%2 && s1 >= 0){
            cost1 += (s1 + 1);
            s1 = -1;
        }
        else if(i%2==0 && s1 <= 0){
            cost1 += (1 - s1);
            s1 = 1;
        }
    }
    //その逆
    for(int i=0;i<n;++i){
        //cout << s2 << endl;
        s2 += a[i];
        if(i%2 && s2 <= 0){
            cost2 += (1 - s2);
            s2 = 1;
        }
        else if(i%2==0 && s2 >= 0){
            cost2 += (s2 + 1);
            s2 = -1;
        }
    }
    cout << min(cost1, cost2) << endl;
    return 0;
}

Measured memory_bytes: 1024