akhauriyash/Code-Regression huggingface dataset:
s = input()
if 1 <= int(s[:2]) <= 12 and 1 <= int(s[2:]) <= 12:
    print("AMBIGUOUS")
elif 0 <= int(s[:2]) <= 99 and 1 <= int(s[2:]) <= 12:
    print("YYMM")
elif 1 <= int(s[:2]) <= 12 and 0 <= int(s[2:]) <= 99:
    print("MMYY")
else:
    print("NA")

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const ll MAX = 10000;
static const ll INFTY = 1e12;
static const ll MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
using P = pair<ll, ll>;
// 入力
// 入力
ll h, w;
ll startX, startY, endX, endY;
vector<vector<char>> s;
vector<vector<ll>> cnts; // 魔法使った回数

using Graph = vector<vector<ll>>;

vector<bool> seen;
ll cnt = 0;

void dfs(const Graph &G, ll v) {

    seen[v] = true; // v を訪問済にする
    cnt++;
    // count++;
    
    // v から行ける各頂点 next_v について
    REP(i, G[v].size()) { 
        ll next_v = G[v][i];
        if( seen[next_v] == true ) continue; // next_v が探索済だったらスルー
        dfs(G, next_v);
    }
}

int main() {

  ll N, M;
  cin >> N >> M;

  Graph _G(N);
  for (int i = 0; i < M; ++i) {
      ll a, b;
      cin >> a >> b;
      a--; b--;
      _G[a].push_back(b);
      _G[b].push_back(a);
  }
  seen.assign(N, false);

  ll max_ = 0;

  REP(i, N){
    if(seen[i]==false){
      cnt=0;
      dfs(_G, i);
      max_ = max(max_, cnt);
    }
  }
  cout << max_ << endl;
   
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 23520
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #ifdef ONLINE_JUDGE
        #pragma GCC target ("avx512f")
    #else
        #pragma GCC target ("avx2")
    #endif
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int h,w,k;
int table[11][1001];
string s;
int ret = 114514;
signed main(){
    cin >> h >> w >> k;
    REP(i,h){
        cin >> s;
        REP(j,w) table[i][j] = (s[j] == '1');
    }
    REP(bits, (1 << (h-1))){
        vvi merged;
        REP(i,w){
            vi mi;
            int di = table[0][i];
            REP(j, h-1){
                if ((bits >> j) & 1){
                    mi.pb(di);
                    di = 0;
                }
                di += table[j+1][i];
            }
            mi.pb(di);
            merged.pb(mi);
        }
        int nh = sz(merged[0]);
        int cnt = 0;
        vi miv = vi(nh);
        REP(i,w){
            REP(j,nh){
                if (merged[i][j] > k) {
                    cnt = 114514;
                    break;
                }
                miv[j] += merged[i][j];
                if (miv[j] > k){
                    cnt++;
                    j = -1;
                    miv = vi(nh);
                }
            }
            if (cnt == 114514) break;
        }
        ret = min(ret, cnt + __builtin_popcount(bits));
        cerr << bits << " " << cnt + __builtin_popcount(bits) << endl;
    }
    cout << ret << endl;
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n),b(n);
	rep(i,n) scanf("%d",&a[i]), a[i]--;
	rep(i,n) scanf("%d",&b[i]), b[i]--;

	vector fa(n,0),fb(n,0);
	vector pos(n,vector<int>());
	rep(i,n){
		fa[a[i]]++;
		fb[b[i]]++;
		pos[a[i]].emplace_back(i);
	}

	int mx=0;
	rep(x,n) mx=max(mx,fa[x]+fb[x]);
	if(mx>n){
		puts("No");
		return 0;
	}

	priority_queue<pair<int,int>> Q;
	rep(x,n) if(fa[x]>0 && fb[x]>0) Q.emplace(fa[x]+fb[x],x);

	vector<int> ans(n,-1);
	while(Q.size()>=2){
		int x=Q.top().second; Q.pop();
		int y=Q.top().second; Q.pop();

		int p=pos[x].back(); pos[x].pop_back();
		int q=pos[y].back(); pos[y].pop_back();
		ans[p]=y;
		ans[q]=x;

		fa[x]--; fb[x]--;
		fa[y]--; fb[y]--;
		if(fa[x]>0 && fb[x]>0) Q.emplace(fa[x]+fb[x],x);
		if(fa[y]>0 && fb[y]>0) Q.emplace(fa[y]+fb[y],y);
	}

	deque<int> Da,Db;
	if(Q.size()==1){
		int x=Q.top().second; Q.pop();
		rep(_,fa[x]) Da.emplace_back(x);
		rep(_,fb[x]) Db.emplace_front(x);
		fa[x]=fb[x]=0;
	}
	rep(x,n) rep(_,fa[x]) Da.emplace_back(x);
	rep(x,n) rep(_,fb[x]) Db.emplace_front(x);
	assert(Da.size()==Db.size());
	rep(i,Da.size()){
		ans[pos[Da[i]].back()]=Db[i];
		pos[Da[i]].pop_back();
	}

	puts("Yes");
	rep(i,n) printf("%d%c",ans[i]+1,i<n-1?' ':'\n');

	return 0;
}


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

