akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const int K = 43;

ll dp[K][2][2];     // 桁DP dp[今何桁目][繰り上がりがあるか][aa以下かどうか]

int main() {
    int n; cin >> n;
    vector<ll> a(n, 0);

    // aa, bb: 一つ目の山と二つ目の山
    // x: aaとbbがxになることで勝てる
    // s: aa+bbは普遍なので守らなければならない
    for(int i = 0; i < n; ++i) cin >> a.at(i);
    ll x = 0;
    for(int i = 0; i < n; ++i) x ^= a.at(i);
    ll aa = a.at(0); ll bb = a.at(1);
    x ^= aa^bb;
    ll s = aa+bb;

    for(int i = 0; i < K; ++i) {
        for(int j = 0; j < 2; ++j) {
            for(int k = 0; k < 2; ++k) {
                dp[i][j][k] = -1;
            }
        }
    }
    dp[0][0][0] = 0;

    // vは2のべき乗
    ll v = 1;
    for(int i = 0; i < K-1; ++i) {
        // cx:xの今見てる桁
        // cs:sの今見てる桁
        // ca:aaの今見てる桁
        int cx = x&1;
        int cs = s&1;
        int ca = aa&1;
        for(int j = 0; j < 2; ++j) {
            for(int k = 0; k < 2; ++k) {
                // -1なら飛ばす
                if(dp[i][j][k] == -1) continue;
                // aとbの桁を全4通り試す
                for(int na = 0; na < 2; ++na) {
                    for(int nb = 0; nb < 2; ++nb) {
                        int ni = i+1;
                        int nj = 0, nk = k;
                        if((na^nb) != cx) continue;
                        int ns = na+nb+j;
                        if(ns%2 != cs) continue;
                        if(ns >= 2) nj = 1;
                        if(ca < na) {
                            nk = 1;
                        }else if(ca == na) {
                            nk = k;
                        }else {
                            nk = 0;
                        }
                        chmax(dp[ni][nj][nk], dp[i][j][k]|(v*na));
                    }
                }
            }
        }
        x >>= 1;
        s >>= 1;
        aa >>= 1;
        v <<= 1;
    }

    // dp[K-1][0][0]:K-1桁目まで見て、繰り上がりがなく、A以下である
    aa = dp[K-1][0][0];
    if(aa == -1 || aa == 0) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = a[0] - aa;
    cout << ans << endl;
}

Measured memory_bytes: 3604
#pragma GCC optimize (2)
#include<bits/stdc++.h>
using namespace std;
vector<int> V, ans;

inline int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}

