akhauriyash/Code-Regression huggingface dataset:
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
string s[2];
int n ;
int dp[100][3][3];

int get_dp(int pos , int i  , int j){
    if( (i == j) != (s[0][pos] == s[1][pos]) ) return 0;
    if(pos == n - 1) return 1; 
    int& res = dp[pos][i][j];
    if(~res)
        return res;
    res = 0; 
    if(s[0][pos] == s[0][pos + 1] && s[1][pos] == s[1][pos + 1]){
        res = (res + get_dp(pos + 1 , i , j)) % mod ;
    }
    else if(s[0][pos] == s[0][pos + 1]){
        for(int nj = 0 ; nj < 3 ; ++nj){
            if(nj == j) continue ;
            res = (res + get_dp(pos + 1 , i , nj)) % mod ;
        }            
    }
    else if(s[1][pos] == s[1][pos + 1]){
        for(int ni = 0 ; ni < 3 ; ++ni){
            if(ni == i) continue ;
            res = (res + get_dp(pos + 1 , ni , j)) % mod;
        }            
    }
    else{
        for(int ni = 0 ; ni < 3 ; ++ni){
            for(int nj = 0 ; nj < 3 ; ++nj){
                if(i == ni || j == nj) continue ;
                res = (res + get_dp(pos + 1 , ni , nj)) % mod;
            }    
        }   
    }
    return res;
}

void solve()
{
    setval(dp , -1);
    cin >> n ;
    rep(i , 2) cin >> s[i];
    int ans = 0;
    rep(i , 3) rep(j , 3){
        ans = (ans + get_dp(0 , i , j)) % mod;
    }
    cout << ans ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

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

using ll = long long int;
using llu = unsigned long long int;
using ld = long double;
const long long int NUM = 1000000;
const long double PI = 2*acos(0.0);
const int INF = 1e9 + 10 ;
const long long int maximum = (-1*INF);
#define LCM(a,b)            (a / __gcd(a,b)) * b
#define GCD(a,b)            __gcd(a,b)
#define dist(x1,y1,x2,y2)   sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define sqr(a)              ((a)*(a))
#define fast                ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define precision(a)        fixed<<setprecision(a)
#define endl                "\n"
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define ms(a,b)             memset((a),(b),sizeof(a))
#define min3(a,b,c)         min(a,min(b,c))
#define max3(a,b,c)         max(a,max(b,c))
#define min4(a,b,c,d)       min(min(a,b),min(c,d))
#define max4(a,b,c,d)       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)     min(min3(a,b,c),min(d,e))
#define REP(i,b)            for(long long int i = 0; i < b; i++)
#define READ(f)             freopen("f", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)

/*bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b)
{
    if(a.ff == b.ff)
        return a.ss <= b.ss;
    return a.ff < b.ff;
}*/

/*map<char, ll> m = { {'q', 9}, {'r', 5}, {'b', 3}, {'n', 3},
                      {'p', 1}, {'k', 0}, {'.', 0} };*/

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    if (n >= b)
        cout << (a * (b-1)) / b;
    else
        cout << ((a * n) / b);
    return 0;
}


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

