akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pi pair<int,int>
#define mp make_pair
//#define int long long
#define endl '\n'

using namespace std;
int n,k,l;

class auxtree
{
    public:

  vector<pair<int,int> > aux; //first: parent second:rank(height)



  auxtree(int v)
  {
     aux.resize(v+1);
    for(int i=1;i<=v;i++)
    {
        aux[i].first=i;
        aux[i].second=0;
    }

  }

  int find_par(int x)
  {
      if(aux[x].first==x)
        return x;
      return aux[x].first=find_par(aux[x].first);
  }

  void tre_union(int x,int y)
  {
       x=find_par(x);
       y=find_par(y);

      if(aux[x].second>aux[y].second)
      {
          aux[y].first=x;
          return;
      }
      else if(aux[y].second>aux[x].second)
      {
          aux[x].first=y;
          return;
      }

      aux[x].second++;
      aux[y].first=x;

  }


};


/*int idrd[(int)2.1e5],idral[(int)2.1e5];

void initialize()
{
    for(int i = 1;i <= n;++i)
        idrd[i] = i,idral[i]=i;
}

int rootroad(int x)
{
    if(idrd[x]==x) return x;
    return idrd[x]=rootroad(idrd[x]);
}

int rootrail(int x)
{
   if(idral[x]==x) return x;
   return idral[x]=rootrail(idral[x]);
}


void unionrd(int x, int y)
{
    int p = rootroad(x);
    int q = rootroad(y);
    idrd[p] = idrd[q];
}

void unionrail(int x, int y)
{
    int p = rootrail(x);
    int q = rootrail(y);
    idral[p] = idral[q];
}
*/

vector< pair<pi,int> > s;
int ans[200005];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>k>>l;
    int x,y;
    auxtree rd(n),ral(n);
    //initialize();
    for(int i=0;i<k;++i)
    {
        cin>>x>>y;
        rd.tre_union(x,y);
        //unionrd(x,y);
    }
    for(int i=0;i<l;++i)
    {
        cin>>x>>y;

        ral.tre_union(x,y);
        //unionrail(x,y);
    }
    for(int i=1;i<=n;++i)
    {
        pair<pi,int> xp= mp(mp(ral.find_par(i),rd.find_par(i)) , i);
        s.push_back(xp);
    }
   sort(s.begin(),s.end());
    for(int i=1;i<=n;++i)
    {
        pi xp= mp(ral.find_par(i),rd.find_par(i));

        // a1=distance(s.begin(),s.lower_bound(mp(xp,0)));
        auto a1=lower_bound(s.begin(),s.end(),mp(xp,0));
        //int a2=distance(s.begin(),s.upper_bound(mp(xp,312345)));
       auto a2=upper_bound(s.begin(),s.end(),mp(xp,312345));
//cout<<i<<" "<<a1<<" "<<a2<<endl;
        cout<<a2-a1<<" ";
    }
    return 0;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-6 ;
int main(){
int n;
cin>>n;
for(int i=n;i>=1;i--){
    double c=sqrt(i);
    if ( c - (int) c < EPS){
        cout<<i;
        return 0;
    }

}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  rep1(i,5){
    int x;
    cin >> x;
    if (x == 0){
      cout << i << endl;
      return 0;
    }
  }
}

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

int main() {
    int n, k, q; cin >> n >> k >> q;
    vector<int> a(n), b;
    for (int i = 0; i < n; i++) cin >> a[i];
    b = a; sort(b.begin(), b.end());
    int ans = 2e9;
    for (int i = 0; i < n; i++) {
        if (i > 0 && b[i-1] == b[i]) continue;
        int t = b[i];
        vector<int> v, w;
        for (int j = 0; j < n; j++) {
            if (a[j] < t) {
                if (v.empty()) continue;
                if (v.size() >= k) {
                    sort(v.rbegin(), v.rend());
                    while (v.size() >= k) {
                        w.emplace_back(v.back());
                        v.pop_back();
                    } 
                }
                v.clear();
            } else {
                v.emplace_back(a[j]);
            }
        }
        if (!v.empty()) {
            if (v.size() >= k) {
                sort(v.rbegin(), v.rend());
                while (v.size() >= k) {
                    w.emplace_back(v.back());
                    v.pop_back();
                }
            }
        }        
        if (w.size() < q) continue;
        sort(w.begin(), w.end());
        ans = min(ans, w[q-1] - w[0]);
    }
    cout << ans << endl;
    return 0;
}

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






#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   100005
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


int main()
{
    ll n,i,k,a[N],s=0;
    cin>>n>>k;
    for0(i,k)
    {
        cin>>a[i];
        s+=a[i];
    }
    if(s<n)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}
































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

