akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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














int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    vector<bool> f(n + 1);
    vector<ll> ans;
    for(ll i = n - 1; i >= 0; i--){
        ll cnt = 0;
        for(ll j = (i + 1) * 2; j <= n; j += (i + 1)){
            if(f[j]) cnt++;
        }
        if(cnt % 2 != a[i]){
            f[i + 1] = true;
            ans.push_back(i + 1);
        }
    }
    for(ll i = 0; i < n; i++){
        ll cnt = 0;
        for(ll j = i + 1; j <= n; j += (i + 1)){
            if(f[j]) cnt++;
        }
        if(cnt % 2 != a[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans.size() << endl;
    REP(i, (ll)ans.size()){
        cout << ans[i] << " \n"[i == (ll)ans.size() - 1];
    }
}


Measured memory_bytes: 3704
from itertools import accumulate
from collections import defaultdict


def main():
    n = int(input())
    prime_counter = defaultdict(int)
    acc = tuple(accumulate(range(1, 42)))  # 10^12 < 2^39

    def facs():
        yield 2
        for x in range(10 ** 6):
            yield x * 2 + 3

    for fac in facs():
        while n % fac == 0:
            n //= fac
            prime_counter[fac] += 1
        if fac * fac > n:
            break
    if n != 1:
        prime_counter[n] += 1

    ans = 0
    for c in prime_counter.values():
        for i, x in enumerate(acc):
            if c < x:
                tmp = i
                break
        ans += tmp
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9448
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
 
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

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

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int K;
    cin >> K;
    
    ll ans = 0;
    for(ll i=1;i<=K;i++){
        for(ll j=1;j<=K;j++){
            for(ll k=1;k<=K;k++){
                ll tmp = gcd(i, j);
                ans += gcd(tmp, k);
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#define SMAX 100000
int main(void)
{
  int i, slen, ans;
  char x, str[SMAX+1];
  scanf("%s%*c", str);
  slen = strlen(str);
  x = str[(slen-1)/2];
  for(i = slen / 2 - 1; i >= 0; i--){
    if(str[i] != x || str[slen-1-i] != x) break;
  }
  ans = slen - i - 1;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;

const ll MOD = 1000000007;

ll modinv(ll x, ll m = MOD) {
  ll b = m;
  ll u = 1;
  ll v = 0;
  ll tmp;
  while (b) {
    ll t = x / b;
    x -= t * b;
    tmp = x;
    x = b;
    b = tmp;
    u -= t * v;
    tmp = u;
    u = v;
    v = tmp;
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

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

  int N, K;
  cin >> N >> K;

  // n-1Cr-1
  // -> K-1Ci-1
  // ボールがK個、箱が1<=i<=N-K+1個
  vector<ll> factorial(1, 1);
  for (int i = 1; i < 3 * N; i++) {
    factorial.push_back((factorial[i-1] * i) % MOD);
  }
  for (int i = 1; i <= K; i++) {
    if (i > N-K+1) {
      cout << 0 << endl;
      continue;
    }
    ll nCr = (((factorial[K-1] * modinv(factorial[K-i])) % MOD * modinv(factorial[i-1])) % MOD);
    ll boxcomb = (((factorial[N-K+1] * modinv(factorial[N-K+1-i])) % MOD * modinv(factorial[i])) % MOD);
    cout << (nCr * boxcomb) % MOD << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
using vec = vector<vector<vector<vector<int>>>>;
 int main(){
 in h;
   cin>>h;
   
   in cnt=0ll;
   in x=h;
   while(x>0){
     cnt ++;
     x /= 2ll;
   }
   
   in ans =1ll;
   rep(i,cnt){
     ans *= 2ll;
   }
   cout<<ans-1ll;
 }

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

const int INF = 1e9;

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

  long long acc[n];
  acc[0] = a[0];
  for (int i=1; i<n; i++) {
    acc[i] = acc[i-1] + a[i];
  }
  long long ans = 2*1e14;
  for (int i=0; i<n-1; i++) {
    long long x = acc[i];
    long long y = acc[n-1] - acc[i];
    ans = min(ans, abs(x-y));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int p,l,r;
};
struct Node T[MAX];
int n;

void preParse(int u){
  if(u==NIL) return ;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}
void inParse(int u){
  if(u==NIL) return ;
  inParse(T[u].l);
  printf(" %d",u );
  inParse(T[u].r);
}
void postParse(int u){
  if(u==NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p=NIL;

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL) T[l].p=v;
    if(r!=NIL) T[r].p=v;
  }

  for(i=0;i<n;i++) if(T[i].p ==NIL) root=i;

  printf("Preorder\n");
  preParse(root);
  printf("\nInorder\n");
  inParse(root);
  printf("\nPostorder\n"); 
  postParse(root);
  printf("\n");

  return 0;   
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,L_2,L_1,Li;
  
  cin>>N;
  L_2=2;
  L_1=1;
  if (N==1)cout<<1<<endl;
  else{
    for(int i=2;i<=N;++i){
      Li=L_2+L_1;
      L_2=L_1;
      L_1=Li;

    }
    cout<<Li<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N_MAX = 999999;
int main(){
    int n, cnt;
    while(cin >> n){
        bool is_prime[N_MAX] = {false};
        is_prime[1] = true;
        for(int i = 2; i*i <= n; i++){ 
            if(!is_prime[i]){
                for(int j = i; i*j <= n; j++){
                    is_prime[i*j] = true;
                }
            }
        }
        cnt = 0;
        for(int k = 1; k <= n; k++){
            if(!is_prime[k]) {
                cnt++;
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 4036
#include<stdio.h>

int main(){
    int a,b,c,x,y=0;
    scanf("%d %d %d",&a,&b,&c);
    for(x=a;x<=b;x++){
        if(c%x==0)y++;
        }
        printf("%d\n",y);
        return 0;
}


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

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

	ll k;
	cin >> k;

	vector<int> a(n);
	for (int& ai : a) {
		cin >> ai;
		--ai;
	}

	vector<int> p(n, -1);
	ll c = 0;
	int curr = 0;
	p[curr] = 0;
	int next = a[curr];
	while (c < k) {
		curr = next;
		next = a[curr];
		++c;

		if (p[curr] != -1) {
			break;
		} else {
			p[curr] = c;
		}
	}

	ll d = c - p[curr];
	k -= c;

	for (int i = 0; i < k % d; ++i) {
		curr = next;
		next = a[curr];
	}

	cout << (curr + 1);
	
	return 0;
}
	

Measured memory_bytes: 4844
m,a[9][2],S[9999];D(d,s){int i=0;if(d==m)S[s]++;else for(;i<=a[d][1];i++)D(d+1,s+i**a[d]);}main(i){for(;scanf("%d",&m),m;){for(i=0;i<m;i++)scanf("%d%d",a[i],a[i]+1);memset(S,0,sizeof(S));D(0,0);for(scanf("%d",&i);i;i--)scanf("%d",&m),printf("%d\n",S[m]);}exit(0);}

Measured memory_bytes: 644
n = gets.to_i
a1 = []
a2 = []
a3 = []
a4 = []
a5 = []
a6 = []
n.times do
    height = gets.to_f
    if height < 165.0
        a1 << "*"
    elsif height < 170.0
        a2 << "*"
    elsif height < 175.0
        a3 << "*"
    elsif height < 180.0
        a4 << "*"
    elsif height < 185.0
        a5 << "*"
    elsif height >= 185.0
        a6 << "*"
    end
end

puts "1:#{a1.join("")}"
puts "2:#{a2.join("")}"
puts "3:#{a3.join("")}"
puts "4:#{a4.join("")}"
puts "5:#{a5.join("")}"
puts "6:#{a6.join("")}"


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e8;

void solve()
{
  int n; cin>>n;
  int ma,mb; cin>>ma>>mb;
  vector<int> a(n, 0);
  vector<int> b(n, 0);
  vector<int> c(n, 0);
  rep(i,n) cin>>a[i]>>b[i]>>c[i];
  vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(410, vector<int>(410, inf)));
  dp[0][0][0]=0;
  for (int i=0; i<n; i++) {
    for (int j=0; j<=400; j++) for (int k=0; k<=400; k++) {
      if (dp[i][j][k]==inf) continue;
      dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
      dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
    }
  }
  int ans=inf;
  for (int i=1; i<=400; i++) {
    for (int j=1; j<=400; j++) {
      if (i*mb==j*ma) ans=min(ans, dp[n][i][j]);
    }
  }
  if (ans==inf) ans=-1;
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 28416
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x,0))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,d;
  cin>>n>>d;
 d=2*d+1;
  if(n%d==0) n=n/d;
  else n=n/d+1;
  cout<<n;
}


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

using namespace std;

// Prioridade
typedef long long   ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i = a; i < (int)(b); i++)
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (((a)/__gcd(a, b)) * b)
#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;
// fim da Prioridade

int main(){
	ll n;
	cin >> n;
	ll ans = 0;
	for(ll l = 1LL, r; l <= n; l = r + 1LL) {
		r = n / (n / l);
		// n / i has the same value for l <= i <= r

		ll lo = l, hi = r, mid;
		while(lo <= hi){
			mid = (lo+hi)>>1LL;
			if(n - (n/l)*mid <= n/l){
				hi = mid - 1;
			}else{
				lo = mid + 1;
			}
		}
		hi++;
		if(n - (n/l)*hi == n/l){
			ans += hi;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,W;
    cin>>n>>W;
    vector<P> wv(n);
    vector<ll> num(4);
    vector<vector<ll> > sum(4,vector<ll>(n+1,0));
    vector<ll> v[4];
    int a,b,c,d;
    rep(i,n){
      cin>>wv[i].first>>wv[i].second;
      a=wv[0].first,b=a+1,c=a+2,d=a+3;
      if(wv[i].first==wv[0].first){
        num[0]++;
        v[0].push_back(wv[i].second);
      }
      if(wv[i].first==wv[0].first+1){
        num[1]++;
        v[1].push_back(wv[i].second);
      }
      if(wv[i].first==wv[0].first+2){
        num[2]++;
        v[2].push_back(wv[i].second);
      }
      if(wv[i].first==wv[0].first+3){
        num[3]++;
        v[3].push_back(wv[i].second);
      }
    }
    a=wv[0].first,b=a+1,c=a+2,d=a+3;
    rep(i,4) sort(begin(v[i]),end(v[i]),greater<ll>());
    sort(begin(wv),end(wv),greater<P>());
    ll ans=0;
    /*
    rep(i,4){
      num[i]=min(num[i],W/(wv[0].first+i));
    }
    */
   rep(i,4)rep(j,num[i]){
     sum[i][j+1]=sum[i][j]+v[i][j];
   }
    rep(i,num[0]+1)rep(j,num[1]+1)rep(k,num[2]+1)rep(l,num[3]+1){
      if(i+j+k+l>n) continue;
      if(i*a+j*b+k*c+l*d>W) continue;
      ll cnt=sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l];
      if(cnt>ans) ans=cnt;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
ll MOD = 1e9 + 7;
constexpr int MAX = 300030;
const double pi = acos(-1);
// constexpr double EPS = 1e-10;
ll LINF = 1e18;

int dx[4] = { 0, 0, -1, 1 };
int dy[4] = { 1, -1, 0, 0 };
int N;
int P[300010];
int D[505][505];

int f(int i, int j) {
	return i * N + j;
}
int pos[300030];

bool isEmpty[505][505];
void solve() {
	cin >> N;

	REP(i, N * N) {
		cin >> P[i];
		P[i]--;
		pos[P[i]] = i;
	}
	int s = N * N;
	REP(i, N) {
		REP(j, N) {
			int res= min({ i, N - i - 1, j, N - j - 1 });
			D[i][j] = res;
		}
	}
	int ans = 0;
	REP(i, N*N) {
		int n = P[i];
		int x = n / N, y = n % N;
		//pe(n + 1); print(D[x][y]);
		ans += D[x][y];
		isEmpty[x][y] = true;
		queue<pii>que;
		que.push({ x,y });
		while (!que.empty()) {
			pii p = que.front();
			que.pop();
			int xx = p.first, yy = p.second;
			REP(k, 4) {
				int nx = xx + dx[k], ny = yy + dy[k];
				int nd = D[xx][yy];
				if (!isEmpty[xx][yy])nd++;
				if (nx < N&&nx >= 0 && ny<N&&ny >= 0 && D[nx][ny]>nd) {
					D[nx][ny] = nd;
					que.push({ nx,ny });
				}
			}
		}
	}
	print(ans);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// int q;
	// cin >> q;
	// while (q--)
	solve();
}


Measured memory_bytes: 9724
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll a,b;
int32_t main(){
CODE_START;
cin>>a;
cin>>b;
if((a*b)%2==0){
    cout<<"No";
}else {
    cout<<"Yes";
}
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int let = N/2;
		if (N % 2 ==1) {
			let++;
		}
		System.out.println((double)let/N);

	}

}

Measured memory_bytes: 35948
#N E S W
def move_func(dice_list, dir):
	new_dice = []
	if dir=="N":
		new_dice.append(dice_list[1])
		new_dice.append(dice_list[5])
		new_dice.append(dice_list[2])
		new_dice.append(dice_list[3])
		new_dice.append(dice_list[0])
		new_dice.append(dice_list[4])
	elif dir=="E":
		new_dice.append(dice_list[3])
		new_dice.append(dice_list[1])
		new_dice.append(dice_list[0])
		new_dice.append(dice_list[5])
		new_dice.append(dice_list[4])
		new_dice.append(dice_list[2])
	elif dir=="S":
		new_dice.append(dice_list[4])
		new_dice.append(dice_list[0])
		new_dice.append(dice_list[2])
		new_dice.append(dice_list[3])
		new_dice.append(dice_list[5])
		new_dice.append(dice_list[1])
	elif dir=="W":
		new_dice.append(dice_list[2])
		new_dice.append(dice_list[1])
		new_dice.append(dice_list[5])
		new_dice.append(dice_list[0])
		new_dice.append(dice_list[4])
		new_dice.append(dice_list[3])
	return new_dice

try:
	while True:
		dice_list = input().split(" ")
		move_cmd = input()
		for cmd in  move_cmd:
			dice_list = move_func(dice_list, cmd)
			
		print(dice_list[0])
except EOFError:
	pass

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

long long count(int m, long long x, vector<long long> sum, vector<long long> pate) {
  if (m == 0) {
    if (x == 0) return 0;
    else return 1;
  }
  if (x <= 1) return 0;
  if (x <= sum.at(m) / 2) return count(m - 1, x - 1, sum, pate);
  if (x == sum.at(m) / 2 + 1) return pate.at(m - 1) + 1;
  if (x <= sum.at(m) - 1) return pate.at(m - 1) + 1 + count(m - 1, x - sum.at(m) / 2 - 1, sum, pate);
  if (x == sum.at(m)) return pate.at(m);
}

int main() {
  int n; cin >> n;
  long long x; cin >> x;
  vector<long long> sum(n + 1), pate(n + 1);
  sum.at(0) = pate.at(0) = 1;
  for (int i = 1; i <= n; i++) {
    sum.at(i) = sum.at(i - 1) * 2 + 3;
    pate.at(i) = pate.at(i - 1) * 2 + 1;
  }
  long long ans = count(n, x, sum, pate);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;

const int Mod=1e9+7;

typedef long long ll;
int n,ans=1,X,Y,cntall,fac[210000],ifac[210000],cmin[210000],F[210000],cnt[210000];
stack<int>S;

struct Node{
	int c,w;
}a[210000];

int pow(int x,int l){
	if(l==0)return 1;
	int t=pow(x,l/2);
	t=(ll)t*t%Mod;
	if(l&1)t=(ll)t*x%Mod;
	return t;
}

int cmp(Node x,Node y){
	return x.w<y.w;
}

int find(int x){
	return F[x]==x?x:F[x]=find(F[x]);
}

void join(int x,int y){
	F[find(x)]=find(y);
}

void work(){
	ans=(ll)ans*fac[cntall]%Mod;
	cntall=0;
	while(!S.empty()){
		int x=S.top();
		S.pop();
		if(cnt[x]==0)continue;
		ans=(ll)ans*ifac[cnt[x]]%Mod;
		cnt[x]=0;
	}
}

int main(){
	scanf("%d %d %d",&n,&X,&Y);
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=(ll)fac[i-1]*i%Mod;
	ifac[n]=pow(fac[n],Mod-2);for(int i=n-1;i>=0;i--)ifac[i]=(ll)ifac[i+1]*(i+1)%Mod;
	for(int i=1;i<=n;i++){
		scanf("%d %d",&a[i].c,&a[i].w);
	}sort(a+1,a+n+1,cmp);
	a[0].w=1<<30;
	int min1=1,min2=0;
	for(int i=2;i<=n;i++){
		if(a[i].c!=a[i-1].c){
			min2=i;break;
		}
	}for(int i=1;i<=n;i++)F[i]=i;
	for(int i=1;i<=n;i++){
		int c=a[i].c,w=a[i].w;
		if(a[cmin[c]].w>w)cmin[c]=i;
		if(a[min1].c==c){
			if(a[min1].w+w<=X)join(i,min1);
		}else{
			if(a[min1].w+w<=Y)join(i,min1);
		}if(a[min2].c==c){
			if(a[min2].w+w<=X)join(i,min2);
		}else {
			if(a[min2].w+w<=Y)join(i,min2);
		}if(a[cmin[c]].w+w<=X)join(i,cmin[c]);
	}for(int i=1;i<=n;i++){
		a[i].w=find(i);
	}sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(a[i].w!=a[i-1].w)work();
		cnt[a[i].c]++;S.push(a[i].c);cntall++;
	}work();
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;

  cout << a * b / 2 << endl;
}

Measured memory_bytes: 3580
#include<stdio.h>
int main(){
	long T,D,L,x[100000]={};
	while(1){
		int count=0;
		scanf("%d %d %d",&T,&D,&L);
		if(T==0&&D==0&&L==0)break;
		for(int i=0;i<T;i++){
			scanf("%d",&x[i]);
		}
		for(int i=0;i<T;i++){
			if(x[i]>=L){
				for(int j=1;j<=D;j++){
					if((i+j)==T)break;
					if(x[i+j]<L){
						count++;
					}
					else{
						count++;
						break;
					}
				}
			}
		}		
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 3476
#include <iostream>
#include <cstring>
using namespace std;
int m[17][17][3];
int main()
{
  int s,x,y,p,x1,y1,x2,y2,i,j;
  cin >> s;
  while(s--){
    memset(m,0,sizeof(m));
    cin >> x >> y >> p;
    x++; y++;
    while(p--){
      cin >> x1 >> y1 >> x2 >> y2;
      if(x1 != x2){
	if(x1 > x2) m[y1+1][x1+1][1] = 1;
	else m[y1+1][x2+1][1] = 1;
      }else{
	if(y1 > y2) m[y1+1][x1+1][2] = 1;
	else m[y2+1][x1+1][2] = 1;
      }
    }
    m[1][1][0] = 1;
    for(i=1;i<=y;i++){
      for(j=1;j<=x;j++){
	if(m[i][j][1] == 0) m[i][j][0] += m[i][j-1][0];
	if(m[i][j][2] == 0) m[i][j][0] += m[i-1][j][0];
      }
    }
    if(m[y][x][0]) cout << m[y][x][0] << endl;
    else cout << "Miserable Hokusai!" << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

#include <vector>

using namespace std;

int main()
{
  string s, t;
  cin >> s;
  cin >> t;

  if (s.length() + 1 != t.length())
  {
    cout << "No" << endl;
    return 0;
  }

  for (auto i = 0; i < s.length(); i++)
  {
    if (s[i] != t[i])
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3628
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# class UnionFind():
#   par = []
#   sizes = []

#   def __init__(self, N):
#     self.par = [i for i in range(N)]
#     self.sizes = [1 for _ in range(N)]

#   def root(self, x: int)-> int:
#     if (self.par[x] == x):
#       return x
#     return self.root(self.par[x])

#   def unite(self, x: int, y: int):
#     rootX = self.root(x)
#     rootY = self.root(y)
#     if rootX == rootY:
#       return
#     self.par[rootX] = rootY
#     self.sizes[rootY] += self.sizes[rootX]

#   def maxSize(self)-> int:
#     return max(self.sizes)

def friends(N, As):
  uf = UnionFind(N)
  setAs = list(set(As))
  for val in setAs:
    uf.union(val[0]-1, val[1]-1)
  ans = 0
  for i in range(N):
    temp = uf.size(i)
    if ans < temp:
      ans = temp
  return ans

if __name__ == "__main__":
  nm = list(map(int, input().split()))
  As =[tuple(map(int, input().split())) for _ in range(nm[1])]
  print(friends(nm[0], As))

Measured memory_bytes: 49876
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        private const long MOD = 1000000007;
        static void SolveA(string[] args)
        {
            int n = ReadAndParseInt();
            Console.WriteLine(n / 3);
        }
    }
}

Measured memory_bytes: 11092
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int n, h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  int c = *max_element(all(a));
  sort(all(b), greater<int>());
  int cnt = 0;
  for (int i = 0; i < b.size(); i++) {
    if (b[i] >= c) {
      h -= b[i];
      cnt++;
    } else {
      break;
    }
    if (h <= 0) {
      cout << cnt << endl;
      return;
    }
  }
  cout << (h + c - 1) / c + cnt << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    vector<int> nums(N.size() + 1);
    vector<int> oturiNums(N.size() + 1);
    for(int i = N.size(); i > 0; i--)
    {
        int num = N.at(i - 1) - '0';
        nums.at(i) += num;
        if(nums.at(i) > 5 || (nums.at(i) == 5 && i > 1 && N.at(i - 2) - '0' >= 5))
        {
            oturiNums.at(i) = 10 - nums.at(i);
            nums.at(i - 1) = 1;
            nums.at(i) = 0;
        }
    }
    ll answer = 0;
    for(int i = 0; i < N.size() + 1; i++)
    {
        answer += nums.at(i) + oturiNums.at(i);
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 9244
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int main()
{
  string s = "";
  cin >> s;

  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
  {
    printf("Bad\n");
  }
  else
  {
    printf("Good\n");
  }

  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=16,MAX_M=16;
const ll MOD=1e9+7;
int N,M,A[MAX_M+2];
ll dp[4][MAX_M+2][1<<MAX_N],fac[1<<MAX_N],ifac[1<<MAX_N];

ll mpw(ll n,ll m){
	ll ret=1;
	while(m){
		if (m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
void fzt(ll *x,ll *y){
	REP(i,1<<N){
		y[i]=x[i];
	}
	REP(i,N){
		REP(j,1<<N){
			if(!((j>>i)&1)){
				y[j+(1<<i)]+=y[j];
				y[j+(1<<i)]%=MOD;
			}
		}
	}
}
void ifzt(ll *x,ll *y){
	REP(i,1<<N){
		y[i]=x[i];
	}
	for(int i=N-1;i>=0;i--){
		REP(j,1<<N){
			if ((j>>i)&1){
				y[j]-=y[j-(1<<i)];
				y[j]+=MOD;
				y[j]%=MOD;
			}
		}
	}
}
	
int main(){
	cin>>N>>M;
	REP(i,M){
		cin>>A[i+1];
	}
	A[0]=1;
	A[M+1]=(1<<N)+1;
	fac[0]=1;
	REP(i,(1<<N)-1){
		fac[i+1]=fac[i]*(i+1)%MOD;
	}
	ifac[(1<<N)-1]=minv(fac[(1<<N)-1]);
	for(int i=(1<<N)-2;i>=0;i--){
		ifac[i]=ifac[i+1]*(i+1)%MOD;
	}
	dp[0][0][0]=1;
	REP(i,M+1){
		fzt(dp[0][i],dp[1][i]);
		REP(j,1<<N){
			int v=j-A[i]+1,w=A[i+1]-A[i]-1;
			if (v>=w){
				dp[2][i+1][j]=fac[v]*ifac[v-w]%MOD*dp[1][i][j]%MOD;
			}
		}
		ifzt(dp[2][i+1],dp[3][i+1]);
		if (i+1<=M){
			REP(j,1<<N){
				if (j-A[i+1]+2>0){
					dp[0][i+1][j]=(j-A[i+1]+2)*dp[3][i+1][j]%MOD;
				}
			}
		}
	}
	cout<<dp[3][M+1][(1<<N)-1]*(1<<N)%MOD<<endl;
	/*
	REP(i,4){
		REP(j,M+2){
			REP(k,1<<N){
				if (i>=3 && j==0 || i<=1 && j==M+1)continue;
				printf("dp[%d][%d][%d]=%lld\n",i,j,k,dp[i][j][k]);
			}
		}
	}
	*/
	return 0;
}

Measured memory_bytes: 37632
while(True):
    m, f, r = map(int, input().split(" "))

    if (m == -1) and (f == -1) and (r == -1):
        exit()

    if (m == -1) or (f == -1):
        print("F")
    elif (m + f >= 80):
        print("A")
    elif (m + f >= 65) and (m + f < 80):
        print("B")
    elif (m + f >= 50) and (m + f < 65):
        print("C")
    elif (m + f >= 30) and (m + f < 50):
        if (r >= 50):
            print("C")
        else:
            print("D")
    else:
        print("F")

Measured memory_bytes: 7704
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


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


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce

# 各クエリO(1)
# 求めたいのは0になるまでの回数
# 事前に1 - 2*10**5まで、になった回数を記録しておくとか？ (小さい方の数は必ずわかっている) (あまりがbit超で10**5を超えないのはわかっている)

# これがクリアされても 2**(2*10**5)の数字であまりが取れない問題がある
# 一回割ってしまえばこっちのもんよ

N = a_int()
X = read()[:-1]
px0 = X.count('1')
px0p = px0 + 1
px0n = (px0 - 1) if px0 != 1 else -1
# 上から、px0-1, px0, px0+1で割ったもの
x0n = 0
x0 = 0
x0p = 0

for i, bit in enu(reversed(X)):
    if bit == '1':
        x0n += pow(2, i, px0n)
        x0n %= px0n
        x0 += pow(2, i, px0)
        x0 %= px0
        x0p += pow(2, i, px0p)
        x0p %= px0p


x0 = [x0n, x0, x0p]  # px0-1, px0, px0+1で割ったもの

first_mod = []  # 後ろから順番に1回だけ操作を行ったときの数字(Xi % popcount(Xi))
for i, bit in enumerate(reversed(X)):
    if bit == '0':
        # 1に反転する
        first_mod.append((x0[2] + pow(2, i, px0p)) % (px0p))
    elif bit == '1':
        if px0n != -1:
            first_mod.append((x0[0] - pow(2, i, px0n)) % (px0n))
        else:
            first_mod.append(-1)


# print(first_mod[::-1], sep='\n')  # これが違うぞーなんでだ
# これは必ずpx0+-1よりも小さいので、事前に対応表を作っておけばすぐに求められる(それとも求めなくてもいいか？)(logがつくからしなくても良さそう)

ans = []
for x in reversed(first_mod):
    if x == -1:
        ans.append(0)
        continue
    cnt = 1  # すでに一回操作しているので
    while x != 0:
        x = x % bin(x).count('1')
        cnt += 1
    ans.append(cnt)


print(*ans, sep='\n')


Measured memory_bytes: 97068
import sys
x = int(input())
l = range(201)
for i in l:
  for j in l:
    if i**5+j**5 == x:
      print(' '.join([str(i),str(-j)]))
      sys.exit()
    elif i**5-j**5 == x:
      print(' '.join([str(i),str(j)]))
      sys.exit()
    else:
      pass

Measured memory_bytes: 9144
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n,m,M[100];
string N[100],s;

int main(){
	while(cin>>n>>m&&n){
		rep(i,n)cin>>N[i]>>M[i];
		int ans=0;
		rep(i,m){
			cin>>s;
			rep(j,n){
				int f=1;
				rep(k,8)if(s[k]!=N[j][k]&&N[j][k]!='*')f=0;
				if(f)ans+=M[j];
			}
		}
		cout<<ans<<endl;
	}
}

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

total = 0
for loc in range(len(B)):
    if A[loc] + A[loc + 1] >= B[loc]:
        total += B[loc]
        A[loc + 1] = min(A[loc + 1], A[loc] + A[loc + 1] - B[loc])
    else:
        total += A[loc] + A[loc + 1]
        A[loc + 1] = 0
print(total)


Measured memory_bytes: 18624
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <numeric>

using namespace std;
using ll = long long;

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

    vector<int> h(N);

    for (auto&& hi : h)  {
        cin >> hi;
    }

    int ans = 1;

    for (int i = 1; i < N; ++i) {
        bool ok = true;
        for (int j = 0; j < i; ++j) {
            if (h[j] > h[i]) {
                ok = false;
            }
        }
        if (ok) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n; cin >> n;
  vi a(n);
  int sum = 0;
  int mc = 0, pc = 0;
  rep(i,n) {
    cin>>a[i];
    if (a[i] < 0) mc++;
    else pc++;
    sum += abs(a[i]);
  }
  sort(all(a));
  int M = (mc==0) ? sum-2*a[0] : sum;
  if (pc == 0) {
    M = sum + 2*a[n-1];
  }
  cout << M << endl;
  if (n == 2) {
    cout << a[1] << " " << a[0] << endl;
    return 0;
  }
  if (mc == 0) {
    rep(i,n-2) {
      cout << a[i] << " " << a[i+1] << endl;
      a[i+1] = a[i] - a[i+1];
    }
    cout << a[n-1] << " " << a[n-2] << endl;
    return 0;
  }
  if (pc == 0) {
    rep(i,n-1) {
      cout << a[n-1] << " " << a[i] << endl;
      a[n-1] = a[n-1] - a[i];
    }
    return 0;
  }
  rep(i,n-1) {
    // rep(i,n) cout << a[i] << " \n"[i==n-1];
    int l = mc-1, r = n-pc;
    if (mc >= pc) {
      cout << a[r] << " " << a[l] << endl;
      a[r] = a[r] - a[l];
      mc--;
    } else {
      cout << a[l] << " " << a[r] << endl;
      a[l] = a[l] - a[r];
      pc--;
    }
  }
  return 0;
}


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

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Scanner sc=new Scanner(System.in);
		String b=sc.nextLine();
		String K ;
		int j=0;
		StringBuilder builder=new StringBuilder("");
		for(int i=0;i<b.length();i++) {
			K=b.substring(i,i+1);
			if(K.equals("B")&&builder.length()>0) {//如果是B空格键就删除前面的元素,如果不是添加进集合中
				builder.delete(j-1,j);
				j--;
			}if(K.equals("1")) {
				builder.append(K);
				j++;
			}if(K.equals("0")){
				builder.append(K);
				j++;
			}
		}
		System.out.println(builder.toString());
          }
}
		

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		StringBuilder str = new StringBuilder(sc.next());
		int N = sc.nextInt();

		for (int i = 0; i < N; i++) {
			String S = sc.next();
			int a = sc.nextInt();
			int b = sc.nextInt() + 1;

			if (S.equals("print")) {
				System.out.println(str.substring(a, b));
			} else if (S.equals("reverse")) {
				str.replace(a, b, (new StringBuilder(str.substring(a, b))).reverse().toString());
			} else {
				String SS = sc.next();
				str.replace(a, b, SS);
			}
		}
	}
}



Measured memory_bytes: 29336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B, N;
    cin >> A >> B >> N;

    ll ans = 0;

    ll l = 1, r = min(B, N);


    if (N < B) {
        cout << (A * N) / B << endl;
    } else {
        cout << (A * (B - 1)) / B << endl;
    }
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 1234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int A, B;

int main()
{
     in >> A >> B;
     if (A + B < 10) { out << A + B << std::endl; }
     else { out << "error" << std::endl; }
     return 0;
}

Measured memory_bytes: 256
class Dice:
    def __init__(self,num):
        self.top = num[0]
        self.front = num[1]
        self.right = num[2]
        self.left = num[3]
        self.back = num[4]
        self.bottom = num[5]

    def south_direction(self):
        front = self.top
        bottom = self.front
        back = self.bottom
        top = self.back
        right = self.right
        left = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left

    def north_direction(self):
        back = self.top
        top = self.front
        front = self.bottom
        bottom = self.back
        right = self.right
        left = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left

    def east_direction(self):
        right = self.top
        front = self.front
        left = self.bottom
        back = self.back
        bottom = self.right
        top = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
        
    def west_direction(self):
        left = self.top
        front = self.front
        right = self.bottom
        back = self.back
        top = self.right
        bottom = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
    
    def print_top(self):
        print(self.top)

num = list(map(int,input().split()))
directions = input()

d = Dice(num)
for i in directions:
    if i == "N":
        d.north_direction()
    elif i == "S":
        d.south_direction()
    elif i == "E":
        d.east_direction()
    elif i == "W":
        d.west_direction()

d.print_top()


Measured memory_bytes: 5612
#include <iostream>
#include <math.h>
using namespace std;
int main(){
  int R;
  string ans;
  cin >> R;
  if (R<1200)
    ans = "ABC";
  else if (R>=1200 and R<2800)
    ans = "ARC";
  else
    ans = "AGC";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

template<class Abel> struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n = 1, Abel SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, Abel SUM_UNITY = 0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, Abel w) {
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	UnionFind<int> uf(n);
	int l, r, d;
	rep(i, m) {
		cin >> l >> r >> d;
		l--; r--;
		if (uf.issame(l, r)) {
			int diff = uf.diff(l, r);
			if (diff != d) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			uf.merge(l, r, d);
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
import numpy as np
# 整数の入力
N = int(input())
# スペース区切りの整数の入力
line = np.array(list(map(int, input().split())))

num = 0
while True:
    l = np.mod(line, 2)
    if 1 in l:
        print(num)
        break
    else:
        num += 1
        line = line / 2
      

Measured memory_bytes: 12504
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = 0;
    int min = Integer.MAX_VALUE;
    for(int i = 0; i < n; i++){
      int tmp = sc.nextInt();
      max = Math.max(max, tmp);
      min = Math.min(min, tmp);
    }
    System.out.println(max - min);
  }
}

Measured memory_bytes: 23124