int main()
{
	int n=read();
	for (int i=1; i<=n; i++) V.push_back(read()-1);
	for (int i=1; i<=n; i++)
	{
		bool flag=0;
		for (int j=V.size()-1; ~j; j--) if (V[j]==j)
		{
			flag=1; ans.push_back(j+1);
			V.erase(V.begin()+j); break;
		}
		if (!flag) {puts("-1"); return 0;}
	}
	for (int i=ans.size()-1; ~i; i--) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10**9+7
    ans = 1
    s, t = [], []
    for i in range(n):
        if a[i] < 0:
            t.append(a[i])
        else:
            s.append(a[i])

    S, T = len(s), len(t)
    ok = False

    if S > 0:
        if n == k:
            ok = (T % 2 == 0)
        else:
            ok = True
    else:
        ok = (k % 2 == 0)

    if not ok:
        a.sort(key=abs)
        for i in range(k):
            ans *= a[i]
            ans %= mod
    else:
        s.sort()
        t.sort(reverse=True)
        if k % 2 == 1:
            ans *= s.pop()
            ans %= mod
        p = []
        while len(s) >= 2:
            x = s.pop()
            x *= s.pop()
            p.append(x)
        while len(t) >= 2:
            x = t.pop()
            x *= t.pop()
            p.append(x)
        p.sort(reverse=True)
        for i in range(k//2):
            ans *= p[i]
            ans %= mod
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33244
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include <numeric>
#include <stdio.h>
#include<cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
 int main() {
   int n, k;
   cin >> n >> k;
   int p[n];
   for(int i=0;i<n;i++) {
     cin >> p[i];
     p[i]++;
   }
   queue<int> que;
   int s = 0;
   int mx = 0;
   for(int i=0;i<n;i++) {
     s += p[i];
     que.push(p[i]);
     if(que.size()>k) {
       s -= que.front();
       que.pop();
     }
     if (que.size() == k) {
       mx = max(mx, s);
     }
   }
   double ans = mx;
   ans /= 2;
   printf("%.10f\n", ans);
   return 0;
 }

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define reprd(i,a,b) for (int i=(a);i>=(b);--i)
#define repr(i,n) reprd(i,n,0)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
int A, B;

// 最大公約数、最小公倍数
ll gcd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main(int argc, const char * argv[]) {
    cin >> A >> B;

    output(lcm(A,B));

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int N, Q;
vi M;
vvi P;
vi F;

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

    string s, sd;
    cin >> sd >> s;

    string ans = "";
    ans += "A";
    ans += s[0];
    ans += 'C';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
int n,a,b;cin >> n >> a >> b;
cout  << min(n*a,b) << endl;


return 0;
}





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

int main() {
	string str;
	cin>>str;
	int temp1=stoi(str.substr(0,2));
	int temp2=stoi(str.substr(2,2));
	
	int flag1=temp2>=1&&temp2<=12;
	int flag2=temp1>=1&&temp1<=12;
	//cout<<flag1<<" "<<flag2<<endl;
	if(flag1==1&&flag2==0)
	{
	    cout<<"YYMM"<<endl;
	}
	else if(flag1==0&&flag2==1)
	{
	    cout<<"MMYY"<<endl;
	}
	else if(flag1==1&&flag2==1)
	{
	    cout<<"AMBIGUOUS"<<endl;
	}
	else
	{
	    cout<<"NA"<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,m; cin >> n >> m;
    VI like(m,0);
    rep(i,n){
        int k; cin >> k;
        VI a(k,0);
        rep(j,k){
            cin >> a[j];
            like[a[j]-1]++;
        }
    }
    int ans = 0;
    rep(i,m) if(like[i] == n) ans++;
    ANS;

    return 0;
}

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100100;

struct edge
{
	int id, g, nxt;

	edge() { }
	edge(int _id, int _g, int _nxt): id(_id), g(_g), nxt(_nxt) { }

};

edge e[(maxn << 1) + 5];
int st[maxn + 5], en = 0;

inline void add_edge(int x, int y, int z)
{
	e[en] = edge(y, z, st[x]), st[x] = en++;
}

int n;

int sz[maxn + 5];
int Max[maxn + 5];

void pre_dfs(int x, int f = -1)
{
	sz[x] = 1;
	Max[x] = 0;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		int y = e[i].id;
		if (y == f) continue;
		pre_dfs(y, x);
		sz[x] += sz[y];
		chkmax(Max[x], sz[y]);
	}
}

LL dep[maxn + 5];

void dfs(int x, int f = -1)
{
	sz[x] = 1;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		int y = e[i].id;
		if (y == f) continue;
		dep[y] = dep[x] + e[i].g;
		dfs(y, x);
		sz[x] += sz[y];
	}
}

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	memset(st, -1, sizeof st), en = 0;
	scanf("%d", &n);
	REP(i, 0, n - 1)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z), --x, --y;
		add_edge(x, y, z); 
		add_edge(y, x, z);
	}
	pre_dfs(0);
	int x = -1;
	REP(i, 0, n)
	{
		Max[i] = max(Max[i], n - sz[i]);
		if (!~x || Max[i] < Max[x]) x = i;
	}
	dfs(x);
	LL ans = 0;
	REP(i, 0, n) ans += dep[i] << 1;
	if ((Max[x] << 1) == n)
	{
		for (int i = st[x]; ~i; i = e[i].nxt) if (sz[e[i].id] == Max[x]) ans -= e[i].g;
	}
	else
	{
		int Min = oo;
		for (int i = st[x]; ~i; i = e[i].nxt) chkmin(Min, e[i].g);
		ans -= Min;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<pair<int,int> >arr(n);
	for(int i=0; i<n; i++){
		cin>>arr[i].first>>arr[i].second;
	}
	for(int i=0; i<n-2; i++){
		int flag=1;
		for(int j=0; j<3; j++){
			if(arr[i+j].first!=arr[i+j].second){
				flag=0;
				break;
			}
		}
		if(flag==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

template<typename T>
struct edge {
    int src, to;
    T cost;
};

template<typename T>
using Graph = vector<vector<edge<T>>>;

using State = string::const_iterator;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    // ifstream in("in.txt");
    // cin.rdbuf(in.rdbuf());

    auto length = [](ll n) {
        ll tmp = 1, k = 1;
        while (tmp * 10 <= n) tmp *= 10, ++k;
        ll ret = 0;
        while (n > 0) {
            ret += (n - tmp + 1) * k;
            n = tmp - 1;
            tmp /= 10;
            --k;
        }
        return ret;
    };

    for (;;) {
        ll N, K; cin >> N >> K;
        if (N == 0) break;

        ll l = 0, r = 1e9;
        while (r - l > 1) {
            ll m = (l + r) >> 1;
            (length(m) < N ? l : r) = m;
        }

        ll len = length(l);

        string ans;
        for (ll num = l+1; ans.size() < N - 1 - len + K; ++num) ans += to_string(num);
        ans = ans.substr(N - 1 - len, K);
        cout << ans << endl;
    }

    return 0;
}




Measured memory_bytes: 3248
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  unless (n == 0) $ do
    solve <$> replicateM n (getl words) >>= mapM_ putStrLn
    main

solve :: [[String]] -> [String]
solve = map fst . sortBy g . map f
  where f (y:ys) = (y, ((length . filter (=="0")) ys, (length . filter (=="1")) ys))
        g a b = if (fst.snd) a == (fst.snd) b
                then (snd.snd) a `compare` (snd.snd) b
                else (fst.snd) b `compare` (fst.snd) a
                                                   
toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Stack struct {
	xs [1000]string
	i  int
}

func (s *Stack) push(x string) {
	s.i++
	s.xs[s.i] = x
}

func (s *Stack) pop() string {
	x := s.xs[s.i]
	s.i--
	return x
}

func nextStr(sc *bufio.Scanner) string {
	sc.Scan()
	s := sc.Text()
	return s
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	//sc.Split(bufio.ScanWords)

	stack := Stack{}

	sc.Scan()
	ss := sc.Text()
	for _, s := range strings.Split(ss, " ") {
		switch s {
		case "*":
			r, err := strconv.Atoi(stack.pop())
			if err != nil {
				panic(err)
			}
			l, err := strconv.Atoi(stack.pop())
			if err != nil {
				panic(err)
			}
			stack.push(strconv.Itoa(l * r))
		case "+":
			r, err := strconv.Atoi(stack.pop())
			if err != nil {
				panic(err)
			}
			l, err := strconv.Atoi(stack.pop())
			if err != nil {
				panic(err)
			}
			stack.push(strconv.Itoa(l + r))
		case "-":
			r, err := strconv.Atoi(stack.pop())
			if err != nil {
				panic(err)
			}
			l, err := strconv.Atoi(stack.pop())
			if err != nil {
				panic(err)
			}
			stack.push(strconv.Itoa(l - r))
		default:
			stack.push(s)
		}
	}
	fmt.Println(stack.pop())
}



Measured memory_bytes: 1156
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N;
ll K;
pair<ll,int> B[SIZE];
int C[SIZE];
ll bit[SIZE];
//bitは1オリジン

int sum(int i){
	ll s = 0;
	while(i>0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i,ll x){
	while(i <= N){
		bit[i] += x;
		i += i & -i;
	}
}
int main()
{
	scanf("%d%lld",&N,&K);
	ll a;
	ll ans=0;
	B[0]=make_pair(0,0);
	for(int i=1;i<=N;i++){
		scanf("%lld",&a);
		B[i].first = B[i-1].first+a-K;
		B[i].second = i;
	}
	//Bについて転置数を求める
	sort(B,B+N+1);
	int c=1;
	for(int i=0;i<=N;i++){
		C[B[i].second] = c;
		if(B[i].first<B[i+1].first)c++;
	}
	//B->Cに移し替えた
	//Cの転置数を求める
	N++;
	for(int i=0;i<N;i++){
		//printf("%lld,",C[i]);
		ans += sum(C[i]);
		add(C[i],1);
	}
	printf("%lld\n",ans);
	return 0;
}


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

long long gcd(long long a, long long b) {
    while (b) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

int main() {
    std::ios::sync_with_stdio(false);
    long long n;
    std::cin >> n;
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int q = 1; q <= n; ++q) {
                long long cur;
                cur = gcd(i, j);
                cur = gcd(cur, q);
                ans += cur;
            }
        }
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3656
import java.util.*;

class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a,b,c;
a =sc.nextInt();
b =sc.nextInt();
c =sc.nextInt();

if(a<b && b<c) System.out.println("Yes");
else System.out.println("No");

}
}

Measured memory_bytes: 17160
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

const int inf=1<<29;
const int M=26;

int n;
string s;

int dp[200001][M+1];

int main(){
	cin>>s;
	n=s.size();
	for(int i=0;i<=n;i++) fill(dp[i],dp[i]+M+1,inf);
	map<int,int> m;
	int res=inf,S=0;
	dp[0][M]=0;
	m[0]=0;
	for(int i=0;i<n;i++){
		int c=s[i]-'a';
		S^=1<<c;
		dp[i+1][M]=dp[i][c];
		for(int j=0;j<M;j++){
			int T=S^(1<<j);
			if(m.find(T)!=m.end()){
				int I=m[T];
				for(int k=0;k<=M;k++) dp[i+1][j]=min(dp[i+1][j],dp[I][k]+(k!=M||I==0?1:0));
			}
		}
		m[S]=i+1;
	}
	for(int i=0;i<=M;i++) res=min(res,dp[n][i]);
	cout<<res<<endl;
}

Measured memory_bytes: 30852
W, H, x, y = map(int, input().split())

if (x==0 and y==0) or (x==0 and y==H) or (x==W and y==0) or (x==W and y==H):
  print(W*H/2, "0")
  exit()

a = min(x*H,(W-x)*H)
b = min(y*W,(H-y)*W)
tmp = '0'
if a == b:
    tmp = '1'
print(W*H/2,tmp)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll fib[50];
    ll n;
    cin>>n;
    fib[0]=fib[1]=1;
    for(int i=2;i<=n;i++){
    	fib[i]=fib[i-1]+fib[i-2];
    }
    cout << fib[n]<<endl;
    return 0;
}




Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;


