akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;

    priority_queue<ll> kind[N];
    for (int i = 0; i < N; ++i) {
        int t;
        ll d;
        cin >> t >> d;
        kind[t - 1].push(d);
    }

    priority_queue<ll> best, remain;
    // best: 各種類で一番美味しいやつを集めたもの
    // remain : bestの余り
    for (int i = 0; i < N; ++i) {
        if (!kind[i].empty()) {
            best.push(kind[i].top());
            kind[i].pop();

            while (!kind[i].empty()) {
                remain.push(kind[i].top());
                kind[i].pop();
            }
        }
    }

    vector<ll> bsum = {0};
    // bestの累積和 (bsum[i] = bestの先頭からi個の総和)
    while (!best.empty()) {
        bsum.push_back(bsum.back() + best.top());
        best.pop();
    }

    vector<ll> rsum = {0};
    // remainの累積和
    while (!remain.empty()) {
        rsum.push_back(rsum.back() + remain.top());
        remain.pop();
    }

    ll ans = 0;
    for (ll x = 1; x <= K; ++x) {
        // 種類が多すぎるケース
        if (x >= bsum.size()) break;

        // 種類が少なすぎて、余り物が足りないケース
        if (K - x >= rsum.size()) continue;

        // bestからx個、remainからK-x個貪欲に選ぶ
        ans = max(ans, bsum[x] + rsum[K - x] + x * x);
    }

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

Measured memory_bytes: 8820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e3 + 5;
ll dp[220][110];
ll sum[220];
void print(ll step , ll rest , ll dig)
{
    if(step == 0) return ;
    cout << dig;
    if(dig == 9) {
        if(rest <= dp[step - 1][dig - 1]){
            print(step - 1 , rest , dig - 1);
          	return ;
        }
        rest -= dp[step - 1][dig - 1];
        print(step - 1 , rest , dig);
        return ;
    }
    if(dig == 0){
        if(rest <= dp[step - 1][dig]){
            print(step - 1 , rest , dig);
            return ;
        }
        rest -= dp[step - 1][dig];
        print(step - 1 , rest , dig + 1);
        return ;
    }
    if(rest <= dp[step - 1][dig - 1]){
        print(step - 1 , rest , dig - 1);
        return ;
    }
    rest -= dp[step - 1][dig - 1];
    if(rest <= dp[step - 1][dig]){
        print(step - 1 , rest , dig);
        return ;
    }
    rest -= dp[step - 1][dig];
    print(step - 1 , rest , dig + 1);
}

int main()
{
    ios::sync_with_stdio(false);
    ll k ; cin >> k;
    for (int i = 0; i <= 9 ; i++) dp[1][i] = 1;
    sum[1] = 9;
    for (int i = 2 ; i <= 11 ; i++){
        for (int j = 0 ; j <= 9 ; j++){
            if(j > 0) dp[i][j] += dp[i - 1][j - 1];
            if(j < 9) dp[i][j] += dp[i - 1][j + 1];
            dp[i][j] += dp[i - 1][j];
            if(j != 0) sum[i] += dp[i][j];
        }
    }
    ll step = 1;
    for (int i = 1 ; i <= 11 ; i++){
        if(k > sum[i]){
            k -= sum[i];
            step++;
        }
        else {
            break;
        }
    }
    ll dig = 1;
    for (int i = 1 ; i <= 9 ; i++){
        if(k > dp[step][i]) k -= dp[step][i] , dig++;
        else break;
    }
    print(step , k , dig);
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split(" ")))

d = 0
for i in range(1,n-1):
  a, b, c = p[i-1:i+2]
  #print("{} {} {}".format(a,b,c))
  if (a < b and b < c) or (a > b and b > c):
    d += 1

print(d)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vi c(n);
    vector<vi> a(n, vi(m));
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    ll ans = INF;
    rep(mask, 1<<n) {
        vi y(m);
        ll tmp = 0;
        rep(i, n) if(mask&(1<<i)) {
            rep(j, m) y[j] += a[i][j];
            tmp += c[i];
        }
        if(*min_element(all(y)) >= x) chmin(ans, tmp);
    }
    if(ans == INF) ans = -1;
    cout << ans << '\n';
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int

void solve(int caseNo)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = LLONG_MIN;
    ans = max(ans, a*c);
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << endl;
}

