akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define rg register
#define il inline
#define maxn 300005
#define ll long long
using namespace std;
int a[maxn] , b[maxn] , c[maxn << 2] , sum[maxn];
il int lowbit(int x){return x & (-x);}
void insert(int i,int x,int n){
	while (i <= n){
		c[i] += x;
		i += lowbit(i);	
	}
}
ll getsum(int i){
	rg ll ans = 0;
	while (i > 0){
		ans += c[i];
		i -= lowbit(i);
	}
	return ans;
}
bool check(int x , int n){
	memset(c,0,sizeof(c));
	ll sum0 = (((ll)n * (ll)(n + 1) >> 1) >> 1) + 1;
	ll cnt = 0;
	int maxsum = -999999999;
	for (rg int i = 1;i <= n;++i) if (a[i] <= x) b[i] = 1;else b[i] = -1;
	for (rg int i = 1;i <= n;++i) {sum[i] = sum[i - 1] + b[i] , maxsum = (sum[i] > maxsum)?sum[i]:maxsum;}
	for (rg int i = 1;i <= n;++i) sum[i] += n;
	maxsum += n;
	insert(n , 1 , maxsum);
	for (rg int i = 1;i <= n;++i){
		cnt += getsum(sum[i] - 1);
		insert(sum[i], 1 , maxsum);
	}
	//cout<<cnt<<endl;
	return cnt >= sum0;
}
int main(){
	rg int n;
	scanf("%d",&n);
	rg int l = 1000000002 , r = -1;
	for (rg int i = 1;i <= n;++i) {scanf("%d",&a[i]);l = (a[i] < l)?a[i]:l , r = (a[i] > r)?a[i]:r;}
	while (l < r){
		rg int mid = (l + r) >> 1;
		if (check(mid , n)) r = mid;
		else l = mid + 1;	
	}
	cout << r;
	return 0;	
}

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

int main() {
  int64_t n,k,sum=0;
  cin >> n >> k;
  vector<int>h(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  
  if (n <= k) {
    cout << 0;
  }
  else if (k < n) {
    for (int i = 0; i < n-k; i++) {
      sum += h.at(i);
    }
    cout << sum;
  }
}

Measured memory_bytes: 1024
n,m = map(int,input().split())
lst1 = [list(input().split()) for i in range(m)]

lst2 = [0]*n #01
lst3 = [0]*n #pena

for i,j in lst1:
    i = int(i)-1
    if lst2[i] == 0:
        if j == "WA":
            lst3[i] += 1
        else:
            lst2[i] = 1
        
        
pena = 0
for i in range(n):
    if lst2[i]  == 1:
        pena += lst3[i]
print(sum(lst2),pena)

Measured memory_bytes: 67160
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
using namespace std;


int main (int argc, char const *argv[])
{
    string A,B,C;
    cin>>A>>B>>C;
    cout<<A[0]<<B[1]<<C[2]<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,w,a,b;
	cin>>h>>w>>a>>b;
	bool ch=true;
	for(ll i=0;i<h;i++){
		if(i>=b){
			ch=false;
		}
		for(ll j=0;j<w;j++){
			if(j<a){
				if(ch){
					cout << 1;
				}
				else{
					cout << 0;
				}
			}
			else{
				if(ch){
					cout << 0;
				}
				else{
					cout << 1;
				}
			}
		}
		cout << endl;
	}
	// your code goes here
	return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
typedef long long ll;
const int INF = 1e9;

int n, a[16][16];
ll dp[1 << 16];
ll cost[1 << 16];

int main() {
  cin >> n;
  rep(i, n) rep(j, n) cin >> a[i][j];

  rep(i, 1 << n) rep(j, n) for (int k = j + 1; k < n; ++k) 
      if (i & (1 << j) && i & (1 << k))
        cost[i] += a[j][k];

  rep(i, 1 << n) for (int j = i; j > 0; j = (j - 1) & i) 
    dp[i] = max(dp[i], dp[i - j] + cost[j]);

  cout << dp[(1 << n) - 1] << endl;

  return 0;
}


Measured memory_bytes: 1280
S = input()

even_success = True
odd_success = True
for i in range(len(S)):
    c = S[i]
    # 偶数番目チェック
    if i % 2 != 0:
        # print('even')
        if c not in ['L', 'U', 'D']:
            # print('even failed', c)
            even_success = False
    else:
        # print('odd')
        if c not in ['R', 'U', 'D']:        
        
            # print('odd failed', c)
            odd_success = False

if even_success and odd_success:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n, c, k;
  cin >> n >> c >> k;
  int t[n];
  rep(i, n) cin >> t[i];
  sort(t, t+n);

  int i = 0;
  int ans = 0;
  while (i < n) {
    int start = i;
    while (i < n && i-start+1 <= c && t[i] <= t[start]+k) i++;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=50+10;

int n,v[maxn];
double kq;

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&v[i]);
  sort(v+1,v+n+1);kq=v[1];
  for(int i=2;i<=n;i++)
    kq=(kq+v[i])/2.0;
  cout<<kq;
}


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

int main() {
    string s;
    int k;
    cin >> s >> k;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != 'a') {
            if (k >= 'z' - s[i] + 1) {
                k -= 'z' - s[i] + 1;
                s[i] = 'a';
            }
        }
    }
    s[s.size() - 1] = (s[s.size() - 1] - 'a' + k) % 26 + 'a';
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