int main() {
    int X, Y;
    cin >> X >> Y;
    int sum = 0;
    if(X ==1 and Y==1){
        sum = 300000 + 300000 + 400000 ;
        cout << sum << endl;
        return 0;
    }

    if(X==1){
        sum += 300000;
    }
    else if(X==2){
        sum += 200000;
    }
    else if(X==3){
        sum += 100000;
    }

    if(Y==1){
        sum += 300000;
    }
    else if(Y==2){
        sum += 200000;
    }
    else if(Y==3){
        sum += 100000;
    }

    cout << sum << endl;

}

Measured memory_bytes: 888
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

int main() {
    char S[11];
    scanf("%s", S);
    size_t len = strlen(S);
    int row = 0, min = 1000;
    for (size_t i=0; i<len; i++) {
        row = (row * 10 + (S[i]-'0')) % 1000;
        const int dif = abs(row-753);
        if (i >= 2 && dif < min) min = dif;
    }
    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 128
ABC = list(map(int,input().split()))
ABC.sort()
a_b = ABC[1]-ABC[0]
a_c = ABC[2]-ABC[1]
b_c = ABC[2]-ABC[0]
list_abc=[]
list_abc.append(a_b)
list_abc.append(a_c)
list_abc.append(b_c)
list_abc.sort()
if list_abc[0]==0:
    if list_abc[1]==0:
        print("No")
    else:
        print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
X, K, D = map(int, input().split())

X = abs(X)

final = -1

q, n = X % D, X // D

if n >= K:
  print(X - K * D)
else:
  if q <= X / 2:
    if (K - n) % 2 == 0:
      print(q)
    else:
      print(D - q)
  else:
    if (K - n) % 2 == 0:
      print(q)
    else:
      print(D - q)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> vector<T> make_vec(size_t n) { return vector<T>(n); }
template<typename T, typename... Args> auto make_vec(size_t n, Args... args) {
    return vector<decltype(make_vec<T>(args...))>(n, make_vec<T>(args...));
}
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U& u, const V... v) {
    for (auto& e : u) fill_v<T>(e, v...);
}

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        chmax(b[i], a[i]);
        if (i != 0) chmax(b[i], b[i-1]);
    }
    ll sum = 0;
    rep(i, n) sum += b[i] - a[i];
    cout << sum << '\n';
}


