akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
    int i, n;
    char moji;
    for(;;){
        scanf("%c", &moji);
        if( moji == '\n' ){
            break;
        }
        else if( moji > 64 && moji < 91 ){
            moji = moji + 32;
            printf("%c", moji);
        }else if( moji > 96 && moji < 123 ){
            moji = moji - 32;
            printf("%c", moji);
        }else{
            printf("%c", moji);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};



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

    string s,t; 
	cin >> s >> t;
    ves ans;
    int l = s.size()-t.size()+1;
    rep(i,max(0,l)){
        string tmp = s;
        rep(j,t.length()) {
            if(i+j>s.size()-1) break;
            if(tmp[i+j]=='?' || tmp[i+j]==t[j]) tmp[i+j] = t[j];
            else break;
            if(j==t.length()-1) {
                for(int k = 0; k < tmp.length(); k ++) {
                    if(tmp[k]=='?') tmp[k] = 'a';
                }
                ans.push_back(tmp);
            }
        }
    }
    sort(ans.begin(), ans.end());
    cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> x(n),y(n),p(n);
    rep(i,n){
        cin>>x[i]>>y[i]>>p[i];
    }
    vector<ll> ans(n+1,inf);
    vector<vector<ll>> dp1(n,vector<ll>(1<<n,inf)),dp2(n,vector<ll>(1<<n,inf));
    rep(i,n){
        rep(S,1<<n){
            dp1[i][S]=abs(y[i]);
            dp2[i][S]=abs(x[i]);
            rep(j,n){
                if(S & 1<<j){
                    chmin(dp1[i][S],abs(y[j]-y[i]));
                    chmin(dp2[i][S],abs(x[j]-x[i]));
                }
            }
        }
    }
    rep(S,1<<n)for(ll T=S;T>=0;T=(T-1)&S){
        ll now=0;
        rep(i,n){
            now+=p[i]*min(dp1[i][T],dp2[i][S^T]);
        }
        chmin(ans[__builtin_popcountll(S)],now);
        if(!T) break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 11172
#include<bits/stdc++.h>
using namespace std;
const int maxn=350;
long  double dp[maxn][maxn][maxn];
int n;
int a[maxn];
int b1;
int b2;
int b3;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
     cin>>n;
     for(int i=1;i<=n;i++){
     	cin>>a[i];
     	if(a[i]==1){
     		b1++;
		 }
		 else if(a[i]==2){
		 	b2++;
		 }
		 else{
		 	b3++;
		 }
	 }
	 for(int i=0;i<=n;i++){
	 	for(int j=0;j<=n;j++){
	 		for(int z=0;z<=n;z++){
	 			if(i+j+z<=n){
	 			if(i==0&&z==0&&j==0){
	 				dp[i][j][z]=0;
				 }
				 if(i>0){
				 	long double u=i;
					 u/=n;
					 u*=(dp[i-1][j+1][z]+1);
					 dp[i][j][z]+=u;
				 }
				 if(j>0){
				 	long double u=j;
					 u/=n;
					 u*=(dp[i][j-1][z+1]+1);
					 dp[i][j][z]+=u;
				 }
				 if(z>0){
				 	long double u=z;
					 u/=n;
					 u*=(dp[i][j][z-1]+1);
					 dp[i][j][z]+=u;
				 }
				 if(i+j+z!=0){
				 long double f=n;
				 long double u=n-(i+j+z);
				 u/=n;
				 u+=dp[i][j][z];
				 f/=(i+j+z);
				 f*=u;
				 dp[i][j][z]=f;
			}
			}
			 }
		 }
	 }
	 cout<<fixed<<setprecision(12)<<dp[b3][b2][b1];
	 }

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

ans = 1

min_A = min(A)
A = sorted(A, reverse=True)

if min_A == 0:
    print(0)
    exit()

for a in A:
    ans *= a
    if ans > 10 ** 18:
        break

if ans > 10 ** 18:
    print(-1)
else:
    print(ans)


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

int main() {
	int n;
	while (cin >> n && n) {
		string s[n];
		for (auto &i : s) {
			cin >> i;
		}
		int dp[n][n]{};	//dp[i][j] := s[i][j]が右下になるような正方形の1辺の長さの最大値
		for (int i = 0; i < n; i++) {
			dp[0][i] = s[0][i] == '.';
			dp[i][0] = s[i][0] == '.';
		}
		for (int i = 1; i < n; i++) {
			for (int j = 1; j < n; j++) {
				if (s[i][j] == '*') {
					continue;
				}
				dp[i][j] = min({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]}) + 1;
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				ans = max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 7968
#include <iostream>
#include <tr1/unordered_map>
#include <cmath>
using namespace std;
class Ord {
  public:
    int x;
    int y;
};

class Mm {
  public:
  //int minxp, minxm, maxxp, maxxm, minyp, minym, maxyp, maxym;
  int maxx, maxy, minx, miny;
  Mm() {
    //minxp = minxm = maxxp = maxxm = minyp = minym = maxyp = maxym = 0;
    maxx = maxy = minx = miny = 0;
  }
  void resist(Ord ord) {
    maxx = max(maxx, ord.x);
    maxy = max(maxy, ord.y);
    minx = min(minx, ord.x);
    miny = min(miny, ord.y);
  }
  int getHeight() {
    return (abs(maxy) + abs(miny) + 1);
  }
  int getWidth() {
    return (abs(maxx) + abs(minx) + 1);
  }
};

int main() {
  while(true) {
    Mm mm;
    int ncard;
    cin >> ncard;
    if(ncard == 0) break;
    tr1::unordered_map<int, Ord> cards;
    Ord zero;
    zero.x = zero.y = 0;
    cards[0] = zero;
    for(int i = 1; i < ncard; ++i) {
      int target, direction;
      cin >> target >> direction;
      int x = cards[target].x;
      int y = cards[target].y;
      switch(direction) {
        case 0:
          --x;
          break;
        case 1:
          --y;
          break;
        case 2:
          ++x;
          break;
        case 3:
          ++y;
          break;
      }
      Ord card;
      card.x = x;
      card.y = y;
      cards[i] = card;
      mm.resist(card);
    }
    cout << mm.getWidth() << " " << mm.getHeight() << endl;
  }
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, X;
    cin >> N >> X;
    vector<ll> S(N);
    REP(i, N) cin >> S[i];

    sort(S.begin(), S.end());
    ll dp[205][X+1];
    REP(i, 205)REP(j, X+1) dp[i][j] = 0;
    REP(i, X+1) dp[0][i] = i;
    REP(i, N){
    	REP(j, X+1){
    		dp[i+1][j] += dp[i][j%S[i]];
    		dp[i+1][j] %= mod;
    		dp[i+1][j] += (dp[i][j] * i % mod);
    		dp[i+1][j] %= mod;
    	}
    }
    cout << dp[N][X] << endl;
    return 0;
}

Measured memory_bytes: 160384
#include <bits/stdc++.h>
using namespace std;
int N, K;
vector<int> dist;
vector< vector<int> > G;

void dfs(int p, int s, int d)
{
    dist[s] = d;
    for(int t : G[s]) {
        if(t != p) dfs(s, t, d + 1);
    }
}

int main() {
    cin >> N >> K;
    dist.resize(N);
    G.resize(N);
    vector<pair<int,int>> E(N-1);
    for(int i=0; i<N-1; ++i) {
        cin >> E[i].first >> E[i].second;
        --E[i].first;
        --E[i].second;
        G[E[i].first].push_back(E[i].second);
        G[E[i].second].push_back(E[i].first);
    }

    int res = 1001001001;
    if(K % 2 == 0) {
        for(int s=0; s<N; ++s) {
            dfs(-1, s, 0);
            int cnt = 0;
            for(int i=0; i<N; ++i) {
                if(dist[i] > (K / 2)) ++cnt;
            }
            res = min(res, cnt);
        }
    } else {
        for(int i=0; i<N-1; ++i) {
            dfs(E[i].second, E[i].first, 0);
            dfs(E[i].first, E[i].second, 0);
            int cnt = 0;
            for(int i=0; i<N; ++i) {
                if(dist[i] > ((K - 1) / 2)) ++cnt;
            }
            res = min(res, cnt);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
ll N;
int ans=0;
int main(){
	ios::sync_with_stdio(false);
	cin>>N;ll n=N;
	for (ll p=2;p*p<=N;++p){
		if (n%p==0){
			int cnt=0;
			while(n%p==0){
				++cnt;n/=p;
			}
			int cur=1;
			while(cnt>=cur){
				cnt-=cur;++cur;++ans;
			}
		}
	}
	if (n>1) ++ans;
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 3652
N = int(input())
H = list(map(int, input().split(' ')))

mx = 0
cnt = 0
prev = H[0]

for i in range(1, N):
    if prev >= H[i]:
        cnt += 1
        mx = max(cnt, mx)
    else:
        cnt = 0
    prev = H[i]
print(mx)


Measured memory_bytes: 15020
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <fstream>
 
using namespace std;
 
#define INF 100000000
#define EPS 1e-9
#define PI acos(-1)
 
typedef long long ll;
typedef pair<int, int> P;

#define MAX_W 50
#define MAX_H 50

int W, H;
string L[MAX_H], R[MAX_H];

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

vector<string> ans_list;



int main(){
  
  while(true){
    
    cin >> W >> H;
    if(W == 0)
      break;
    
    int lsx, lsy, rsx, rsy, lgx, lgy, rgx, rgy;
    
    for(int i = 0; i < H; i++){
      cin >> L[i] >> R[i];
      for(int j = 0; j < W; j++){
	if(L[i][j] =='L'){
	  lsx = j;
	  lsy = i;
	}
	if(R[i][j] == 'R'){
	  rsx = j;
	  rsy = i;
	}
	if(L[i][j] == '%'){
	  lgx = j;
	  lgy = i;
	}
	if(R[i][j] == '%'){
	  rgx = j;
	  rgy = i;
	}
      }
      
    }
    

    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	for(int k = 0; k < H; k++){
	  for(int l = 0; l < W; l++){
	    dp[i][j][k][l] = INF;
	  }
	}
      }
    }

    dp[lsy][lsx][rsy][rsx] = 0;
    
    queue<P> que1, que2;
    que1.push(P(lsx, lsy));
    que2.push(P(rsx, rsy));
    
    bool flag = false;

    while(que1.size()){
      P p1 = que1.front();
      P p2 = que2.front();
      que1.pop();
      que2.pop();
      int lx = p1.first;
      int ly = p1.second;
      int rx = p2.first;
      int ry = p2.second;
      
      if(lx == lgx && ly == lgy && rx == rgx && ry == rgy){
	flag = true;
	break;
      }
      
      for(int i = 0; i < 4; i++){
	int lnx = lx + dx[i];
	int lny = ly + dy[i];
	int rnx = rx + dx[(i+2)%4];
	int rny = ry + dy[i];

	if(lnx == -1 || lnx == W || lny == -1 || lny == H){
	  lnx = lx;
	  lny = ly;
	}
	if(L[lny][lnx] == '#'){
	  lnx = lx;
	  lny = ly;
	}

	if(rnx == -1 || rnx == W || rny == -1 || rny == H){
	  rnx = rx;
	  rny = ry;
	}
	if(R[rny][rnx] == '#'){
	  rnx = rx;
	  rny = ry;
	}

	if((lnx == lgx && lny == lgy) || (rnx == rgx && rny == rgy)){
	  if(!(lnx == lgx && lny == lgy && rnx == rgx && rny == rgy)){
	    continue;
	  }
	}
	  

	if(dp[lny][lnx][rny][rnx] == INF){
	  // printf("%d:%d %d:%d -> %d:%d %d:%d\n", lx,ly,rx,ry,lnx, lny, rnx, rny);
	  dp[lny][lnx][rny][rnx] = dp[ly][lx][ry][rx] + 1;
	  que1.push(P(lnx, lny));
	  que2.push(P(rnx, rny));
	}
	
      }

    }
    
    if(flag){
      ans_list.push_back("Yes");
    }
    else{
      ans_list.push_back("No");
    }
    
    

  }
  
  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 26560
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=3e5+5,M=3e5+5,MOD=1e9+7,OO=1e9;

double dist(pair<int,int>a,pair<int,int>b){
	return sqrt((a.first-b.first)*(a.first-b.first)+(b.second-a.second)*(b.second-a.second));
}
int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	//file();
 	
 	int n;
 	
 	scanf("%d",&n);

 	std::vector<pair<int,int>> a(n);

 	for(int i=0;i<n;i++)scanf("%d %d" ,&a[i].first,&a[i].second);

 	std::vector<int> perm(n);

 	for(int i=0;i<n;i++)perm[i]=i;
 	double sum = 0;
 	do{
 		for(int i=1;i<n;i++){
 			sum+=dist(a[perm[i]],a[perm[i-1]]);
 		}
 	}while(next_permutation(all(perm)));

 	ll curr = 1;

 	while(n)curr*=n,n--;

 	printf("%.9f\n",sum/curr );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, tmp, num = 0;
    cin >> n;
    tmp = n;
    for(int i = 0; i < 8; i++)
    {
        num += n % 10;
        n /= 10;
        if(n < 1)
        {
            break;
        }
    }

    if(tmp % num == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000000
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
int getbit(int s, int i)
{ return (s >> i) & 1; }
int cntbit(int s)
{ return __builtin_popcountll(s); }
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

int main()
{
    int n,k;
    cin>>n>>k;
    int x,y;
    map<int,int> mp;
    for(int i=0;i<k;i++)
    {
         cin>>x;
         while(x--)
         {
              cin>>y;
              mp[y]++;
         }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
         if(!mp[i])
          ans++;
    }
    cout<<ans<<e;
}


Measured memory_bytes: 3632
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

A = np.array(A, dtype=int)

a = set(A[::2])
b = set(np.msort(A)[::2])

ans = len(a - b)
print(ans)


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  ll l, r;
  cin >> l >> r;
  ll i_max = min(r - 1, l + 2019);
  ll j_max= min(r, i_max + 1);
  int ans = 2019;
  for (ll i = l; i <= i_max; ++i) {
    for (ll j = i+1; j <= j_max; ++j) {
      if ((i * j) % 2019 < ans) { ans = (i * j) % 2019; }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
 int N, M;
  int x, y;
  int z;
   cin >> N >> M;
  vector<int> vecx(M);
  vector<int> vecy(M);

  for (int i=0; i<M; i++) cin >> vecx.at(i) >> vecy.at(i);
  sort(vecx.begin(), vecx.end());
  sort(vecy.begin(), vecy.end());
  x=vecx.at(M-1);
  y=vecy.at(0);
  z= y-x+1;
  if (z<0) z=0;

    cout << z << endl;
}

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

typedef long long ll;
typedef unsigned long long llu;

int main(int argc, char *argv[]) {
  ll k, x;
  cin >> k >> x;

  for (ll i = x-(k-1); i < x+k; ++i) {
    cout << i << " ";
  }
  cout << endl;
  
  return 0;
}

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

using namespace std;

string sumString(string a, string b) {
  if (a.size() > b.size()) swap(a, b);
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  for (int i = 0; i < a.size(); i++) {
    if (a[i] + b[i] - 2 * '0' < 10) {
      b[i] += a[i] - '0';
    } else {
      b[i] = (a[i] + b[i] - 2 * '0') % 10 + '0';
      int j = i + 1;
      while (j < b.size() && b[j] == '9') {
        b[j++] = '0';
      }
      if (j == b.size()) b += "1";
      else b[j] += 1;
    }
  }
  reverse(b.begin(), b.end());
  return b;
}

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

  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;

    string ans = sumString(a, b);
    cout << (ans.size() <= 80 ? ans : "overflow") << endl;
  }

  return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
const int INF=1e9;
struct Q
{
    int x;
    int y;
    Q(int a,int b){
        x=a;
        y=b;
    }
};
int main(){
    int h,w;
    cin>> h >> w;
    vector< vector<int>> dist(h, vector<int>(w, INF));
    vector< vector<char>> A(h, vector<char>(w));
    REP(i,h)REP(j,w)cin >> A[i][j];
        

    queue<Q> que;
    REP(i,h)REP(j,w)if(A[i][j]=='#'){
        que.push(Q(i,j));
        dist[i][j]=0;
    }

    while(!que.empty()){
        Q c_node = que.front();
        que.pop();
        REP(i,4){
            Q n_node = Q(c_node.x+dx[i], c_node.y+dy[i]);
            if(0<=n_node.x && n_node.x<=h-1 && 0<=n_node.y && n_node.y<=w-1&&
            A[n_node.x][n_node.y]=='.' && dist[n_node.x][n_node.y]==INF){
                dist[n_node.x][n_node.y]=dist[c_node.x][c_node.y]+1;
                que.push(n_node);
            }
            
        }
    }
    // REP(i,h) {
    //     REP(j,w) cout << dist[i][j] << " ";
    //     cout << endl;
    //     }

    int ma = -1;
    REP(i,h) REP(j,w) ma = max(dist[i][j],ma);
    cout << ma << endl;
   return 0;
}




Measured memory_bytes: 13056
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int left = 0, right = n-1;
        
        System.out.println(0);
        String sL = sc.next();
        if(sL.equals("Vacant")) return;
        System.out.println(n-1);
        String sR = sc.next();
        if(sR.equals("Vacant")) return;
        while(true){
            int tmp = left + (right - left) /2;
            System.out.println(tmp);
            String sT = sc.next();
            if(sT.equals("Vacant")) return;
            if(sT.equals(sL) && (tmp-left) % 2 == 1 || !sT.equals(sL) && (tmp-left) % 2 == 0){
                right = tmp;
                sR = sT;
            }else{
                left = tmp;
                sL = sT;
            }
        }
    }
}


Measured memory_bytes: 25508
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

//WA

int main(void){
	int N,K,L,x,y,d1[200010]={},d2[200010]={};
	map<ll,int>M;
	vector<int> T[200010]; //鉄道
	vector<int> D[200010]; //道路
	scanf("%d%d%d",&N,&K,&L);
	rep(i,K){
		scanf("%d%d",&x,&y);
		T[x].push_back(y);
		T[y].push_back(x);
	}
	rep(i,L){
		scanf("%d%d",&x,&y);
		D[x].push_back(y);
		D[y].push_back(x);
	}
	reg(i,1,N){
		if(d1[i]!=0)continue;//ここを忘れるな
		queue<int> Q;
		Q.push(i);
		d1[i]=i;
		while(!Q.empty()){
			int a = Q.front();Q.pop();
			rep(j,T[a].size()){
				int q = T[a][j];
				if(d1[q]==0){
					d1[q]=i;
					Q.push(q);
				}
			}
		}
	}
	reg(i,1,N){
		if(d2[i]!=0)continue;//ここを忘れるな
		queue<int> Q;
		Q.push(i);
		d2[i]=i;
		while(!Q.empty()){
			int a = Q.front();Q.pop();
			rep(j,D[a].size()){
				int q = D[a][j];
				if(d2[q]==0){
					d2[q]=i;
					Q.push(q);
				}
			}
		}
	}
	reg(i,1,N)M[(ll)d1[i]*(N+1)+d2[i]]++;

	reg(i,1,N){
		printf("%d",M[(ll)d1[i]*(N+1)+d2[i]]);
		if(i!=N)printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 27940
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define Rep1(i,k,n) for(int i=k ; i<=n ; i++)
#define rrep(i,n) for(int i=n ; i>=0 ; i--)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

vi prime;
vector<bool> isp;
void makePrime(int n){
    isp.assign(n+1,true);
    for(int i=2 ; i <= n ; i++){
        if(!isp[i]) continue;

        for(int k = i*2 ; k <= n ; k += i){
            isp[k] = false;
        }

        prime.pb(i);
    }
    Sort(prime);
}
/*
bool check(int n){
    bool ans = true;
    for(int i = 2;  i * i <= n ; i++){
        if(n%i == 0) ans = false;
    }
    return ans;
}
*/

vi mq;
void makeQ(){
    mq.pb(13);
    for(int i = 19 ; i <= 100000000 ; i+= 30){
        bool a = binary_search(ALL(prime),i-8);
        if(!a) continue;
        bool b = binary_search(ALL(prime),i-6);
        if(!b) continue;
        bool c = binary_search(ALL(prime),i-2);
        if(!c) continue;
        bool d = binary_search(ALL(prime),i);
        if(!d) continue;
        mq.pb(i);
    }
}


int main(){
    makePrime(10000000);
    makeQ();
    /*
    rep(i,mq.size()){
        cout << mq[i] << endl;
    }
    */

    int n;
    
    while(true){
        cin >> n;
        if(n == 0)break;
        
        rep(i,mq.size()){
            if(mq[i] > n) {
                cout << mq[i-1] << endl;
                break;
            }
            if(i == mq.size()-1) cout << mq[i] << endl;
        }
    }
}



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

int main() {
    int n, l; cin >> n >> l;
    int a[n];
    int sum0 = 0;
    rep(i, n){
        a[i] = i+l;
        sum0 += a[i];
    }
    int s = INF;
    bool minus = false;
    rep(i, n){
        if(s > abs(a[i])){
            if(a[i] < 0) minus = true;
            else minus = false;
            s = abs(a[i]);
        }
        s = min(s, abs(a[i]));
    }
    cout << (!minus? sum0-s: sum0+s) << endl;


    return 0;
}

Measured memory_bytes: 3584
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! { n, k, a: [usize; n] };
    let mut dp = vec![0; k + 1];
    for i in a[0]..(k + 1) {
        let mut bin = vec![true; 101];
        for &x in &a {
            if x <= i {
                bin[dp[i - x]] = false;
            }
        }
        for j in 0..101 {
            if bin[j] {
                dp[i] = j;
                break;
            }
        }
    }
    println!("{}", if dp[k] == 0 { "Second" } else { "First" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    priority_queue<pair<ll, ll>> pq;
    rep(i, m) {
        ll b, c;
        cin >> b >> c;
        pq.push(make_pair(c, b));
    }
    rep(i, n) {
        if (pq.empty()) break;
        auto p = pq.top(); pq.pop();
        if (a[i] >= p.first) break;
        p.second--;
        a[i] = p.first;
        if (p.second > 0) pq.push(p);
    }
    cout << accumulate(all(a), 0LL) << endl;
    return 0;
}


Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x = in.nextInt();
        long a[] = new long[n];
        long b[] = new long[n];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }

        b = Arrays.copyOfRange(a, 0, n);

        if (a[0] > x) b[0] = x;

        for (int i = 0; i < n - 1; i++) {
            if (b[i] + b[i + 1] > x) {
                b[i + 1] -= (b[i] + b[i + 1]) - x;
            }
        }

        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += a[i] - b[i];
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 60648
N, A = (int(i) for i in input().split())
x = [int(i) for i in input().split()]
sumx = sum(x)
DP = [[[0] * (N+1) for i in range(sumx+1)] for i in range(N+1)]
DP[0][0][0] = 1
for i in range(N):
    for j in range(sumx+1):
        for k in range(i+1):
            if j - x[i] >= 0:
                DP[i+1][j][k+1] += DP[i][j-x[i]][k]
            DP[i+1][j][k] += DP[i][j][k]

res = 0
for i in range(1,N+1):
    if i * A <= sumx:
        res += DP[N][i * A][i]
print(res)

Measured memory_bytes: 103772
#include <stdio.h>

void swap(int*, int*);

int main(void){
    int a, b, c, count = 0;
    scanf("%d%d%d", &a, &b, &c);
    if(a > b)
        swap(&a, &b);
    if(b > c)
        swap(&b, &c);
    if(a > b)
        swap(&a, &b);
    count += (c - b);
    a += count;
    if((c - a) % 2 == 0)
        count += ((c - a) / 2);
    else
        count += (((c - a)/2) + 2);
    printf("%d\n", count);
    return 0;
}

void swap(int *a,int *b){
    int mv;
    mv = *a;
    *a = *b;
    *b = mv;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
int main()
{
	ll n, m;
	scanf("%lld %lld", &n, &m);
	ll dap = 12345678999999;
	for (int i = 1; i < n; i++)
	{
		vector<ll> vt;
		vt.resize(3);
		vt[0] = m * i;
		ll ch = m / 2;
		ll ch1 = ch;
		if (m % 2)ch1++;
		vt[1] = ch * (n-i);
		vt[2] = ch1 * (n-i);
		sort(vt.begin(), vt.end());
		dap = min(dap, vt[2] - vt[0]);
	}
	for (int i = 1; i < m; i++) {
		vector<ll> vt;
		vt.resize(3);
		vt[0] = n * i;
		ll ch = n / 2;
		ll ch1 = ch;
		if (n % 2)ch1++;
		vt[1] = ch * (m-i);
		vt[2] = ch1 * (m-i);
		sort(vt.begin(), vt.end());
		dap = min(dap, vt[2] - vt[0]);
	}
	if (n >= 3)
		dap = min(dap, m);
	if (n % 3 == 0)
		dap = min(dap, (ll)0);
	if (m >= 3)
		dap = min(dap, n);
	if (m % 3 == 0)
		dap = min(dap, (ll)0);
	printf("%lld\n", dap);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int t(int a, int b, int c) {
	return a * 60 * 60 + b * 60 + c;
}

int main() {
	rep(i, 3) {
		int a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;

		int res = t(d, e, f) - t(a, b, c);
		cout << res / 3600 << " ";
		res %= 3600;

		cout << res / 60 << " ";
		res %= 60;

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

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (X, t) = Slice2<long>();
            WriteLine(Max(0, X - t));
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

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

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

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int ans;
char c[40][40];
int a,b;


void bfs(int sx, int sy) {
	queue< pair<int,int> > q;
	queue< PII > qp;
	q.push(MP(sx,sy));
	c[sx][sy] = 'x';
	for (int i = 1; i < 1000; i++) {
		while (!q.empty()) {
			PII v = q.front(); //get value
			q.pop();
			int x = v.first, y = v.second;
			if (c[x+1][y] == '.'){ qp.push(MP(x+1,y)); c[x+1][y] = 'x'; ans++; }
			if (c[x-1][y] == '.'){ qp.push(MP(x-1,y)); c[x-1][y] = 'x'; ans++; }
			if (c[x][y+1] == '.'){ qp.push(MP(x,y+1)); c[x][y+1] = 'x'; ans++; }
			if (c[x][y-1] == '.'){ qp.push(MP(x,y-1)); c[x][y-1] = 'x'; ans++; }

		}
		while (!qp.empty()) {
			q.push(qp.front());
			qp.pop();
		}
		//		for (int h = 0; h < b+2; h++) {
		//			for (int w = 0; w < a+2; w++) {
		//				cout << c[w][h];
		//			}
		//			cout << endl;
		//		}
		//		cout << endl;

	}
}

int main(int argc, char const* argv[])
{
	while (true) {
		int sx,sy;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			break;
		}
		for (int h = 0; h < b+2; h++) {
			for (int w = 0; w < a+2; w++) {
				if (h == 0 || w == 0 || h == b+1 || w == a+1) {
					c[w][h] = '#';
				}
				else {
					cin >> c[w][h];
					if (c[w][h] == '@') {
						sx = w;
						sy = h;
					}
				}
			}
		}

		ans = 1;
		bfs(sx,sy);
		cout << ans << endl;
	}
	return 0;

}



Measured memory_bytes: 3028
# -*- coding: utf-8 -*-

a, v = map(int, input().split())
b, w = map(int, input().split())
T = int(input())

k = b - a
flag = False

if k >= 0:
    l = T*v - T*w 
    if (k <= l):
        flag = True

if k < 0:
    k = a - b
    l = T*v - T*w
    if (k <= l):
        flag = True


if (flag == True):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9200
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    auto s = readln.chomp;
    auto len = s.length;

    long[string][11] memo;
    long solve(size_t i, char[][] acm) {
        auto key = acm.to!string;
        if (key in memo[i]) return memo[i][key];

        long ret;
        if (i == len) {
            ret = acm.dup.map!(to!long).reduce!"a+b";
        } else {
            ret = solve(i+1, acm[0..$-1] ~ (acm[$-1] ~ s[i])) + solve(i+1, acm ~ [s[i]]);
        }
        return memo[i][key] = ret;
    }

    writeln(solve(1UL, [[s[0]]]));
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  priority_queue<double> que;
  REP(i,n) {
    double v;
    cin >> v;
    que.push(-v);
  }
  while(que.size()>1){
    double a,b;
    a = que.top();
    que.pop();
    b = que.top();
    que.pop();
    que.push((a+b)/2);
  }
  cout << fixed;
  cout << setprecision(9) << -que.top() << endl;
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vi a(N);
    rep(i,N) cin>>a[i];
    sort(all(a));
    int n=1,p=1;
    FOR(i,1,N-2){
        if (a[i]<0) n++; else p++;
    }
    ll now;
    vector<pi> ope;
    if (p==1){
        now = a.back();
        rep(i,N-1){
            ope.pb({now,a[i]});
            now-=a[i];
        }
    }else{
        now = a.front();
        rep(i,p-1){
            ope.pb({now,a[N-i-1]});
            now-=a[N-i-1];
        }
        ope.pb({a[N-p],now});
        now = a[N-p]-now;
        rep(i,n-1){
            ope.pb({now,a[i+1]});
            now-=a[i+1];
        }
    }
    cout<<now<<endl;
    rep(i,N-1){
        cout<<ope[i].fi<<" "<<ope[i].se<<endl;
    }
    return 0;
}


Measured memory_bytes: 4652
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#define ll long long
using namespace std;


int main() {
    int N;
    cin>>N;
    map<int,int> counts;
    for(int i=1;i<=N;i++) {
        int x;
        cin>>x;
        counts[x]++;
    }
    
    vector<pair<int,int> > counts_vec;
    for(auto x : counts) {
        if (x.second > 1) {
            counts_vec.push_back(x);
        }
    }
    
    ll ans = 0;
    for(int j=0;j<counts_vec.size();++j) {
        if (counts_vec[j].second >= 4) {
            ans = (ll)counts_vec[j].first * (ll)counts_vec[j].first;
        }
    }
    
    int sz = counts_vec.size();
    if (counts_vec.size() >= 2) {
        ans = max(ans, (ll)counts_vec[sz-1].first * (ll)counts_vec[sz-2].first);
    }
    
    cout << ans << endl;
    
}

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

int main() {
  int n,m,ac=0;
  cin >> n >> m;

  int p;
  string s;
  bool q[100005]={false};
  int wa[100005]={0};

  int waa=0;
  rep(i,m){
    cin >> p >> s;
    if (!q[p] && s=="WA") {
      wa[p]++;
    } else if (!q[p] && s=="AC") {
      ac++;
      q[p] = true;
      waa+=wa[p];
    }
  }
  cout << ac << " " << waa << endl;

  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  int homework[M],Hday=0,Aday;
  for(int i;i<M;i++){
    cin >> homework[i];
    Hday+=homework[i];
  }
  Aday=N-Hday;
  if(Aday<0){
    Aday=-1;
  }
  cout << Aday << endl;
}


Measured memory_bytes: 3664
<?php
while ($line = fgets(STDIN)) {
    $data = explode(" ", rtrim($line));
    if ($data[0] == '0' and $data[1] == '0') exit;
    for ($i = 0; $i < $data[0]; $i++) {
        for ($j = 0; $j < $data[1]; $j++) {
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
}

Measured memory_bytes: 15548
#include <vector>
#include <bits/stdc++.h>
#include <utility>
#include <climits>
#define LL long long
using namespace std;


void solve(long long N, long long C, std::vector<std::vector<long long>> D, std::vector<std::vector<long long>> tab){
    vector<map<LL, LL>> cnts(3);
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cnts[(i+1+j+1)%3][tab[i][j]]++;
        }
    }

    vector<vector<pair<LL, LL>>> costs(3);
    for(int m=0; m<3; m++){
        for(int c=1; c<=C; c++){
            auto cost = 0ll;
            for(auto kv: cnts[m]){
                cost += kv.second*D[kv.first-1][c-1];
            }
            costs[m].emplace_back(make_pair(cost, c));
        }
        sort(costs[m].begin(), costs[m].end());
    }

    auto ans=LONG_LONG_MAX;

    for(int a=0; a<3; a++){
        for(int b=0; b<3; b++){
            for(int c=0; c<3; c++){
                auto m0 = costs[0][a];
                auto m1 = costs[1][b];
                auto m2 = costs[2][c];
                if(m0.second==m1.second || m1.second==m2.second || m2.second==m0.second)continue;
                ans=min(ans, m0.first+m1.first+m2.first);
            }
        }
    }

    cout << ans << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long C;
    scanf("%lld",&C);
    std::vector<std::vector<long long>> D(C, std::vector<long long>(C));
    for(int i = 0 ; i < C ; i++){
        for(int j = 0 ; j < C ; j++){
            scanf("%lld",&D[i][j]);
        }
    }
    std::vector<std::vector<long long>> c(N, std::vector<long long>(N));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < N ; j++){
            scanf("%lld",&c[i][j]);
        }
    }
    solve(N, C, std::move(D), std::move(c));
    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    ll n,m,x,ans=2e9;
    cin>>n>>m>>x;
    int a[n][m+1];
    for (int i=0;i<n;i++){
        for (int j=0;j<=m;j++){
            cin>>a[i][j];
        }
    }
    for (int i=0;i<(1<<n);i++){
        ll sum=0;
        ll c[m+1]={0};
        for (int j=0;j<n;j++){
            if (i&(1<<j)){
                sum+=a[j][0];
                for (int k=1;k<=m;k++){
                    c[k]+=a[j][k];
                }
            }
        }
      //  cout<<"sum = "<<sum<<endl;
        bool v=1;
        for (int j=1;j<=m;j++){
            if (c[j]<x)
                v=0;
        }
        if (v){
            ans=min(ans,sum);
        }
    }
    cout<<(ans==2e9?-1:ans)<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int
main() {
	int k, s;
	int ret = scanf("%d %d", &k, &s);
	if (k < 2 || k > 2500) return 0;
	if (s < 0 || s > (3 * k)) return 0;
	ret = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			int t = s - i - j;
			if (t >= 0 && t <= k) {
				ret++;
			}
		}
	}
	printf("%d\n", ret);
	return 0;
}


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

int main()
{
    int n; cin>>n;
    map<long long, long long> cnt;
    long long res=0;
    for(int i=0; i<n; ++i) {
        int t; cin>>t;
        ++cnt[t];
        res+=t;
    }
    int q; cin>>q;
    while (q--) {
        long long b, c; cin>>b>>c;
        res-=cnt[b]*b;
        res+=cnt[b]*c;
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<res<<'\n';
    }
}


Measured memory_bytes: 9536
#include <bits/stdc++.h>
using namespace std;
int main () {
  long A, B, C, K;
  cin >> A >> B >> C >> K;
  long ans = 0;
  if(A >= K){
    cout << K << endl;
  } else if(A + B >= K){
    cout << A << endl;
  } else cout << A + (K - A - B) * -1  << endl;
  
  return 0;
}

Measured memory_bytes: 3636