using namespace std;

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

int main() {

    int n;
    char c;
    cin >> n;

    bool yellow = false;
    for (int i = 0; i < n; i++) {
        cin >> c;
        if (c == 'Y') yellow = true;
    }

    puts(yellow ? "Four" : "Three");

    return 0;
}


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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int tam=100002;
ll n,C;
ll dis[tam];
ll nut[tam];
ll suf[tam];
ll pre[tam];
pair<ll,int> mx[tam];
pair<ll,int> mx2[tam];



int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>C;
    ll ans=0;
    ll ans2=0;
    int idx=0;
    f(n){
        cin>>dis[i+1]>>nut[i+1];
        pre[i+1]=pre[i]+nut[i+1]+dis[i]-dis[i+1];
        //cout<<pre[i+1]<<endl;
        if(pre[i+1]>ans){
            ans=pre[i+1];
            idx=i+1;
        }
        mx[i+1]=pair<ll,int>(ans,idx);
        ans2=max(ans2,pre[i+1]);
        //cout<<i+1<<" "<<ans<<" "<<idx<<endl;
        
    }
    dis[n+1]=C;
    int i;
    ans=0;
    idx=0;
    fr(i,n,1){
        suf[i]=suf[i+1]+nut[i]+(C-dis[i+1])-(C-dis[i]);
        if(suf[i]>ans){
            ans=suf[i];
            idx=i;
        }
        ans2=max(ans2,suf[i]);
        mx2[i]=pair<ll,int>(ans,idx);
    }
    fr(i,n,1){
        pair<ll,int> res=mx[i-1];
        ll cost=res.ff+suf[i]-min(dis[res.ss],C-dis[i]);
        ans2=max(ans2,cost);
        //cout<<i<<" "<<res.ff<<" "<<res.ss<<" "<<ans<<endl;
//        cout<<res.ff<<"+ "<<suf[i]<<"-"<<min(dis[res.ss],C-dis[i])<<" "<<cost<<endl;
    }
    fi(i,1,n+1){
        pair<ll,int> res=mx2[i+1];
        ll cost=res.ff+pre[i]-min(C-dis[res.ss],dis[i]);
        ans2=max(ans2,cost);
    }
    cout<<ans2<<endl;
    
    return 0;
}



Measured memory_bytes: 6528
#include <stdio.h>
#include <math.h>
 
int main() {
 
  double d1,d2,d3,d4;
  int i,j,k,l,n;
  double x[1020] = {0};
  double y[1020] = {0};
  double z[1020] = {0};
  double o,p,q,max;
  max = -1;
  o=0;
  p=0;
  q=0;
  d1 = 0;
  d2 = 0;
  d3 = 0;
  d4 = 0;
 
  scanf("%d",&n);
 
  for(i=0; i<n; i++) {
    scanf("%lf",&x[i]);
  }
 
  for(i=0; i<n; i++) {
    scanf("%lf",&y[i]);
  }
 
  for(i=0; i<n;i++) {
 
    o = (x[i] - y[i]) * (x[i] - y[i]);
    p = (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]);
    p = p*p;
    p = sqrt(p);
   
    d3 = d3 + p;
    d2 = d2+o;
    d1 = d1 + sqrt(o); 
 
    if(max < sqrt(o)) {
      max = sqrt(o);
    }
 
    
  }
 
  d2 = pow(d2,1.0/2);
  d3 = pow(d3,1.0/3);
  d4 = max;
 
  printf("%.11lf\n%.11lf\n%.11lf\n%.11lf\n" ,d1,d2,d3,d4);
 
  return 0;
 
}


Measured memory_bytes: 2112
import sys

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7


def LI(): return list(map(int, sys.stdin.readline().split()))


n, k = LI()
graph = [[] for i in range(n)]
for i in range(n - 1):
    a, b = LI()
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
ans = 1
check = [False] * n
stack = [0]
ans = 1
while len(stack) > 0:
    x = stack.pop()
    check[x] = True
    count = 0
    for i in graph[x]:
        if not check[i]:
            count += 1
            stack.append(i)
    if x == 0:
        temp = 1
        for i in range(count):
            temp = temp * (k - 1 - i) % INF
        ans = ans * temp % INF
    else:
        temp = 1
        for i in range(count):
            temp = temp * (k - 2 - i) % INF
        ans = ans * temp % INF
print((ans * k) % INF)

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

using namespace std;

// int ans = 1e9;

int log_(int n, int a) {
    if (n < a) return 1;
    return (a * log_(n / a, a));
}

int withdraw(int n) {
    if (n == 0) return 0;
    int num9 = 1 + withdraw(n - log_(n, 9)), num6 = 1 + withdraw(n - log_(n, 6));
    return min(num9, num6);
}