Measured memory_bytes: 4748
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

void solve() {
	int n; cin >> n;
	vector<int> r(n), c(n);
	vector<int> x, y;
	rep(i, n) {
		cin >> r[i] >> c[i]; r[i]--; c[i]--;
		x.push_back(r[i]);
		y.push_back(c[i]);
	}
	sort(x.begin(), x.end());
	int len = unique(x.begin(), x.end())-x.begin();
	if (len != n) {
		cout << -1 << endl; return;
	}
	sort(y.begin(), y.end());
	len = unique(y.begin(), y.end()) - y.begin();
	if (len != n) {
		cout << -1 << endl; return;
	}
	vector<int> p(n);
	rep(i, n) {
		p[c[i]] = r[i];
	}
	vector<bool> used(n, false);
	int ans = 0;
	rep(i, n) {
		if (used[i])continue;
		used[i] = true; int tmp = 1;
		int cur = i;
		while (!used[p[cur]]) {
			cur = p[cur]; used[cur] = true;
			tmp++;
		}
		ans += tmp - 1;
	}
	cout << ans << endl;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> map(h + 2, vector<bool>(w + 2));
    for(int i = 0; i < h; i++){
        string s;
        cin >> s;
        for(int j = 0; j < w; j++){
            if(s[j] == '.'){
                map[i + 1][j + 1] = true;
            }
        }
    }
    vector<vector<int>> dis(h + 2, vector<int>(w + 2));
    queue<pair<int, int>> que;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(!map[i][j]) que.push(make_pair(i, j));
        }
    }
    while(!que.empty()){
        auto p = que.front();
        int x = p.first;
        int y = p.second;
        que.pop();
        for(int i = 0; i < 4; i++){
            int cx = x + dx[i];
            int cy = y + dy[i];
            if(!map[cx][cy] || dis[cx][cy]){
                continue;
            }
            dis[cx][cy] = dis[x][y] + 1;
            que.push(make_pair(cx, cy));
        }
    }
    int mx = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            mx = max(mx, dis[i][j]);
        }
    }
    cout << mx;
}