int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

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

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A*B*C==175&&A+B+C==17){
    cout << "YES" << endl;
  }
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  int n;
  cin>>n;
  vector<int> c(n),w(n);
  rep(i,n) cin>>c[i]>>w[i];
  vector<int> acc(n+1,0);
  rep(i,n) acc[i+1] = acc[i]+w[i];
  // w[i...j) = acc[j]-acc[i]

  vector<vector<bool>> rdp(n, vector<bool>(n+1, false));
  // [i,r) ok?
  rep(i,n) rdp[i][i+1] = true;
  repl(d,2,n+1) rep(i,n){
    int j=i+d;
    if(j>n) break;
    if(c[i] >= acc[j]-acc[i+1] && rdp[i+1][j]) rdp[i][j] = true;
    if(c[j-1] >= acc[j-1]-acc[i] && rdp[i][j-1]) rdp[i][j] = true;
  }

  vector<vector<int>> dp(n, vector<int>(n+1,INF));
  // dp[i][j] i?????§?????????[0,j)?????????????????????
  dp[0][0] = 1;
  dp[0][1] = 1;
  repl(i,1,n){
    rep(j,i+1) dp[i][j] = dp[i-1][j]+1;
    rep(j,i+1) if(rdp[j][i+1]) dp[i][i+1] = min(dp[i][i+1], dp[i-1][j]+j-i+1);
  }

  cout << *min_element(all(dp[n-1])) << endl;

  return 0;
}

Measured memory_bytes: 7108
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace Template
{
    public class Scanner
    {
        public string NextLine => Console.ReadLine();
        public int NextInt => int.Parse(NextLine);
        public long NextLong => long.Parse(NextLine);
        public double NextDouble => double.Parse(NextLine);
 
        public string[] StrAry(char separator = ' ') => Console.ReadLine().Split(separator);
        public int[] IntAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), int.Parse);
        public long[] LongAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), long.Parse);
        public double[] DoubleAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), double.Parse);
    }
 
    internal class Template
    {
        public static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
        private static void Fill<T>(T[] src, T value, int len) { for (int i = 0; i < len; i++) { src[i] = value; } }
 
        static void Solve() 
        {
            var scan = new Scanner();
            var line = scan.IntAry();
            int A = line[0], B = line[1];
            if (A == 1 && B == 1) Console.WriteLine("Draw");
            else if (A == 1) Console.WriteLine("Alice");
            else if (B == 1) Console.WriteLine("Bob");
            else
            {
                if (A == B) Console.WriteLine("Draw");
                else if (A > B) Console.WriteLine("Alice");
                else Console.WriteLine("Bob");
            }
        }
 
        private static void Main()
        {
            Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Console.Out.Flush();
        }
    }
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> hoge(n),now(n),ans;

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

	for(int i = n-1;0<=i;i--)
	{
		ll sum = 0;
		for(int j = i;j<n;j+=i+1)
		{
			sum += now[j];
		}
		//cout<<sum<<';'<<hoge[i]<<endl;
		if(sum%2!=hoge[i])
		{
			now[i]++;
			ans.push_back(i+1);
		}
	}
	cout<<ans.size()<<endl;
	for(auto i:ans)cout<<i<<' ';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool is_seki_day(int m, int d) {
  int d1 = d % 10;
  int d10 = (d - d1) / 10;
  if (m == d1 * d10 and d1 >= 2 and d10 >= 2) {
    return true;
  }
  return false;
}

