akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<db> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
typedef vector<pd> vpd; 

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 

#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)

const int MX  = 2e5+5; 
const int MOD = 1e9+7; // 998244353;
const ll  INF = 1e18; 
const ld  PI  = acos((ld)-1);

const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 

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

constexpr int pct(int x) { return __builtin_popcount(x); } // number of ones 
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) 
template<class T> T cdiv(T a, T b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 

int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true 
		int mid = (lo+hi)/2; 
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}

template<class T> void remDup(vector<T>& v) { 
	sort(all(v)); v.erase(unique(all(v)),end(v)); 
}

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if (sizeof...(t)) cerr << ", ";
	DBG(t...); 
}
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

// FILE I/O
void setIn(str S) { freopen(S.c_str(),"r",stdin); }
void setOut(str S) { freopen(S.c_str(),"w",stdout); }
void setIO(str S = "") {
	ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(S)) { setIn(S+".in"), setOut(S+".out"); } // for USACO
}

int32_t main() { 
	
	setIO();

    int n; cin >> n;

    vi v1,v2;
    F0R(i,n) {
        int x,y; cin >> x >> y;
        v1.pb(x+y); v2.pb(x-y);    
    }

    sort(all(v1)); sort(all(v2));

    cout << max(v1.bk-v1.ft,v2.bk-v2.ft) << "\n";

}

Measured memory_bytes: 5184
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string a;int s[4];
int main()
{
	cin>>a;
	for(int i=0;i<=2;i++)
		if(a[i]=='a')
			s[1]++;
		else if(a[i]=='b')
			s[2]++;
		else
			s[3]++;
	for(int i=1;i<=3;i++)
		if(s[i]>=2)
		{
			printf("No");
			return 0;
		}
	printf("Yes");
	return 0;
}

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

vector< vector<char> >V(8,vector<char>(8));
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};

bool update;
int idx,idy,count;
bool can[8];

bool in(int x,int y){
	return x>=0 && y>=0 && x<8 && y<8;
}

void check(int k){
	char me,you;
	bool tcan[8];
	count=0;
	memset(can,false,sizeof(can));
	if(k==0){me='o';you='x';}
	else{me='x';you='o';}
	for(int iy=0;iy<8;iy++){
		int tcount,ttcount;
		for(int ix=0;ix<8;ix++){
			int x=ix,y=iy;
			if(k!=0){
				x=7-ix;
				y=7-iy;
			}
			tcount=0;
			memset(tcan,false,sizeof(tcan));
			if(V[y][x]!='.')
				continue;
			for(int d=0;d<8;d++){
				int nx=x+dx[d],ny=y+dy[d];
				ttcount=0;
				while(in(nx,ny)&&V[ny][nx]==you){
					nx+=dx[d];ny+=dy[d];ttcount++;
				}
				if(in(nx,ny) && V[ny][nx]==me &&ttcount>0){
					tcount+=ttcount;
					update=true;
					tcan[d]=true;
				}
			}
			if(tcount>count){
				idx=x;idy=y;count=tcount;update=true;
				for(int i=0;i<8;i++) can[i]=tcan[i];
			}
		}
	}
}

void put(int k){
	char me,you;
	if(count==0)
		return;
	if(k==0){me='o';you='x';}
	else{me='x';you='o';}
	V[idy][idx]=me;
	for(int d=0;d<8;d++){
		if(can[d]){
			int nx=idx+dx[d],ny=idy+dy[d];
			while(in(nx,ny) && V[ny][nx]==you){
				V[ny][nx]=me;nx+=dx[d];ny+=dy[d];
			}
		}
	}
}

void print(){
	for(int y=0;y<8;y++){
		for(int x=0;x<8;x++)
			cout<<V[y][x];
		cout<<endl;
	}
}


int main()
{
	for(int y=0;y<8;y++)
		for(int x=0;x<8;x++)
			cin>>V[y][x];

	update=true;
	while(update){
		update=false;
		check(0);
		put(0);
		check(1);
		put(1);
	}
	print();
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[3002][3002][2];
ll ar[3002];
ll f(int i, int j, bool st)
{
    ll &ans = dp[i][j][st];
    if (ans != -1)
        return ans;
    if (i == j)
        return ar[i];
    ans = -3e13;
    ans = max(ans, -f(i + 1, j, !st) + ar[i]);
    ans = max(-f(i, j - 1, !st) + ar[j], ans);
    return ans;
}
int main()
{
    memset(dp, -1, sizeof(dp));
    int n; cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> ar[i];
    }
    cout << f(0, n - 1, 1);
    return 0;
}