Measured memory_bytes: 12560
import Data.Array.IO
main = do
  n <- readLn :: IO Int
  let as = flip
        map
        [(x, y, z) | x <- [1 .. 100], y <- [1 .. 100], z <- [1 .. 100], x+y+z <= 300]
        $ \(x, y, z) -> x ^ 2 + y ^ 2 + z ^ 2 + x * y + y * z + z * x
  ar <- newArray (1,n) 0 :: IO (IOUArray Int Int)
  flip mapM_ as $ write n ar
  flip mapM_ [1..n] $ \i -> print =<< readArray ar i
  where
      write n ar i | i <= n = writeArray ar i =<< (+1) <$> (readArray ar i)
              | otherwise = return ()


Measured memory_bytes: 4808
#include<stdio.h>
int main(){
  int a,A[100],N,i,j,minj,cnt=0;
  scanf("%d",&N);
  for(i=0;i<=N-1;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=N-1;i++){
  
    
  for(j=minj=i;j<=N-1;j++){
    if(A[j]<A[minj])minj=j;
  }
  if(A[i]>A[minj]){
     
    //A[i]toA[minj]wokoukan
    a=A[i];
    A[i]=A[minj];
    A[minj]=a;
      if(i!=minj)cnt++;
  }
    
  }
  
  
  
 
 

for(j=0;j<N-1;j++){
  printf("%d ",A[j]);
 }
printf("%d\n",A[N-1]);
  printf("%d\n",cnt);
return 0;
}




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

int main()
{
    int n;
    int arr[10] = {1000,2000,3000,4000,5000,6000,7000,8000,9000,10000};
    cin>>n;
    for(int i = 0; i < 10; i++)
    {
        if(arr[i] >= n)
        {
            cout<<arr[i] - n<<endl;
            break;
        }
    }
    return 0;
}

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

bool dp[101];

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

	int n;

	cin >> n;

	memset(dp,false,sizeof(dp));
	dp[0] = true;

	for(int i=0;i<=100;i++)
	{
		if(dp[i])
		{
			if(i+4<=100)
			{
				dp[i+4] = true;
			}
			if(i+7<=100)
			{
				dp[i+7] = true;
			}
		}
	}

	if(dp[n])
	{
		cout << "Yes" << '\n';
	}
	else
	{
		cout << "No" << '\n';
	}
	
	return 0;	
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int input = sc.nextInt();
		long min;
		long n[] = new long [input];
		int countm =  0;
		
		long v = sc.nextInt();
		if(v<0) countm+=1;
		n[0]=Math.abs(v);
		min =n[0];
		
		for (int i=1 ; i<input ; i++ ){
			v = sc.nextInt();
			if(v<0) countm+=1;
			n[i]=Math.abs(v);
			if(min>n[i]){
				min = n[i];
			}
			
		}
		long ans = 0;
		for (int i=0 ; i<input ; i++ ){
			ans += n[i];
		}
		if(countm%2==1){
			ans -=2*min;
		}


		System.out.println(ans);
	}

}

Measured memory_bytes: 49396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793

int main() {
	int n, l;
	cin >> n >> l;
	vector<string>s(n);
	for (int i = 0; i < n; i++)cin >> s[i];
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++)cout << s[i];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2000 + 5;