int main() {
	int n;
	string *s;
	string sCnt;	// 数えている文字
	map<string, int> m;
	int max = 1;
	
	cin >> n;
	
	s = new string[n];
	
	for(int i=0; i<n; i++){
		cin >> s[i];
	}
	sort(s, s+n);
	
	for(int i=0; i<n; i++){
		if (m.count(s[i]) == 0) {
			m.insert(map<string, int>::value_type(s[i], 1));
		} else{
			m[s[i]] = m[s[i]]+1;
			if(m[s[i]] > max){
				max = m[s[i]];
			}
		}
	}
	
	auto begin = m.begin(), end = m.end();
	for(auto iter = begin; iter != end; iter++){
		if(iter->second == max){
			cout << iter->first << "\n";
		}
	}
	
	delete[] s;
	
	return 0;
}

Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N, K, sum;
  sum=0;
  cin >> N >> K;
  vector<int> vec(N);
  
  for (int i=0; i<N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  if(N<K) {
    cout << "0" << endl;
  }
  
  else {

    for (int i=0; i<K; i++) {
      vec.at(i)=0;
    }

    for (int i=0; i<N; i++) {
      sum+=vec.at(i);
    }

    cout << sum << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  vector<int> height;
  int i = 0, n;
  while (scanf(" %d ", &n) == 1) {height.push_back(-n);}
  sort(height.begin(), height.end());
  for (i = 0; i < 3; i++) {
    printf("%d\n", -1 * height[i]);
  }
  return 0;
}

Measured memory_bytes: 0
<?php
fscanf(STDIN,"%d %d",$r,$c);
$sum_c=array_fill(0,$c,0);
for($i=0;$i<$r;++$i){
    $input=explode(" ",trim(fgets(STDIN)));
    for($j=0;$j<$c;++$j){
        $sum_c[$j]=$sum_c[$j]+$input[$j];
    }
    echo join(" ",$input)," ",array_sum($input),PHP_EOL;
}
echo join(" ",$sum_c)," ",array_sum($sum_c),PHP_EOL;
 

Measured memory_bytes: 15608
# D - Banned K
from collections import Counter


def main():
    N, *A = map(int, open(0).read().split())
    cnt = Counter(A)
    total = sum(v * (v - 1) // 2 for v in cnt.values())
    res = [total - (cnt[a] - 1) for a in A]
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 46296
n,m=map(int,input().split())
x=[2,5,5,4,5,6,3,7,6]#各数に使うマッチ棒の本数
a=[]#使う数字でけ格納するリスト
for i in map(int,input().split()):
    a.append([i,x[i-1]])#数と使う本数をリストで入力
    #ここでタプルにするとソートできない
a.sort(reverse=True)
tuple(a)
#ソートしないと、大きい数字が先に来ないので間違う
#(OK)print(a)使える数字だけ
dp=[0]*(n+1)
#dp[i]：ちょうどi本使った時に表せる最大の数
#ループの順番が、いまひとつ、腑に落ちない
for i in range(m):#外側ループが使用できる数
    for j in range(n+1):#マッチ棒は0からnまで使える
        if j==0 or dp[j]!=0:
        #(NG)if dp[j]!=0: 「jの範囲を1始め」でもNG
            if j+a[i][1]<=n:#マッチ棒が使用範囲内なら
                #print(dp[j+a[i][1]],dp[j]*10+a[i][0])
                #print(max(dp[j+a[i][1]],dp[j]*10+a[i][0]))
                dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])
#この更新はDP典型。右１項が左と同じ。右は両項とも、前から使っているj本に
#新しく使うi番目を使った　本数での数を表している。
print(dp[n])

Measured memory_bytes: 16488
#include <stdio.h>
#include <string.h>
#define INF 100000
#define Com 2000000
int A[Com];
int s=0;

void insert(int);
void increaseKey(int,int);
int extractMax();
void maxHeapify(int);

int main(){

  char c[10];
  int k;
  while(1){
    scanf("%s",c);
    if(strcmp(c,"insert")==0){
      scanf("%d",&k);
      insert(k);
    }
    else if(strcmp(c,"extract")==0){
      printf("%d\n",extractMax());
    }

    else if(strcmp(c,"end")==0) break;
  }

  return 0;
}

void insert(int k){
  s++;
  A[s]=-INF;
  increaseKey(s,k);
 
}

void increaseKey(int i,int k){
  int a;

  A[i]=k;
  while(i > 1 && A[i] > A[i/2]){
    a=A[i];
    A[i]=A[i/2];
    A[i/2]=a;
    i=i/2;
  }
}

int extractMax(){
  int max;

  max=A[1];
  A[1]=A[s];
  s--;
  maxHeapify(1);
  return max;
}

void maxHeapify(int i){
 int l,r;
  int largest;
  int t;

  l=2*i;
  r=2*i+1;


  if(l <= s && A[l] > A[i]){
    largest=l;
  }
  else {
    largest=i;
  }

  if(r <=s && A[r] > A[largest]){
    largest=r;
  }

  if(largest!=i){
    t=A[i];
    A[i]=A[largest];
    A[largest]=t;
    maxHeapify(largest);
  }
}

