akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

namespace DPF
{
	struct DIM
	{
		ll i;
		ll j;
		void Set(ll si, ll sj)
		{
			i = si;
			j = sj;
		}
	};
	struct DP
	{
		ll value;
		DIM from;			// どこから遷移したかのメモ
		bool update_value;	// valueを更新したかどうか
	};

	void Run()
	{
		string s, t;
		cin >> s >> t;
		s += " "; t += " ";
		s.insert(0, " ");
		t.insert(0, " ");

		vector<vector<DP>> dp(size(s), vector<DP>(size(t)));
		rep(i, 1, size(s) - 1)
		{
			rep(j, 1, size(t) - 1)
			{
				if (s[i] == t[j])
				{
					dp[i][j + 1].value = dp[i - 1][j].value + 1;
					dp[i][j + 1].from.Set(i - 1, j);
					dp[i][j + 1].update_value = true;
				}
				else
				{
					if (dp[i][j].value < dp[i - 1][j + 1].value)
					{
						dp[i][j + 1].value = dp[i - 1][j + 1].value;
						dp[i][j + 1].from.Set(i - 1, j + 1);
						dp[i][j + 1].update_value = false;
					}
					else
					{
						dp[i][j + 1].value = dp[i][j].value;
						dp[i][j + 1].from.Set(i, j);
						dp[i][j + 1].update_value = false;
					}
				}
			}
		}

		string ans;
		DIM dim; dim.Set(size(s) - 2, size(t) - 1);
		while (dp[dim.i][dim.j].value != 0)
		{	// DPの最後から前に向かってLCSを構築する
			if (dp[dim.i][dim.j].update_value)
				ans += s[dim.i];

			dim = dp[dim.i][dim.j].from;
		}
		reverse(all(ans));
		cout << ans;
	}
}

int main(void)
{
	DPF::Run();
	return 0;
}


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


bool isA(string &s){
	if(s.size()<6)return false;
	if(s[0]!='>'||s[1]!='\'')return false;
	int i=2;
	while(s[i]=='=')i++;
	int cnt=i-2;
	if(cnt==0||s[i]!='#')return false;
	for(i++;i<s.size()&&s[i]=='=';i++)cnt--;
	if(cnt||i==s.size()||s[i]!='~')return false;
	return i+1==s.size();
}
bool isB(string &s){
	if(s.size()<6)return false;
	if(s[0]!='>'||s[1]!='^')return false;
	int i=2;
	for(;i<s.size()&&s[i]=='Q';){
		if(i+1<s.size()&&s[i+1]=='=')i+=2;
		else break;
	}
	if(i==2)return false;
	if(i+2==s.size()&&s[i]=='~'&&s[i+1]=='~')return true;
	return false;
}


int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(isA(s))cout<<"A\n";
		else if(isB(s))cout<<"B\n";
		else  cout<<"NA\n";
	}
	return 0;
}

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

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    rep(i,n-1) ans+=ans/(k-1)+1;
    cout<<ans<<endl;
    return 0;
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){

int N;
cin >> N;
vector<int>No(1000000, 0);
REP(i, N){
	int x;
	cin >> x;
	No.at(x)++;
}
int ans = -1;
for(int i = 1; i <=100000; i++){
	int tmp = No.at(i - 1) + No.at(i) + No.at(i + 1);
	ans = max(ans, tmp); 
}

print(ans);

}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int n,s[1000010],t[1000010],sx[1000010],tx[1000010],x=0,y=0,ans=0,m=0,fa[1000010];
map <int,int> pos;
void judge()
{
    bool flag=false;
    for (int i=1;i<=n;++i)
        if (sx[i]!=tx[i])
        {
            flag=true;
            break;
        }
    if (!flag)
    {
        cout<<"0"<<endl;
        exit(0);
    }
    sort(sx+1,sx+n+2),sort(tx+1,tx+n+2);
    for (int i=1;i<=n+1;++i)
        if (sx[i]!=tx[i])
        {
            cout<<"-1"<<endl;
            exit(0);
        }
}
int find(int x)
{
    if (fa[x]==x) return x;
    else return fa[x]=find(fa[x]);
}
int main()
{
    pos.clear();
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&s[i]);
        x^=s[i],sx[i]=s[i];
    }
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&t[i]);
        y^=t[i],tx[i]=t[i];
    }
    sx[n+1]=s[n+1]=x;
    tx[n+1]=t[n+1]=y;
    judge();
    for (int i=1;i<=n;++i)
        if (s[i]!=t[i])
        {
            ++ans;
            if (pos[s[i]]==0) pos[s[i]]=++m;
            if (pos[t[i]]==0) pos[t[i]]=++m;
        }
    if (pos[s[n+1]]==0) pos[s[n+1]]=++m;
    if (pos[t[n+1]]==0) pos[t[n+1]]=++m;
    for (int i=1;i<=m;++i) fa[i]=i;
    for (int i=1;i<=n;++i) if (s[i]!=t[i]) fa[find(pos[s[i]])]=find(pos[t[i]]);
    for (int i=1;i<=m;++i) if (fa[i]==i) ++ans;
    printf("%d\n",ans-1);
}