int n;
pair<ll,int> a[N];
ll f[N][N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].first;
		a[i].second=i;
	}
	sort(a,a+n,greater<pair<int,int> >());
	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			int k=i-j;
			f[j+1][k]=max(f[j+1][k],f[j][k]+a[i].first*abs(a[i].second-j));
			f[j][k+1]=max(f[j][k+1],f[j][k]+a[i].first*abs(n-k-1-a[i].second));
		}
	}
	ll ans=0;
	for(int i=0;i<=n;i++) ans=max(ans,f[i][n-i]);
	cout<<ans;
	return 0;
}

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

int main() {
    int n,m;
    cin>>n>>m;
    int ans[m]={0};
    //int temp=n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        while(x--){
            int y;
            cin>>y;
            ans[y-1]++;
        }
    }
    int count=0;
    for(int i=0;i<m;i++){
        if(ans[i]==n)count++;
    }
    cout<<count;
}

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


int main() {
	int N = 0;
	int K[10000], P[10000];
	cin >> N;
	for (int i = 0;i<N;i++) {
		cin >> K[i];
		cin>>	P[i];
	}
	for (int i = 0;i<N;i++) {
		int ans = K[i]%P[i];
		if (ans == 0) {
			cout << P[i] << endl;
		}
		else {
			cout << ans << endl;
		}
	}



	return 0;
}

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

int main(){
  int a, b, w;
  cin >> w >> a >> b;
  if(b > a + w) cout << b - a - w << endl;
  else if(a > b + w) cout << a - b - w << endl;
  else cout << "0" <<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String o="No";
        int[][] a=new int[3][3];
        for(int i=0;i<3;i++){
        	for(int j=0;j<3;j++){
            	a[i][j]=sc.nextInt();
            }
        }
        int n=sc.nextInt();
      int b=0;
      boolean[][] c=new boolean[3][3];
        for(int k=0;k<n;k++){
          b=sc.nextInt();
        	for(int i=0;i<3;i++){
        		for(int j=0;j<3;j++){
            		if(a[i][j]==b){
                		c[i][j]=true;
                	}	
            	}
        	}
        }
      for(int i=0;i<3;i++){
      	if(c[i][0]&&c[i][1]&&c[i][2])o="Yes";
      }
      for(int i=0;i<3;i++){
      	if(c[0][i]&&c[1][i]&&c[2][i])o="Yes";
      }
      if(c[0][0]&&c[1][1]&&c[2][2])o="Yes";
       if(c[0][2]&&c[1][1]&&c[2][0])o="Yes";
      
      System.out.println(o);
    }
    
}