Measured memory_bytes: 4696
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] flag = new int[n+1][n+1];
        //Arrays.fill(flag[][],false);
        int[] num = new int[n+1];

        for(int i =0;i<m;i++){
                int a = sc.nextInt();
                int b = sc.nextInt();
                flag[a][b]++;
                flag[b][a]++;
        }

        for(int i  =1;i<n+1;i++){
            for(int j =1;j<n+1;j++){
                num[i]+=flag[i][j];
            }
            System.out.println(num[i]);
        }
    }
}






Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  pll p[m];
  rep(i,m)cin >> p[i].second >> p[i].first;  
  sort(p,p+m,greater<pll>());
  ll index=0;
  ll ans=0;
  ll b[n]={};
  rep(i,m){
    for(int j=index;j<min(n,index+p[i].second);j++){
      b[j]=p[i].first;
    }
    index+=p[i].second;
    index=min(index,n);
  }
  rep(i,n){
    ans+=max(a[i],b[i]);
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }


int main()
{
    fast_io();
    #ifdef __LOCAL
        freopen("A_input.txt", "r", stdin);
        freopen("A_output.txt", "w", stdout);
    #endif

    char C;
    cin >> C;
    cout << (char)(C+1) << endl;
}


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

int main(){
	vector<int> a(3);
    for (int i=0;i<3;i++){
    	cin>>a.at(i);
    }
  
    sort(a.begin(),a.end());
    
    if(a.at(0)==5 && a.at(1)==5 && a.at(2)==7){
    	cout<<"YES"<<endl;
    }else{
    	cout<<"NO"<<endl;
    }
}
     

Measured memory_bytes: 256
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin >> s >> t;
	int cnt = 0;
	rep(i,3){
		if(s[i] == t[i]) ++cnt;
	}
	cout <<cnt << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)