int main() {
    int n;
    cin >> n;
    cout << withdraw(n) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>
 
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cassert>
 
using namespace std;
 
#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)
 
#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
	string A;
	cin >> A;
	string res = "";
	vector<int> v;
	int cnt = 0;
	bool used[26] = {};
	v.push_back(A.size());
	rrep(i,A.size()) {
		if(!used[A[i]-'a']) cnt++;
		used[A[i]-'a'] = true;
		if(cnt == 26) {
			rep(j,26) used[j] = false;
			cnt = 0;
			v.push_back(i);
		}
	}
	reverse(all(v));
	rep(i,v.size()) {
		bool f[26] = {};
		int j;
		if(i) {
			j = v[i-1];
			char c = res[res.size()-1];
			while(c != A[j]) j++;
			j++;
		}
		else {
			j = 0;
		}
		for(; j < v[i]; j++) {
			f[A[j]-'a'] = true;
		}
		rep(k,26) {
			if(!f[k]) {
				res += 'a'+k;
				break;
			}
		}
	}

	cout << res << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
    vector<int> count(26,0);
    string s;
    cin >> s;
    for(int i=0; i<s.length(); i++){
        count[s[i]-'a']++;
    }
    int flag=1;
    for(int i=0; i<26; i++){
        if(count[i]%2!=0)flag=0;
    }
    cout << (flag?"Yes":"No") << endl;
    return 0;
}


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

/*
3
0 10 20
10 0 -100
20 -100 0
*/
vector<vector<int> >v;
int rabbits;
vector<ll>score;
vector<ll>dp;
ll calscr(int x){
    ll ans=0;
    for(int i=0;i<16;i++){

        if(x&(1<<i)){
            for(int j=i+1;j<16;j++){
                if(x&(1<<j)){
                    ans+=v[i][j];
                }
            }
        }
    }
    return ans;
}
void fillscore(int n){

    for(int i=1;i<(1<<n);i++){
        score[i] = calscr(i);
    }
}
ll maxscore(int rabbits){
    if(dp[rabbits]!=-1){
        return dp[rabbits];
    }
    ll ans=0;
    for(int subset = rabbits;subset !=0;subset =(subset-1)&rabbits){
        ans = max(ans, score[subset] + maxscore(rabbits^subset));
    }
    return dp[rabbits] = ans;
}
void solve(){
    int n;cin>>n;
    score.resize(1<<n,0);
    dp.resize(1<<n,-1);
    dp[0]=0;
    v.resize(n,vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>v[i][j];
        }
    }
    fillscore(n);
    rabbits = (1<<n) -1;
    cout << maxscore(rabbits)<<"\n";
}

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

    cout.precision(10);
    int t=1;//cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, x, a[100100], res;

signed main() {
	cin >> n >> x;
	rep(i,n) cin >> a[i];
	if (a[0]>x) res += a[0]-x, a[0] = x;
	reps(i,1,n) {
		int t = a[i]+a[i-1]-x;
		if (t>0) a[i] -= t, res += t;
	}
	cout << res << endl;
}

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



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

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

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BShiftOnly {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vi A(n);
        in >> A;
        int res = INT_MAX;
        trav(x, A) {
            ckmin(res, __builtin_ctz(x));
        }
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BShiftOnly solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3616
x,k,d=list(map(int,input().split()))
x=abs(x)
if k%2:
  k-=1
  x=abs(x-d)
d*=2
k=k//2
t=x//d
if k<=t:
  print(x-k*d)
else:
  print(min(x%d,d-(x%d)))
  

Measured memory_bytes: 61600
import numpy as np
N = int(input())
seq = np.array(list(map(int, input().split())))

M, m, x, y = seq.max(), seq.min(), seq.argmax(), seq.argmin()
print(2 * N - 1)
if M + m >= 0:
    for i in range(N):
        print(x + 1, i + 1)
    for i in range(N - 1):
        print(i + 1, i + 2)
else:
    for i in range(N):
        print(y + 1, i + 1)
    for i in range(N - 1, 0, -1):
        print(i + 1, i)


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

using namespace std;

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

	int n;
	cin >> n;

	deque<int> d;
	while (n--) {
		string s;
		cin >> s;

		if (s[0] == 'i') {
			int x;
			cin >> x;
			d.push_front(x);
		} else {
			int sz = s.size();
			if (sz == 6) {
				int x;
				cin >> x;
				for (auto i = d.begin(); i != d.end(); ++i) {
					if (*i == x) {
						d.erase(i);
						break;
					}
				}
			} else if (sz == 11) {
				d.pop_front();
			} else {
				d.pop_back();
			}
		}
	}

	if (!d.empty()) {
		cout << d[0];
		for (auto i = 1; i < d.size(); ++i) {
			cout << ' ' << d[i];
		}
	}

	cout << '\n';
}


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