#define MAX 500000

int n;

int merge(int *A, int left, int mid, int right) {
  
  int cnt=0,n1,n2,L[MAX],R[MAX],i,j,k;
  
  n1 = mid - left;
  n2 = right - mid;

  for(i=0;i<=n1;i++){
    L[i] = i;
  }
  for(i=0;i<=n2;i++){
    R[i] = i;
  }
  
  for(i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1] = 10e9+1;
  R[n2] = 10e9+1;
  
  i = 0;
  j = 0;
  
  // merge from two list to one list
  for( k = left ; k < right ; k++){
    if( L[i] <= R[j] ){
      A[k] = L[i];
      i++;
    }
    else {
      A[k] = R[j];
      j++;
    }
    cnt++;
  }

  
  return cnt;
}

int mergeSort(int *A, int left, int right){
  int mid,cnt=0;
  
  if(left+1 < right){
    mid = (left + right)/2;
    cnt += mergeSort(A, left, mid);
    cnt += mergeSort(A, mid , right);
    cnt += merge(A, left, mid, right);
  }
  return cnt;
}


int main(char args[]){
  
  int S[MAX],cnt=0,i;
  
  // input 
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%d",&S[i]);
  }
  
  cnt = mergeSort(S,0,n);
  
  // output
  for(i=0;i<n-1;i++) {
    printf("%d ",S[i]);
  }
  printf("%d\n",S[n-1]);
  printf("%d\n",cnt);
  
  return 0;  
}

Measured memory_bytes: 5488
a,b=map(int,input().split())
m=100*a
n=80*b
l=min(100*(a+1)/8,80*(b+1)/8)
r=max(m,n)
def aprint(num):
    if l<=num:
        print(-1)
    else:
        print(num)