int main()
{
    int i, n, m, k, x, y, comp;

    cin >> n >> m >> k;

    vector <int> adj[n+1];
    int used[n+1], ans[n+1], cnn[n+1];
    queue <int> q;

    for(i=0; i<m; i+=1)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    memset(used, 0, sizeof(used));
    ans[0]=0;
    memset(cnn, 0, sizeof(cnn));
    
    comp=0;
    for(i=1; i<=n; i+=1)
    {
        if(!used[i])
        {
            comp+=1;
            used[i]=comp;
            q.push(i);
        }
        while(!q.empty())
        {
            x=q.front();
            q.pop();
            cnn[comp]+=1;

            for(auto y:adj[x])
            {
                if(!used[y])
                {
                    used[y]=comp;
                    q.push(y);
                }
            }
        }
    }

    for(i=1; i<=n; i+=1)
        ans[i]=cnn[used[i]]-adj[i].size()-1;

    for(i=0; i<k; i+=1)
    {
        cin >> x >> y;
        if(used[x]==used[y])
        {
            ans[x]-=1;
            ans[y]-=1;
        }
    }

    for(i=1; i<=n; i+=1)
        cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 8312
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repm(i, a, n) for (int i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

ll calc(ll n, ll a, ll b)
{
    string tmp = to_string(n);
    return a * n + b * tmp.size();
}

int main()
{
    int n;
    cin >> n;
    vi a(n);
    vii x(n, vi(n)), y(n, vi(n));
    rep(i, 0, n)
    {
        cin >> a[i];
        rep(j, 0, a[i])
        {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;

    repm(i, (2 << (n - 1)) - 1, 0)
    {
        bitset<15> bit(i);
        //cout << bit << endl;
        /*rep(j, 0, 15) cout << bit[j];
        cout << endl;*/

        bool f = false;
        rep(j, 0, n)
        {
            //cout << j << " " << bit[j] << endl;
            if (bit[j] == 1)
            {
                rep(k, 0, a[j])
                {
                    if (y[j][k] == 1 && bit[x[j][k] - 1] == 1)
                        continue;
                    if (y[j][k] == 0 && bit[x[j][k] - 1] == 0)
                        continue;
                    f = true;
                    break;
                }
            }
            if (f)
                break;
            if (j == n - 1)
            {
                int cnt = 0;
                rep(k, 0, 15)
                {
                    if (bit[k] == 1)
                        cnt++;
                }
                //cout << "cnt" << cnt << endl;
                ans = max(ans, cnt);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from heapq import heapify, heappop, heappush
N = int(input())
vvv = list(map(int, input().split()))
heapify(vvv)
for _ in range(N - 1):
    x = heappop(vvv)
    y = heappop(vvv)
    heappush(vvv, (x + y)/2)
print(vvv[0])


Measured memory_bytes: 9068
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

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

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, m; cin>>n>>m;
	vector<int> h(n+1);
	for(int i = 1; i <= n; i++) cin>>h[i];
	vector<vector<int>> vec(n+1);
	for(int i = 0; i < m; i++){
		int a, b; cin>>a>>b;
		vec[a].pb(b);
		vec[b].pb(a);
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		bool c = 1;
		for(auto x: vec[i]){
			if(h[x] >= h[i]) c = 0;
		}
		if(c) ans++;
	}
	cout<<ans<<endl;
}

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

using namespace std;

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

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

   int n;

   while(cin >> n){
      if(n == 0) break;
      int ans = 0;
      for(int i = 1; i < n / 2 + 1; ++i){
         int tmp = i;
         for(int j = i + 1; j < n; ++j){
            tmp += j;
            if(tmp > n) break;
            if(tmp == n) ans++;
         }
      }
      cout << ans << endl;
   }

   return 0;
}


Measured memory_bytes: 3100
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

constexpr bool isLeapYear(const int &y) {
  return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);
}

void solve() {
  vvi vv;
  int a, b;
  while (cin >> a >> b, a) {
    vi v;
    for (int x = a; x <= b; x++) {
      if (isLeapYear(x)) v.pb(x);
    }
    vv.pb(v);
  }
  if (vv.size()) {
    if (vv[0].size()) {
      cout << vv[0][0] << endl;
      loop(j, 1, vv[0].size()) cout << vv[0][j] << endl;
    } else {
      cout << "NA" << endl;
    }
    loop(i, 1, vv.size()) {
      cout << endl;
      if (vv[i].size()) {
        cout << vv[i][0] << endl;
        loop(j, 1, vv[i].size()) cout << vv[i][j] << endl;
      } else {
        cout << "NA" << endl;
      }
    }
  }
}

Measured memory_bytes: 3008
import datetime
h1,m1,h2,m2,k = map(int,input().split(' '))
dt1 = datetime.datetime(year=2020, month=5, day=30, hour=h1,minute=m1)
dt2 = datetime.datetime(year=2020, month=5, day=30, hour=h2,minute=m2)
dt3 = int((dt2-dt1).seconds/60-k)
print(dt3 if dt3 >=0 else 0)

Measured memory_bytes: 9444
import itertools
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

N=[int(i) for i in range(n)]
nn=2**n
ans=float("inf")
for _ in range(n//2+1):
  for com in itertools.combinations(N,2*_):
    i=0
    for ura in com:
      i+=2**ura
    E,O=[],[]
    for j in range(n):
      if i&(1<<j)==0:
        if j%2==0:
          E.append(A[j]*100+j)
        else:
          O.append(A[j]*100+j)
      else:
        if j%2==0:
          O.append(B[j]*100+j)
        else:
          E.append(B[j]*100+j)
    if len(E)!=(n+1)//2:
      continue
    else:
      E.sort()
      O.sort()

      chk=True
      C=[E[0]%100]
      prev=E[0]//100
      for i in range(1,n):
        ii=i//2
        if i%2==0:
          C.append(E[ii]%100)
          if E[ii]//100<prev:
            chk=False
            break
          else:
            prev=E[ii]//100
        else:
          C.append(O[ii]%100)
          if O[ii]//100<prev:
            chk=False
            break
          else:
            prev=O[ii]//100
    
    if chk:
      ten=0
      for i1 in range(n):
        for i2 in range(i1+1,n):
          if C[i1]>C[i2]:
            ten+=1
      ans=min(ans,ten)
print(-1 if ans==float("inf") else ans)



Measured memory_bytes: 49884
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int A, B;
	std::cin >> A >> B;
	std::cout << std::max({ A + B,A - B,A * B }) << std::endl;
}

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

Measured memory_bytes: 892
#include <algorithm>
#include <iostream>

using namespace std;

int dfs(string tmp, int size, int num) {
  // cout << tmp << endl;
  if (tmp.size() == size) {
    bool has3 = false, has5 = false, has7 = false;
    for (int i = 0; i < tmp.size(); i++) {
      if (tmp[i] == '3') {
        has3 = true;
      } else if (tmp[i] == '5') {
        has5 = true;
      } else if (tmp[i] == '7') {
        has7 = true;
      } else {
        has3 = false;
        break;
      }
    }
    if (has3 && has5 && has7 && stoi(tmp) <= num)
      return 1;
    else
      return 0;
  }
  int ret = 0;
  string number[] = {"3", "5", "7"};
  for (int i = 0; i < 3; i++) {
    ret += dfs(tmp + number[i], size, num);
  }

  return ret;
}

int main() {
  int ans = 0;
  string n;
  cin >> n;
  for (int i = 3; i <= n.size(); i++) {
    // cout << i << endl;
    ans += dfs("", i, stoi(n));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define MAXN 56
using namespace std;
int queue[MAXN], plate[MAXN];
int main() {
	int N,K,i,max=0;
	cin >> N >> K;
	for (i = 0; i < N; i++) {
		cin >> queue[i];
	}
	int R = min(K, N);
	for (int take = 0;take<= R;take++){
		for (int left = 0; left <= take; left++) {
			int send = K - take;
			int sum = 0;
			int right = take - left;
			int leftpoint = 0, rightpoint = N - 1,point=0,sendpoint=0;
			int leftChance = left;
			while (leftChance--)
			{
				plate[point++] = queue[leftpoint++];
			}
			while (right--)
			{
				plate[point++] = queue[rightpoint--];
			}
			sort(plate, plate + point);
			while (send-- && plate[sendpoint] < 0)
			{
				sendpoint++;
			}
			for (int i = sendpoint; i < point; i++)
				sum += plate[i];
			if (sum > max)
				max = sum;
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#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 REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL dp[51],dp2[51];
LL f(int N,LL X){
    X=min(X,dp[N]);
    if(!N)return 1;
    if(X==1)return 0;
    X--;
    if(X<=dp[N-1])return f(N-1,X);
    LL v=dp2[N-1];
    X-=dp[N-1];
    if(X)X--,v++;
    if(X)v+=f(N-1,X);
    return v;
}
int main(){
    dp[0]=dp2[0]=1;
    REPP(i,1,51)dp[i]=dp[i-1]*2+3,dp2[i]=dp2[i-1]*2+1;
    int N;
    LL X;
    R(N,X);
    W(f(N,X));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;
int n, m, dp[2][301][301];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	cin >> n >> m;
	int cur = 0, next = 1;
	dp[cur][1][1] = 1;
	
	rep(i, m){
		memset(dp[next], 0, sizeof(dp[next]));
		rep(j, n+1) rep(k, n+1) if(dp[cur][j][k]){
			
			//1に戻れるところにいく
			(dp[next][j][j] += dp[cur][j][k] * (ll)k % mod) %= mod;
			
			//1からすでにいけるところのうち1に戻れないところにいく
			(dp[next][j][k] += dp[cur][j][k] * (ll)(j - k) % mod) %= mod;
			
			//1からいけなかったところにいく
			if(j + 1 <= n)
			(dp[next][j + 1][k] += dp[cur][j][k] * (ll)(n - j) % mod) %= mod;
		}
		swap(cur, next);
	}
	cout << dp[cur][n][n] << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;

struct edge{
  int to, cost, time, r;
};


int N; // 駅の数
int M; // 路線の数
int H; // 一日の時間
int K; // 会社数
int S; // スタート
int T; // ゴール
int P; // パスポートの種類数
vector< vector< edge > > info;
int dp[1 << 8];

int Dijkstra(int bit){ //0円ならbitが1
  priority_queue< Pii, vector< Pii >, greater< Pii > > que;
  vector< vector< int > > min_cost( N, vector< int >( H + 1, INF));

  que.push( Pii( 0, Pi( S, 0)));
  min_cost[S][0] = 0;

  while(!que.empty()){
    Pii p = que.top(); que.pop();
    int cost = p.first, idx = p.second.first, time = p.second.second;
    if(idx == T) return cost;
    if(cost > min_cost[idx][time]) continue;
    for(int i = 0; i < info[idx].size(); i++){
      edge& e = info[idx][i];
      if(time + e.time > H) continue;
      int next_cost;
      if((bit >> e.r) & 1) next_cost = cost;
      else next_cost = cost + e.cost;
      if(next_cost < min_cost[e.to][time + e.time]){
        min_cost[e.to][time + e.time] = next_cost;
        que.push( Pii( next_cost, Pi( e.to, time + e.time)));
      }
    }
  }
  return INF;
}

int main(){
  while(cin >> N >> M >> H >> K, N){
    info.resize(N);
    fill_n( dp, 1 << K, INF);

    for(int i = 0; i < M; i++){
      int a, b, c, h, r;
      cin >> a >> b >> c >> h >> r;
      a--, b--, r--;
      info[a].push_back( (edge){ b, c, h, r});
      info[b].push_back( (edge){ a, c, h, r});
    }
    cin >> S >> T;
    S--, T--;
    cin >> P;
    for(int i = 0; i < P; i++){
      int l, cost, bit = 0;
      cin >> l >> cost;

      for(int j = 0; j < l; j++){
        int k;
        cin >> k;
        k--;
        bit |= (1 << k);
      }
      dp[bit] = min( dp[bit], cost);

    }
    dp[0] = 0;

    for(int i = 0; i < 1 << K; i++){
      if(dp[i] == INF) continue;
      for(int j = 0; j < 1 << K; j++){
        dp[i | j] = min( dp[i | j], dp[i] + dp[j]);
      }
    }

    int ret = INF;
    for(int i = 0; i < 1 << K; i++){
      if(dp[i] == INF) continue;
      ret = min( ret, Dijkstra(i) + dp[i]);
    }
    if(ret == INF) puts("-1");
    else cout << ret << endl;

    info.clear();
    
  }
}

Measured memory_bytes: 1368
n = int(input())
a = list(map(int, input().split()))
odds = 0
evens2 = 0
evens4 = 0
for ai in a :
    if ai % 4 == 0 :
        evens4 += 1
    elif ai % 2 == 0 :
        evens2 += 1
    else :
        odds += 1

if evens4 >= odds :
    print('Yes')
elif odds - evens4 == 1 and evens2 == 0 :
    print('Yes')
else :
    print('No')

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

int main() {
    int n,y;
    cin >> n >> y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for(int a=0;a<=n;a++){
        for(int b=0;a+b<=n;b++){
            int c = n - a - b;
            int total = 10000*a+5000*b+1000*c;
            if(total == y){
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
    return 0;
}

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

int main(){
	int n, x;
	cin >> n >> x;
	int mind = __INT_MAX__;
	int total = 0;

	rep(i, n){
		int a;
		cin >> a;
		total += a;
		mind = min(mind, a);
	}

	cout << (x-total)/mind + n << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

constexpr int mod = 1000000007;
struct mint {
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint &operator+=(const mint &a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator-=(const mint &a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator*=(const mint &a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }
};
ostream &operator<<(ostream &os, const mint &m) {
  os << m.x;
  return os;
}

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

  int n, k;
  cin >> n >> k;
  vector<ll> min_v(n + 1), max_v(n + 1);
  rep(i, 1, n + 1) min_v[i] = min_v[i - 1] + i;
  max_v[n] = n;
  repr(i, 0, n) max_v[i] = max_v[i + 1] + i;
  sort(max_v.begin(),max_v.end());


  mint ans = 0;
  rep(i,k-1,n+1)
    ans+=max_v[i]-min_v[i]+1;
  
  cout << ans << endl;
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
int a[6], qaq = -0x7fffffff, sum;
int main() {
	for (int i = 1; i <= 5; ++i) {
		scanf("%d", &a[i]);
		int qwq = ceil(double(a[i] * 1.00 / 10)) * 10 - a[i];
		qaq = max(qaq, qwq);
		sum += ceil(double(a[i] * 1.00 / 10)) * 10;
	}
	printf("%d", sum - qaq);
	return 0;
}

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

using namespace std;

#define MOD 1000000007

int main() {
    int n, k;

    scanf("%d", &n);
    scanf("%d", &k);

    int_fast64_t s = 0;

    for(int i = k; i <= n + 1; i++) {
        // (2 * n - i + 1) * i / 2 - ((i - 1) * i / 2)
        s += (int_fast64_t) (n - i + 1) * i + 1;
    }

    printf("%d\n", s % MOD);

    return 0;
}

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

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    string s;
    int K;
    cin >> s >> K;
    vector<string> subs;
    for (int i = 0; i < (int)s.size(); i++) {
        for (int j = 1; j <= min((int)s.size() - i, 5); j++) subs.push_back(s.substr(i, j));
    }
    sort(subs.begin(), subs.end());
    subs.erase(unique(subs.begin(), subs.end()), subs.end());
    //~ for (string ss: subs) cout << ss << " ";
    cout << subs[K-1] << "\n";
}


Measured memory_bytes: 1660
num, k = map(int, input().split())

s = input()


prev = s[0]

ans = 0
chance = 0
prev = ""

for i in range(num-1):
  x = s[i]
  y = s[i+1]
  if x != y:
    chance += 1
  else:
    ans += 1

    
print(ans + min([chance, k*2]))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int  i,j,m,n,a,b,k,count=0;
    cin>>n;
    for(i=1;i<10;i++)
    {
        for(j=1;j<10;j++)
        {
            if(i*j==n)
            {
                cout<<"Yes"<<endl;
                count=1;
                break;
            }
        }
        if(count==1)
        {
            break;
        }

    }
    if(count==0)
    {
        cout<<"No"<<endl;
    }


}


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

int main(){
  int n,m;
  cin>>n>>m;
  int a[100005];
  rep(i,n) cin>>a[i];
  map<int,ll> ma;
  int sum=0;
  ma[sum]++;
  rep(i,n){
    sum=(sum+a[i])%m;
    ma[sum]++;
  }
  ll ans=0;
  for(auto p:ma){
    ll v=p.second;
    ans+=v*(v-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 4608
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define vi(v)	vector < int > v;
#define	all(v)	v.begin(), v.end()

using namespace std;
int main()
{
	int m,n,sum = 0;
	cin>>n>>m;
    int a[n];
	for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    	int v = ((sum + (4*m) - 1)/(4*m)), c=0;
    sort(a, a+n);
    for(int i=0;i<n-1;i++)
    {
        if(a[i]<v)
            c++;

    }
    if(n-c>=m)
        cout<<"Yes";
    else
        cout<<"No";



return 0;
}

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

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll N, M; cin >> N >> M;
	if (N == 1 && M == 1) {
		cout << 1 << endl;
	}
	else if (N == 1) {
		cout << M - 2 << endl;
	}
	else if (M == 1) {
		cout << N - 2 << endl;
	}
	else {
		cout << (M - 2)*(N - 2) << endl;
	}

	return 0;
}

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

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

	int N, T;
	cin >> N >> T;

	vector<int> t( N+1 );
	for( int i = 0; i < N; ++i ) { cin >> t[i]; }

	t[N] = t[N-1] + T;

	int64_t result = 0;
	for( int i = 0; i < N; ++i ) {
		result += min( t[i] + T, t[i+1] ) - t[i];
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int X,Y;
    cin>>X>>Y;
    cout<<(int)floor(log2l(Y)-log2l(X)+1)<<endl;
    return 0;
}


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

int main(){

  int N, M, ans=0;
  cin >> N >> M;
  int K[N], A[N][M];
  int L[M+1];

  for(int i=0; i<N; i++){
    cin >> K[i];
    for(int j=0; j<K[i]; j++){
      cin >> A[i][j];
    }
  }

  for(int i=1; i<=M; i++){
    L[i] = 0;
  }

  for(int i=0; i<N; i++){
    for(int j=0; j<K[i]; j++){
      L[A[i][j]]++;
    }
  }

  for(int i=1; i<=M; i++){
    if(L[i]==N)ans++;
  }

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"

	"gonum.org/v1/gonum/graph/simple"
	"gonum.org/v1/gonum/graph/topo"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	g := simple.NewDirectedGraph()
	for i := 0; i < n; i++ {
		g.AddNode(simple.Node(i))
	}
	for i := 0; i < m; i++ {
		a := getNextInt64(scanner)
		b := getNextInt64(scanner)
		if a == b {
			continue
		}
		g.SetEdge(simple.Edge{F: simple.Node(a), T: simple.Node(b)})
	}
	sccs := topo.TarjanSCC(g)
	fmt.Fprintln(writer, len(sccs))
	for i := len(sccs) - 1; i >= 0; i-- {
		fmt.Fprint(writer, len(sccs[i]))
		for j := 0; j < len(sccs[i]); j++ {
			fmt.Fprintf(writer, " %d", sccs[i][j])
		}
		fmt.Fprintln(writer, "")
	}
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)


typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////




ll SOLVE(){
    
    string s,t;cin>>s>>t;
    map<char,set<ll>>mp;
    rep(i,0,s.size()-1){
        mp[s[i]].insert(i);
    }
    ll ans=0;
    ll pos=0;
    for(auto x:t){
        if(mp[x].size()==0){
            cout<<-1;return 0;
        }
        auto nxt=mp[x].lower_bound(pos);
        if(nxt==mp[x].end()){
            ans++;
            pos=*(mp[x].begin())+1;
        }else{
            pos=*nxt+1;
        }
    }
    cout<<pos+ans*s.size()<<endl;
    
    
    return 0;
}

int main(){fastio
    
    clock_t start = clock();
    SOLVE();
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    cerr<<endl<<time<<"ms"<<endl;
    
    return 0;
}


Measured memory_bytes: 5200
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    A=[]
    for i in range(H):
        a=input()
        if a!='.'*W:
            A.append(a)
    ans=[[] for _ in range(len(A))]
    for i in range(W):
        f=False
        for j in range(len(A)):
            if A[j][i]=='#':
                f=True
                break
        if f:
            for j in range(len(A)):
                ans[j]+=A[j][i]
    for x in ans:
        print(''.join(x))

if __name__ == '__main__':
    main()


Measured memory_bytes: 41072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

long long dp[110000];

int main() {
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    for (int i = 0; i < 110000; ++i) dp[i] = INF;
    dp[0]=0;
    
    rep(i,n){
        for(int j=1;j<=k;j++){
            chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
                      
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1536
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{

  ll n, x;

  cin >> n >> x;
  ll l[n + 1];
  rep(i, n)
  {
    cin >> l[i];
  }

  ll ans = 0;
  ll count = 1;

  for (ll i = 0; i < n; i++)
  {
    ans += l[i];
    if (ans > x)
    {
      break;
    }
    count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

signed main()
{
	int X; cin >> X;

	int ans = 0;

	ans += X / 500 * 1000;
	X %= 500;
	ans += X / 5 * 5;

	cout << ans << endl;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<ll>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

P f(int x){
    int a = x % 10;
    int b = 0;
    while(x > 0){
        b = x % 10;
        x /= 10;
    }
    return P(a, b);
}

int main(){
    int N;
    cin >> N;
    map<P, int> freq;
    for(int i = 1; i <= N; i++){
        freq[f(i)]++;
    }

    int ans = 0;
    for(int i = 1; i <= N; i++){
        P tmp = f(i);
        swap(tmp.first, tmp.second);
        ans += freq[tmp];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
const int MAXN = 1e5;
typedef long long LL;
int A[MAXN];
int main()
{
	int N, L, idx = -1, i;
	scanf("%d%d", &N, &L);
	for(i=0; i<N; ++i)
		scanf("%d", A+i);
	for(i=1; i<N; ++i)
		if(LL(A[i-1])+A[i] >= L)
		{
			idx = i;
			break;
		}
	if(idx == -1)
		puts("Impossible");
	else
	{
		puts("Possible");
		for(i=1; i<idx; ++i)
			printf("%d\n", i);
		for(i=N-1; i>idx; --i)
			printf("%d\n", i);
		printf("%d\n", idx);
	}
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 整数配列の入力
            var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var dict = new Dictionary<int, int>();

            for (int j = 0; j < a.Length; j++) {
                for(int i = -1; i < 2; i++) {
                    if(dict.ContainsKey(a[j] + i) == false) {
                        dict.Add(a[j] + i, 0);
                    }

                    dict[a[j] + i]++;
                }
            }

            var max = dict.Values.Max();

            Console.WriteLine(max);

            Console.Out.Flush();
        }
    }
}


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

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz size
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<ll> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

ll solve(ll n, vector<ll> a, vector<ll> b) {
	vector<pair<ll, ll> > p;
	rep(i,3) {
		if(a[i] < b[i]) {
			p.pb(mp(a[i],b[i]));
		}
	}
	if(p.sz() == 0) return n;
	if(p.sz() == 1) {
		return n % p[0].fi + (n / p[0].fi) * p[0].se;
	}
	if(p.sz() == 2) {
		ll ret = 0;
		for(ll x = 0; x * p[0].fi <= n; ++x) {
			ll y = (n - x * p[0].fi)/p[1].fi;
			ll r = n - x * p[0].fi - y * p[1].fi;
			ret = max(ret, r + x * p[0].se + y * p[1].se);
		}
		return ret;
	}
	if(p.sz() == 3) {
		ll ret = 0;
		for(ll x = 0; x * p[0].fi <= n; ++x) {
			for(ll y = 0; x * p[0].fi + y * p[1].fi <= n; ++y) {
				ll z = (n - x * p[0].fi - y * p[1].fi)/p[2].fi;
				ll r = n - x * p[0].fi - y * p[1].fi - z * p[2].fi;
				ret = max(ret, r + x * p[0].se + y * p[1].se + z * p[2].se);
			}
		}
		return ret;
	}
}

int main()
{
	fastio();
	
	ll n;
	vi a(3), b(3);
	cin >> n;
	rep(i, 3) cin >> a[i];
	rep(i, 3) cin >> b[i];
	n = solve(n, a, b);
	n = solve(n, b, a);
	cout << n;
}

Measured memory_bytes: 256