public class Main {

    public static void main(String[] argv) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int W = Integer.parseInt(str[1]);

        int[] v = new int[n];
        int[] w = new int[n];
        int sumOfV = 0;
        for (int i = 0; i < n; i++) {
            str = br.readLine().split(" ");
            v[i] = Integer.parseInt(str[0]);
            w[i] = Integer.parseInt(str[1]);
            sumOfV += v[i];
        }


        int[][] dp = new int[n+1][sumOfV+1];
        dp[n][0] = 0;
        for(int i=1; i<=sumOfV; i++) dp[n][i] = Integer.MAX_VALUE/2;

        for(int i=n-1; i>=0; i--){
            for(int j=0; j<=sumOfV; j++){
                if(v[i] > j){
                    dp[i][j] = dp[i+1][j];
                } else {
                    dp[i][j] = Integer.min(dp[i+1][j], dp[i+1][j-v[i]] + w[i]);
                }
            }
        }
        int ans = sumOfV;
        while(dp[0][ans] > W) ans--;
        System.out.println(ans);
    }

}

Measured memory_bytes: 29244
#
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
#print(N, A)

#
alice = 0
bob = 0
for i in range(N//2):
    alice += A[i*2]
    bob += A[i*2 + 1]
if N%2!=0:
    alice += A[-1]

#
print(alice - bob)


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

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

Measured memory_bytes: 256
#include<stdio.h>

int main (void){

  int n,flag0,flag1,i,time;
  int item[10001]={};
  while(1){
    flag1=0;
    flag0=0;
    scanf("%d",&n);
    if(n==0)break;
    if(n>=2){
      for(i=0;i<n;i++){
	scanf("%d",&item[i]);
      }
      for(i=0;i<n;i++){
	if(item[i]==1){
	  flag1++;
	}else if(item[i]==0){
	  flag0++;
	}
      }
      if(n-2<flag0+flag1){
	printf("NA\n");
      }else{
	time = n+1-flag0;
	printf("%d\n",time);
      } 
    }else{ //n=1
      scanf("%d",&item[0]);
      if(item[0]>=2){
	printf("2\n");
      }else{
	printf("NA\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 660
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n;
    cin >> n;
    if(n==1){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }
}

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

#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007
#define hash(n) unordered_map<int,int>mp(n)

 
int main() 
{ 
	JJ;
    int n,k; cin>>n>>k;
    int prices[n];
    FOR(i,0,n){
    	cin>>prices[i];
    }
    sort(prices,prices+n);
    long sum=0;
    FOR(i,0,k){
    	sum+=prices[i];
    }
    cout<<sum<<endl;
    
} 

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int a = 0;
    for( int i = 0; i < s.size(); ++i ) if( s[i] == '1' ) ++a;;
    cout << a << endl;
    return 0;
}


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

int main(){
    int N,cnt_min = 200;
    cin >> N;
    for(int i = 0; i < N;i++){
        int x,m = 0; 
        cin >> x;
        while(x % 2 == 0){
            x /= 2;
            m++;
        }
         cnt_min = min(m,cnt_min);
    }
    cout << cnt_min << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from random import randint
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
import sys
import os
import re
sys.setrecursionlimit(9999)
inf = float('inf')
mod = int(1e9) + 7
mod_ = 998244353
N = 5001
 
'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''


def main():
	n, m = map(int, input().split())
	print(max(0, n-2*m))


BUFSIZE = 8192
class FastI(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = StringIO()
		self.newlines = 0
 
	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
		self.newlines = 0
		return self.buffer.read()
 
	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count("\n") + (not b)
			ptr = self._buffer.tell()
			self._buffer.seek(0, 2), self._buffer.write(
				b), self._buffer.seek(ptr)
		self.newlines -= 1
		return self._buffer.readline()
class FastO(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = __pypy__.builders.StringBuilder()
		self.write = lambda s: self._buffer.append(s)
 
	def flush(self):
		os.write(self._fd, self._buffer.build())
		self._buffer = __pypy__.builders.StringBuilder()
def print(*args, **kwargs):
	sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop("end", "\n"))
	if kwargs.pop("flush", False):
		file.flush()
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
	def bootstrap(cont):
		call, arg = cont.switch()
		while True:
			call, arg = cont.switch(to=continulet(
				lambda _, f, args: f(*args), call, arg))
	cont = continulet(bootstrap)
	cont.switch()
	main()

Measured memory_bytes: 30956
#include <iostream>

using namespace std;

int main(){
    int array[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin >> k;

    cout << array[k-1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
bool panduan(int n){
	int weishu=0;
	while(n!=0){
		weishu++;
		n/=10;
	}
	if(weishu%2==1)return true;
	else return false;
}
int main(){
	int n,num=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(panduan(i))num++;
	} 
	cout<<num<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int m1, d1;
int m2, d2;
int m[20] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main(void)
{
	scanf("%d %d", &m1, &d1);
	scanf("%d %d", &m2, &d2);
	
	if(m[m1] == d1)
	{
		printf("1");
	}
	
	else
	{
		printf("0");
	}
	
	return 0;
}

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

using ll = long long;
using P = pair<ll,int>;

const ll MOD = 1000000007;
const ll INF = 1ll<<60;
ll mod(ll a, ll m) { return (a % m + m) % m; }

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;

    vector<vector<P>> G(n);
    for (int i = 0; i < m; i++) {
        int u, v; ll d;
        cin >> u >> v >> d;
        u--; v--;
        G[u].push_back(P(d, v));
        G[v].push_back(P(d, u));
    }

    vector<ll> ds(n,INF), dt(n,INF), ns(n,0), nt(n,0);

    ds[s] = 0; ns[s] = 1;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0ll, s));
    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        ll d = p.first;
        int v = p.second;
        if (ds[v] < d) continue;
        for (auto nv : G[v]) {
            if (ds[nv.second] > ds[v] + nv.first) {
                ds[nv.second] = ds[v] + nv.first;
                ns[nv.second] = ns[v];
                que.push(P(ds[nv.second], nv.second));
            }
            else if (ds[nv.second] == ds[v] + nv.first) {
                ns[nv.second] += ns[v];
                ns[nv.second] %= MOD;
            }
        }
    }

    dt[t] = 0; nt[t] = 1;
    que.push(P(0ll, t));
    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        ll d = p.first;
        int v = p.second;
        if (dt[v] < d) continue;
        for (auto nv : G[v]) {
            if (dt[nv.second] > dt[v] + nv.first) {
                dt[nv.second] = dt[v] + nv.first;
                nt[nv.second] = nt[v];
                que.push(P(dt[nv.second], nv.second));
            }
            else if (dt[nv.second] == dt[v] + nv.first) {
                nt[nv.second] += nt[v];
                nt[nv.second] %= MOD;
            }
        }
    }

    ll dist = ds[t];
    ll ans = (ns[t] * nt[s]) % MOD;
    for (int v = 0; v < n; v++) {
        if (ds[v] == dt[v] && ds[v] + dt[v] == dist) {
            ll sub = (ns[v] * nt[v]) % MOD;
            ans = mod(ans - sub * sub % MOD, MOD);
        }
        for (auto nv : G[v]) {
            int from = v, to = nv.second;
            ll d = nv.first;
            if (ds[from] + d + dt[to] != dist) continue;
            if (ds[from] + d != ds[to] || dt[to] + d != dt[from]) continue;
            if (ds[from] < dt[from] && ds[to] > dt[to]) {
                ll sub = (ns[from] * nt[to]) % MOD;
                ans = mod(ans - sub * sub % MOD, MOD);
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  ll k;
  cin >> n;
  cin >> k;
  int a[n];
  REP(i,n){
    cin >> a[i];
    a[i]--;
  }
  
  vector<bool> visited(n,false);
  int now = 0;
  int dist = 0;
  while(!visited[now]){
    visited[now] = true;
    now = a[now];
    dist++;
  }
  //cout << dist <<endl;
  int join = now;
  now = 0;
  int distJ = 0;
  while(now != join){
    now = a[now];
    distJ++;
  }
 // cout << distJ <<endl;
  now = 0;
  while(now != join && k > 0){
    now  = a[now];
    k--;
  }
  k = k%(dist-distJ);
  while(k > 0){
    now = a[now];
    k--;
  }
  cout << now+1 << endl;
  return 0;
}

Measured memory_bytes: 4424
using System;
using System.Linq;
using static System.Console;

class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(ReadLine());
        var s = ReadLine();
        var k = int.Parse(ReadLine());

        var c = s[k-1];
        foreach (var a in s)
        {
            Write(a==c ? c : '*');
        }
        WriteLine();
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int ctr = 0;
    for(int i=0; i<3; i++){
        if(s[i]==t[i])
            ctr++;
    }
    cout << ctr;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
    //ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	cout << (n + (2-1))/2 << endl;
    return 0;
}

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

int main() {
  int n;  cin >> n;
  int v[100];
  for(int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for(int i = 0; i < n; i++) {
    cout << v[i] << (i == n-1 ? "\n" : " ");
  }

  //---Insertion Sort---//
  for(int j = 1; j < n; j++) {
    int key = v[j];
    int k = j - 1;
    while(k >= 0 && key < v[k]) {
      v[k + 1] = v[k];
      k--;
    }
    v[k + 1] = key;
    for(int i = 0; i < n; i++) {
      cout << v[i] << (i == n-1 ? "\n" : " ");
    }
  }
}



Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

int main(){

    ll n;
    cin >> n;

    vector<ll> nums(n);

    bool zero = false;

    ll zeroSum = 0;
    ll mn = 1e9+7; 
    ll minusCnt = 0;

    for (int i = 0; i < n; i++){
        cin >> nums[i];
        if (nums[i] < 0) minusCnt++;
        mn = min(abs(nums[i]), mn);
        if (!nums[i]) zero = true;
        zeroSum += abs(nums[i]);
    }

    if (zero){
        cout << zeroSum << endl;
    }
    else if (minusCnt % 2 == 0){
        cout << zeroSum << endl;
    }
    else {
        cout << zeroSum - (mn * 2) << endl;
    }

    return 0;
}


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

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

bool prime[200000000];
void Eratosthenes(int n)
{
  for (int i = 2; i <= (int)sqrt(n) + 1; ++i)
  {
    if (prime[i] == true)
    {
      for (int j = i * 2; j <= n; j += i)
      {
        prime[j] = false;
      }
    }
  }
}

int main()
{
  int x;
  cin >> x;
  for (int i = 0; i <= 10000000; ++i)
    prime[i] = true;
  Eratosthenes(10000000);
  int ans = 0;
  for (int i = x; i <= 10000000; ++i)
  {
    if (prime[i])
    {
      ans = i;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10496
from heapq import heappush,heappop

n,m=[int(x) for x in input().rstrip().split()]
ab=[[] for i in range(10**5)]

for i in range(n):
  a,b=[int(x) for x in input().rstrip().split()]
  ab[a-1].append(-b)

ans=0
time=0
l=[]
for i in range(m):
  for b in ab[i]:
    heappush(l,b)
  if l:
    ans-=heappop(l)

print(ans)

Measured memory_bytes: 22388
// 幅優先探索であらかじめすべての状態の最小手数を計算する
// 8!=40320なので、余裕で計算できる
// 最終状態01234567からさかのぼって幅優先探索

#include <iostream>
#include <queue>
#include <map>
using namespace std;
typedef pair<int, int> P;
// 最終状態01234567からある状態にするまでの最小手数
map<string,int> d;

void bfs() {
  // 最終状態への手数は0
  string start = "01234567";
  d[start] = 0;
  // キューを作る
  queue<string> qu;
  qu.push(start);
  // キューが空になるまでループ
  while(qu.size()) {
    string a = qu.front();
    qu.pop();
    int i = a.find_first_of('0');
    string s[3];
    s[0] = a;
    s[1] = a;
    s[2] = a;
    // 上下の交換
    int j = (i + 4) % 8;
    s[0].replace(i,1,1,s[0].at(j));
    s[0].replace(j,1,1,'0');
    // 右との交換
    if (i % 4 != 3) {
      s[1].replace(i,1,1,s[1].at(i+1));
      s[1].replace(i+1,1,1,'0');
    }
    // 左との交換
    if (i % 4 != 0) {
      s[2].replace(i,1,1,s[2].at(i-1));
      s[2].replace(i-1,1,1,'0');
    }
    // まだ最終手数がわかっていない文字列をキューにぶっこむ
    for (int k = 0; k < 3; k++) {
      if (d.find(s[k]) == d.end()) {
        qu.push(s[k]);
        d[s[k]] = d[a] + 1;
      }
    }
  }
}

int main() {
  // 先に最小手数のリストを作る
  bfs();

  int n;
  while (true) {
    string str;
    for (int i = 0; i < 8; i++) {
      if (!(cin >> n)) return  0;
      str += n + '0';
    }
    cout << d[str] << endl;
  }
}

Measured memory_bytes: 3460
N = gets.to_i

problems = N.times.map { gets.split.map(&:to_i) }

r_min = Float::INFINITY
l_max = 0

problems.each do |l, r|
  l_max = l if l_max < l
  r_min = r if r_min > r
end

def f(list)
  min_r_asc = Array.new(N, Float::INFINITY)
  min_r_desc = Array.new(N, Float::INFINITY)
  max_l_asc = Array.new(N, 0)
  max_l_desc = Array.new(N, 0)

  max_l_asc[0] = list[0][0]
  min_r_asc[0] = list[0][1]
  max_l_desc[N - 1] = list[N - 1][0]
  min_r_desc[N - 1] = list[N - 1][1]

  1.upto(N - 1) do |i|
    max_l_asc[i] = [max_l_asc[i - 1], list[i][0]].max
    min_r_asc[i] = [min_r_asc[i - 1], list[i][1]].min
  end

  (N - 2).downto(0) do |i|
    max_l_desc[i] = [max_l_desc[i + 1], list[i][0]].max
    min_r_desc[i] = [min_r_desc[i + 1], list[i][1]].min
  end

  ans = 0

  0.upto(N - 2) do |i|
    s = min_r_asc[i] - max_l_asc[i] + 1
    t = min_r_desc[i + 1] - max_l_desc[i + 1] + 1

    v = [s, 0].max + [t, 0].max

    ans = v if ans < v
  end

  ans
end

list_a = problems.sort_by { |l, r| -[r_min - l + 1, 0].max }
list_b = problems.sort_by { |l, r| -[r - l_max + 1, 0].max }
list_c = problems.sort_by { |l, r| -[r - l + 1, 0].max }

puts [f(list_a), f(list_b), f(list_c)].max


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
#define MAX 305

int H,W;
char t[MAX][MAX];


int mem[MAX][MAX][MAX];
int calc(int a,int b,int ah,int bh){
  if(mem[a][ah][bh]!=-1)
    return mem[a][ah][bh];
  if(ah==0||bh==0)return 0;

  int res=calc(a,b,ah-1,bh-1);
  if(t[ah-1][a]==t[bh-1][b])res++;
  return mem[a][ah][bh]=res;
}

int dp[MAX][MAX];
int solve(int a,int b){
  fill( (int*)dp[0], (int*)dp[MAX], 1e9);
  dp[H][H]=0;
 
  for(int i=H;i>=0;i--){
    for(int j=H;j>=0;j--){
      if(dp[i][j]==1e9)continue;
      if(i){
        dp[i-1][j]=min(dp[i-1][j],dp[i][j]+calc(a,b,i,j));
      }
      if(j){
        dp[i][j-1]=min(dp[i][j-1],dp[i][j]+calc(a,b,i,j) );
      }
    }
  }
  return dp[0][0];
}





int main(){
  memset(mem,-1,sizeof(mem));
  fill( (int*)dp[0], (int*)dp[MAX], 1e9);
  
  cin>>H>>W;
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>t[i][j];
    }
  }

  int ans=0;
  for(int i=0;i+1<W;i++){
    ans+=solve(i,i+1);
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 111616
using System;

namespace ITP1_4_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int n = int.Parse(N);
            string str = Console.ReadLine();
            string[] parseStr = str.Split((char[])null);
            int[] counter = new int[n];

            int min = 1000000;
            int max = -1000000;
            double sum = 0;

            if (n <= 0 || 10000 < n)
                Environment.Exit(0);

            for (int i = 0; i < n; i++)
            {
                counter[i] = int.Parse(parseStr[i]);
                if (counter[i] < min)
                    min = counter[i];
                if (counter[i] > max)
                    max = counter[i];
                sum = sum + counter[i];
            }       
           
            Console.WriteLine("{0} {1} {2}", min, max, sum);
        }
    }
}


Measured memory_bytes: 18132
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main() {
  int h, w;
  cin >> h >> w;
  int div = 1e9 + 7;
  vector<string> c(h);
  for (int i = 0; i < h; i++) {
    cin >> c[i];
  }
  vector<vector<int>> dp(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    if (c[i][0] == '.') {
      dp[i][0] = 1;
    } else {
      break;
    }
  }
  for (int j = 0; j < w; j++) {
    if (c[0][j] == '.') {
      dp[0][j] = 1;
    } else {
      break;
    }
  }
  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (c[i][j] == '#') {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % div;
    }
  }
  cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 5248
#include<iostream>
#include<cstdio>

using namespace std;

int D,N,X,ans,counter=0,p =0;
int main(){
    cin >> N >> D >> X;
    int A; 
    for(int i = 0;i < N;i++){
        p=0;
        cin >> A;
        while(p*A + 1 <= D){
            if(p*A + 1 <= D){
                p++;
            }
        }
        counter = counter + p;
    }
    ans = X + counter;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  long long sum=0;
  for(int i=1;i<=n;i++){
    if(i%3==0||i%5==0){
      continue;
    }
    else{
sum+=i;
    
  }
  }
  cout<<sum<<endl;
}
  
  

Measured memory_bytes: 3596
import java.util.*

fun main(args:Array<String>):Unit {
    while(true){
        val (n, m, z) = readLine()!!.trim().split(' ').map(String::toInt)
        if ( n== 0 && m == 0 && z == 0) return
        val stations = Array(n){ Stack<Int>() }
        val rails = Array(m){
            val (s, d) = readLine()!!.trim().split(' ').map(String::toInt)
            stations[s - 1].push(it * 2)
            stations[d - 1].push(it * 2 + 1)
            Pair(s - 1, d - 1)
        }
        val newRails = Array(m * 2 + 1){Array(m * 2 + 1){false}}
        for (i in 0 until m){
            val (first, second) = rails[i]
            stations[second].filterNot{ it / 2 == i }.forEach { newRails[i * 2][it] = true }
            stations[first].filterNot { it / 2 == i }.forEach { newRails[i * 2 + 1][it] = true }
            if (first == 0) newRails[i * 2 + 1][m * 2] = true
            if (second == 0) newRails[i * 2][m * 2] = true
        }
        val res = exponent(newRails, z)
        println(if (stations.last().any{goal -> res[goal].last()}) "yes"
        else "no")
    }
}
fun exponent(base:Array<Array<Boolean>>, exp:Int):Array<Array<Boolean>> {
    return when(exp){
        1 -> base
        else -> exponent(base, exp / 2).let{if (exp % 2 == 1) it * it * base else it * it}
    }
}
operator fun Array<Array<Boolean>>.times(other:Array<Array<Boolean>>):Array<Array<Boolean>>{
    return this.map { booleans ->
        (0 until booleans.size).map{column -> (0 until this.size).any{booleans[it] && other[it][column]} }.toTypedArray()
    }.toTypedArray()
}


Measured memory_bytes: 72064
#include <iostream>
#include <queue>
#include <utility>
#include <string>

using namespace std;

int main()
{
	queue<pair<string, int>> ps, ep;
	int n, q, t = 0;

	cin >> n >> q;

	for (int i = 0; i < n; i++) {
		pair<string, int> p;
		cin >> p.first >> p.second;
		
		ps.push(p);
	}

	while (!ps.empty()) {
		auto p = ps.front();
		ps.pop();

		p.second -= q;
		t += q;
		if (p.second <= 0) {
			t += p.second;
			p.second = t;
			ep.push(p);
		} else {
			ps.push(p);
		}
	}

	for (int i = 0; i < n; i++) {
		cout << ep.front().first << ' ' << ep.front().second << endl;
		ep.pop();
	}
}

Measured memory_bytes: 6156
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	class data implements Comparable{

		String name;

		int win;

		int lose;

		int draw;

		int point;

		data(String n,int w,int l,int d){

			this.name = n;

			this.win = w;

			this.lose = l;

			this.draw = d;

			this.point = w*3+d;

		}

		@Override

		public int compareTo(Object arg0) {

			return -this.point + ((data)arg0).point;

		}

		@Override

		public String toString() {

			return name+","+point;

		}

	}

	void run(){

		for(boolean first = true;;first = false){

			int n = sc.nextInt();

			if(n == 0)

				break;

			if(!first){

				System.out.println();

			}

			data[] d = new data[n];

			for(int i= 0; i < n ;i ++){

				d[i] = new data(sc.next(),sc.nextInt(),sc.nextInt(),sc.nextInt());

			}

			Arrays.sort(d);

			for(int i = 0; i < n; i++){

				System.out.println(d[i]);

			}

		}

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

Int modpow(Int a, Int n, Int mod) {
    Int ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret = ret * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }

    return ret;
}

vector<Int> factorials(0), invs(0);
bool is_ncr_table = false;
void calc_ncr_table(Int n, Int mod) {
    is_ncr_table = true;

    // 1! ~ n! の計算
    Int f = 1;
    factorials.push_back(f);
    for (Int i = 1; i < n + 1; i++) {
        f *= i;
        f %= mod;
        factorials.push_back(f);
    }
    // n!^-1 の計算
    Int inv = modpow(factorials[n], mod - 2, mod);
    // (n-1)!^-1 ~ 1!^-1 の計算
    invs.assign(n, 1);
    invs[n] = inv;
    for (Int i = n; i >= 1; i--) {
        inv *= i;
        inv %= mod;
        invs[i - 1] = inv;
    }
}

Int factorial(Int n, Int mod = 1) {
    Int ret = 1;
    if (mod == 1) {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
        }

        return ret;
    } else {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
            ret %= mod;
        }

        return ret;
    }
}

Int ncr(Int n, Int r, Int mod, bool use_table = false) {
    if (use_table) {
        // modが素数の場合のみ
        if (!is_ncr_table) {
            calc_ncr_table(n, mod);
        }
        return factorials[n] * invs[r] * invs[n - r] % mod;
    } else {
        Int x = 1;
        for (Int i = n - r + 1; i < n + 1; i++) {
            x *= i;
            x %= MOD;
        }
        return x * modpow(factorial(r, mod), mod - 2, mod) % mod;
    }
}

int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256