Measured memory_bytes: 25044
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
struct mint {
    int x;
    mint(int x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return *this *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
mint F[2100010];
void fact(void) {
	F[0] = mint(1);
	F[1] = mint(1);
	for (int i = 2; i <= 2100000; i++) {
        mint x(i);
		F[i] = x * F[i - 1];
	}
}
 
mint square(mint x) {
    return x * x;
}
 
mint power(mint x, int y) {
    if (y == 0) return mint(1);
    else if (y == 1) return x;
    else if (y % 2 == 0) return square(power(x, y / 2));
    else return square(power(x, y / 2)) * x;
}
 
mint P(int n, int r) {
	if (n < r || n < 0 || r < 0) return mint(0);
	return F[n]/F[n - r];
}
 
mint C(int n, int r) {
	if (n < r || n < 0 || r < 0) return mint(0);
	mint ret;
	ret = F[n]/(F[n - r] * F[r]);
	return ret;
}
mint H(int n, int r) {
	if (n == 0 && r == 0) return mint(1);
	return C(n + r - 1, r);
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    fact();
    int S; cin >> S;
    mint ans = 0;
    REP(i, 1, S) {
        int remain = S - i * 3;
        if(remain < 0) continue;
        else ans += F[remain + i - 1]/F[remain]/F[i - 1];
        //cout << i << " " << ans.x << " " << remain << endl;
    }
    cout << ans.x << endl;
    return 0;
}
//ooooo||

Measured memory_bytes: 20060
n,s = map(int,input().split())
a = list(map(int,input().split()))
c = [0]*(s+1)
ans = 0
mod = 998244353
for i in range(n):
    c_=c.copy()
    if a[i] <= s:
        for j in range(a[i],s+1):
            c[j] += c_[j-a[i]]
        c[a[i]] += i+1
    ans += c[s]
    ans %= mod

print(ans)

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

int n,a,b;
vector <ll> v;

bool check(ll t)
{
    ll u = a-b;
    ll ans = 0;
    for (auto it:v)
    {
        if (it <= t*b)
            continue;
        else
            ans += ((it-t*b)/u + (((it-t*b)%u) ? 1 : 0));
    }
    if (ans <= t)
        return true;
    else
        return false;
}

int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for (int i = 0; i<n; i++)
    {
        ll h;
        scanf("%lld",&h);
        v.push_back(h);
    }
    int lo = 0, hi = 1000000000;
    while(lo<hi)
    {
        int mid = (lo+hi)/2;
        if (check(mid))
            hi = mid;
        else
            lo = mid+1;
        if (hi==lo)
            break;
    }
    printf("%d",lo);
}

Measured memory_bytes: 1400
#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 col[100100];
vector<vector<int> > E;

pll dfs(int n, int c, bool & flg) {
	pll res(0,0);
	if(col[n]) {
		if(col[n] != c) flg = false;
		return res;
	}
	col[n] = c;
	for(int i = 0; i < E[n].size(); i++) {
		pii tmp;
		tmp = dfs(E[n][i], c*-1, flg);
		res.fi += tmp.fi;
		res.se += tmp.se;
	}
	if(c > 0) res.fi++;
	else res.se++;
	return res;
}

int main() {
	int N, M;
	cin >> N >> M;
	E.resize(N);
	rep(i,M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}

	ll res = 0;
	for(int i = 0; i < N; i++) {
		if(!col[i]) {
			bool f = true;
			pll tmp;
			tmp = dfs(i,1,f);
			if(f) {
				res += tmp.fi * tmp.se;
			}
			else {
				ll v = tmp.fi + tmp.se;
				res += v * (v-1) / 2;
			}
		}
	}
	cout << res - M << endl;
	return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    string s;
    cin >> s;
    if(s == "ABC")puts("ARC");
    else puts("ABC");

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

bool can_buy[100100] = {true};

int main() {
    int x;
    cin >> x;

    for (int i = 0; i < 6; ++i) {
        for (int j = 0; j + 100 + i <= x; ++j) {
            if (!can_buy[j]) continue;
            can_buy[j + 100 + i] = can_buy[j];
        }
    }
    cout << can_buy[x] << endl;
    return 0;
}


Measured memory_bytes: 384
//header
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>

//main
int main(void)
{
	int a, b, k,j=2;

	scanf("%d%d%d", &a, &b, &k);

	for(int i=k;i!=0;i--,j++){
		if (j % 2 == 0) {
			if (a % 2 == 1) {
				a--;
			}
			b += a / 2;
			a /= 2;
		}
		else {
			if (b % 2 == 1) {
				b--;
			}
			a += b / 2;
			b /= 2;
		}
	}

	printf("%d %d\n", a, b);

	return 0;
}




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

using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 313
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define IINF 1000000000
#define mp make_pair
#define pb push_back
#define remove pop
#define all(x) x.begin(), x.end()


int n, k;
ll h[MAXN];


ll dp[MAXN][MAXN][MAXN];

int main() {
	if (fopen("FILENAME.in", "r")) {
		freopen("FILENAME.in", "r", stdin);
		freopen("FILENAME.out", "w", stdout);
	}
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);


	cin >> n >> k;

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

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

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

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= k; j++) {
			for (int l = 0; l <= i; l++) {
				if (dp[i][j][l] == INF) continue;

				//cout << "at " << i << ' ' << j << ' ' << l << " have " << dp[i][j][l] << endl;
				dp[i + 1][j + 1][l] = min(dp[i + 1][j + 1][l], dp[i][j][l]); //Skipped

				dp[i + 1][j][i + 1] = min(dp[i + 1][j][i + 1], dp[i][j][l] + max(0LL, h[i] - (l == 0 ? 0 : h[l - 1])));
			}
		}
	}

	ll answer = INF;

	for (int i = 0; i <= k; i++) {
		for (int l = 0; l <= n; l++) {
			answer = min(answer, dp[n][i][l]);
		}
	}

	cout << answer << endl;

}

//GCD GCD GCD USE GCD IN MATH

Measured memory_bytes: 231680
import sys

def dijkstra(v_count: int, edges: list, start: int,
             *, adj_matrix: bool = False, unreachable=float("inf")) -> list:
    """ ダイクストラ法
    :param v_count: 頂点数
    :param edges: 辺のリスト(隣接リストor隣接行列)
    :param start: スタートする頂点
    :param adj_matrix: edgesに渡したリストが隣接行列ならTrue
    :param unreachable: 到達不能を表すコスト値
                        隣接行列の辺の有無の判定および返すリストの初期値に使用
    """
    from heapq import heappush, heappop

    vertices = [unreachable] * v_count
    vertices[start] = 0
    q, rem = [(0, start)], v_count - 1

    while q and rem:
        cost, v = heappop(q)
        if vertices[v] < cost:
            continue
        rem -= 1

        dests = (filter(lambda x: x[1] != unreachable, enumerate(edges[v]))
                 if adj_matrix else edges[v])

        for dest, _cost in dests:
            newcost = cost + _cost
            if vertices[dest] > newcost:
                vertices[dest] = newcost
                heappush(q, (newcost, dest))

    return vertices