Measured memory_bytes: 19200
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, K = map(int, input().split())
    H = sorted(map(int, input().split()))
    if K >= N:
        print(0)
    else:
        print(sum(H[:N-K]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 26024
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


N, K = map(int, input().split())
x = list(map(int, input().split()))


# s = [0]  # type: List[int]
# sum_ = 0
# for i in range(N):
#     sum_ += x[i]
#     s.append(sum_)
def abs(n):
    if n >= 0:
        return n
    else:
        return -n
times = []                      # type: List[int]
for i in range(N-K+1):
    t = x[i+K-1] - x[i]
    t += min(abs(x[i+K-1]), abs(x[i]))
    times.append(t)

debug(times)
print(min(times))


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

int main() {
    int x, y, z;
    int count = 0;
    int a = 0, b = 0, c = 0;
    while (cin >> x >> y >> z) {
        int l = max(x, max(y, z));
        if (l >= (x + y + z - l)) break;
        vector<int> v = {x, y, z};
        sort(v.begin(), v.end());
        int rhs = v[0] * v[0] + v[1] * v[1];
        int lhs = v[2] * v[2];
        if (lhs == rhs) {
            a++;
        } else if (lhs < rhs) {
            b++;
        } else {
            c++;
        }
        count++;
    }
    cout << count << " " << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 3128
#include <iostream>

using namespace std;

typedef long long ll;

const int MAX_N = 5e3 + 5;
const ll INF = 1e14;

ll dp [MAX_N][MAX_N];
int arr [MAX_N];
ll premin [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  ll A, B;
  cin >> A >> B;

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

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  
  for (int i = 1; i <= n; i++) {
    premin[0] = dp[i - 1][0];
    for (int j = 1; j <= n; j++) {
      premin[j] = min(premin[j - 1], dp[i - 1][j]);
    }
    
    for (int j = 0; j <= n; j++) {
      if (arr[i] < j) {
	dp[i][j] = dp[i - 1][j] + B;
      } else if (arr[i] == j) {
	dp[i][j] = premin[j - 1];
      } else if (arr[i] > j) {
	dp[i][j] = dp[i - 1][j] + A;
      }
    }
  }

  ll ans = INF;
  for (int j = 1; j <= n; j++) {
    ans = min(ans, dp[n][j]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 195840
n,k = [int(i) for i in input().split()]
w = []
v = []
for _ in range(n):
    a,b = [int(i) for i in input().split()]
    w.append(a)
    v.append(b)

dp = [[0 for _ in range(k+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(k+1):
        if j >= w[i]:
            dp[i+1][j] = max(dp[i][j-w[i]]+v[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[-1][-1])


Measured memory_bytes: 171656
import math
A,B=map(int,input().split())
eight=[]
i=0
ten=[]
for a in range(1,1001):
    if math.floor(a*0.08)==A:
        eight.append(a)
    if math.floor(a*0.1)==B:
        ten.append(a)

for a in eight:
    if a in ten:
        print(a)
        i=1
        break
if i==0:
    print("-1")


Measured memory_bytes: 9216
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll 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; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int X;
    cin >> X;
    while(1){
        if(is_prime(X)){
            cout << X << endl;
            return 0;
        }
        else{
            X++;
        }
    }
}


Measured memory_bytes: 256
n = int(input())
l = [0]
ans = []
a = 0
cur = 1
while a < 1000000000000001:
  a += 26**cur
  cur += 1
  l.append(a)
l = list(reversed(l))
for i in range(len(l)-1):
  if l[i] >= n:
    ans.append(0)
  else:
    div = min((n-l[i+1]-1)//(l[i]-l[i+1]),26)
    n = n-div*(l[i]-l[i+1])
    ans.append(div)
ans.append(n)
ans =list(map(lambda x:x+96, ans))
for i in range(len(ans)):
  if ans[i] > 96:
    ans2 = ans[i:]
    break
ans2 = "".join([chr(i) for i in ans2])
print(ans2)

Measured memory_bytes: 9248
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N;
  vector<ll> A(N), sum(N+1, 0);
  REP(i,N) {
    cin>>A[i];
    sum[i+1] = sum[i] + A[i];
  }
  ll ans = 1LL << 62;
  for(int i = 1; i <= N; i++) {
    ll left = sum[i], right = sum[N] - left;
    //    cout << i << " " << left << " " << right << endl;
    chmin(ans, abs(left - right));
  }
  cout << ans << endl;
  return 0;
}


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

int main(void) {
  int n, l;
  cin >> n >> l;
  string s[n];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  
  for (int i = 0; i < n; i++) {
    for (int j = n-1; j > i; j--) {
      if (s[j] < s[j-1]) {
        string tmp;
        tmp = s[j]; s[j] = s[j-1]; s[j-1] = tmp;
      } 
    }
  }
  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N;
int A[200000], B[200000];

struct cmp {
    bool operator() (int a, int b) const {
        return B[a] < B[b];
    }
};

priority_queue<int, vector<int>, cmp> pq;

bool chk(int i) {
    return A[i] < B[i] and B[(i+1)%N] < B[i] and B[(i-1+N)%N] < B[i];
}

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    rep(i, N) if (chk(i)) pq.push(i);
    
    ll res = 0;
    while(sz(pq) > 0) {
        int t = pq.top(); pq.pop();
        int ava = (B[t]-A[t])/(B[(t+1)%N]+B[(t-1+N)%N]);
        res += ava;
        B[t] -= ava*(B[(t+1)%N]+B[(t-1+N)%N]);
        if (chk((t+1)%N)) pq.push((t+1)%N);
        if (chk((t-1+N)%N)) pq.push((t-1+N)%N);
    }

    if (equal(A, A+N, B)) cout << res << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 2428
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int ret = 0;
    ret = max(ret, a * 10 + b + c);
    ret = max(ret, b * 10 + a + c);
    ret = max(ret, c * 10 + a + b);

    cout << ret;
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define dF2(i,a,b) for(int i=a;i>(b);--i)
#define eF(i,u) for(int i=h[u];i;i=nxt[i])
#define SZ(x) ((int)(x).size())
#define prts(x) return puts(x),0
#define pirtf(x) return printf("%d\n",x),0
#define re return
typedef long long LL;
const int INF=0x3f3f3f3f;

map<int,int> mp;

int n,q,m,k,Ans;
int a[200005];

int main(){
	scanf("%d",&n);
	F(i,1,n) scanf("%d",a+i), ++mp[a[i]];
	sort(a+1,a+n+1);
	dF(i,n,1){
		if(mp[a[i]]==0) continue;
		dF(j,30,0){
			int v=(1<<j)-a[i], o=0;
			if(v<0) break;
			if(v==a[i]) o=1;
			if(mp[v]>o) {++Ans, --mp[v], --mp[a[i]]; break;}
		}
	}
	printf("%d\n",Ans);
	return 0;
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if (e - a <= k) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
int t[35],k;
struct r{
	int x,y;
}a[1050];
int main(){
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
	for (int i=1;i<=n;i++)if (((a[i].x+a[i].y)&1)!=((a[1].x+a[1].y)&1))return printf("-1\n"),0;
	int m=31;
	if (!((a[1].x+a[1].y)&1))m++;
	printf("%d\n",m);
	for (int i=30;i>=0;i--)printf("%d ",t[k++]=(1<<i));
	if (m==32)printf("1");
	printf("\n");
	for (int i=1;i<=n;i++){
		if (m==32)a[i].x--;
		for (int j=0;j<=30;j++){
			if (abs(a[i].x)>abs(a[i].y))
				a[i].x<0?(a[i].x+=t[j],printf("L")):(a[i].x-=t[j],printf("R"));
			else a[i].y<0?(a[i].y+=t[j],printf("D")):(a[i].y-=t[j],printf("U"));
		}
		if (m==32)printf("R");
		putchar('\n');
	}
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Numerics;
using System.Diagnostics;

class Program
{
    public void Slove()
    {
        string input = Console.ReadLine();
        int n = int.Parse(input);
        int[][] dp = Enumerable.Range(0, n)
            .Select(x => new int[3]
                .Select(y => int.MaxValue)
                .ToArray()
            )
            .ToArray();
        dp[0] = new int[3];
        foreach(int i in Enumerable.Range(0, n))
        {
            dp[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if(i != 0)
            {
                foreach(int j in Enumerable.Range(0, 3))
                {
                    dp[i][j] += dp[i - 1].Where((x, index) => index != j).Max();
                }
            }
        }   
        Console.WriteLine(dp[n - 1].Max());
    }
    static void Main(string[] args)
    {
        var p = new Program();
        p.Slove();
    }
}


Measured memory_bytes: 31456
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> h(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &h[i]);
  }
  vector<ll> dp(N + 10, INF);
  dp[0] = 0;
  for (int i = 1; i < N; ++i)
  {
    if (i - 2 >= 0)
      dp[i] = min({dp[i], dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])});
    else
      dp[i] = min({dp[i], dp[i - 1] + abs(h[i] - h[i - 1])});
  }
  cout << dp[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 1792
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n, p = MAP()
c = Counter(prime_factorize(p))

if len(c) == 0:
    ans = 1
else:
    i = 0
    ans = 1
    while c.most_common()[i][1] >= n:
        ans *= c.most_common()[i][0]**(c.most_common()[i][1]//n)
        if i != len(c) - 1:
            i += 1
        else:
            break
print(ans)

Measured memory_bytes: 10092
#include <bits/stdc++.h>
using namespace std;
const int M = 100001;
int n, m, i, u, v, ans, in[M], dis[M];
bool vis[M];
vector < int > adj[M];
void dfs(int s)
{
    for(auto it : adj[s])
    {
        dis[it] = max(dis[it], dis[s] + 1);
        if(--in[it] == 0) vis[it] = true, dfs(it);
    }
    ans = max(ans, dis[s]);
}

int main ()
{
    cin >> n >> m;
    for(i = 1; i <= m; i++)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        ++in[v];
    }
    for(i = 1; i <= n; i++)
    {
        if(!vis[i] and !in[i]) vis[i] = true, dfs(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 16180
import math
n = int(input())
a = list(map(int, input().split()))
nmax = 10**6

check = [0]*(nmax + 5)
for i in a:
    check[i] += 1

pairwise = True
for i in range(2, nmax + 5):
    cnt = 0
    for j in range(i, nmax + 5, i):
        cnt += check[j] 
    if cnt > 1:
        pairwise = False

if pairwise == True:
    print('pairwise coprime')
    exit()

x = 0
for i in a:
    x = math.gcd(x,i)
if x == 1:
    print('setwise coprime')
else:
    print('not coprime')





Measured memory_bytes: 194312
#D
N, Q = map(int, input().split())
#digraph a -> b
score = [0 for i in range(0,N+1)]
edge = []
aba = edge.append
ope = []
pxa = ope.append
for _ in range(N-1):
    aba(tuple(map(int, input().split())))
edge.sort() #ascending order
for _ in range(Q):
    ope = tuple(map(int, input().split()))
    score[ope[0]] += ope[1] #id
for i in range(N-1):
    score[edge[i][1]] += score[edge[i][0]]
score.remove(score[0])
print(*score)


Measured memory_bytes: 44928
N=int(input())
count=0
for i in range(N):
    a,b=map(int,input().split())

    if a==b:
        count+=1
        if count==3:
            print("Yes")
            exit()
        else:
            pass
            
    else :
        count=0

if count !=3:
    print('No')

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std ;
int main()
{
	int a[100],n,add=0,big=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
}
	for(int i=0;i<n;i++)
	{
		add=add+a[i];
		big=max(a[i],big);
	}
	if((add-big)>big)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	

	return 0;
}

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

#define ll long long
#define dd double

using namespace std;



int main(){
    int N;
    cin >> N;
    bool ans = false;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(N == i * j) ans = true;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}

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

using namespace std;

#define B       (cout << "Sehen Sie mich!" << endl)
#define VB(val) (cout << val << endl)

int main()
{
        int n;
        cin >> n;
        int a[n];
        for (int i = 0; i < n; i++)
                cin >> a[i];
        int ret = -1;
        bool exit = true;

        while (exit) {
                for (int i = 0; i < n; i++) {
                        if (a[i] % 2 == 1) {
                                exit = false;
                                break;
                        }
                        a[i] /= 2;
                }
                ret++;
        }
        VB(ret);
}

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

int main() 
{
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		map<double, int>s;
		int c;
		cin >> c;
		for (int b = 0; b < a; b++) 
		{
			double k = 100;
			int d, e, f;
			cin >> d >> e >> f;
			if (f == 1) {
				k += c*e;
			}
			else {
				for (int h = 0; h < c; h++) {
					k += k*e / 100;
				}
			}
			s.insert(pair<double, int>(k / 100, d));
		}
		auto y = s.end();
		y--;
		cout << y->second << endl;
	}
}

Measured memory_bytes: 3076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] list = str.split(" ");
		int a = Integer.parseInt(list[0]);
		int b = Integer.parseInt(list[1]);
		int c = Integer.parseInt(list[2]);
		
		if(a<=c && c<=b){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
	}

}


Measured memory_bytes: 23124
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

def main():
    n, m = getList()
    uf = UnionFind(n)
    costs = getList()

    q = []
    for i, c in enumerate(costs):
        heapq.heappush(q, (c, i))
    # print(q)
    hen = 0
    for _ in range(m):
        a, b = getList()
        if not uf.same_check(a, b):
            uf.union(a,b)
            hen += 1
 
    # print(uf.par)
    ans = 0
    used = defaultdict(int)
    kaburi = []
    mc = 0
    while(q):
        c1, m1 = heapq.heappop(q)
        if uf.find(m1) not in used.keys():
            ans += c1
            used[uf.find(m1)] = 1
            mc += 1
        else:
            heapq.heappush(kaburi, (c1, m1))

    # print(kaburi, hen, ans)
    if mc == 1:
        print(0)
        return 

    if len(kaburi) >= 2 * (n - hen - 1) - mc:
        for _ in range(2 * (n - hen - 1) - mc):
            c1, m1 = heapq.heappop(kaburi)
            ans += c1
        print(ans)
        return 
    else:
        print("Impossible")
        return


if __name__ == "__main__":
    main()
    # solve()



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

using namespace std;
using ll = long long;

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a < b) swap(a, b);
  int ans = max(a + b, a + a - 1);
  cout << ans << endl;
  return 0;
}


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

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

long long modinv(int a, int m) {
    int x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        int u = x / y;
        int x0 = y; y = x - y * u; x = x0;
        int r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}

const int M = 1000000007;

int comb(int n, int k) {
    long long ret = 1, d = 1;
    for (int i = 0; i < k; i++) {
        d = d * (i+1) % M;
        ret = ret * (n - i) % M;
    }
    return ret * modinv(d, M) % M;
}

int main() {
    int n, a, b; cin >> n >> a >> b;
    long long ans = modexp(2, n, M) - 1 - comb(n, a) - comb(n, b);
    cout << (ans % M + M) % M << endl;
}


Measured memory_bytes: 256
/*
        KUNAL RAUT (ZUKONIT14)  :- "DO WHAT YOU LIKE!" 
                -PICT,PUNE! :)
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define mod 1000000007
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000001
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define forci(p,n) for(ll i=p;i<(ll)n;i++)
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test ll t;cin>>t;while(t--)
ll zero=0;

ll gcd(ll a,ll b){    if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) {    return (a/gcd(a,b)*b);}
ll expo(ll x, ll y) {ll res=1;x=x%mod;while(y>0){if(y&1)res=(1ll*res*x)%mod;
    y=y>>1;x=(1ll*x*x)%mod;} return res;}
ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
bool prime(ll n){ll i;if(n==1) return false;for(i=2;i<=sqrt(n);i++){if(n%i==0)return false;}return true;}
 
/*ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (ll i=2; i<MAXN; i++)
        spf[i] = i;
    for (ll i=4; i<MAXN; i+=2)
        spf[i] = 2;
    for (ll i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (ll j=i*i; j<MAXN; j+=i)
            if (spf[j]==j)
            spf[j] = i;
        }
    }
}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b)return(a.second<b.second);*/
 
//https://www.youtube.com/watch?v=k4V3Mo61fJM
 
using namespace std;

signed main()
{
    bolt;
    ll n;cin>>n;
    ll a[n][3];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    ll h[n][3]={0};
    h[0][0]=a[0][0];
    h[0][1]=a[0][1];
    h[0][2]=a[0][2];
    forci(1,n)
    {
        h[i][0]=a[i][0]+max(h[i-1][1],h[i-1][2]);
        h[i][1]=a[i][1]+max(h[i-1][2],h[i-1][0]);
        h[i][2]=a[i][2]+max(h[i-1][0],h[i-1][1]);
    }
    cout<<max(h[n-1][0],max(h[n-1][1],h[n-1][2]));
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	vector<int> a(n);
	map<int,int> m;
	rep(i,n){
		cin >> a[i];
		m[ a[i] ]++;
	}

	int diameter = prev(m.end(),1)->first;

	bool f = true;
	if(diameter % 2 == 0){
		range(i, diameter / 2 + 1, diameter + 1){
			m[i]-=2;
		}
		m[diameter / 2]--;

		for(auto i : m){
			if(i.second < 0){
				f = false;
			}
			if(i.second > 0 && i.first < diameter / 2 + 1){
				f = false;
			}
		}
	}else{
		range(i, (diameter + 1) / 2, diameter + 1){
			m[i]-=2;
		}

		for(auto i : m){
			if(i.second < 0){
				f = false;
			}
			if(i.second > 0 && i.first < (diameter + 1) / 2 + 1){
				f = false;
			}
		}
	}
	cout << (f ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
A, B, C, X = 4.times.map { gets.to_i }
patterns = []
(0..A).each do |a|
  (0..B).each do |b|
    (0..C).each do |c|
      patterns << [a, b, c] if a*500 + b*100 + c*50 == X
    end
  end
end
puts patterns.size


Measured memory_bytes: 1788
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = (a + d - 1) / d;
	int y = (b + c - 1) / b;
	if(x < y) cout << "No";
	else cout << "Yes";
}


 // a b c a b c a b c a b c
 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  //	cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 3644
//abc045_b.cpp
//Sun Oct 21 11:00:21 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
int acard,bcard,ccard;
string x,y,z;

char cardplay (char turn){
	char nextturn;
	if (turn == 'a'){
		if (acard == x.size()){
			return 'A';
		}
		nextturn = x[acard];
		acard++;
	}else if (turn == 'b'){
		if (bcard == y.size()){
			return 'B';
		}
		nextturn = y[bcard];
		bcard++;
	}else if (turn == 'c'){
		if (ccard == z.size()){
			return 'C';
		}
		nextturn = z[ccard];
		ccard++;
	}
	cardplay(nextturn);
}

int main(){
	acard = 0;
	bcard = 0;
	ccard = 0;
	cin >> x >> y >> z;

	cout << cardplay('a') << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int x;
  cin >> x;

  for(int i = x;;i++){
    bool flag = true;
    for(int j = 2;j * j <= x;j++){
      if(i % j == 0){
        flag = false;
        break;
      }
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,b,f,r,v,h[5][4][11]={},i,j,k,l;
	scanf("%d",&n);
	for(l=1;l<=n;l++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		for(i=1;i<=4;i++){
			for(j=1;j<=3;j++){
				for(k=1;k<=10;k++){
					if((b==i && f==j) && r==k){
						h[i][j][k]+=v;
					}
				}
			}
		}
	}
	for(i=1;i<=4;i++){
		for(j=1;j<=3;j++){
			for(k=1;k<=10;k++){
				printf(" %d",h[i][j][k]);
			}
			printf("\n");
		}
		if(i!=4){
			for(l=0;l<20;l++){
				printf("#");
			}
			printf("\n");
		}
	}
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string s;cin>>s;
    rep(i,s.size()){
        cout<<'x';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3604
'use strict';
console.log(function(args){
  const tmp = args.trim().split('\n');
  const N = tmp[0]|0;
  const A = tmp[1].split(' ').map(v=>parseInt(v,10));
  const s = [0];
  const map = new Map([[0,1]]);
  for ( let i = 0; i < N; i++ ) {
    s.push( A[i] + s[i] );
    map.set(s[i+1], (map.get(s[i+1])|0) + 1);
  }
  let count = 0;
  for ( let v of map.values() ) {
    count += v * ( v - 1 ) / 2;
  }
  return count.toString();
}(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 76944
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
#include <set>
#define ALL(X) X.begin(), X.end()
#define SZ(A) int((A).size())
#define RALL(X) X.rbegin(), X.rend()
#define FOR(B) for (size_t i = 0; i < B; i++)
#define FOR2(B) for (size_t j = 0; j < B; j++)
#define FORE(B) for (size_t i = 1; i <= B-1; i++)
#define FORC(A, B) for (size_t i = A; i < B; i++)
#define PRINT(X) cout << X << endl
#define PRINTALL(E, X) { FOR(X) {cout << E[i] << endl; } }
#define PRINTSIDE(E, X) { FOR(X) {cout << E[i] << " ";} }
#define READALLI(V, N) FOR(N) {int x; cin >> x; V.push_back(x); }
#define READALL(V, N) FOR(N) {LL x; cin >> x; V.push_back(x); }
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXN 100000
#define SQRSIZE  317
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<LL>VL;
typedef vector<PII> VPII;
typedef map<int, int> MII;
typedef map<char, int>MCI;
typedef map<string, int> MSI;
typedef set<int> SI;
const int INF = (1 << 30);

int main() {
    LL q = 0;
    int n = 0;
    cin >> n >> q;
    set<LL> divisors;
    for(int i = 1; i < sqrt(q) + 100; i++){
        if(q % i == 0){
            divisors.insert(i);
            divisors.insert(q / i);
        }
    }

    set<LL>::iterator it;
    LL ans = 0;
    for(it = divisors.begin(); it != divisors.end(); ++it){
        if((q / n) >= *it){
            ans = *it;
        }
    }
    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 REPR(i,n) for(int i =n; i >=0; --i)

#define REP_(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

#define ll long long

//const ll MOD = 1000000007;

//const  long double PI=(acos(-1));

//const  long double EPS=0.0000000001;

int main(){
    int n;cin >> n;
    vector<int> t(n);
    vector<string> s(n);
    char x[10000];
    REP(i,n){
        cin >> s[i] >> t[i];
    }
    cin >> x;

    bool f = false;
    ll ans = 0;
    REP(i,n){
        if(f)ans+= t[i];
        if(s[i] == x)f = true;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<string>
#include<iostream>

using namespace std;
int n,d,x;
int p[50][50];
int dp[11][100002];

int main(){
        scanf("%d%d%d",&n,&d,&x);
        for(int i=0;i<d;i++){
                for(int j=0;j<n;j++){
                        scanf("%d",&p[i][j]);
                }
        }

  for(int i=0;i<d-1;i++){
    for(int j=0;j<=100000;j++){
      dp[i][j]=j;
      for(int k=0;k<n;k++){
        if(j<p[i][k] || p[i+1][k]<=p[i][k]) continue;
        dp[i][j]=max(dp[i][j],p[i+1][k]+dp[i][j-p[i][k]]);
        }}}

  //cout << "dp[0][1]:" << dp[0][1] << endl;
  //cout << "dp[0][5]:" << dp[0][5] << endl;
  //cout << "dp[1][7]:" << dp[1][7] << endl;
  int ans=x;

  for(int i=0;i<d-1;i++) ans=dp[i][ans];

        printf("%d\n",ans);

        return 0;
}

Measured memory_bytes: 5284
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    String[] s = new String[n];
    for(int i = 0; i < n; i++) {
      s[i] = sc.next();
    }
    Arrays.sort(s);
    String ans = "";
    for(int i = 0; i < n; i++) {
      ans += s[i];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 24276
#include <stdio.h>
int main()
{
int W, H, x, y, r;
scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

if ((r <= x)&& (x<= W-r)&&(r <= y) &&(y<= H - r))
printf("Yes\n");
else
printf("No\n");

return 0;
}

Measured memory_bytes: 2680
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author KY2001
 */


#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class CSpecialTrains {
public:
  int solve(std::istream &cin, std::ostream &cout) {
    int N;
    cin >> N;
    vector<int> C(N - 1);
    vector<int> S(N - 1);
    vector<int> F(N - 1);
    rep(i, N - 1) {
      cin >> C[i] >> S[i] >> F[i];
    }
    rep(i, N) {
      int now = 0;
      FOR(j, i, N - 1) {
        now = max(now, S[j]);
        if ((now - S[j]) % F[j] != 0) {
          now += (F[j] - ((now - S[j]) % F[j]));
        }
        now += C[j];
      }
      cout << now << endl;
    }
  }
};


signed main() {
	CSpecialTrains solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,k; string s; cin >> n >> k >> s;
  int score=0;
  rep(i,n) {
    if (s[i]=='R') {
      if (i+1 < n && s[i+1] == 'R') score++;
    } else {
      if (i && s[i-1]=='L') score++;
    }
  }
  cout << min(n-1, score+2*k) << endl;
  return 0;
}

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

#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};


void preorder(Node T[], int id){
    
    if (id == NIL) return; // id : parent
    
    cout << " " << id;
    
    if (T[id].left != NIL) preorder(T, T[id].left);
    if (T[id].right != NIL) preorder(T, T[id].right);
}


void inorder(Node T[], int id){
    if (id == NIL) return;
    if (T[id].left != NIL) inorder(T, T[id].left);
    cout << " " << id;
    if (T[id].right != NIL) inorder(T, T[id].right);
}

void postorder(Node T[], int id){
    if (id == NIL) return;
    if (T[id].left != NIL) postorder(T, T[id].left);
    if (T[id].right != NIL) postorder(T, T[id].right);
    cout << " " << id;
}


int main(){
    int i, n, id, left, right;
    Node T[25];
    
    cin >> n;
    
    // initialization
    for (int i = 0; i < n; i++){
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }
    
    for (int i = 0 ; i < n; i++){
        cin >> id >> left >> right;
        T[id].left = left;
        T[id].right = right;
        T[left].parent = id;
        T[right].parent = id;
    }
    
    
    // rootを探す
    
    int root = 0;
    for (int i = 0; i < n; i++){
        if (T[i].parent == NIL){
            root = i;
            break;
        }
    }
    
    cout << "Preorder" << endl;
    preorder(T, root);
    cout << endl;
    
    cout << "Inorder" << endl;
    inorder(T, root);
    cout << endl;
    
    cout << "Postorder" << endl;
    postorder(T, root);
    cout << endl;
    
    return 0;
}


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

using ll = long long;
using ld = long double;

void solve() {
  int n;
  cin >> n;

  vector<bool> ok(n);
  for(int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    ok[i] = (x == y);
  }
  for(int i = 0; i < n - 2; i++) {
    if(ok[i] && ok[i + 1] && ok[i + 2]) {
      cout << "Yes" << '\n';
      return;
    }
  }
  cout << "No" << '\n';
  return;
}

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

  int TC = 1;
  for(int i = 1; i <= TC; i++) {
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        long a = sc.NextLong();
        long b = sc.NextLong();
        long n = sc.NextLong();

        long max = Math.Min(n, b - 1);

        long answer = (a * max) / b + a * (max / b);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27412