int main() {
  long double r,ans;
  const double pi=3.14159265358979323846;
  cin>>r;
  
  ans=pi*2*r;

  cout<<fixed<<setprecision(20)<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3792
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n;i>0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int a;
    cin>>a;
    cout<<a*800-(a/15)*200<<endl;
    
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=a[i]*(-1)
import heapq
heapq.heapify(a)
for j in range(m):
  b=heapq.heappop(a)*(-1)
  heapq.heappush(a,(b//2)*(-1))
c=sum(a)
print(c*(-1))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
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; }



int main(){
    ll n;
    cin >> n;
    vector<vector<ll> > G(201, vector<ll> (201, INF));
    rep(i, n) {
        string str;
        cin >> str;
        rep(j, n) {
            int x = str[j] - '0';
            if(x == 1) G[i][j] = x;
        }
    }

    // 二部グラフ問題
    vector<ll> dp(n, -1);
    queue<ll> que;
    que.push(0);
    dp[0] = 0;
    bool ok = true;
    while(que.size() > 0) {
        ll v = que.front();
        que.pop();
        ll now = dp[v];
        ll to = (now + 1) % 2;
        rep(j, n) {
            if(G[v][j] == INF) continue;
            else if(dp[j] == -1) {
                dp[j] = to;
                que.push(j);
            }
            else if(dp[j] == now) {
                ok = false;
                break;
            }
        }
        if(!ok) break;
    }
    if(!ok) {
        cout << -1 << endl;
        return 0;
    }

    rep(k, n){
        rep(i, n){
            rep(j, n){
                chmin(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    ll d = 0;
    rep(i, n) {
        rep(j, n) {
            if(i == j) continue;
            chmax(d, G[i][j]);
        }
    }

    cout << d+1 << endl;
}

Measured memory_bytes: 3964
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
ll n,c,mm[100005],tm[100005],ans;
P s[100005];
int main(void){
    scanf("%lld%lld",&n,&c);
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&s[i].F,&s[i].S);
    }
    ll q=0;
    for(int i=0;i<n;i++){
        ll k=s[i].F;
        q+=s[i].S;
        mm[i]=q-k;
        tm[i]=max(q-2*k,tm[i-1]);
        ans=max(mm[i],ans);
    }
    ll hm=0,sm=0;
    q=0;
    for(int i=n-1;i>=0;i--){
        ll k=c-s[i].F;
        q+=s[i].S;
        sm=q-k;
        hm=max(q-2*k,hm);
        ans=max(sm,ans);
        if(i>0){
            ans=max(ans,sm+tm[i-1]);
            ans=max(ans,hm+mm[i-1]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------
  
//  if(a+b > c+d) anss = "Left";
//  else anss = "Balanced";
  
  cout << 48-a << endl;

}

Measured memory_bytes: 256
#!/usr/bin/python3

import array
import os
import sys


def main():
    S = inp()
    T = inp()
    print(solve(S, T))


def solve(S, T):
    sn = len(S)
    tn = len(T)

    sd = [[sn + 1] * (sn + 1), [sn + 1] * (sn + 1)]
    for i in range(sn):
        idx = ord(S[i]) - ord('0')
        for j in range(i, -1, -1):
            if sd[idx][j] != sn + 1:
                break
            sd[idx][j] = i + 1
    td = [[tn + 1] * (tn + 1), [tn + 1] * (tn + 1)]
    for i in range(tn):
        idx = ord(T[i]) - ord('0')
        for j in range(i, -1, -1):
            if td[idx][j] != tn + 1:
                break
            td[idx][j] = i + 1
    #dprint('sd', sd)
    #dprint('td', td)

    sb = [[[] for _ in range(sn + 2)] for _ in range(2)]
    for b in (0, 1):
        for i in range(sn + 1):
            sb[b][sd[b][i]].append(i)
        sb[b][sn + 1].append(sn + 1)
    tb = [[[] for _ in range(tn + 2)] for _ in range(2)]
    for b in (0, 1):
        for i in range(tn + 1):
            tb[b][td[b][i]].append(i)
        tb[b][tn + 1].append(tn + 1)
    #dprint('sb', sb)
    #dprint('tb', tb)

    INF = max(sn, tn) + 2
    arr_temp = [INF] * (tn + 2)
    dists = [array.array('i', arr_temp) for _ in range(sn + 2)]
    q = set()
    q.add((sn + 1, tn + 1))
    d = 0
    while q:
        nq = set()
        for i, j in q:
            if dists[i][j] != INF:
                continue
            dists[i][j] = d
            for b in (0, 1):
                for ni in sb[b][i]:
                    for nj in tb[b][j]:
                        if dists[ni][nj] == INF and (ni, nj) not in q:
                            nq.add((ni, nj))
        d += 1
        q = nq

    #dprint('dists', dists)

    ans = []
    i, j = 0, 0
    d = dists[0][0]
    while (i, j) != (sn + 1, tn + 1):
        #dprint('->', i, j)
        ni = sd[0][i] if i < sn + 1 else sn + 1
        nj = td[0][j] if j < tn + 1 else tn + 1
        if dists[ni][nj] == d - 1:
            ans.append('0')
        else:
            ans.append('1')
            ni = sd[1][i] if i < sn + 1 else sn + 1
            nj = td[1][j] if j < tn + 1 else tn + 1
        i = ni
        j = nj
        d -= 1

    return ''.join(ans)


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



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

int main() {
  int n;
  cin >> n;
  map <string, int> m;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    m[s] += 1;
  }
  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;

const int N = 1e5 + 10;
int a[N];
LL sum[N];

int main() {
	int n, m, v, p;
	scanf("%d%d%d%d", &n, &m, &v, &p);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	sort(a + 1, a + n + 1, greater<int>());
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
	int ans = p;
	for (int i = p + 1; i <= n; i++) {
		if (a[i] + m < a[p]) continue;
		int k = max(0, v - (p + n - i));
		int t = i - p;
		if (1LL * t * (a[i] + m) - (sum[i - 1] - sum[p - 1]) >= 1LL * k * m) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

	vector<int> c(n), t(n);

	int min_c = 2147483647;
	int min_c_index = -1;

	for (int i = 0; i < n; i++) {
		cin >> c[i] >> t[i];
		if (t[i] <= x) {
			if (chmin(min_c, c[i])) {
				min_c_index = i;
			}
		}
	}

	if (min_c_index == -1) {
		cout << "TLE" << endl;
		return 0;
	}
	
	cout << c[min_c_index] << endl;
		
	return 0;
}

Measured memory_bytes: 256
def resolve():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * m
    b = [0] * m
    s = [[-1] for j in range(n)]
    ans=0
    x=1
    for i in range(m):
        a[i], b[i] = map(int, input().split())
    for i in range(m):
        s[a[i]-1].append(b[i])
        s[b[i]-1].append(a[i])
    for i in range(n):
        if len(s[i])!=1:
            for j in s[i]:
                if j!=-1:
                    if h[i]<=h[j-1]:
                        x=0
        ans+=x
        x=1
    print(ans)
resolve()

Measured memory_bytes: 97032
fileprivate struct Scanner {
    private var elements = [String]()
    private var index = 0
    
    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }
    
    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }
    
    mutating func nextInt() -> Int {
        return Int(next())!
    }
    
    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

func rotate(point: Point) -> Point {
    Point(x: -point.y, y: point.x)
}

func rotate(direction: String) -> String {
    switch direction {
    case "U": return "L"
    case "L": return "D"
    case "D": return "R"
    default: return "U"
    }
}

func flip(point: Point) -> Point {
    Point(x: point.x, y: -point.y)
}

func flip(direction: String) -> String {
    switch direction {
    case "U": return "D"
    case "D": return "U"
    default: return direction
    }
}

struct Point {
    let x: Int
    let y: Int
}

func main() {
    var scanner = Scanner()
    let N = scanner.nextInt()
    var P = [Point]()
    var U = [String]()
    
    for _ in 0 ..< N {
        let x = scanner.nextInt()
        let y = scanner.nextInt()
        P.append(Point(x: x, y: y))
        U.append(scanner.next())
    }
    
    func solve() -> Int {
        let I = (0 ..< N).sorted { P[$0].x > P[$1].x }
        var diag = [Int: Int]()
        var yoko = [Int: Int]()
        var answer = Int.max
        for i in I {
            if U[i] == "R", let value = diag[P[i].x - P[i].y] {
                answer = min(answer, (value - P[i].y) * 10)
            }
            if U[i] == "R", let value = yoko[P[i].y] {
                answer = min(answer, (value - P[i].x) * 5)
            }
            if U[i] == "D" {
                diag[P[i].x - P[i].y] = P[i].y
            }
            if U[i] == "L" {
                yoko[P[i].y] = P[i].x
            }
        }
        return answer
    }
    
    var answer = Int.max
    for _ in 0 ..< 4 {
        for _ in 0 ..< 2 {
            answer = min(answer, solve())
            
            for i in 0 ..< N {
                P[i] = flip(point: P[i])
                U[i] = flip(direction: U[i])
            }
        }
        for i in 0 ..< N {
            P[i] = rotate(point: P[i])
            U[i] = rotate(direction: U[i])
        }
    }
    if answer == Int.max {
        print("SAFE")
    } else {
        print(answer)
    }
}

main()


Measured memory_bytes: 31644
n=int(input())
ls=list(map(int,input().split()))

lss=[]
for idx,seito in enumerate(ls):
    lss.append([seito,idx+1])
lsss=sorted(lss)
mapped_list = list(map(lambda x: x[1], lsss))
print(" ".join(list(map(str,mapped_list))))

Measured memory_bytes: 72492
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int lower = max(A, C);
    int upper = min(B, D);
    cout << max(0, upper - lower) << endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define T3I tuple<int, int, int>
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

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

    int a, b, c;
    cin >> a >> b >> c;
    if(a != b && a != c && b != c) {
        cout << "No" << endl;
    }else if(a == b && b == c) {
        cout << "No" << endl;
    }else {
        cout << "Yes" << endl;
    }
}

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

int n;
set<string> st;
vector<vector<string> > group;
map<string,int> gindex;
vector<bool> flag;


void func(int index){
	flag[index] = true;
	map<string,int>::iterator it;

	for(int i = 0; i < group[index].size(); ++i){
		it = gindex.find(group[index][i]);

		if( it == gindex.end() ){
			st.insert(group[index][i]);
		}
		else if( !flag[it->second] ){
			func(it->second);
		}
	}
}


int main(){
	char str[30];
	int n;

	while( scanf("%d", &n), n != 0 ){
		group.assign(n, vector<string>());
		flag.assign(n, false);
		st.clear();
		gindex.clear();

		for(int i = 0; i < n; ++i){
			scanf(" %[^:]:", str);
			gindex[str] = i;
			char ch = ',';
			while(ch != '.'){
				scanf("%[^,.]%c", str, &ch);
				group[i].push_back(str);
			}
		}

		func(0);
		printf("%d\n", st.size() );
	}
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
ll inf = 1e18;
ll p = 1e9 + 7;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ll i, j, y, x,  z, w, g, key, t, k, n, m, a, b;
    ll t2, t3, t4, t1, t5, t6;
    //string s;
    ld d, s, t;
    cin >> d >> t >> s;
    ld time = d / s;
    //cout << time;
    if (time > t)
        cout << "No";
    else
        cout << "Yes";

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define ull unsigned long long int
#define lli long long int
#define li long int

#define si(n) scanf("%d",&n)
#define sl(n) scanf("%ld",&n)
#define sll(n) scanf("%lld",&n)

#define pi(n) printf("%d",n)
#define pl(n) printf("%ld",n)
#define pll(n) printf("%lld",n)

using namespace std;

const int MAX=1e5+5;

int main() {
    // freopen("a.in","r",stdin);
    // freopen("a.out","w",stdout);
    int A[3]; cin >> A[0] >> A[1] >> A[2];
    vector<int> V;
    V.pb(abs(A[0]-A[1]));
    V.pb(abs(A[0]-A[2]));
    V.pb(abs(A[2]-A[1]));

    sort(V.begin(),V.end());
    cout << V[0] + V[1] << "\n";

    return 0;
}


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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
template<class T>
int print(T& x){ cout << x << '\n'; return 0;}
#define debug(x) cerr << #x << ": " << x << '\n'

template<typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

  int n;
  cin >> n;
  vi mons(n);
  rep(i,n) cin >> mons[i];

  int ans = mons[0];

  rep(i,n){
    ans = gcd(ans, mons[i]);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 640
n = int(input())
t,a = (int(x) for x in input().split())
b = list(map(int, input().split()))
for i in range(n):
    b[i] = t - b[i]*0.006
m = abs(a-b[0])
ans = 1
for i in range(n):
    if abs(a-b[i]) < m:
        m = abs(a-b[i])
        ans = i+1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
    int x;
    int s;
    int m;
    int h;
    scanf("%d",&x);
    s=x%60;
    h=x/3600;
    m=(x-3600*h)/60;
    printf("%d:%d:%d\n",h,m,s);    
    return 0;
}


Measured memory_bytes: 2112
#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 vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#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 SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#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*(LL)INF;
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;
}

void Main()
{
    LL n,k;cin>>n>>k;
    VL a(n);
    REP(i,n){
        cin>>a[i];
    }

    LL result = 0;

    ROF(i,0,50){
        LL x = 1LL<<i;
        if(result+x > k){
            continue;
        }
        LL t1=0;
        LL t2=0;
        REP(j,n){
            if(a[j]&x){
                t1++;
            }
            else{
                t2++;
            }
        }
        if(t1<t2){
            //dump(x)
            //cerr<<x<<" "<<t1<<" "<<t2<<endl;
            result += x;
        }
    }

    //dump(result)

    LL f = 0;
    REP(i,n){
        f += a[i]^result;
    }
    cout<<f<<endl;

    
	return;
}

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

Measured memory_bytes: 3996
#include<stdio.h>

int n;
char stable;

void print_array(char s[],int d[],char sorteds[],int sortedd[],int freq[]){
    int i,j,cnt;
    stable='1';
    for(i=0;i<n;i++){
        if(freq[sortedd[i]]>1 && stable=='1'){
            cnt = freq[sortedd[i]];
            j=0;
            while(cnt--){
               if(stable=='1'){
                   while(d[j]!=sortedd[i]) j++;
                   if(s[j]!=sorteds[i]) stable='0';
                   j++;
               }
               if(i>0) printf(" ");
               printf("%c%d",sorteds[i],sortedd[i]);
               if(cnt>0) i++;
            }
        }
        else{
            if(i>0) printf(" ");
            printf("%c%d",sorteds[i],sortedd[i]);
        }
    }
    printf("\n");
    if(stable=='1') printf("Stable\n");
    else printf("Not stable\n");
}

void bubble_sort(char bs[],int bd[]){
    int i,j,dkey;
    char skey;

    for(i=0;i<n;i++){
        for(j=n-1;j>=i+1;j--){
            if(bd[j]<bd[j-1]){
                dkey = bd[j];
                bd[j] = bd[j-1];
                bd[j-1] = dkey;

                skey = bs[j];
                bs[j] = bs[j-1];
                bs[j-1] = skey;
            }
        }
    }
}

void selection_sort(char ss[],int sd[]){
    int i,j,mini,dkey;
    char skey;

    for(i=0;i<n;i++){
        mini=i;
        for(j=i;j<n;j++){
            if(sd[j]<sd[mini]){
                mini = j;
            }
        }
        if(mini!=i){
            dkey = sd[i];
            sd[i] = sd[mini];
            sd[mini] = dkey;

            skey = ss[i];
            ss[i] = ss[mini];
            ss[mini] = skey;
        }
    }
}

int main(){
    char str[3],s[36],bs[36],ss[36];
    int freq[10],d[36],bd[36],sd[36];
    int i;

    scanf("%d",&n);
    for(i=0;i<10;i++) freq[i]=0;
    for(i=0;i<n;i++){
        scanf("%s",&str);
        s[i] = str[0];
        d[i] = str[1]-'0';
        freq[d[i]]++;
        bs[i] = ss[i] = s[i];
        bd[i] = sd[i] = d[i];
    }

    bubble_sort(bs,bd);
    print_array(s,d,bs,bd,freq);

    selection_sort(ss,sd);
    print_array(s,d,ss,sd,freq);

    return 0;
}

Measured memory_bytes: 612
#ABC148-F Playing Tag on Tree
"""
与えられるグラフは木構造
青木くん(追いかける方)がいる頂点を根とすると、この問題は解きやすくなる。
そうした場合、高橋くんが追いつかれずに行ける頂点の中で、最も深さが深い葉に行くのが最適。
そのような頂点は頂点u,vからの距離によって求めることができ、結果的に高橋くんが行ける最深部の葉から
根までの距離が答えとなる。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,u,v = map(int,readline().split())
u,v = u-1,v-1 #u:高橋くん初期位置,v:青木くん初期位置

g = [[] for _ in range(n+1)] #隣接リスト
for i in range(n-1):
    a,b = map(int,readline().split())
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)

#根からの距離を記録
#rank:rootからの距離
root = v
rank = [0]*n
new = [root] #深さを揃えて探索する必要があるのでstackとは若干異なる
c = 1
while len(new):
    tank = []
    for e in new:
        for go in g[e]:
            if go != root and rank[go] == 0:
                rank[go] = c
                tank.append(go)
    c += 1
    new = tank

#まず、高橋くんが最大でどの頂点まで戻れるのかを求める
now = u
res = rank[u]-(rank[u]-1)//2 #制限は(u-g間の距離-1)//2
ans = (rank[u]-1)//2 #戻れる最大の回数をansに入れる
while True:
    for e in g[now]:
        if rank[e] < rank[now]:
            if rank[e] < res: #制限より大きいならそこには行けない
                break
            else:
                now = e #nowに戻れる最大の頂点を格納
        else:
            continue
    if rank[e] < res: #制限より大きいならそこには行けない
        break

#ans + nowからの最大の深さが答え。
new = [now]
while new:
    tank = []
    for e in new:
        for go in g[e]:
            if rank[go] > rank[e]: #深さが増すなら
                tank.append(go)
    ans += 1
    new = tank

print(ans-1 if rank[u]%2==1 else ans)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	if(N%K) cout<<1<<endl;
	else cout<<0<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 892
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.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().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let W = read::<i32>();
    let mut a = read::<i32>();
    let mut b = read::<i32>();

    if a > b {
        let tmp = a;
        a = b;
        b = tmp;
    }

    if b <= a + W {
        println!("0");
    } else {
        println!("{}", b-a-W);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int a,b;
  cin >> a >> b;
  int ans = 2 * max(a,b);
  if(a != b) ans--;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9+5;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    string s;
    cin >> s;
    string t;
    cin >> t;
    int n = s.length();
    int m = t.length();
    int dp[n+1][m+1];
    for (int i=0; i<=n; i++) {
        for (int j=0; j<=m; j++) {
            if (i == 0 || j == 0)
                dp[i][j] = 0;
            else if (s[i-1] == t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    int i=n, j=m;
    string ans = "";
    while (i > 0 && j > 0) {
        if (s[i-1] == t[j-1]) {
            ans += s[i-1];
            i--;
            j--;
        } else if (dp[i][j-1] > dp[i-1][j]) {
            j--;
        } else
            i--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}


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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	if(n == 2){
		cout << abs(h[0] - h[1]) << endl;
		return 0;
	}
	vector<int> dp(n);
	dp[1] = abs(h[0] - h[1]);
	for(int i(2);i<n;++i){
		priority_queue<int> c;
		for(int j = max(0,i-k);j<i;++j){
			c.push( -(abs(h[i] - h[j]) + dp[j]));
		}
		dp[i] = -c.top();
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
import Control.Monad

main :: IO ()
main = do
  [w, h, n] <- (map read . words) <$> getLine :: IO [Int]
  rows <- replicateM n $ (map read . words) <$> getLine :: IO [[Int]]
  let left   = maximum $ map (\[x, y, a] -> x) $ filter (\[x, y, a] -> a == 1) ([0, 0, 1]:rows)
      right  = minimum $ map (\[x, y, a] -> x) $ filter (\[x, y, a] -> a == 2) ([w, 0, 2]:rows)
      bottom = maximum $ map (\[x, y, a] -> y) $ filter (\[x, y, a] -> a == 3) ([0, 0, 3]:rows)
      top    = minimum $ map (\[x, y, a] -> y) $ filter (\[x, y, a] -> a == 4) ([0, h, 4]:rows)

  print $ if right <= left || top <= bottom
          then 0
          else (right - left) * (top - bottom)


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  string s; cin >> s;
  int x=753;
  int ans=INF;
  rep(i,0,s.size()-2){
    chmin(ans,abs(x-stoll(s.substr(i,3))));
  }
  cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <unordered_map>

using namespace std;

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a)
    cin >> i;
  unordered_map<int, int> mp;
  ll ans{};
  for (int i = n - 1; i >= 0; i--)
  {
    ans += mp[a[i] + i];
    mp[i - a[i]]++;
  }
  cout << ans << endl;
}


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

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int n = s.length();
    int m = t.length();
    int mini = 1000005;
    int flag = 0;
    for(int i = 0;i<n;i++)
    {
        int count = 0;
        for(int j = 0;j<m;j++)
        {
            if(i+j>=n)
            {
                flag = 1;
                break;
            }
            if(t[j]!=s[i+j])
            {
                count++;
            }
        }
        if(flag==1)
        {
            break;
        }
        mini = min(mini,count);
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int t,n,i,j,k,l,l1;
  cin>>n;
  string s1,s2;
  cin>>s1>>s2;
  for(i=0;i<n;i++)
  {
    cout<<s1[i]<<s2[i];
  }
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

template<class T> inline T C(T x,T y){
    if(x<y)return 0;
    T div=min(x-y,y);
    T v=max(x-y,y);
    ll bunbo=1,bunshi=1;
    irep(i,x-div+1,x+1){
        bunshi*=i;
    }
    rep(j,1,div+1){
        bunbo*=j;
    }
    return bunshi/bunbo;
}
template<class T> inline T modC(T x,T y,ll mod){
    if(x<y)return 0;
    T div=min(x-y,y);
    ll bunbo=1,bunshi=1;
    irep(i,x-div+1,x+1){
        bunshi*=i;
        bunshi%=mod;
        if(bunshi<0)bunshi+=mod;
    }
    rep(j,1,div+1){
        bunbo*=j;
        bunbo%=mod;
        if(bunbo<0)bunbo+=mod;
    }
    T ans=bunshi*modinv(bunbo,mod)%mod;
    if(ans<0)ans+=mod;
    return ans;
}
long long INF = 1LL<<60;
int main( ){
    ll N,K;
    cin>>N>>K;
    ll mod=1e9+7;
    vll gcdres(K+1,0);
    irep(i,1,K+1){
        ll quem=K/i;
        gcdres[i]=modpow(quem,N,mod)%mod;
        if(gcdres[i]<0)gcdres[i]+=mod;
        if(quem>=2){
            rep(j,2,quem+1){
                gcdres[i]-=gcdres[i*j];
                gcdres[i]%=mod;
                if(gcdres[i]<0)gcdres[i]+=mod;
            }
        }
    }
    ll ans=0;
    rep(i,1,K+1){
        ans+=gcdres[i]*i%mod;
        ans%=mod;
        if(ans<0)ans+=mod;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 4052