if (r/8)//1==r/8:
    aprint(r//8)
else:
    aprint(int(r//8)+1)

Measured memory_bytes: 3188
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>


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


int main (void)
{
    int s,w;
    cin>>s>>w;

    if(s>w) cout<<"safe"<<endl;

    else cout<<"unsafe"<<endl;
}

Measured memory_bytes: 3108
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

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

#define INF 1e18
#define MOD 1e9 + 7

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

char RGB[3] = {'R', 'G', 'B'};
map<char, int> m;

int main() {
    ios_base::sync_with_stdio(false);
    m['R'] = 0;
    m['G'] = 1;
    m['B'] = 2;

    int n;
    cin >> n;
    string s;
    cin >> s;

    int suf[n+1][3];
    memset(suf, 0, sizeof suf);
    for(int i = n-1; i >= 0; i--) {
        for(int j = 0; j < 3; j++) {
            suf[i][j] = suf[i+1][j] + (s[i] == RGB[j]);
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            if(s[j] == s[i]) continue;

            int c;
            for(int k = 0; k < 3; k++) if(s[i] != RGB[k] && s[j] != RGB[k]) c = k;
            ans += suf[j+1][c] - (j+j-i < n && s[j+j-i] == RGB[c]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll s;
	cin >> s;
	ll a, b;
	a = (ll)(sqrt((double)s) + 0.5);
	b = s / a;
	if (a * b < s) {
		b++;
	}
	ll minu = a * b - s;
	ll a1 = 0, b1 = 0;
	if (minu) {
		a1 = 1;
		b1 = minu;
	}
	cout << 0 << " " << 0 << " " << b1 << " " << a << " " << b << " " << a1
		 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long miin=9999999,maax=-9999999,mini,maxi;
int main()
{
	int n,i,j;
	scanf("%d",&n);
	long long a[100];
	long long c[100];
	long long b[100][2];
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		c[i]=a[i];
		if(a[i]>maax)
		{
			maax=a[i];maxi=i;
		}
		if(a[i]<miin)
		{
			miin=a[i];mini=i;
		}
		
	}
	
	int ct=0;
	for(i=0;i<n-1&&ct<=2*n;i++)
	{
		while(a[i+1]<a[i]&&ct<=2*n)
		{
			b[ct][0]=maxi;
			b[ct][1]=i+1;
			a[i+1]+=maax;
			if(a[i+1]>maax)
			{
				maax=a[i+1];
				maxi=i+1;
			}
			ct++;
		}
		//printf("%lld+++++%lld__%d\n",a[i],a[i+1],i);
	}
//	printf("%d---------\n",ct);
	if(i==n-1&&ct<=2*n)
	{
		//printf("****\n");
		printf("%d\n",ct);
		for(i=0;i<ct;i++)
		{
			printf("%lld %lld\n",b[i][0]+1,b[i][1]+1);
		}
	}
	else
	{
		ct=0;
		for(i=n-1;i>0;i--)
		{
			while(c[i]<c[i-1])
			{
				c[i-1]+=miin;
				b[ct][0]=mini;
				b[ct][1]=i-1;
				ct++;
				if(c[i-1]<miin)
				{
					miin=c[i-1];
					mini=i-1;
				}
			}
		}
		printf("%d\n",ct);
		for(i=0;i<ct;i++)
		{
			printf("%lld %lld\n",b[i][0]+1,b[i][1]+1);
		}
	}
}

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

int main(){
    long long X;
    std::cin >> X;
    
    
    for(long long i=-200; i<200; i++){
        for(long long j=-200; j<200; j++){
            long long tmp = (i * i * i * i * i) - (j * j * j * j * j);
            if(tmp == X){
                std::cout << i << " " << j << std::endl;
                return 0;
            }
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007



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

   int top = S.size() - T.size();
   while(top >= 0) {
       bool can = true;
       for(int i = top;i < top + T.size();i++) {
           if('a' <= S.at(i) && S.at(i) <= 'z') {
               if(S.at(i) != T.at(i - top)) {
                   can = false;
                   break;
               }
           }
       }

       if(can) {
           for(int i = top;i < top + T.size();i++) {
               S.at(i) = T.at(i - top);
           }
           break;
       }
       top--;
   }

   if(top < 0) {
       cout << "UNRESTORABLE" << endl;
   }else {
       for(int i = 0;i < S.size();i++) {
           if(S.at(i) == '?') {
               cout << 'a';
           }else {
               cout << S.at(i);
           }
       }

       cout << endl;
   }

}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main() {
  
    int h,w ;
    cin>>h>>w ;

    char c[h][w] ;
   
   for (int i = 0; i < h; i++)
   {
       for(int j=0;j<w;j++)
       {
         cin >> c[i][j] ;
       }
   }

   for (int i = 0; i < h; i++)
   {
       for(int j=0;j<w;j++)
       {
         cout << c[i][j] ;
       }
       cout << endl ;
       
       for(int j=0;j<w;j++)
       {
         cout << c[i][j] ;
       }
        cout << endl ;
       
   }
   


  return 0 ;
}

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

int main(void){
    ll N;
    cin >> N;
    
    ll ans = 0;
    ans += N / 500 * 1000;
    N %= 500;
    ans += N / 5 * 5;
    
    cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

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

const int INF = 1111111111;

using namespace std;

void init()
{
}

void solve()
{
	int a, b;
	cin >> a >> b;
	cout << (a * b) << endl;
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    print((1000 - n % 1000) % 1000);

    return 0;
}

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

int main(){
	int n,k = 0;
  cin >> n;
  for (int i=0; i<n; i++){
    string a;
    cin >> a;
    if (a == "Y") {
      k = 1;}
    else continue;
  }
  if (k == 1) {
    cout << "Four" << endl;}
  else {
    cout << "Three" << endl;}
}


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

int main(){
    int h[5];
    while(cin >> h[0]){
        if(h[0] == 0) break;
        cin >> h[1] >> h[2] >> h[3] >> h[4];
        int rs[5];
        bool r = false;
        bool s = false;
        bool p = false;
        for(int i=0; i<5; ++i){
            switch(h[i]){
                case 1:
                    r = true;
                    break;
                case 2:
                    s = true;
                    break;
                case 3:
                    p = true;
            }
        }
        if(r&&s&&p)
            rs[0] = rs[1] = rs[2] = rs[3] = rs[4] = 3;
        else if((r&&!s&&!p)||(!r&&s&&!p)||(!r&&!s&&p))
            rs[0] = rs[1] = rs[2] = rs[3] = rs[4] = 3;
        else if(!r)
            for(int i=0; i<5; ++i)
                (h[i]==2)?rs[i]=1:rs[i]=2;
        else if(!s)
            for(int i=0; i<5; ++i)
                (h[i]==3)?rs[i]=1:rs[i]=2;
        else
            for(int i=0; i<5; ++i)
                (h[i]==1)?rs[i]=1:rs[i]=2;
        for(int i=0; i<5; ++i){
            cout << rs[i] << endl;
        }
    }
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int>> mpN(N,vector<int>(N,0));
  vector<vector<int>> mpM(M,vector<int>(M,0));
  
  string p;
  
  for (int i=0; i<N; i++) {
    cin >> p;
    for (int j=0; j<N; j++) {
      if (p[j] == '#') {
        mpN[i][j]++;
      }
    }
  }
  for (int i=0; i<M; i++) {
    cin >> p;
    for (int j=0; j<M; j++) {
      if (p[j] == '#') {
        mpM[i][j]++;
      }
    }
  }
  
  bool br = false;
  
  for (int i=0; i<N-M+1; i++) {
    for (int j=0; j<N-M+1; j++) {
      for (int k=0; k<M; k++) {
        for (int l=0; l<M; l++) {
          if (mpM[k][l] != mpN[i+k][j+l]) {
            br = true;
            break;
          }
        }
        if (br) {
          br = false;
          break;
        }
        if (k == M-1) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    const int INF = 100000000;
    int n,m;
    cin >> n >> m;
    int a[1000], b[1000], c[1000], dist[100][100];
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j){
                dist[i][j]=0;
            }else{
                dist[i][j]=INF;
            }
        }
    }
    for(int i=0; i<m; i++){
        dist[a[i]][b[i]]=min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]]=min(dist[b[i]][a[i]], c[i]);
    }

    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }

    int ans=m;
    for(int i=0; i<m; i++){
        bool shortest=false;
        for(int j=0; j<n; j++) if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
        if(shortest==true){
            ans=ans-1;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 888
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

#define ll long long

using namespace std;

signed main() {
	ll n, k, q; cin >> n >> k >> q;
	vector<ll> gain(n + 1);
	for (int i = 0; i <= n; ++i)
		gain[i] = 0;
	for (int i = 0; i < q; ++i) {
		int a; cin >> a;
		gain[a] += 1;
	}
	// i人目の失う得点はq-gain[i]
	for (int i = 1; i <= n; ++i) {
		if (q - gain[i] < k) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void)
{
    int a,b,c,s=0;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b) s++;
    if(b==c) s++;
    if(c==a) s++;
    if(s==1)
        printf("Yes\n");
    else 
        printf("No\n");
    return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//


int main() {
  int n, k;
  cin >> n >> k;
  vi p(n), c(n);
  rep(i, n) {int np; cin >> np; p[i] = np-1;}
  rep(i, n) cin >> c[i];
  vvi d;
  vi used(n, 0);
  rep(i, n) {
    if (used[i]) continue;
    vi nd;
    used[i] = 1;
    int ni = p[i];
    nd.push_back(i);
    while(!used[ni]) {
      used[ni] = 1;
      nd.push_back(ni);
      ni = p[ni];
    }
    d.push_back(nd);
  }
  ll ans = -LINF;
  rep(i, d.size()) {
    rep(j, d[i].size()) {
      vi dd = d[i];
      rep(k, d[i].size()) dd.push_back(d[i][k]);
      vi md;
      for (int m = j; m < j + d[i].size(); ++m) md.push_back(dd[m]);
      int l = md.size();
      ll tot = 0;
      rep(i, l) tot += c[md[i]];
      ll t = 0;
      rep(i, l) {
        t += c[md[i]];
        if (i+1 > k) break;
        ll now = t;
        if (tot > 0) {
          ll e = (k-(i+1))/l;
          now += tot*e;
        }
        ans = max(ans, now);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3772
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(0<=(x-r)&&(x+r)<=w&&0<=(y-r)&&(y+r)<=h)cout<< "Yes" <<endl;
	else cout << "No"<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const int INF=1e9;


int main(){
  int x1,x2,x3,x4,x5;

  rep(i,5){
    int a;
    cin>>a;
    if(a!=i+1){
      cout<<i+1<<endl;
      return 0;
    }
  }
  
  return 0;
  
}


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

typedef long long ll;

const int INF = 1e9 + 10;
const ll INFLL = 3e18;

int main(){
	
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	
	int n, l;
	cin >> n >> l;
	
	vector<string> v(n);
	for(int i = 0 ; i < n ; i ++)
		cin >> v[i];
	
	sort(v.begin(), v.end());
	
	for(int i = 0 ; i < n ; i ++)
		cout << v[i];
	cout << "\n";
	
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val n, k = Scanner.nextInt

	pw.println(Seq.fill(n)(Scanner.nextInt).sorted.take(k).sum)
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 54888
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;

int main (){
  ll N, K, Q;
  cin >> N >> K >> Q;

  ll a[N];
  for ( ll i=0; i<N; i++){
    a[i] = K-Q;
  }

  while (Q--){
    ll no;
    cin >> no;
    a[no-1] ++;
  }


  for ( ll i=0; i<N; i++){
    if ( a[i] <= 0){
      cout << "No" <<endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}

  




Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int dp[1001][1001];
#define MOD 1000000007
long long noOfPaths(vector<vector<char>>&v,int i,int j,int di,int dj){
    if(i>di || j>dj || v[i][j]=='#')
     return 0;
    if(i==di && j==dj)
     return 1;
    if(dp[i][j]!=-1) return dp[i][j];
    return dp[i][j]=(noOfPaths(v,i+1,j,di,dj)+noOfPaths(v,i,j+1,di,dj))%MOD;  
}
int main()
{  ios::sync_with_stdio(false);
   cin.tie(0);  
   int m,n;
   cin>>m>>n;
   vector<vector<char>>v(m,vector<char>(n));
   for(int i=0;i<m;i++){
     for(int j=0;j<n;j++)
       cin>>v[i][j];
   }
   memset(dp,-1,sizeof(dp));
   cout<<noOfPaths(v,0,0,m-1,n-1);
     return 0;
}


Measured memory_bytes: 8224
#include <bits/stdc++.h>
#include <cstring>
#include <ctype.h>
#include<stdlib.h>

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;
int gcd(int x,int y)
{        
    return x ? gcd(y%x,x) : y;   
}  

int main()
{
    fastio;
    int n;
    cin>>n;
    int p[n+1];
    for(int i=1; i<=n; i++)
    cin>>p[i];
    int x=n;
    int a[n+1],b[n+1];
    for(int i=1; i<=n; i++)
    {
        a[i]=(i*x);
        b[i]=((n-i)*x);
    }

    for(int i=1; i<=n; i++)
    b[p[i]]+=i;


    for(int i=1; i<=n; i++)
    cout<<a[i]<<' ';
    cout<<nl;
    
    for(int i=1; i<=n; i++)
    cout<<b[i]<<' ';
    cout<<nl;

    bdyptb;
}

Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}



//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

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

	if (D == 25) {
		cout << "Christmas" << endl;
	}
	if (D == 24) {
		cout << "Christmas Eve" << endl;
	}
	if (D == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	if (D == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int a[310][310];
vector<bool> usable(310,true);

int dfs(int depth, int n, int m, vector<bool>& usable){
  if(depth==m){
    return n;
  }
  vector<int> temp(m,0);
  int max_v=0;
  int max_s;
  int res;
  REP(i,n){
    REP(j,m){
      if(usable[a[i][j]]){
        temp[a[i][j]]++;
        if(max_v<temp[a[i][j]]){
          max_v=temp[a[i][j]];
          max_s=a[i][j];
        }
        break;
      }
    }
  }
  usable[max_s] = false;
  res = min(max_v, dfs(depth+1, n, m, usable));
  return res;
}
  
    
int main(){
  
  int n,m;
  cin>>n>>m;
  REP(i,n){
    REP(j,m){
      cin>>a[i][j];
      a[i][j]--;
    }
  }
  
  int ans;
  ans = dfs(0, n, m, usable);
  cout<<ans<<endl;
  return 0;
}


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

struct Swimmer{
    int t, v, c;
    bool operator < (const Swimmer &s) const {return v < s.v;};
};

int N;
vector<int> T, C;

void solve(){
    deque<Swimmer> q[2];
    
    vector<Swimmer> vec;
    for(int i=0; i<N; i++){
        int v, c; cin >> v >> c;
        vec.push_back({0, v, c});
    }
    sort(vec.begin(), vec.end());
    for(int i=0; i<N; i++)
        q[0].push_back(vec[i]);
    
    int ans = 0;
    while(!q[0].empty() || !q[1].empty()){
        int cur;
        if(q[0].empty())
            cur = 1;
        else if(q[1].empty())
            cur = 0;
        else if(q[0].front().t < q[1].front().t){
            cur = 0;
        }else{
            cur = 1;
        }
        
        auto s = q[cur].front(); q[cur].pop_front();
        
        if(cur == 0){
            if(s.c == 0)
                ans = s.t;
            else{
                s.t += s.v;
                if(!q[cur^1].empty() && q[cur^1].back().t > s.t)
                    s.t = q[cur^1].back().t;
                s.c--;;
                q[cur^1].push_back(s);
            }
        }else{
            s.t += s.v;
            if(!q[cur^1].empty() && q[cur^1].back().t > s.t)
                s.t = q[cur^1].back().t;
            q[cur^1].push_back(s);
        }
        vector<Swimmer> vec;
        while(!q[cur^1].empty() && q[cur^1].back().t == s.t){
            vec.push_back(q[cur^1].back()); q[cur^1].pop_back();
        }
        sort(vec.begin(), vec.end());
        for(auto s: vec)
            q[cur^1].push_back(s);
            
    }
    cout << ans << endl;
}

int main(){
    while(cin >> N, N){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3116
#include <iostream>

using namespace std;

#define MAX 100001
long long a[MAX];
long long b[MAX];

int main(){
    long long N;
    cin >> N;
    for(long long i=0;i<N+1;i++){
        cin >> a[i];
    }
    for(long long i=0;i<N;i++){
        cin >> b[i];
    }
    long long count = 0;
    for(long long i=0;i<N;i++){
        if(a[i] > b[i]){
            count += b[i];
            continue;
        }
        count += a[i];
        long long d = b[i] - a[i];
        if(a[i+1] > d){
            a[i+1] -= d;
            count += d;
        }else{
            count += a[i+1];
            a[i+1] = 0;
        }
    }
    cout << count << endl;
    return 0;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

/**
 * @brief 文字列を分割する
 * @param target 分割対象の文字列。 ex: "a, b, c"
 * @param separator 区切り文字列。 ex: ", "
 * @return 分割された文字列の一覧
 */
std::vector<string> strsplit(const std::string& target, const std::string& separator) {
  const auto separator_length = separator.length(); // 区切り文字の長さ
  auto list = std::vector<std::string>();

  if (separator_length == 0) {
    list.push_back(target);
  } else {
    auto offset = std::string::size_type(0);
    while (1) {
      auto pos = target.find(separator, offset);
      if (pos == std::string::npos) {
        list.push_back(target.substr(offset));
        break;
      }
      list.push_back(target.substr(offset, pos - offset));
      offset = pos + separator_length;
    }
  }
  return list; // ex: list == {"a", "b", "c"}
}


int main(){
  string s;
  getline(cin, s);

  vector<ll> stack;
  const vector<string> ss = strsplit(s, " ");
  rep(i, ss.size()) {
    const auto& cur = ss[i];
    if (cur == "+") {
      const ll v1 = stack.back();
      stack.pop_back();
      const ll v2 = stack.back();
      stack.pop_back();
      stack.push_back(v2 + v1);

    } else if (cur == "-") {
      const ll v1 = stack.back();
      stack.pop_back();
      const ll v2 = stack.back();
      stack.pop_back();
      stack.push_back(v2 - v1);
    } else if (cur == "*") {
      const ll v1 = stack.back();
      stack.pop_back();
      const ll v2 = stack.back();
      stack.pop_back();
      stack.push_back(v2 * v1);
    } else {
      ll v = stoll(cur);
      stack.push_back(v);
    }
  }

  cout << stack.back() << endl;

  return 0;
}



Measured memory_bytes: 3240
import math

n = int(input())


def f(x, y, z):
    return (x**2) + (y**2) + (z**2) + (x * y) + (y * z) + (z * x)


dp = [0 for _ in range(60001)]
C = 100
for i in range(1, C):
    for j in range(1, C):
        for k in range(1, C):
            dp[f(i, j, k)] += 1

print(*dp[1:n + 1])


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

#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define khela_shuru int main()
#define khela_shesh return 0
#define MOD 1000000007
#define PI acos(-1)
#define ll long long
#define vi vector<int>
#define vii vector <pair<int, int>>
#define FOR(i,a,b) for(int (i)=(a); i<(b); i++)
#define en '\n'

khela_shuru{

    ///Balsal jinish daka dakir kaaj ekhane

    FAST_IO;

    /// Bhulbhal coding shuru ekhan theke

    int n{}, m{}, sum{};
    cin >> n >> m;

    int ara[m];

    for(int i=0; i<m; i++) {
        cin >> ara[i];
        sum += ara[i];
    }

    if(sum>n)
        cout << -1 << endl;
    else
        cout << (n-sum) << endl;

    khela_shesh;
}


Measured memory_bytes: 3652
#include <cstdio>

int main(){
	while(true){
		int n, r;
		scanf("%d%d", &n, &r);
		if(n == 0 || r == 0){ break; }
		int cards[50], tmp[50];
		for(int i = 0; i < n; i++){
			cards[i] = n - i;
		}
		for(int i = 0; i < r; i++){
			int p, c;
			scanf("%d%d", &p, &c);
			for(int j = 0; j < p - 1; j++){
				tmp[j] = cards[j];
			}
			for(int j = 0; j < c; j++){
				cards[j] = cards[p + j - 1];
			}
			for(int j = 0; j < p - 1; j++){
				cards[c + j] = tmp[j];
			}
		}
		printf("%d\n", cards[0]);
	}
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

const int MAXN = 5e5;
int bit[MAXN+1];
vpii gran[MAXN+1];
int n, q;

void update(int i, int delta)
{
    for(++i; i<=n; i+=i&-i)
        bit[i] += delta;
}

int query(int i)
{
    int sum = 0;
    for(; i>0; i-=i&-i)
        sum += bit[i];
    return sum;
}

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

    vi v(n);
    memset(bit,0,sizeof(bit));
    for(auto &z : v)
        cin >> z;

    for(int i = 0; i < q; ++i)
    {
        int l, r;
        cin >> l >> r, --l, --r;
        gran[r].pb({l,i});
    }
    vi ans(q);
    map<int,int> mp;
    for(int i = 0; i < n; ++i)
    {
        if(mp.count(v[i]))
            update(mp[v[i]],-1);
        update(i,1);
        mp[v[i]] = i;
        if(!gran[i].empty())
        {
            for(auto e : gran[i])
            {
                ans[e.se] = query(n) - query(e.fi);
            }
        }
    }

    for(auto z : ans)
        cout << z << '\n';
}



Measured memory_bytes: 54748
#include <iostream>
#include <string.h>

using namespace std;

int main(void)
{
    int s;
    int x[10000] = {0};
    int b;
    int a;

    cin >> s;
    b = s;
    x[b]++;

    int ans = 0;
    for (int i = 2; i <= 1000000; i++) {
        if (b%2 == 0) {
            a = b/2;
        }
        else {
            a = 3 * b + 1;
        }
        x[a]++;
        if (x[a] == 2) {
            ans = i;
            break;
        }
        b = a;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
   int s, i = 0, j = 0, cnt = 0;
   int a[1000000];
   
   scanf("%d",&s);
   a[i] = s;

   if((s < 1) || (s > 100)) {
      return 0;
   }
   
   while (i < 1000000) {
     j = 0;
     cnt = 0;
     while (j <= i) {
        if (a[i] == a[j] ) {
           cnt++;
           if(cnt == 2) {
              printf("%d\n",j + 1);
              return 0;
           }
        }
        j++;
     }
     if (a[i] % 2 == 0)  {
        a[i + 1] = a[i] / 2;
     }
     else if (a[i] % 2 != 0)  {
        a[i + 1] = 3 * a[i] + 1;
     }
     
     i++;
   }
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>

int main() {
  int n;
  while (std::cin >> n) {
    std::vector<int> a;
    for (int i = 0; i < n; ++ i) {
      int x;
      std::cin >> x;
      a.push_back(x);
    }
    std::sort(a.begin(), a.end());
    int ma = a.back(), mi = a.front();
    int res = 0;
    for (int i = 1; i < n - 1; ++ i) {
      if (a[i] > 0) {
        mi -= a[i];
      } else {
        ma -= a[i];
      }
    }
    res = ma - mi;
    std::cout << res << std::endl;
    ma = a.back(), mi = a.front();
    for (int i = 1; i < n - 1; ++ i) {
      if (a[i] > 0) {
        std::cout << mi << " " << a[i] << std::endl;
        mi -= a[i];
      } else {
        std::cout << ma << " " << a[i] << std::endl;
        ma -= a[i];
      }
    }
    std::cout << ma << " " << mi << std::endl;
  }
  return 0;
}


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int n, x[200005], y[200005];

int main() {
	read(n);
	for (int i = 0; i < n; ++i) {
		int X, Y;
		read(X), read(Y);
		x[i] = X + Y, y[i] = X - Y;
	}
	print(std::max(*std::max_element(x, x + n) - *std::min_element(x, x + n), *std::max_element(y, y + n) - *std::min_element(y, y + n)));
}


Measured memory_bytes: 9016
s=input()
N=len(s)
ans=N//2
for i in range(N//2+1,N):
  if s[N-i:i]=="0"*(2*i-N) or s[N-i:i]=="1"*(2*i-N):
    ans=i
if s=="0"*N or s=="1"*N:
  ans=N
print(ans)
    
    
  
  
  

Measured memory_bytes: 3404
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
typedef vector<vector<int > > vec2int;
typedef vector<vector<bool > > vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int h, w;
  cin >> h >> w;
  vec2bool g(h,vecbool(w,false));
  char tmp;
  REP(i,h){
    REP(j,w){
      cin >> tmp;
      if(tmp == '.'){
	g[i][j] = true;
      }
    }
  }
  vec2int cost(h,vecint(w,0));
  int ans = 0;
  int tmpmax = 0;
  int x, y;
  int x2, y2;
  REP(i,h){
    REP(j,w){
      if(!g[i][j]) continue;
      REP(i2, h){
	REP(j2, w){
	  cost[i2][j2] = -1;
	}
      }
      cost[i][j] = 0;
      tmpmax = 0;
      /////bfs
      queue<pair<int, int>> q;
      q.push(make_pair(i,j));
      while(!q.empty()){
	x = q.front().first;
	y = q.front().second;
	q.pop();
	REP(k,4){
	  x2 = x + dx[k];
	  y2 = y + dy[k];
	  if(x2 < 0 || h - 1 < x2 || y2 < 0 || w - 1 < y2) continue;
	  if(cost[x2][y2] >= 0 || !g[x2][y2] ) continue;
	  cost[x2][y2] = cost[x][y] + 1;
	  tmpmax = max(cost[x2][y2], tmpmax);
	  q.push(make_pair(x2, y2));
	}
      }
      /////bfs
      ans = max(tmpmax, ans);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
class UnionFind {
  constructor(n) {
    this.p = new Array(n).fill(null).map((_, i) => i)
    this.height = new Array(n).fill(0)
    this.size = new Array(n).fill(1)
  }

  unite(a, b) {
    this.link(this.findSet(a), this.findSet(b))
  }

  link(a, b) {
    if (a === b) return null

    if (this.height[a] > this.height[b]) {
      this.p[b] = a
      this.size[a] += this.size[b]
    } else {
      this.p[a] = b
      this.size[b] += this.size[a]

      if (this.height[a] === this.height[b]) {
        this.height[b]++
      }
    }
  }

  findSet(x) {
    if (this.p[x] === x) return x
    return this.findSet(this.p[x])
  }
}

const main = (input) => {
  input = input.trim().split('\n')
  const [n,] = input.shift().split(' ').map(Number)
  input = Array.from(new Set(input))

  const uf = new UnionFind(n+1)

  for (let i=0; i<input.length; i++) {
    const [a, b] = input[i].split(' ').map(Number)
    uf.unite(a, b)
  }

  // const ans = Math.max(...uf.size)
  // let max = 0
  // console.log(uf.size)
  // for (let i=0; i<uf.size.length; i++) max = Math.max(max, (uf.size[i]|| 0))
  return console.log(uf.size.reduce((a, b) => Math.max(a, (b || 0)), 0))
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main(void){
  int N;
  cin >> N;
  ll A[2*N + 2];
  A[0] = -1;
  A[N] = -1;
  for(int i=0; i<N; i++){
    cin >> A[i+1];
    A[i+1 + N] = A[i+1];
  }
  
  ll evenans = 0;
  ll oddans = 0;
  
  int cnt = 1;
  for(int i=1; i<=N; i+=2) oddans += A[i];
  for(int i=2; i<=N; i+=2) oddans -= A[i];   
//  cout << oddans << endl;

  for(int i=3; i<=N+1; i+=2) evenans -= A[i];
  for(int i=2; i<=N+1; i+=2) evenans += A[i];
//  cout << evenans << endl;

  
  for(int i=1; i<=N; i++){
    int ithans = 0;
    if(i==1){
      cout << oddans;
    }else if(i==2){
      cout << evenans;
    }else if(i%2 == 1){
      oddans = oddans -2*(A[i-2+N]-A[i-1+N]);
      cout << oddans;
    }else if(i%2 == 0){
      evenans = evenans -2*(A[i-2+N]-A[i-1+N]);
      cout << evenans;      
    }
    if(i!=N) cout << " ";
  }
  cout << endl;
  
}

Measured memory_bytes: 2816
#include <iostream>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n )
	{
		if ( n > 2 )
		{
			int m = 0;
			int cnt = 1;
			for ( int i = 0; i < n-2; i++ )
			{
				m += cnt;
				cnt++;
			}
			cout << 2 * n + m << endl;
		}
		else
			cout << 2 * n << endl;
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class NewClassC
{
    static void Main(string[] args)
    {
        ABC_A();
    }

    static void ABC_A()
    {
        int[] arr = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

        var line = Console.ReadLine().Trim();
        int k = Int32.Parse(line);
        Console.WriteLine(arr[k-1]);
    }
    static void ABC_B()
    {
    }
    static void ABC_C()
    {
    }
    static void ABC_D()
    {

    }
    static void ABC_E()
    {

    }
    static void ABC_F()
    {

    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  if(a>b){
    cout << 2*a-1 <<endl;
  }
  else if (a<b){
    cout << 2*b-1 << endl;
  }
  else{
    cout << a+b <<endl;
  }
}
    

Measured memory_bytes: 256
#include <iostream>
int main() {
    int a, b;
    char op;
    while (true) {
        std::cin >> a >> op >> b;
        if (op == '?') break;
        int r;
        if (op == '+') r = a + b;
        else if (op == '-') r = a - b;
        else if (op == '*') r = a * b;
        else r = a / b;
        printf("%d\n", r);
    }
    return 0;
}

Measured memory_bytes: 3220