int main() {
  int M, D;
  cin >> M >> D;

  int result = 0;
  for (int m = 1; m <= M; ++m) {
    for (int d = 20; d <= D; ++d) {
      if (is_seki_day(m, d)) {
        result += 1;
      }
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int rcnt[3];

int fix(char c){
	if(c == 'R')return 0;
	if(c == 'G')return 1;
	else return 2;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	string s;
	cin >> n >> s;
	ll ans = 0;
	rep(i,0,n){
		int dual = 1;
		int cur = fix(s[i]);
		rep(j,0,3)if(j != cur)dual *= rcnt[j];

		rep(len,0,i){
			if(i - 2 * len < 0){
				break;
			}
			int x = i - 2*len;
			int y = i - len;
			if(s[x] != s[y] && s[y] != s[i] && s[i] != s[x]){
				--dual;
			}
		}
		ans += dual;
		++rcnt[cur];
	}
	cout << ans << '\n';
}


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

#define ll long long

using namespace std;

int main(void){
    ll N, Q;
    cin >> N >> Q;
    set<pair<ll, ll>> x_stop, y_stop;
    x_stop.insert(make_pair(N, N));
    y_stop.insert(make_pair(N, N));
    ll ans = (N - 2) * (N - 2);
    for(int q = 0; q < Q; q++){
        int type;
        cin >> type;
        ll p;
        cin >> p;
        if(type == 1){
            auto itr = x_stop.lower_bound(make_pair(p, 0));
            ans -= itr->second - 2;
            y_stop.insert(make_pair(itr->second, p));
        }else{
            auto itr = y_stop.lower_bound(make_pair(p, 0));
            ans -= itr->second - 2;
            x_stop.insert(make_pair(itr->second, p));
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	long N,M=10;
	int l=0;
	cin>>N;
	while(N>=M/10){
		l+=(N%M)/(M/10);
		M*=10;
	}
	if(N%l==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,t,s,r;
    cin>>n;
    if(n>=500)
    {
        t=n/500;
        s=n%500;
        r=s/5;
        cout<<t*1000+r*5<<endl;
    }
    else
    {
        s=n%500;
        r=s/5;
        cout<<r*5<<endl;
    }
    return 0;


}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main()
    {
        int n;
        cin>>n;
        if(n>=0&&n<1200) cout<<"ABC"<<endl;
        if(n>=1200&&n<2800) cout<<"ARC"<<endl;
        if(n>=2800) cout<<"AGC"<<endl;
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int N, a, b, *nam;
    a = 0;
    cin >> N;
    nam = new int[N-1];
    for(int i=0; i<N; i++)
        cin >> nam[i];
    for(int i=0; i<N; i++)
    {
        if(i+1 != nam[i])
        {
            a++;
        }
    }
    if(a<=2)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int r,d,x;
  cin >> r >> d >> x;
  rep(i,10){
    x = x*r-d;
    cout<<x<<endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

const ll mod=1e9+7;
int main(){
      ll n,m;
      cin>>n>>m;
      ll a[m];
      rep0(i,m){
            cin>>a[i];
      }
      bool ng[n+1];
      fill(ng,ng+n+1,false);
      rep0(i,m){
            ng[a[i]]=true;
      }
      ll ptn[n+1];
      fill(ptn,ptn+n+1,0);
      ptn[0]=1;
      if(!ng[1])ptn[1]=1;
      REP(i,2,n+1){
            if(!ng[i]){
                  ptn[i]=(ptn[i-1]+ptn[i-2])%mod;
            }
      }
      cout<<ptn[n]<<endl;

      return 0;
}

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

int main(){
  int N,T;
  cin>>N>>T;
  int ans=10000;
  int c[N],t[N];
  for (int i=0;i<N;i++){
    cin>>c[i]>>t[i];
    if(t[i]<=T){
      ans=min(c[i],ans);
    }
  }
  if(ans==10000){
    cout<<"TLE"<<endl;
    return 0;
  }
  cout<<ans<<endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N), d(N, 0);
    rep(i, N) {
        cin >> x[i];
        d[i] = abs(x[i] - X);
    }
    int ans = d[0];
    rep(i, N) {
        ans = __gcd(ans, d[i]);
    }
    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  double D=0;
  vector<double> vec(N);
  for (int i : vec){
    cin >> vec.at(i);
    D = D + (1 / vec.at(i));
  }
  cout << 1 / D << endl;
}

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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

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

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}


int main() {
    int h,w;
    cin>>h>>w;

    vector<vector<char>>hw(h+2,vector<char>(w+2,'.'));

    rep2(i,1,h){
        rep2(j,1,w){
            cin>>hw[i][j];
        }
    }

    rep2(i,1,h+1){
        rep2(j,1,w+1){
            if(hw[i][j]=='#'){
                if(hw[i-1][j]!='#'&&hw[i+1][j]!='#'
                   &&hw[i][j-1]!='#'&&hw[i][j+1]!='#'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }

    cout<<"Yes"<<endl;
}




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

using namespace std;

char S[10005];

int main(){
    int N;
    scanf("%d", &N);

    N%=26;

    scanf(" %s", S);

    int len = strlen(S);
    for(int i = 0; i < len; i ++){
        S[i] += N;
        if(S[i] > 'Z'){S[i] -= 26;}
        printf("%c", S[i]);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	int n;
	ll ans = 0;
	cin >> n;
	map<string, int> mp;
	rep(i, 0, n) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		ans += mp[s];
		mp[s]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	string s; cin >> s;
	int len = s.size(), cnt = 0;
	for (int i = 0; i < len/2; i++) {
		if (s[i] != s[len - 1 - i]) cnt++;
	}
	cout << cnt << endl;
}




Measured memory_bytes: 3588
#include <stdio.h>
#define MIN(x,y) ((x) < (y) ? (x) : (y))

int main(void) {
	int n, x, i, j, k, p, q, r, c;
	for(;;) {
		scanf("%d %d", &n, &x);
		if ((n == 0) && (x == 0)) {
			break;
		}
		c = 0;
		for (i = n; i>0; i--) {
			p = x - i;
			for (j = MIN(p,i-1); j>0; j--) {
				for (k = MIN((q=p-j),j-1); ((r=q-k)>=0)&(k>0); k--) {
					if (!r) {
						c++;
					}
				}
			}
		}
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int N,K;
int h[100000];
LL dp[100000][100];

LL solve(int now, int nokori){
	if(nokori < 0) return MAX;
	if(now == N-1) return abs(h[now]-h[now-(K-nokori)]);
	if(dp[now][nokori] != LL_MAX) return dp[now][nokori];
	return dp[now][nokori] = min(solve(now+1, nokori-1), abs(h[now]-h[now-(K-nokori)]) + solve(now+1, K-1));
}

int main(){
	cin >> N;
	K = 2;
	for(int i=0; i<N; i++){
		cin >> h[i];
		for(int j=0; j<K; j++) dp[i][j] = LL_MAX;
	}

	cout << solve(1,K-1) << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll ans=-1;
  rep1(i,n){
    if(a.at(i-1)==a.at(i)&&ans==-1){
      ans=a.at(i);
      i++;
    }else if(a.at(i-1)==a.at(i)){
      ans*=a.at(i);
      cout<<ans<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.nextLine();
		String T = sc.nextLine();

		if (S.equals(T.substring(0, S.length()))) {
			System.out.print("Yes");
		} else {
			System.out.print("No");
		}

		sc.close();

	}
}


Measured memory_bytes: 35680
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 100 + 5 ; 
const int P = 1e9 + 7 ; 
int n, a[N], dp[N][N][N] ; 
signed main()
{
    n = gi() ; int m = 2 * n ; 
    for( re int i = 1; i < m; ++ i ) a[i] = gi() ; 
    sort( a + 1, a + m ) ;
    dp[n][0][0] = 1 ; 
    for( re int i = n - 1; i >= 1; -- i ) {
        int dl = ( a[i] != a[i + 1] ), dr = ( a[m - i] != a[m - i - 1] ) ;
        rep( l, 0, m ) {
            rep( r, 0, m ) {
                dp[i][l + dl][r + dr] = ( dp[i][l + dl][r + dr] + dp[i + 1][l][r] ) % P ; 
                for( re int k = 0; k < l + dl; ++ k )
                    dp[i][k][r + 1 + dr] = ( dp[i][k][r + 1 + dr] + dp[i + 1][l][r] ) % P ; 
                for( re int k = 0; k < r + dr; ++ k )
                    dp[i][l + 1 + dl][k] = ( dp[i][l + dl + 1][k] + dp[i + 1][l][r] ) % P ; 
            }
        }
    }
    int Ans = 0 ; 
    rep( l, 0, m ) rep( r, 0, m ) Ans = ( Ans + dp[1][l][r] ) % P ;
    cout << Ans << endl ; 
	return 0 ;
}

Measured memory_bytes: 6400
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <deque>
using namespace std;
typedef long long int ll;

struct Dice{
    int a,b,c,d,e,f;
};

void rotate(Dice &D,char c){
    int tmp;
    if(c=='N'){
        tmp=D.a;D.a=D.b;D.b=D.f;D.f=D.e;D.e=tmp;
    }
    if(c=='S'){
        tmp=D.a;D.a=D.e;D.e=D.f;D.f=D.b;D.b=tmp;
    }
    if(c=='W'){
        tmp=D.a;D.a=D.c;D.c=D.f;D.f=D.d;D.d=tmp;
    }
    if(c=='E'){
        tmp=D.a;D.a=D.d;D.d=D.f;D.f=D.c;D.c=tmp;
    }
}

void spin(Dice &D){
    int tmp;
    tmp=D.b;D.b=D.c;D.c=D.e;D.e=D.d;D.d=tmp;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    Dice D;
    cin >> D.a >> D.b >> D.c >> D.d >> D.e >> D.f;
    int q; cin >> q;
    while(q--){
        int x,y; Dice z=D;
        cin >> x >> y;
        if(x==z.c||x==z.d)rotate(z,'E');
        while(x!=z.a){
            rotate(z,'N');
        }
        while(y!=z.b){
            spin(z);
        }
        cout << z.c << endl;
    } 
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000


int main(){
	
	int n;
	cin>>n;
	
	deque<int> b(0);
	
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(i%2==0)b.push_back(a);
		else b.push_front(a);
	}
	
	if(n%2==1)reverse(b.begin(),b.end());
	
	for(int i=0;i<b.size();i++){
		if(i!=0)cout<<' ';
		cout<<b[i];
	}
	
	
    return 0;
}



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

long long gcd(long long a,long long b){
	while(1){
		if(a<b) swap(a,b);
		if(!b) break;
		a %= b;
	}
	return a;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >>  b;
    cout << lcm(a,b) << endl;
}


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

int main()
{
	int x, y, tmp;

	while (1) {
		cin >> x >> y;
		if (x == 0 & y == 0) break;
		if (x > y) {
			tmp = x;
			x = y;
			y = tmp;
		}
		cout << x << " " << y << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160
l = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(l[K])


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

const int MOD = 1000000007;

// begin() end()
#define all(x) (x).begin(),(x).end()

#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 lcm(int number1,int number2){
	return number1 * number2 / gcd(number1,number2);	
}
  
int main(){
int N , M;
cin >> N >> M;

vector<pair<int, int>>a(M);

for(int i = 0; i < M; i++) {
    cin >> a[i].second >> a[i].first;
}
sort(all(a));

int b = 0;
int cnt = 0;
REP(i, M){
    if(a[i].second > b) {
        b = a[i].first - 1;
        cnt++;
    }
}

cout << cnt << endl; 
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
#define m_p make_pair
const int N = 100005;

int n, m, v, pp;
int a[N];

int ans;

long long qq[N];

bool stg(int x)
{
	for (int i = 1; i <= n; ++i)
		qq[i] = 0;
	long long q = 0;
	qq[x] += m;
	q += m;
	for (int i = 1; i <= n; ++i)
	{
		if (i == x)
			continue;
		if (a[i] > a[x] + m)
			break;
		if (a[i] + m <= a[x] + m)
		{
			qq[i] += m;
			q += m;
		}
		else
		{
			qq[i] += (a[x] + m - a[i]);
			q += qq[i];
		}
	}
	for (int i = n; i >= 1; --i)
	{
		if (q >= (m * 1LL * v))
			break;
		q += (m - qq[i]);
		qq[i] = m;
	}
	int t = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (a[x] + qq[x] >= a[i] + qq[i])
			++t;
	}
	return t >= pp;
}

int main()
{
	scanf("%d%d%d%d", &n, &m, &v, &pp);
	pp = n - pp + 1;
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int l = 1, r = n;
	while (l <= r)
	{
		int m = (l + r) / 2;
		if (stg(m))
		{
			ans = m;
			r = m - 1;
		}
		else
			l = m + 1;
	}
	printf("%d\n", n - ans + 1);
	//system("pause");
	return 0;
}

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

using namespace std;
typedef long long ll;

ll h[100001];

bool can_banish(ll times, int N, ll A, ll B) {
    ll rest = times;
    for(int i = 0; i < N; i++) {
        if(h[i] - B * times <= 0) continue;
        rest -= (h[i] - B * times + (A - B) - 1) / (A - B);
        if(rest < 0) return false;
    }

    return true;
}

int main(void) {
    int i, N;
    ll A, B;
    ll l = -1, r = 0;
    scanf("%d%lld%lld", &N, &A, &B);
    for(i=0; i<N; i++) {
        scanf("%lld", h+i);
        r = max(r, 1LL * (h[i] + B - 1) / B);
    }

    ll mid = (r + l) / 2;
    while(r - l > 1) {
        if(can_banish(mid, N, A, B)) {
            r = mid;
            mid = (r + l) / 2;
        }
        else {
            l = mid;
            mid = (r + l) / 2;
        }
    }

    return !printf("%lld\n", r);
}

Measured memory_bytes: 1152
m, d = map(int, input().split())
cnt = 0
for i in range(1, m+1):
  for j in range(11, d+1):
    d_1 = j % 10
    d_10 = j // 10
    if((d_1 * d_10) == i and (d_1 >= 2 and d_10 >= 2)):
      cnt += 1
print(cnt)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(void){
    int n,mx = 0,huku = 0,mx2 = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
        if(mx == a[i]) huku++;
        if(a[i] > mx){
            huku = 0;  // でかいのでリセット
            mx2 = mx;
            mx = a[i];
        }
        if(a[i] > mx2 && a[i] < mx) mx2 = a[i];
    }
    for(int i = 0;i < n;i++){
        if(a[i] != mx) cout << mx << endl;
        else if(a[i] == mx && huku != 0) cout << mx << endl;
        else cout << mx2 << endl;
    }
    return 0;
}


Measured memory_bytes: 2432
(defun solve (r g b n)
  (let ((ans 0))
    (loop :for ri :from 0 :to (floor (/ n r))
          :do
             (loop :for gi :from 0 :to (floor (/ (- n (* ri r)) g))
                   :do
                      (if (zerop (rem (- n (* ri r) (* gi g)) b))
                          (setf ans (1+ ans)))))
    ans))

(defun main ()
  (let ((r (read))
        (g (read))
        (b (read))
        (n (read)))
    (format t "~A~%" (solve r g b n))))

(main)


Measured memory_bytes: 16360
#include <iostream>
#include <memory>
#include <limits>
#include <numeric>
#include <string>
#include <sstream>

std::unique_ptr<int[]> add_sentinel(int const* arr, const int n)
{
    auto ret = std::make_unique<int[]>(n + 1);
    std::copy(arr, arr + n, ret.get());

    static const int sentinel = std::numeric_limits<int>::max();
    ret[n] = sentinel;

    return ret;
}

int merge(int* arr, const int n)
{
    const auto m = n >> 1;
    const auto array0 = add_sentinel(arr, m);
    const auto array1 = add_sentinel(arr + m, n - m);
    int i0 = 0;
    int i1 = 0;
    for (int i = 0; i < n; ++i) {
        arr[i] = array0[i0] < array1[i1] ? array0[i0++] : array1[i1++];
    }
    return n;
}

int merge_sort(int* arr, const int n) 
{
    static int count = 0;
    if (n > 1) {
        const auto m = n >> 1;
        merge_sort(arr, m);
        merge_sort(arr + m, n - m);
        count += merge(arr, n);
    }
    return count;
}

void print(int* arr, const int n, const int i)
{
    if (i == n - 1) {
        std::cout << arr[i] << std::endl;
        return;
    }
    std::cout << arr[i] << " ";
    
    return print(arr, n, i + 1);
}


void print(int* arr, const int n)
{
    print(arr, n, 0);
    return;
}

int main()
{
    int n;
    {
        std::string buf;
        std::getline(std::cin, buf);
        n = std::stoi(buf);
    }

    int arr[500000];
    {
        std::string buf;
        std::getline(std::cin, buf);
        std::stringstream stream;
        stream << buf;
        for (int i = 0; std::getline(stream, buf, ' '); ++i) {
            arr[i] = std::stoi(buf);
        }

    }

    const int count = merge_sort(arr, n);
    print(arr, n);
    std::cout << count << std::endl;

    return 0;
}

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

// @author: pashka

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

    int n, m, t;
    cin >> n >> m >> t;
    vector<int> x(m), y(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    if (t == 2) {
        if (n == 2) {
            cout << -1;
            return 0;
        }
        int b = x[0];
        int c = y[0];
        int k = 0;
        int a = 0;
        string s(m, 'v');
        while (a == b || a == c) a++;
        for (int i = 1; i < m; i++) {
            if (x[i] == b && y[i] == c) {
                k = i;
            } else if (x[i] == a || y[i] == a) {
                int xx = x[i];
                int yy = y[i];
                if (yy == a) swap(xx, yy);
                if (yy != b && yy != c) {
                    if (x[i] == a) {
                        s[i] = '^';
                    } else {
                        s[i] = 'v';
                    }
                } else {
                    int aa, bb, cc;
                    if (yy == b) {
                        s[k] = 'v';
                        aa = c;
                        if (a < b) {
                            bb = a;
                            cc = b;
                        } else {
                            bb = b;
                            cc = a;
                        }
                    } else {
                        s[k] = '^';
                        aa = b;
                        if (a < c) {
                            bb = a;
                            cc = c;
                        } else {
                            bb = c;
                            cc = a;
                        }
                    }
                    a = aa;
                    b = bb;
                    c = cc;
                    k = i;
                }
            } else if (x[i] == b || x[i] == c) {
                s[i] = '^';
            }
        }
        cout << s;
    } else {
        const int MAX = 50000;
        vector<bitset<MAX>> a(n);
        for (int i = 0; i < n; i++) a[i][i] = 1;
        for (int i = m - 1; i >= 0; i--) {
            a[y[i]] |= a[x[i]];
            a[x[i]] = a[y[i]];
        }
        bitset<MAX> xx;
        for (int i = 0; i < n; i++) {
            xx[i] = 1;
        }
        for (int i = 0; i < n; i++) {
            xx &= a[i];
        }
        int t = -1;
        for (int i = 0; i < n; i++) {
            if (xx[i]) t = i;
        }
//        cerr << t << "\n";
        if (t == -1) {
            cout << -1;
        } else {
            string s(m, '.');
            bitset<MAX> z;
            z[t] = 1;
            for (int i = m - 1; i >= 0; i--) {
                if (z[x[i]]) {
                    s[i] = '^';
                    z[y[i]] = 1;
                }
                else if (z[y[i]]) {
                    s[i] = 'v';
                    z[x[i]] = 1;
                } else {
                    s[i] = 'v';
                }
            }
            cout << s << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 306688
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn is_reachable(targets: Vec<(u32, (i32, i32))>) -> bool {
    let mut step = 0;
    let mut start = (0, 0);
    for target in targets {
        let limit = target.0 - step;
        let len = ((target.1).0 - start.0).abs() + ((target.1).1 - start.1).abs();
        let len = len as u32;

        if limit < len || limit % 2 != len % 2 {
            return false;
        }

        step = target.0;
        start = target.1;
    }

    return true;
}

pub fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let n: u32 = read(&mut stdin).unwrap();
    let targets: Vec<(u32, (i32, i32))> = (0..n)
        .map(|_x| {
            (
                read(&mut stdin).unwrap(),
                (read(&mut stdin).unwrap(), read(&mut stdin).unwrap()),
            )
        })
        .collect();

    if is_reachable(targets) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
/*
	##############################
	#  Author: Pratyush Gaurav   #
	#  College: NIT ROURKELA     #
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define rep(i,a,b) for(i = a ; i < b ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)
#define mem(a,b)memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()

#define endl '\n'

const long long INF = 2000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

lli a[200][200];

void solve()
{
    lli n,tot = 0,last,i;
    cin >> n;
    vlli v(n+2,0),pre;
    REP(i,1,n) {
        cin >> v[i];
    }
    pre.push_back(0);
    REP(i,1,n) {
        pre.push_back(abs(v[i] - v[i-1]));
    }
    REP(i,1,pre.size()-1) {
        pre[i] += pre[i-1];
    }
    REP(i,1,n) {
        lli ans;
        if (i != n) {
            ans = pre[i - 1] + pre[pre.size() - 1] - pre[i+1] + abs(v[i + 1] - v[i - 1]) + abs(v[n]);
        }
        else {
            ans = pre[pre.size()-2] + abs(v[n-1]);
        }
        cout << ans << "\n";
    }
}
int main()
{
    opt;
    lli t = 1;
    while(t--)
        solve();
    return 0;
}










Measured memory_bytes: 2932
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

//#define EVEL 1

int N;

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

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

	cin >> N;
	if(N%10 == 9 || N/10 == 9) cout << "Yes";
	else cout << "No";
  return 0;
}


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

int N;
string S;

int main() {
    cin >> N;
    set<string> s;
    for (int i=0; i<N; i++) {
        cin >> S;
        s.insert(S);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 19232
cord = input()
step = int(input())
for i in range(step):
    thread = input().split()
    if thread[0] == 'print':
        print(cord[int(thread[1]): int(thread[2])+1])
    elif thread[0] == 'replace':
        cord = cord[:int(thread[1])] + thread[3] + cord[int(thread[2])+1:]
    else:
        cord = cord[:int(thread[1])] + cord[int(thread[1]):int(thread[2])+1][::-1] + cord[int(thread[2])+1:]


Measured memory_bytes: 5612
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


VVI g;
vector<bool> seen;

void dfs(int v) {
    seen[v] = true;
    for (auto next_v : g[v]) { 
        if (seen[next_v]){
            continue;
        }
        dfs(next_v);
    }
}

void Main()
{
    int n,m;cin>>n>>m;

    //vector<vector<PII>> c(n);
    g.resize(n);
    REP(i,m){
        int x,y,z;cin>>x>>y>>z;
        x--;
        y--;
        //c[x].push_back(MP(y,z));
        //c[y].push_back(MP(x,z));
        g[x].PB(y);
        g[y].PB(x);
    }

    seen.resize(n);
    int result = 0;

    REP(i,n){
        if(seen[i]){
            continue;
        }

        dfs(i);

        result++;
    }

    

    cout<<result<<endl;



	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(a) for(int i=0;i<a;i++)
#define nrep(a,b) for(int i=a;i<b;i++)
#define mrep(a) for(int i=a;i>=0;i--)
#define ll long long
#define INF 1145141919
using namespace std;



int main(){
	ll n; cin >> n;
	vector<string> s(n);
	rep(n) cin >> s[i];
	vector<vector<ll> > s_n(n);
	rep(n) for (int j = 0; j < s[i].length(); j++) s_n[i].push_back(s[i][j] - 'a');
	rep(n) sort(s_n[i].begin(), s_n[i].end());
	vector<vector<bool> > use_flag(n,vector<bool>(50));
	vector<char> ans;
	bool flag;
	rep(s_n[0].size()){
		flag = true;
		for (int j = 1; j < n; j++){
			for (int k = 0; k < s_n[j].size(); k++){
				if (!use_flag[j][k] && s_n[0][i] == s_n[j][k]){
					use_flag[j][k] = true;
					break;
				}if (k == s_n[j].size()-1) flag = false;
			}if (!flag) break;
		}if (flag) ans.push_back((char)(s_n[0][i] + 'a'));
	}rep(ans.size()) cout << ans[i];
	if(ans.size()>0) cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#pragma gcc optimize("O3")
#pragma gcc optimize("unroll-loops")
#pragma gcc target("avx2,see4")
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define X 300010
#define Y 10010
ll fac[X],ivf[X];
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
void init(){
	fac[0]=ivf[0]=1;
	for(ll i=1;i<X;i++){
		fac[i]=fac[i-1]*i%mod;
		ivf[i]=ivf[i-1]*po(i,mod-2)%mod;
	}
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll WAY(ll h,ll w){
	return C(h+w,w);	
}

ll N,M,K;
ll nf[Y],mf[Y];
ll dp[Y],cop[Y];
int main(){
	init();
	cin>>N>>M>>K;
	for(ll k=0;k<=K;k++)dp[k]=0; dp[0]=1;
	for(ll k=0;k<=K;k++){
		ll resn=0;
		for(ll i=0;i<=k;i++){
			mad(resn,dp[i]*WAY(N-1,k-i));
		}
		nf[k]=resn;
		ll resm=0;
		for(ll i=0;i<=k;i++)mad(resm,dp[i]*WAY(M-1,k-i));
		mf[k]=resm;
		
		for(ll i=0;i<=k;i++)cop[i]=dp[i]; cop[k+1]=0;
		for(ll i=1;i<=k+1;i++)mad(cop[i],cop[i-1]);
		for(ll i=0;i<=k+1;i++)dp[i]=cop[i];
	}
	ll ans=0;
	for(ll k=0;k<=K;k++){
		mad(ans,WAY(N+2*k,M+2*(K-k))*nf[k]%mod*mf[K-k]);
	}
	cout<<ans<<endl;
}




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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

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

  sort(l.rbegin(), l.rend());

int sum = 0;
  for(int i=1; i<n; ++i){
    sum += l[i];
  }
  if(l[0]<sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}  


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   long long r,d,x;
   cin>>r>>d>>x;
   for(int i=0;i<10;i++)
   {
       x=(r*x)-d;
       cout<<x<<" ";
   }
      return 0;
}


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

struct Edge{int s,t,cost;};

int main(){
	int V,E,r;
	cin >> V >> E >> r;
	
	vector<Edge> G(E);
	for (int i=0;i<E;i++){
		cin >> G[i].s >> G[i].t >> G[i].cost;
	}
	
	vector<int> d(V,INT_MAX);
	d[r]=0;
	
	for (int i=0;i<V;i++){
		for (int j=0;j<E;j++){
			Edge e=G[j];
			if(d[e.s]==INT_MAX){
				continue;
			}else{
				if(d[e.t]>d[e.s]+e.cost){
					d[e.t]=d[e.s]+e.cost;
				}
			}
		}
	}
	bool flag=0;
	for (int j=0;j<E;j++){
			Edge e=G[j];
			if(d[e.s]==INT_MAX){
				continue;
			}else{
				if(d[e.t]>d[e.s]+e.cost){
					flag=1;
					break;
				}
			}
		}
	
	if(flag){
		cout << "NEGATIVE CYCLE" <<endl;
	}else{
	for (int i=0;i<V;i++){
		if(d[i]==INT_MAX){
			cout << "INF" << endl;
		}else{
			cout << d[i] << endl;
		}
	}
	}
	return 0;
}

Measured memory_bytes: 3132
import math

a,b = (int(x) for x in input().split())

c = b*10
i = 0
flag = False
while i<10:
    if math.floor(0.08*c)==a:
        ans = c
        flag = True
        break
    c += 1
    i += 1

if flag:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 3188
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e15;

LL dp[1010][1010];
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M; cin >> N >> M;
  VI D(N); REP(i,N) cin >> D[i];
  VI C(M); REP(i,M) cin >> C[i];

  fill((LL*)dp, (LL*)dp+1010*1010, INF);
  dp[0][0] = 0;
  for(int i=0;i<N;++i)
	for(int j=0;j<M;++j){
	  dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
	  dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+C[j]*D[i]);
	}
  
  LL ans = INF;
  REP(j,M+1) ans = min(ans, dp[N][j]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}

ll cnt_digit(ll n){
  ll digit = 0;
  while(n > 0){
    n /= 10, digit++;
  }
  return digit;
}

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

  ll ans = cnt_digit(n);
  for(ll i = 1LL; i*i <= n; i++){
    if(n % i == 0){
      ll b = n / i;
      ll digit = max(cnt_digit(b), cnt_digit(i));
      ans = min(ans, digit);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a,b;
    cin>>a>>b;
    string s;

    if(a>b)
    {
        swap(a,b);
    }
    int x=b-'0';
    for(int i=1;i<=x;i++)
        {
            s+=a;
        }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <queue>
#define LL long long
using namespace std;
struct node
{
    LL l,r;
}a[100001];
bool cmp(node a,node b)
{
    if(a.r==b.r)
        return a.l<b.l;
    return a.r<b.r;
}
int main()
{
    LL N,M,i;
    scanf("%lld%lld",&N,&M);
    for(i=0;i<M;i++)
        scanf("%lld%lld",&a[i].l,&a[i].r);
    sort(a,a+M,cmp);
    int now=a[0].r,ans=1;
    for(i=1;i<M;i++)
    {
        if(a[i].l>=now)
        {
            now=a[i].r;
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1792