Measured memory_bytes: 141312
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
    int number ,sum;
    string x;
    while (cin >> x) {
        if (x == "0") {
            break;
        }
        sum = 0;
        for (int i = 0; i < x.size(); i++) {
            number = x[i] - '0';
            sum += number;
        }
        cout << sum << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;
const double eps = 1e-6;

int n, t;
int a[N];
int res;

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

    int l = -1, r = -1;
    while(n--)
    {
        int st;
        cin >> st;
        if(st > r)
        {
            res += r - l;
            l = st, r = st + t;
        }
        else r = max(r, st + t);
    }

    res += r - l;

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,d;
int x[11][11];
int main(){
	cin>>n>>d;
	rb(i,1,n){
		rb(j,1,d){
			scanf("%d",&x[i][j]);
		}
	}
	int res=0;
	rb(i,1,n){
		rb(j,i+1,n){
			int tot=0;
			rb(k,1,d){
				tot+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			
			rb(k,1,tot){
				if(k*k==tot){
					res++;
				}
			}
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100010],n,cnt[2];
bool gao()
{
  for(int i=1;i<=n;i++)  if(a[i]&1)  a[i]--;
  cnt[0]=cnt[1]=0;int gcd=a[1];
  for(int i=2;i<=n;i++)  gcd=__gcd(a[i],gcd);
  for(int i=1;i<=n;i++)  cnt[(a[i]/=gcd)&1]++;
  if(cnt[0]&1)  return 1;
  else if(cnt[1]>1)  return 0;
  else
  {
    for(int i=1;i<=n;i++)
      if(a[i]==1)  return cnt[0]&1?1:0;
    return gao()^1;
  }
}
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
    scanf("%d",a+i);
    cnt[a[i]&1]++;
  }
  if(cnt[0]&1)  puts("First");
  else if(cnt[1]>1)  puts("Second");
  else
  {
    for(int i=1;i<=n;i++)
      if(a[i]==1)
	  {  
	    puts(cnt[0]&1?"First":"Second");
		return 0;
	  }
    puts(gao()^1?"First":"Second");
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
int n, c, l[6], size[32];
s64 f[32][301], g[32][301], h[32][301];
int trans(int a1, int a2, int b1, int b2) {
	return std::min(n*c, std::max(a1*n+a2+(a2>=b2), b1*n+b2));
}
int main() {
	scanf("%d%d", &n, &c);
	for(int i=0; i<n; ++i) scanf("%d", l+i);
	std::sort(l, l+n);
	f[0][l[n-1]*n]=1;
	int fs=(1<<(n-1))-1;
	for(int i=1; i<=fs; ++i) size[i]=size[i&i-1]+1;
	for(int i=0; i<c; ++i) {
		for(int s=0; s<=fs; ++s) {
			memset(g[s], 0, n*i*sizeof(s64));
			memcpy(g[s]+n*i, f[s]+n*i, (n*(c-i)+1)*sizeof(s64));
		}
		for(int x=0; x<n-1; ++x)
			for(int s=1<<x; s<=fs; s=s+1|1<<x)
				for(int j=0; j<=n*c; ++j) if(g[s-(1<<x)][j])
					for(int k=1; k<=size[s]; ++k) g[s][trans(j/n, j%n, i+l[x], k)]+=g[s-(1<<x)][j];
		for(int k0=0; k0<n; ++k0) {
			for(int s=0; s<=fs; ++s) {
				memset(h[s], 0, (n*c+1)*sizeof(s64));
				h[s][n*i+k0]=f[s][n*i+k0];
			}
			for(int x=0; x<n-1; ++x)
				for(int s=1<<x; s<=fs; s=s+1|1<<x)
					for(int j=0; j<=n*c; ++j) if(h[s-(1<<x)][j])
						for(int k=k0+1; k<=size[s]; ++k) h[s][trans(j/n, j%n, i+l[x], k)]+=h[s-(1<<x)][j];
			for(int s=0; s<=fs; ++s)
				for(int j=0; j<=n*c; ++j) g[s][j]-=h[s][j];
		}
		for(int s=0; s<=fs; ++s) memcpy(f[s], g[s], (n*c+1)*sizeof(s64));
	}
	s64 tot=1;
	for(int i=1; i<n; ++i) tot*=c*i;
	printf("%.22Lf\n", 1.0l*f[fs][n*c]/tot);
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=505;
int s[N],t[N];
bool visr[N],visc[N];
ull a[N][N],u[N],v[N],b[N],c[N];
int n;
int main()
{
    ull one=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&s[i]);
    for(int i=1;i<=n;i++) scanf("%d",&t[i]);
    for(int i=1;i<=n;i++) scanf("%llu",&u[i]);
    for(int i=1;i<=n;i++) scanf("%llu",&v[i]);
    for(ull k=0;k<64;k++)
    {
        memset(visr,false,sizeof(visr));
        memset(visc,false,sizeof(visc));
        vector<int>r,c;
        for(int i=1;i<=n;i++)
        {
            if(s[i]==0) r.push_back(i);
            if(t[i]==0) c.push_back(i);
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
        {
            if(s[i]==0&&(u[i]>>k&1)||t[j]==0&&(v[j]>>k&1)||s[i]==1&&(u[i]>>k&1)&&t[j]==1&&(v[j]>>k&1)&&!(visr[i]&&visc[j]))
                a[i][j]|=one<<k,visr[i]=visc[j]=true;
        }
        bool f1=false,f2=false;
        int p1=0,p2=0;
        for(int i=1;i<=n;i++)
            if((u[i]>>k&1)&&s[i]==1&&!visr[i])
        {
            f1=true;
            a[i][c[p2]]|=one<<k;
            p2++;if(p2==c.size()) p2=0;
        }
        for(int i=1;i<=n;i++)
            if((v[i]>>k&1)&&t[i]==1&&!visc[i])
        {
            f2=true;
            a[r[p1]][i]|=one<<k;
            p1++;if(p1==r.size()) p1=0;
        }
        assert(!(f1&&f2));
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
    {
        if(s[i]) b[i]|=a[i][j];
        else b[i]&=a[i][j];
        if(t[j]) c[j]|=a[i][j];
        else c[j]&=a[i][j];
        if(j==1) b[i]=a[i][j];
        if(i==1) c[j]=a[i][j];
    }
    for(int i=1;i<=n;i++)
        if(u[i]!=b[i]||v[i]!=c[i])
    {
        printf("-1\n");return 0;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        printf(j==n?"%llu\n":"%llu ",a[i][j]);
}


Measured memory_bytes: 7436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i=2; i*i<=n; i++) {
    while (n%i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

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;
}

// 逆元
ll modinv(ll a)
{
  ll b=mod, x=1, y=0;
  while (b) {
    ll t = a/b;
    a -= t*b; swap(a, b);
    x -= t*y; swap(x, y);
  }
  x %= mod;
  if (x<0) x += mod;
  return x;
}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (int i=0; i<N; i++){
    cin >> A[i];
  }

  map<int, int> mp;
  for (int i=0; i<N; i++) {
    map<int, int> tmp = prime_factor(A[i]);
    for (auto v : tmp) {
      if (mp.count(v.first) == 0) mp[v.first] = v.second;
      else mp[v.first] = max(mp[v.first], v.second);
    }
  }
  ll l = 1;
  for (auto v : mp) {
    ll tmp = modpow(v.first, v.second);
    l = l * tmp % mod;
  }
  ll ans = 0;
  for (int i=0; i<N; i++) {
    ll tmp = l * modinv(A[i]) % mod;
    ans = (ans + tmp) % mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 768
/**
 *     author: nayakashutosh9
 *     college: National Institute of Technology, Rourkela
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
const int N = 200005;

/*******************************************************************/




int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	// int t, z = 1; cin >> t;
	// cin.ignore();
	// while (t--) {

	// }
	int n; cin >> n;
	vector<int> a(n);
	int x = 0;
	for (int i = 0; i < n; i++) cin >> a[i], x ^= a[i];
	for (int i = 0; i < n; i++) cout << (x ^ a[i]) << " ";
	return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    pair<int, int> q[m];//first:bi second:ai
    for(int i = 0; i < m; i++) {
        cin >> q[i].second >> q[i].first;
    }
    sort(q, q + m);
    int res = 0, l = 1;
    for (int i = 0; i < m; i++)
    {
        if(l <= q[i].second) {
            res++;
            l = q[i].first;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4408
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n,a,b;
  cin>>n>>a>>b;
  int ans = 0;
  rep(i,n + 1) {
    int t = i;
    int sum = 0;
    while(t > 0) {
      sum += t % 10;
      t /= 10;
    }
    if(sum >= a && sum <= b) {
      ans += i;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        string str = ReadLine();
        int A = int.Parse(str[0].ToString());
        int B = int.Parse(str[1].ToString());
        int C = int.Parse(str[2].ToString());
        int D = int.Parse(str[3].ToString());

        int ans = 0;

        if (A+B+C+D == 7) { ans = 0; }
        else if (A-B+C+D == 7) { ans = 1; }
        else if (A+B-C+D == 7) { ans = 2; }
        else if (A-B-C+D == 7) { ans = 3; }
        else if (A+B+C-D == 7) { ans = 4; }
        else if (A-B+C-D == 7) { ans = 5; }
        else if (A+B-C-D == 7) { ans = 6; }
        else if (A-B-C-D == 7) { ans = 7; }

        bool op1 = (ans & 1) == 1;
        bool op2 = (ans & 2) == 2;
        bool op3 = (ans & 4) == 4;

        String ansStr = A.ToString() + (op1 ? "-" : "+") + B.ToString() + (op2 ? "-" : "+")
            + C.ToString() + (op3 ? "-" : "+") + D.ToString() + "=7";

        WriteLine(ansStr);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	cin>>n;
	vi m(n);
	vp in(n);
	rep(i,n)cin>>m[i]>>in[i].first>>in[i].second;
	int N=1<<n;
	vector<vector<pair<double,int> > >dp(N,vector<pair<double,int> >(n,pair<double,int>(inf,inf)));
	rep(i,n)dp[1<<i][i]=pair<double,int>(in[i].first*70./2000.,-1);
	loop(i,1,N)rep(j,n)if(i&1<<j){
		int sum=0;
		rep(k,n)if(i&1<<k)sum+=in[k].second;
//		cout<<i<<" "<<j<<" "<<sum<<endl;
		rep(k,n)if(!(i&1<<k)&&dp[i|1<<k][k].first>dp[i][j].first+abs(in[j].first-in[k].first)*(ll)(70+sum*20)/2000.){
			dp[i|1<<k][k]=pair<double,int>(dp[i][j].first+abs(in[j].first-in[k].first)*(ll)(70+sum*20)/2000.,j);
		}
	}
	double mi=inf;
	rep(i,n)mi=min(mi,dp[N-1][i].first);
	rep(i,n)if(mi==dp[N-1][i].first){
		vi out;
		out.pb(i);
		int t=i,T=N-1;
		while(dp[T][t].second!=-1){
			out.pb(dp[T][t].second);
			int tmp=t;
			t=dp[T][t].second;
			T-=1<<tmp;
		}
		for(int j=out.size()-1;j>=0;j--)
			cout<<m[out[j]]<<(j?" ":"\n");
		break;
	}
}

Measured memory_bytes: 9984
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  int i;
  for(i=0;i<n;i++) cin >> h[i];
  int cnt = 0;
  for(i=0;i<n;i++){
    if(h[i]>=k) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 3700
#!/usr/bin/env python3
from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, A: "List[int]"):
    def g():
        ctr = Counter(A)
        for key in sorted(ctr.keys(), reverse=True):
            for _ in range(ctr[key] // 2):
                yield key
    gg = g()
    try:
        print(next(gg) * next(gg))
    except StopIteration:
        print(0)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24868
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    x = gete(int)
    MAX_I = 100005
    p = [True] * MAX_I
    p[0], p[1] = False, False

    for i in range(2, MAX_I):
        if p[i]:
            for j in range(2 * i, MAX_I, i):
                p[j] = False

    for i in range(x, MAX_I):
        if p[i]:
            print(i)
            break


if __name__ == "__main__":
    main()

Measured memory_bytes: 40176
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()

if N % 2 == 1:
    print(0)
    exit()

ans = []
n = N // 10
ans.append(n)

baisuu = 5
while baisuu <= n:
    ans.append(n // baisuu)
    baisuu *= 5

print(sum(ans))


Measured memory_bytes: 38256
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  if B[j][i]=="1":
   d+=1
  else:
   e+=1
 f+=(d*e*pow(2,61-i,mod))%mod
 f%=mod
print(f)


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  string S;
  cin >> S;

  for (auto &c: S) {
    cout << "x";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(void) {
    int n; cin >> n;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    ll MIN = h[n-1];
    for(int i=n-2;i>=0;i--) {
        if(h[i]-MIN>=2) {
            puts("No"); return 0;
        }
        MIN = min(MIN,h[i]);
    }
    puts("Yes");
}




Measured memory_bytes: 1024
use std::cmp::max;
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    let mut buf = String::new();
    handle.read_line(&mut buf).unwrap();
    let N = buf.trim().parse::<usize>().unwrap();
    buf.clear();

    let mut tests = Vec::with_capacity(N);
    for _ in 0..N {
        handle.read_line(&mut buf).unwrap();
        let A = buf.trim().parse::<usize>().unwrap();
        buf.clear();

        let mut t = Vec::with_capacity(A);
        for _ in 0..A {
            handle.read_line(&mut buf).unwrap();
            let tup = {
                let tmp = buf
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse::<usize>().unwrap())
                    .collect::<Vec<_>>();
                (tmp[0] - 1, tmp[1] == 1)
            };
            t.push(tup);
            buf.clear();
        }
        tests.push(t);
    }

    let mut ans = 0;
    'outer: for i in 0..(1 << N) {
        let mut n_honests = 0;
        for j in 0..N {
            if i & (1 << j) != 0 {
                // j は正直者
                n_honests += 1;

                for &(x, y) in &tests[j] {
                    if y && (i & 1 << x) == 0 {
                        continue 'outer;
                    }
                    if !y && (i & 1 << x) != 0 {
                        continue 'outer;
                    }
                }
            }
        }
        // 矛盾がなければOK
        ans = max(ans, n_honests);
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


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

}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int H = sc.nextInt(), W = sc.nextInt();
        boolean[][] map = new boolean[H][W];
        int[][] cost = new int[H][W];
        for(int i=0;i<H;i++){
            char[] c = sc.next().toCharArray();
            for(int j=0;j<W;j++){
                map[i][j] = String.valueOf(c[j]).equals(".");
                cost[i][j] = 999;
            }
        }
        cost[0][0] = map[0][0] ? 0 : 1;
        for(int i=1;i<H+W;i++){
            for(int j=0;j<=i;j++){
                if(j >= H || i-j >= W){
                    continue;
                }
                int costFromL = 999, costFromU = 999;
                if(j != 0){
                    costFromL = cost[j-1][i-j];
                    if(map[j-1][i-j] != map[j][i-j]){
                        costFromL++;
                    }
                }
                if(i-j != 0){
                    costFromU = cost[j][i-j-1];
                    if(map[j][i-j-1] != map[j][i-j]){
                        costFromU++;
                    }
                }
                cost[j][i-j] = Math.min(costFromL, costFromU);
                //System.out.println(j + ", " + (i-j) + ", " + cost[j][i-j]);
            }
        }
        if(cost[H-1][W-1] == 0){
            System.out.println("0");
        }else {
            System.out.println((cost[H - 1][W - 1] - 1) / 2 + 1);
        }
    }

    private static long combination(long n, long k){
        if(k <= 0 || n <= 0 || n <= k){
            return 1;
        }
        return factorial(n) / (factorial(k) * factorial(n - k));
    }

    private static long combination(long n, long k, long mod){
        if(k <= 0 || n <= 0 || n <= k){
            return 1;
        }
        return factorial(n, mod) / (factorial(k, mod) * factorial(n - k, mod)) % mod;
    }

    private static long factorial(long l){
        long ans = 1;
        while(l > 0){
            ans *= l;
            l--;
        }
        return ans;
    }

    private static long factorial(long l, long mod){
        long ans = 1;
        while(l > 0){
            ans *= l;
            ans %= mod;
            l--;
        }
        return ans;
    }
}


Measured memory_bytes: 24020
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 100000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int freq[MAX + 5];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int n, i, x, y, q;
    ll sum = 0;
    cin >> n;
    for (i = 0; i < n; ++i) {
        cin >> x;
        freq[x]++;
        sum += x;
    }
    cin >> q;
    while (q-- > 00) {
        cin >> x >> y;
        sum -= 1LL * freq[x] * x;
        sum -= 1LL * freq[y] * y;
        freq[y] += freq[x];
        freq[x] = 0;
        sum += 1LL * freq[y] * y;
        cout << sum << "\n";
    }

    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string str,out;
    cin >> str;
    int len = str.length();
    len -= 2;
    cout << str[0] << len << str[str.length()-1] << endl;

    return 0;
}

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



template<int NV> struct UF {
    int par[NV], cnt[NV];
    UF() { rep(i, 0, NV) par[i] = i, cnt[i] = 1; }
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) { // xをyにくっつける
        x = operator[](x); y = operator[](y);
        if (x != y) par[x] = y, cnt[y] += cnt[x];
    }
};
int N;
//-----------------------------------------------------------------
set<int> E[101010];
UF<101010> uf;
void merge(int a, int b) {
    //printf("[%d %d]\n", a, b);
    a = uf[a], b = uf[b];
    if (a == b) return;
    if (E[a].size() > E[b].size()) swap(a, b);

    set<pair<int, int>> next;

    for (int to : E[a]) if (to != b) {
        E[to].erase(a);
        if (E[to].count(b)) next.insert({ b, to });
        E[to].insert(b);
        E[b].insert(to);
    }
    E[b].erase(a);
    E[a].clear();

    uf(a, b);

    for (auto p : next) merge(p.first, p.second);
}
void addEdge(int _a, int _b) {
    int a = uf[_a];
    int b = uf[_b];
    //printf("<%d %d>\n", a, b);
    if (!E[a].count(b)) {
        E[a].insert(b);
        E[b].insert(a);
        return;
    }

    merge(a, b);
}
//-----------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, 0, N - 1) {
        int a, b; scanf("%d%d", &a, &b);
        addEdge(a, b);
    }
    rep(i, 0, N - 1) {
        int a, b; scanf("%d%d", &a, &b);
        addEdge(a, b);
    }

    set<int> u;
    rep(i, 1, N + 1) u.insert(uf[i]);

    if (u.size() == 1) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 29184
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-15 19:53:54

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

ll go(ll x){
	ll res = 0;
	while((x+1)%4 != 0){
		res ^= x;
		x--;
	}
	return res;
}
int main(int argc, char const *argv[])
{
	ll l, r;
	cin >> l >> r;
	cout << (go(l-1)^go(r)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N;
    string S;
    cin >> S;
    N = S.size();
    int sum[N+1];
    sum[0] = 0;
    map<int, int> mp;
    mp[0]++;
    int res = 1;
    rep(i,N){
        int x = S[N-1-i] - '0';
        sum[i+1] = (sum[i] + x * res) % 2019;
        mp[sum[i+1]]++;
        res = (res*10) % 2019;
    }
    int ans = 0;
    for(auto p : mp){
        int x = p.second;
        ans += x * (x-1) / 2;
    }
    cout << ans << endl;
}

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

const int MAXN = 200005;

long long a[MAXN];

int main() {

  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> a[i];

    if (a[i] > i) {
      printf("-1\n");
      return 0;
    }
  }

  long long ans = 0;

  int h = 0;
  for (int i = N-1; i > 0; i--) {
    if (a[i] > h) {
      ans += a[i];
      h = a[i] - 1;
    } else if (a[i] < h) {
      printf("-1\n");
      return 0;
    } else {
      h--;
    }
  }

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

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;

    int w[101];
    fill(w, w+101, 0);
    for (int i = 2; i <= n; i++) {
        int j = 2;
        int t = i;
        while (t > 1) {
            if (t % j == 0) {
                w[j]++;
                t = t / j;
            } else {
                j++;
            }
        }
    }

    int c2=0, c4=0, c14=0, c24=0, c74=0;
    for (int i = 2; i < 101; i++) {
        if (w[i] >= 74) c74++;
        if (w[i] >= 24) c24++;
        if (w[i] >= 14) c14++;
        if (w[i] >= 4)  c4++;
        if (w[i] >= 2)  c2++;
    }

    int ans = 0;
    ans += c74;
    ans += c24 * (c2-1);
    ans += c14 * (c4-1);
    ans += c4 * (c4-1) * (c2-2) / 2;

    cout << ans;
    return 0;
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mod = (int)1e7+9;
#define REP0(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<=n;i++)
#define F first
#define S second
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define inf (int)(1e18)
#define prec(x) fixed<<setprecision(x)<<x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

void solve(){
   string s,t;
   cin>>s>>t;
   int m = s.length();
   int n = t.length();
   string r = "";
   vector<vi> dp(m+1,vi(n+1,0));
   REP(i,1,m){
       REP(j,1,n){
           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]);
           }
       }
   } 
//    cout<<dp[m][n]<<endl;
    int i=m,j=n;
    while(i>0 && j > 0){
        if(s[i-1] == t[j-1]){
            r = r+s[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
    reverse(all(r));
    cout<<r<<endl;
}


int main(){
    fastio;
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
    int tc = 1;
    // cin>>tc;
    for(int i=1;i<=tc;i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 38996
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string S;
	cin >> S;
	sort(S.begin(), S.end());
	if (S[0] == S[1] && S[2] == S[3] && S[1] != S[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

signed main()
{
    int N; cin>>N;
    vector<int> cnt(13);
    cnt[0]++;
    for(int i=0;i<N;i++){
	int d; cin>>d;
	cnt[d]++;
    }

    if(cnt[0]>1 or cnt[12]>1){
	cout<<0<<endl;
	return 0;
    }
    for(int i=1;i<=11;i++){
	if(cnt[i]>2){
	    cout<<0<<endl;
	    return 0;
	}
    }

    int ans=0;
    const int K=11;
    for(int S=0;S<(1<<K);S++){
	vector<int> v;
	for(int i=0;i<cnt[0];i++) v.push_back(0);
	for(int i=0;i<cnt[12];i++) v.push_back(12);
	for(int i=0;i<K;i++){
	    if(cnt[i+1]==0) continue;
	    if(cnt[i+1]==1){
		if(S>>i&1) v.push_back(i+1);
		else v.push_back(24-(i+1));
	    }else{
		v.push_back(i+1);
		v.push_back(24-(i+1));
	    }
	}
	v.push_back(24);
	sort(v.begin(),v.end());
	int min_diff=1e9;
	for(int i=0;i+1<v.size();i++){
	    min_diff=min(min_diff,v[i+1]-v[i]);
	}
	ans=max(ans,min_diff);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 100002;

int n, m;

vector <int> edges[N_MAX];

bool visited[N_MAX];

bool color[N_MAX];

bool oddCycle;

int cnt;

void dfs (int u, int last = -1)
{
    visited[u] = true;
    cnt++;
    for(int v : edges[u])
        if(visited[v] == false)
        {
            color[v] = !color[u];
            dfs(v, u);
        }
        else if(color[v] == color[u])
            oddCycle = true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    ll cntOdd = 0, cntGraphs = 0, cntSingle = 0;
    for(int i = 1; i <= n; i++)
        if(visited[i] == false)
        {
            oddCycle = false;
            cnt = 0;
            dfs(i);
            if(cnt == 1)
                cntSingle++;
            else if(oddCycle == false)
                cntOdd++;
            else
                cntGraphs++;
        }
    cout << (cntOdd * 2 + cntGraphs) * cntOdd + (cntOdd + cntGraphs) * cntGraphs + cntSingle * n * 2 - cntSingle * cntSingle << "\n";
    return 0;
}


Measured memory_bytes: 14060
N = input()
list = list(map(int,input().split()))

base = [0] * len(list)

result = 0
flag = False
exit = False

while not exit:
  for i, value in enumerate(list):
    if base[i] < value:
      if flag is False:
        flag = True
        result += 1
      base[i] += 1
    else:
      if flag is True:
        flag = False
    if base == list:
      exit = True
  flag = False

print(result)


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){

  int N,X,Y,W,H;
  int n,x,y;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>X>>Y>>W>>H;
    cin>>n;
    int cnt=0;
    for(int j=0;j<n;j++){
      cin>>x>>y;
      if(X<=x && Y<=y && x<=X+W && y<=Y+H) cnt++;
    }
    cout<<cnt<<endl;
  }  
  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
#define maxn 2005
#define LL long long
using namespace std;
LL dp[maxn][maxn];
struct node{
	int seq,val;
}a[maxn];
int cmp(node a,node b){
	return a.val<b.val;
}
int main(){//大的值最后放
	int i,j,len,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i].val),a[i].seq=i;
	sort(a+1,a+1+n,cmp);//按值自小到大排序
	for(i=1;i<=n;i++)dp[i][i]=(LL)a[1].val*abs(a[1].seq-i);//神奇的初始化
	for(len=2;len<=n;len++)//区间长度
		for(i=1;i+len-1<=n;i++){//左边界
			j=i+len-1;//右边界
			dp[i][j]=max(dp[i+1][j]+(LL)a[len].val*abs(a[len].seq-i),dp[i][j-1]+(LL)a[len].val*abs(a[len].seq-j));
		}
	printf("%lld\n",dp[1][n]);
	return 0;
}

Measured memory_bytes: 24340
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cstdlib>
using namespace std;
#define rep(x,to) for(int x = 0; x <(to); ++(x))
typedef pair<int,int> pi;
int memo[1000][5];
int w,h;
string str;
int dist(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}

int main() { 
	while(cin >> w >> h && (w||h)) {
		pi s,g;
		vector<pi> f[5];
		rep(i,h) {
			cin >> str;
			rep(j,w) {
				if(str[j] == 'S') s = make_pair(i,j);
				else if(str[j] == 'G') g = make_pair(i,j);
				else if(str[j] == '1') f[str[j]-'1'].push_back(make_pair(i,j));
				else if(str[j] == '2') f[str[j]-'1'].push_back(make_pair(i,j));
				else if(str[j] == '3') f[str[j]-'1'].push_back(make_pair(i,j));
				else if(str[j] == '4') f[str[j]-'1'].push_back(make_pair(i,j));
				else if(str[j] == '5') f[str[j]-'1'].push_back(make_pair(i,j));
			}
		}
		int ans = 1 << 30, ret = -1;
		rep(i,5) {
			int cur = i, next = (i+1)%5;
			rep(j,f[next].size()) {
				memo[j][next] = dist(s, f[next][j]);
			}
			cur = next, next =(next+1)%5;
			rep(j,3) {
				rep(k,f[next].size()) {
					memo[k][next] = 1 << 30;
					rep(l,f[cur].size()) {
						memo[k][next] = min(memo[k][next], memo[l][cur] + dist(f[cur][l], f[next][k]));
					}
				}
				cur = next, next = (next+1)%5;
			}
			rep(j,f[cur].size()) {
				int tmp = memo[j][cur] + dist(f[cur][j], g);
				if(tmp < ans) {
					ans = tmp, ret = i;
				}
			}
		}
		if(ans == 1<<30) cout << "NA" << endl;
		else cout << ret + 1 << " " << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1288
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define	abs(a) ((a)<0?-(a):(a))

typedef struct data {
	struct data *prev;
	struct data *next;
	int id;
	int count;
} data;



int main(void){
	/* === input paramater === */
	int n;
	int m;
	int q;
	int *a;
	/* === operate paramater === */
	int i;
	data *d;
	data *p;
	bool *complete;
	int allow;

	/* === input === */
	scanf("%d%d%d",&n,&m,&q);
	a = calloc(sizeof(int),q+1);
	for(i=1;i<=q;i++){
		scanf("%d",&a[i]);
	}
	/* === prepare === */
	d = calloc(sizeof(data),m+1);
	for(i=0;i<=m;i++){
		d[i].id = i;
	}
	p = d;
	d[0].count = n;
	for(i=q;i>0;i--){
		if(d[a[i]].count == 0){
			d[a[i]].prev = p;
			p->next = &d[a[i]];
			p = &d[a[i]];
		}
		d[a[i]].count = min(d[a[i]].count+1,d[a[i]].prev->count);
	}
	/* === core === */
	complete = calloc(sizeof(bool),m+1);
	allow = 0;
	while(d != NULL && d->count == n){
		complete[d->id] = true;
		while(complete[allow])allow++;
		d = d->next;
	}
	while(d != NULL){
		if(d->id != allow){
			printf("No\n");
			return 0;
		}
		complete[allow] = true;
		while(complete[allow]) allow++;
		d = d->next;
	}
	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 2944
import numpy as np

n = int(input())

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

x = np.array(x)
args = np.argsort(x, kind="quicksort")

mid = int(n/2)
l, r = x[args][mid-1:mid+1]

for i in range(n):
	if (x[i]<=l):
		print(r)
	else:
		print(l)

Measured memory_bytes: 34184
#include <iostream>

using namespace std;

int main() {
	int N;

	cin >> N;

	int **option = new int*[N], **DP = new int*[N];

	for (int i = 0; i < N; i++) {
		option[i] = new int[3];
		DP[i] = new int[3];
	}

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

	DP[0][0] = option[0][0];
	DP[0][1] = option[0][1];
	DP[0][2] = option[0][2];

	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			if (DP[i - 1][(j + 1) % 3] + option[i][j]
		> DP[i - 1][(j + 2) % 3] + option[i][j])
				DP[i][j] = DP[i - 1][(j + 1) % 3] + option[i][j];
			else
				DP[i][j] = DP[i - 1][(j + 2) % 3] + option[i][j];

		}
	}

	int max;
	max = DP[N - 1][0];
	for (int i = 1; i < 3; i++) {
		if (max < DP[N - 1][i])
			max = DP[N - 1][i];
	}

	for (int i = 0; i < N; i++) {
		delete[] option[i];
		delete[] DP[i];
	}
	delete[] option;
	delete[] DP;


	cout << max << endl;
}

Measured memory_bytes: 8064
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.*;
public class Main {
	static int INF = (int)1e9 + 7;
	int N,M;
	int[] c;
	int[][] dp;
	
	public void solve() {
		N = nextInt();
		M = nextInt();
		c = new int[M];
		dp = new int[M + 1][N + 1];
		
		for(int i = 0;i < M;i++){
			c[i] = nextInt();
		}
		
		for(int i = 0;i < M + 1;i++){
			Arrays.fill(dp[i],INF);
		}
		
		
		dp[0][N] = 0;
		for(int i = 1;i <= M;i++){
			for(int j = N;j >= 0;j--){
				
				if(j - c[i - 1] >= 0){
					dp[i][j - c[i - 1]] = Math.min(dp[i][j - c[i - 1]],dp[i - 1][j] + 1);
					dp[i - 1][j - c[i - 1]] = Math.min(dp[i - 1][j - c[i - 1]],dp[i - 1][j] + 1);
				}
				dp[i][j] = Math.min(dp[i][j],dp[i - 1][j]);
				
			}
		}
		out.println(dp[M][0]);
	}
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
 
	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;
 
	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}
 
	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}
 
	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}
 
	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
 
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}
 
	public int nextInt() {
		return Integer.parseInt(next());
	}
 
	public long nextLong() {
		return Long.parseLong(next());
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 29576
#include <math.h>
#include <stdio.h>
int n, sqrtN;
long long ans, d;
char buf[8], out[20];
k;
i;
s;
X;
int main() {
    s = read(0, buf, 8);
    for(;;) {
        k = buf[i++];
        if(k < '0') break;
        n = n * 10 + k - '0';
    }
    const int sqrtN = sqrt(n);
    ans = -(long long)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
    for(int i = 1; i <= sqrtN; ++i) {
        const int a = n / i;
        ans += ((long long)i * (i + a) * (a + 1 - i));
    }
    i = 20;
    do {
        out[--i] = ans % 10 + '0';
        ans /= 10;
    } while(ans);
    write(1, out + i, 20 - i);
}


Measured memory_bytes: 1800
N = int(input())
pre_stone = 0
div = 10**9+7
dp = 1
dp_dict = {}
for _ in range(N):
    c = int(input())
    if pre_stone != c:
        pre_stone = c
        if c not in dp_dict:
            dp_dict[c] = 0
        dp += dp_dict[c]
        dp_dict[c] = dp

print(dp%div)


Measured memory_bytes: 27104
a = [int(input()) for _ in range(int(input()))]

dp = [[0] * 5 for _ in range(len(a) + 1)]

for i, x in enumerate(a):
    y = x % 2 + (x == 0) * 2
    z = (x + 1) % 2
    
    dp[i+1][0] = min(dp[i][0:1]) + x
    dp[i+1][1] = min(dp[i][0:2]) + y
    dp[i+1][2] = min(dp[i][0:3]) + z
    dp[i+1][3] = min(dp[i][0:4]) + y
    dp[i+1][4] = min(dp[i][0:5]) + x

print(min(dp[-1]))

Measured memory_bytes: 67852
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int n;
		
		if (a <= b) {
			n = a;
		} else {
			n = a - 1;
		}
		
		System.out.println(n);
	}
}


Measured memory_bytes: 22868