n = int(input())
edges = [[] for _ in [0]*n]
for a in (tuple(map(int, l.split())) for l in sys.stdin):
    edges[a[0]] = tuple(zip(a[2::2], a[3::2]))
vertices = dijkstra(n, edges, 0)
for i, n in enumerate(vertices):
    print(i, n)


Measured memory_bytes: 67740
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define fi first
#define se second
#define pi pair<LL,LL>
#define LL long long
using namespace std;
const LL inf=2e9;
const LL mod=1e9+7;
LL n,h[110];
LL pow(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;b>>=1;
	}
	return ans;
}
pi solve(LL l,LL r,LL k)//l r区间大于k的部分
{
	LL Min=inf,cnt=0;pi ans;
	for(LL i=l;i<=r;i++)
	{
		if(h[i]<Min) Min=h[i],cnt=1;
		else if(h[i]==Min) cnt++;
	}
	if(cnt==(r-l+1))
	{
		ans.fi=(pow(2,r-l+1)+mod-2)%mod;
		ans.se=pow(2,Min-k-1);
		//printf("1:%lld %lld %lld %lld\n",l,r,ans.fi,ans.se);
		return ans;
	}
	LL re=r-l+1,s0=1,s1=1,last=0;
	for(LL i=l;i<=r+1;i++) if(!last&&h[i]>Min) last=i;
	else if(last&&(h[i]<=Min||i>r))
	{
		re-=i-last;
		pi tmp=solve(last,i-1,Min);
		s0=s0*(tmp.fi+4*tmp.se%mod)%mod;
		s1=s1*(2*tmp.se%mod)%mod;
		last=0;
	}
	s0=(s0+mod-s1)%mod;
	//printf("s:%lld %lld\n",s0,s1);
	ans.fi=s0*pow(2,re)%mod;
	(ans.fi+=(s1*(pow(2,re)-2+mod)%mod)%mod)%=mod;
	ans.se=s1*pow(2,Min-k-1)%mod;
	//printf("2:%lld %lld %lld %lld\n",l,r,ans.fi,ans.se);
	return ans;
} 
int main()
{
	scanf("%lld",&n);
	for(LL i=1;i<=n;i++) scanf("%lld",&h[i]);
	if(n==1)
	{
		printf("%lld",pow(2,h[1]));
		return 0;
	}
	LL tot=1;
	for(LL i=1;i<=n;i++) if(h[i]>h[i-1]&&h[i]>h[i+1])
	{
		(tot*=pow(2,h[i]-max(h[i-1],h[i+1])))%=mod;
		h[i]=max(h[i-1],h[i+1]);
	}
	pi ans=solve(1,n,0);
	printf("%lld",tot*((ans.fi+ans.se*2)%mod)%mod);
}

Measured memory_bytes: 256
#include<stdio.h>

int gcd(int a,int b){
  int lar,sma;
  if(a>b){
    lar = a;
    sma = b;
  }else{
    lar = b;
    sma = a;
  }
  if(lar%sma == 0){
    return sma;
  }else{
    return gcd(b,a%b);
  }
}

int main(){
  int k;
  char buf[10];

  if(fgets(buf,sizeof(buf),stdin)!=NULL){
    sscanf(buf,"%d",&k);
  }

  int x,y,z;
  int sum = 0;
  for(x=1;x<=k;x++){
    for(y=1;y<=k;y++){
      for(z=1;z<=k;z++){
        sum += gcd(gcd(x,y),z);
      }
    }
  }

  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 1696
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 998244353ll;
const dou pi=3.141592653589793;

//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう
int main(){
    int n,m;
    std::cin >> n>>m;
    std::vector<bool> b(n+5,1);
    rep(i,m){
        int d;
        std::cin >> d;
        b[d]=0;
    }
    std::vector<ll> dp(n+3);
    dp[0]=1;
    rep(i,n){
        if(!b[i])continue;
        else{
            if(b[i+1]){
                dp[i+1]+=dp[i];
                dp[i+1]%=MOD;
            }
            if(b[i+2]){
                dp[i+2]+=dp[i];
                dp[i+2]%=MOD;
            }
            
        }
    }
    std::cout << dp[n] << std::endl;
}


Measured memory_bytes: 1024