akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
using namespace std;

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

    if(s[0] == 'A'){
        long long count_C = 0;
        for(long long i = 0; i < s.size(); i++){
            if(i == 0 || i == 1 || i == s.size()-1){
                continue;
            }

            if(s[i] == 'C'){
                count_C++;
            }
        }

        long long count_big = 0;
        if(count_C == 1){
            for(long long i = 0; i < s.size(); i++){
                if(isupper(s[i]) != 0){
                    count_big++;
                }
            }

            if(count_big == 2){
                printf("AC\n");
                
            }
            else{
                printf("WA\n");
            }
        }
        else{
            printf("WA\n");
        }
    }
    else{
        printf("WA\n");
    }
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>

using namespace std;

int b[100001];

int main(){

    int n,temp;
    vector<int> a;
    cin >> n;
    for(int i=0;i<n;i++){
	cin >> temp;
	a.push_back(temp);
    }
    fill(b,b+n,1<<30);
    for(int i=0;i<n;i++){
	*lower_bound(b,b+n,a[i]) = a[i];
    }
    int res = 0;
	res = lower_bound(b,b+n,1<<30) - b;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2068
#include <stdio.h>
#include <math.h>
int main()
{
  double x,y,x1,y1,x2,y2,a,b,c,z,s=0;
  scanf("%lf,%lf",&x,&y);
  scanf("%lf,%lf",&x1,&y1);
  while((scanf("%lf,%lf",&x2,&y2)) != EOF){
    a = sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1));
    b = sqrt((x-x2)*(x-x2) + (y-y2)*(y-y2));
    c = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
    z = (a+b+c)/2;
    s += sqrt(z * (z - a) * (z - b) * (z - c));
    x1 = x2;
    y1 = y2;
  }
  printf("%.6lf\n",s);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int sum = 1e9;
  for (int i = 0; i < 2; i++) {
    int cnt = 0;
    for (int j = 0; j < s.length(); j++) {
      if (j % 2 == 0) {
        if(s[j] != ('0' + i)) {
          cnt++;
        }
      } else {
        if(s[j] == ('0' + i)) {
          cnt++;
        }
      }
    }
    sum = min(sum, cnt);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	static String s;
	static char[] t;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		s = sc.next();
		t = s.toCharArray();
		long ans = 0;
		ans += dfs(0, "");
		System.out.println(ans);
	}

	public static long dfs(int n, String x) {
		if(n == s.length()) {
			x = x.replace("+", "A");
			String[] c = x.split("A");
			long sum = 0;
			for(int i = 0 ; i < c.length ; i++) {
				sum += Long.valueOf(c[i]);
			}
			return sum;
		}
		long ret =  0;
		ret += dfs(n + 1, x + t[n]);
		if(n != 0) ret += dfs(n + 1, x + "+" + t[n]);
		return ret;
	}

}


Measured memory_bytes: 25812
using System;

public class AtCoder
{
    public static void Main()
    {
        //問題
        //0以上の整数nに対し、f(n)を次のように定義します。
        //f(n)=1 (n<2のとき)
        //f(n)=nf(n−2) (n≥2のとき)
        //整数Nが与えられます。
        //f(N)を10進法で表記した時に末尾に何個の0が続くかを求めてください。
        //0≤N≤10^18

        //解法
        //Nが0もしくは奇数の場合、2が素因数に現れないので計算するまでもなく答えは0
        //Nが0より大きい偶数の場合、5の倍数の方が圧倒的に少ないので5の素因数の個数が答え
        var N = long.Parse(Console.ReadLine());
        if(N==0 || N % 2 == 1)
        {
            Console.WriteLine(0);
        }
        else
        {
            long count = 0;
            long ten = 10;
            while (N >= ten)
            {
                count += N / ten;
                ten *= 5;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
#define int long long int
#define double long double
using namespace std;
#define INT_MAX 1000000007
#define INF 1000000007
const int MAX_N = 1 << 17;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

signed main()
{
int h,w,k;
std::cin >> h >> w >> k;
std::vector<std::vector<int>> amida;
for(int i = 0; i < h; i++){
    std::vector<int> temp;
    for(int j = 0; j < w; j++){
        int tempi = 0;
        temp.push_back(tempi);
    }
    amida.push_back(temp);
}
std::vector<int> check(8,0);
check[0] = 1;
check[1] = 1;
check[2] = 2;
check[3] = 3;
check[4] = 5;
check[5] = 8;
check[6] = 13;
check[7] = 21;

if(w == 1){
    std::cout << 1 << std::endl;
} else {
int flagz = w - 2;
int flago = w - 3;
int f = w % 2;
amida[0][0] = check[w - 1];
amida[0][1] = check[w - 2];
for(int i = 1; i < h; i++){
    amida[i][0] = (amida[i - 1][0]*check[w - 1] % INF + amida[i - 1][1] * check[w - 2]%INF)%INF;
    amida[i][w - 1] = (amida[i - 1][w - 1]*check[w - 1] % INF + amida[i - 1][w - 2] * check[w - 2]%INF)%INF;
    for(int j = 1; j < w - 1; j++){
        amida[i][j] = (amida[i - 1][j - 1]*(check[j - 1]*check[w - 1 - (j)])%INF + amida[i - 1][j]*(check[j] * check[w - 1 - j]) % INF + amida[i - 1][j + 1]*(check[j]*check[w - 1 - (j + 1)])%INF) % INF;
    }
}
std::cout << amida[h - 1][k - 1] % INF << std::endl;
}
return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

bool U[10];

int main() {
    REP(i, 4) {
        ll a;
        cin >> a;
        U[a] = true;
    }

    if (U[1] && U[9] && U[7] && U[4])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

int main() {
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;
        queue<int> members;
        for (int i = 1; i <= n; i++) {
            members.push(i);
        }
        while (members.size() != 1) {
            int cnt = 0;
            while (true) {
                int member = members.front(); members.pop();
                cnt++;
                if (cnt == m) break;
                members.push(member);
            }
        }
        cout << members.front() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
    bool flag = true ;
    while(flag){
        int x, y ;
        cin >> x >> y ;
        if(x ==0 && y == 0){
            flag = false ;
        }
        else{
            if(x>y){
                int tmp ;
                tmp = x ;
                x = y ;
                y = tmp ;
            }
            cout << x <<" "<<y<<endl ;
        }
    }

  return 0 ;
}


Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// ll mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,temp,temp2,m,x,y,sum=0,o;
    double a;
    cin >> a;
    cout << 2*3.14159265*a;
        
}


Measured memory_bytes: 3804
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
int flag=0;
int main()
{
	cin>>n;
	int i,j;
	for(i=1;i<=9;i++)
	{
		for(j=1;j<=9;j++)
		{
			if(i*j==n)
			{
				flag=1;
				break;
			}
		}
	}
	if(flag)cout<<"Yes";
	else cout<<"No";
}

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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);


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

  vector<int> a(N);
  int sum = 0;
  for(int i = 0; i < N; i++) {
      cin >> a.at(i);
      sum += a.at(i);
  }

  sort(a.begin(), a.end(), greater<int>());

  double th = (double)sum / (4*M);
  for(int i = 0; i < M; i++) {
    if(a.at(i) < th) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,M,R;
double cx[2000],cy[2000],cz[2000],cr[2000],x[15],y[15],z[15],X,Y,Z,b[15];
int inter[2000];
int main(){
	while(true){
		cin>>N>>M>>R;
		if(N==0) break;
		rep(i,N) inter[i]=0;
		rep(i,N) cin>>cx[i]>>cy[i]>>cz[i]>>cr[i];
		rep(i,M) cin>>x[i]>>y[i]>>z[i]>>b[i];
		cin>>X>>Y>>Z;
		rep(j,M) b[j]/=( (X-x[j])*(X-x[j])+(Y-y[j])*(Y-y[j])+(Z-z[j])*(Z-z[j]) );
//		rep(j,M) show(b[j]);
		double ans=0;
		rep(i,N) rep(j,M){
			double A=(X-x[j])*(X-x[j])+(Y-y[j])*(Y-y[j])+(Z-z[j])*(Z-z[j]);
			double B=-2* ((X-x[j])*(X-cx[i])+(Y-y[j])*(Y-cy[i])+(Z-z[j])*(Z-cz[i]));
			double C=(X-cx[i])*(X-cx[i])+(Y-cy[i])*(Y-cy[i])+(Z-cz[i])*(Z-cz[i])-cr[i]*cr[i];
			double D=B*B-4*A*C;
			if(D<0) continue;
			for(int s=-1;s<=1;s+=2){
				double xx=(-B+s*sqrt(D))/(2.0*A);
				if(0<xx&&xx<1) inter[i]|=(1<<j);
			}
		}
//		rep(i,N) show(inter[i]);
		rep(i,1<<M){
			int a=0;
			rep(j,N) if(inter[j]&i) a++;
			if(a<=R){
				double tmp=0;
				rep(j,M) if((i>>j)&1) tmp+=b[j];
				chmax(ans,tmp);
			}
		}
		printf("%.12f\n",ans);
	}
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n; cin >> n;
    vi wh(n+1), bl(n+1);  // csum
    rep(i,n) {
        char ch; cin >> ch;
        if(ch=='#') bl[i+1] = 1;
        else wh[i+1] = 1;
        bl[i+1] += bl[i];
        wh[i+1] += wh[i];
    }
//    rep(i,n+1) cout << bl[i] << (i==n ? '\n' : ' ');
//    rep(i,n+1) cout << wh[i] << (i==n ? '\n' : ' ');

    int ans = inf;
    for(int bndry = 1; bndry < n; ++bndry) {
        chmin(ans, bl[bndry]-bl[0] + wh[n]-wh[bndry]);
    }
    chmin(ans, *--wh.end());
    chmin(ans, *--bl.end());
    cout << ans << '\n';

//    debug(cnt1);debug(cnt2);
    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}
 

int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n, m;
    cin>>n>>m;
    ll sum = 0;;
    for (int i = 0; i < m; i++){
        ll a;
        cin>>a;
        sum += a;
    }

    ll ans = (n-sum<0) ? -1 : n-sum;
    cout<<ans<<"\n";

    return 0;
}
 

Measured memory_bytes: 3164
N = int(input())
B = list(map(int, input().split()))
A = [0] * N
Ans = 0
A[0] = B[0]
A[N-1] = B[N-2]

for i in range(0,N-2):
  if B[i] >= B[i+1]:
    A[i+1] = B[i+1]
  else:
    A[i+1] = B[i]

for j in range(N):
  Ans = Ans + A[j]

print(Ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h == 0 && w == 0) {
                break;
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 33304
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    //freopen("E:\\Codes\\Problem\\C++\\AAA.txt", "r", stdin);
    //freopen("C:\\Users\\Dell\\Desktop\\Problem\\BBB.txt", "w", stdout);
	
	int arr[3],f5=0 , s7=0;
	for(int i=0 ; i<3 ; i++){
		cin>>arr[i];
	}
	
	for(auto it : arr){
		if(it==5)f5++;
		else if(it==7)s7++;
	}
	if(f5==2 && s7 ==1)
		cout<<"YES"<<endl;
	else{
		cout<<"NO"<<endl;
	}
}



Measured memory_bytes: 3572
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
#define MOD 1000000007
#define MAXE9 1000000000

int i, j, k, l;

int main(){
    int N=0;
    int swap=0;
    int tmp;
    int A[100];
    scanf("%d", &N);
    for(i=0;i<N;i++){
        scanf("%d", &A[i]);
    }
    for(i=0;i<N-1;i++){
        for(j=N-1;j>i;j--){
            if(A[j] < A[j-1]){
                tmp =A[j-1];
                A[j-1] = A[j];
                A[j] = tmp;
                swap++;
            }
        }
    }
    for(i=0;i<N;i++){
        printf("%d",A[i]);
        if(i<N-1) printf(" ");
    }
    printf("\n");
    printf("%d\n", swap);
}




Measured memory_bytes: 2104
N,M=map(int,input().split())
ac,wa=0,0
task=[0]*N
for m in range(M):
    p,S=input().split()
    p=int(p)-1
    if task[p]!=-1 and S=="WA":
        task[p]+=1
    elif task[p]!=-1 and S=="AC":
        ac+=1
        wa+=task[p]
        task[p]=-1
print(ac,wa)

Measured memory_bytes: 3828
//InTheNameOfGod
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
const int maxn =2e5+5 ;
ll n,a[maxn],s;
map<ll,int> mp;
ll re;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    mp[0]++;
    rep(i,0,n)
    {
        cin>>a[i];
        s+=a[i];
        re+=mp[s];
        mp[s]++;
    }
    cout<<re;
    return 0;
}


Measured memory_bytes: 14336
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M >> K >> Q;
	cout << max(N*M, K*Q) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int A[]=new int[3];
		
		for(int i=0;i<3;i++){
			A[i]=s.nextInt();
		}
		if(A[0]==5&&A[1]==7&&A[2]==5){
			System.out.print("YES");
		}else if(A[0]==5&&A[1]==5&&A[2]==7){
			System.out.print("YES");
		}else if(A[0]==7&&A[1]==5&&A[2]==5){
			System.out.print("YES");
		}else System.out.print("NO");
		
		
		

	}

}

Measured memory_bytes: 21844
import bisect as bs
l=int(input())
lst=sorted(list(map(int,input().split())))
n=lst[l-1]
lst[l-1]=float("inf")
m=bs.bisect_right(lst,n/2)
if n/2 - lst[m-1] <= lst[m] -n/2:
  print(n,lst[m-1])
else:
  print(n,lst[m])

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

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  
  if(S.size() <= N)
    cout << S << endl;
  else{
    for(int i=0; i<N; i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
  return 0;

}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iterator>
int main() {
  int n,i,x=0,y=0;
  std::cin>>n;
  int a[n] = {};
  for(i=0;i<n;++i) std::cin>>a[i];
  std::sort(a, a+n);
  for(i=n-1;i>=0;--i)(i%2==(n-1)%2?x:y) += a[i];
  std::cout<<x-y<<"\n";
}
    

Measured memory_bytes: 256
#include <stdio.h>
#define BCD(c) 5 * (5 * (5 * (5 * (5 * (5 * (5 * (c & 128) + (c & 64)) + (c & 32)) + (c & 16)) + (c & 8)) + (c & 4)) + (c & 2)) + (c & 1)

int main(void) {
        char nums[12];
        int len = 0;
        char numbuf;
        while(1) {
                numbuf = getchar();
                if (numbuf=='\n') break;
                nums[len] = numbuf - '0';
                len++;
        }
//      for (int i=0;i<len;i++) printf("%d",nums[i]);
//      printf("\n");
        long sum = 0;
        long sumbuf;
        long multiplier;
        for (int i=0;i<(1<<(len-1));i++) {
                multiplier = 1;
                sumbuf = nums[len-1];
                for (int j=0;j<=len-2;j++) {
                        if (i&(1<<j)) multiplier=1;
                        else multiplier *= 10;
                        sumbuf += nums[len-2-j] * multiplier;
                }
//              printf("%10d  %10ld\n", BCD(i), sumbuf);
                sum += sumbuf;
        }
        printf("%ld\n",sum);
        return 0;
}

Measured memory_bytes: 128
rig=[int(i) for i in input().split(" ")]
while True:
    ke=rig[0]+rig[1]
    ans=1
    count=10
    while True:
        if ke<count:
            print(ans)
            break
        else:
            ans+=1
            count=count*10
    try:rig=[int(i) for i in input().split(" ")]
    except:break

Measured memory_bytes: 7752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i= 0; i < n;i++) {
			int number = sc.nextInt();

			if(number % 2 == 0) {
				if(number % 3 ==0 || number % 5 ==0) {

				}else {
					System.out.println("DENIED");
					return;
				}
			}
		}
		System.out.println("APPROVED");
	}

}

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

#define rep(i,a,b) for(i=a;i<=b;i++)

int GCD(int a,int b){
	return a==0?b:GCD(b%a,a);
}

int main(){
	int maxi=0;
	int ffsum=0;
	int N,K,A,i;
	cin>>N>>K;
	bool otomat=false;
	rep(i,1,N){
		cin>>A;
		maxi=max(maxi,A);
		ffsum=GCD(ffsum,A);
		if(A==K){
			otomat=true;
		}
	}
	
	if((!(K%ffsum) && maxi>=K) || otomat){
		cout<<"POSSIBLE\n";
	}
	else{
		cout<<"IMPOSSIBLE\n";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int n;
  cin >> n;
  int ans;
  switch (n)
  {
    case 111:
      ans = 999;
      break;
    case 119:
      ans = 991;
      break;
    case 191:
      ans = 919;
      break;
    case 911:
      ans = 199;
      break;
    case 199:
      ans = 911;
      break;
    case 919:
      ans = 191;
      break;
    case 991:
      ans = 119;
      break;
    case 999:
      ans = 111;
      break;
    default:
      break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1e18 : 1e9;
const int MOD = 1000000007;
const long double EPS = 1e-8;

string n;
long long dp[20][2][1000][2];

long long rec(int k = 0, bool tight = true, int uesan = 0, bool flag = false) {
	if (k == n.size()) {
		return flag;
	}

	if (dp[k][tight][uesan][flag] != -1) {
		return dp[k][tight][uesan][flag];
	}

	int x = n[k] - '0';
	int r = (tight ? x : 9);
	long long res = 0;
	rep (i, r + 1) {
		res += rec(k + 1, tight && i == r, uesan / 10 % 10 * 100 + uesan % 10 * 10 + i,
							 flag || uesan / 100 == 5 && uesan /10 % 10 == 1 && i == 3);
	}
	return dp[k][tight][uesan][flag] = res;
}

signed main() {
	cin >> n;
	memset(dp, -1, sizeof(dp));
	cout << rec() << endl;
	return 0;
}


Measured memory_bytes: 3844
import java.util.*

fun main(args: Array<String>){
    val sc:Scanner= Scanner(System.`in`)
    var a:Int
    var b:Int
    var ans=true
    var adj = arrayOf(0,0,0,0,0)
    for(i in 1..3){
        a=sc.nextInt()
        b=sc.nextInt()
        adj[a]++
        adj[b]++
    }
    for(i in 1..4){
        if(adj[i]==3 || adj[i]==0){
            ans=false
        }
    }
    if(ans) println("YES")
    else println("NO")

}

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

int main() {
	int a,b;
	cin>>a>>b;
	if(a==2) {
		if(b==2) cout<<"Yes";
		else cout<<"No";
	}
	else if((a%2==1 && a<8) || (a%2==0 && a>7)) {
		if((b%2==1 && b<8) || (b%2==0 && b>7)) cout<<"Yes";
		else cout<<"No";
	}
	else if((a%2==0 && a<7) || (a%2==1 && a>8)) {
		if((b%2==0 && b<7) || (b%2==1 && b>8)) cout<<"Yes";
		else cout<<"No";
	}
	cout<<endl;
}

Measured memory_bytes: 256
N, A = map(int, raw_input().split())
x = [v - A for v in map(int, raw_input().split())]
dp = {}
def dfs(i, W):
    if i < 0:
        return int(W == 0)
    if (i, W) in dp:
        return dp[i, W]
    dp[i, W] = dfs(i-1, W) + dfs(i-1, W-x[i])
    return dp[i, W]
print dfs(N-1, 0) - 1

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

int main() {
  string a, b;
  cin >> a >> b;
  int x = stoi(a + b); //文字列を整数に変換

  for (int i = 1; i <= 1000; i ++) {
    if (i * i == x) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
main = do
  s <- getLine
  t <- getLine
  case solve s t of
    Nothing -> do
      putStrLn "UNRESTORABLE"
    Just u -> do
      putStrLn u

solve :: String -> String -> Maybe String
solve [] t = Nothing
solve s t =
  let this = if fit s t then Just (map (\x -> if x == '?' then 'a' else x) (t ++ (drop (length t) s))) else Nothing
      si = if head s == '?' then 'a' else head s
  in case solve (tail s) t of
    Just u -> case this of
      Nothing -> Just (si:u)
      Just r -> Just (min r (si:u))
    Nothing -> this

fit :: String -> String -> Bool
fit [] [] = True
fit (x:xs) [] = True
fit [] (x:xs) = False
fit (si:s) (ti:t) = if si == '?' || si == ti then fit s t else False


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll x1;
	cin>>x1;
	ll x = 180-x1;

	ll n = (360)/__gcd(180-x,360LL);
	cout<<n<<endl;
	// if(360 % (180-x) == 0){
	// 	cout<<360 / (180-x)<<endl;
	// }
	// else {
	// 	cout<<(360*(180-x))/__gcd(360LL,180-x)<<endl;
	// }
	return 0;
}

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

#define dump(a) cerr << #a << " " << a << endl
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using vi = vector<int>;

int main(){
  int n, m;
  while(cin >> n >> m, n){
    map<int, int> ans;
    rep(i,n){
      int d, v; cin >> d >> v;
      ans[d] = max(ans[d], v);
    }
    int num = 0;
    for(auto p : ans) num += p.second;
    cout << num << endl;
  }
}


Measured memory_bytes: 3104
#include <iostream>

using namespace std;
 
int main(){
    int A,B,C;
 
    cin >> A >> B >> C;

    for(int i = 1; i <= B; i++){
        if((A*i)%B == C){
            cout << "YES" << endl;
            exit(0);
        }
    }

    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 *   author: Shubham Srivastava
 *   created: 29 January 2019  01:56:22
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long long dp[100005][3] = {-1};
long long task[100005][3];

long long rec(long long n, long long i,long long flag)
{
	if(i == n)
		return 0;
	if(dp[i][flag] != -1)
		return dp[i][flag];
	long long ans;
	if(flag == 0)
	{
		ans = max(task[i][flag] + rec(n, i+1, 1), task[i][flag] + rec(n, i+1, 2));
	}
	else if(flag == 1)
	{
		ans = max(task[i][flag] + rec(n, i+1, 0), task[i][flag] + rec(n, i+1, 2));
	}
	else if(flag == 2)
	{
		ans = max(task[i][flag] + rec(n, i+1, 0), task[i][flag] + rec(n, i+1, 1));
	}
	dp[i][flag] = ans;
	return dp[i][flag];
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    long long n;
    cin>>n;
    for(int i=0;i<n;i++){
    	cin>>task[i][0]>>task[i][1]>>task[i][2];
    	dp[i][0] = -1; dp[i][1] = -1; dp[i][2] = -1;
    }
    cout<< max(rec(n, 0, 0), max(rec(n, 0, 1), rec(n, 0 ,2)));

return 0;
}

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

int main(){
    int n, h;
    cin >> n >> h;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    int max = a[n - 1];
    int id = n;
    for (int i = 0; i < n; i++){
        if(b[i] <= max){
            id = i;
            break;
        }
    }
    int ans = 0;
    for (int i = 0; i < id; i++){
        h -= b[i];
        ans++;
        if (h <= 0){
            break;
        }
    }
    if(h > 0){
        while(h > 0){
            h -= max;
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
    ll n;
    cin>>n;
    ll sum=0;
    for(int i=1; i<=n; i++){
        if(i%3==0){
            continue;
        }
        else if(i%5==0){
            continue;
        }
        else{
            sum+=i;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3624
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    sx,sy,tx,ty = LI()
    r = ''
    x = ty-sy
    y = tx-sx
    r += 'U'*x
    r += 'R'*y
    r += 'U'
    r += 'L'*(y+1)
    r += 'D'*(x+1)
    r += 'R'

    r += 'R'*y
    r += 'U'*x
    r += 'R'
    r += 'D'*(x+1)
    r += 'L'*(y+1)
    r += 'U'

    return r


print(main())


Measured memory_bytes: 6432
#from bisect import bisect_right
#from collections import deque
import itertools
import numpy as np

def main():
    H, W, K = tuple(int(c) for c in input().split())
    C = np.zeros((H,W))
    for h in range(H):
        line = input()
        for w in range(len(line)):
            if line[w]=='#':
                C[h,w] = 1
    #bit全探索
    ans = 0
    for p_h in itertools.product([True,False], repeat=H):
        for p_w in itertools.product([True,False], repeat=W):
            C_t = C.copy()
            C_t[p_h, :] = 0
            C_t[:, p_w] = 0
            if C_t.sum() == K:
                #print(C_t)
                ans += 1
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 27172
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
using namespace std;
long long int check[15] = { 1,1,1,1,1,1,1,1,1,1,1,1,1 };
long long int d, g, p[15] = {}, c[15] = {},in=999999999;

int che(long long int n, long long int num) {
	for (int i = 0; i < n; i++) {
		if (num == check[i]) { return 0; }
	}
	return 1;
}
void select(long long int time, long long int ac, long long int nokori) {
	for (int i = 1; i <= d; i++) {
		if (che(time,i) == 1) {
			check[time] =i ;
			if (nokori <= 100 * i*p[i] + c[i]) {
				if (nokori <= 100 * i*p[i]) {
					if (ac + ((nokori-1) / (100 * i))+1 < in) {
						in = ac + ((nokori-1) / (100 * i)) + 1;
					}
				}
				else {
					if (ac +p[i] < in) {
						in = ac + p[i];
					}
				}
			}
			else {

				select(time+1,ac + p[i], nokori - (100 * i*p[i] + c[i]));
			}
		}
	}
}
int main() {
	
	cin >> d >> g;
	for (int i = 1; i <= d; i++) {
		cin >> p[i] >> c[i];
	}
	select(0,0, g);
	cout << in;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
//#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

signed main() {
  int h,w; cin >> h >> w;
  vector<string> a(h);
  rep(i,h) cin >> a[i];
  map<char,int> count;
  rep(i,h) for(auto &c:a[i]) count[c]++;

  bool hodd=h%2, wodd=w%2;
  if(h==1 && w==1) {
    puts("Yes");
  }
  else if((h==1 && wodd) || (hodd && w==1)) {
    bool odd_=false;
    for(auto [k,v] : count) {
      if(v%2) {
        if(odd_) {
          puts("No");
          return 0;
        }
        odd_=true;
      }
    }
    puts("Yes");
  }
  else if((h==1 && !wodd) || (!hodd && w==1)) {
    for(auto [k,v] : count) {
      if(v%2) {
        puts("No");
        return 0;
      }
    }
    puts("Yes");
  }
  else if(hodd != wodd) {
    int ok2 = hodd ? w/2 : h/2;
    int n2 = 0;
    for(auto [k,v] : count) {
      if(v%2) {
        puts("No");
        return 0;
      }
      else if(v%4) {
        n2++;
        if(n2 > ok2) {
          puts("No");
          return 0;
        }
      }
    }
    puts("Yes");
  }
  else if(hodd && wodd) {
    bool odd_=false;
    int ok2 = (h+w-2)/2;
    int n2 = 0;
    for(auto [k,v] : count) {
      if(v%2) {
        if(odd_) {
          puts("No");
          return 0;
        }
        odd_=true;
      }
      else if(v%4) {
        n2++;
        if(n2 > ok2) {
          puts("No");
          return 0;
        }
      }
    }
    puts("Yes");
  }
  else {// if(!hodd && !wodd)
    for(auto [k,v] : count) {
      if(v%4) {
        puts("No");
        return 0;
      }
    }
    puts("Yes");
  }
}


Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {
	public static void main(String args[]) {

		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int m = sc.nextInt();

		Queue<Integer> q = new PriorityQueue<Integer>(Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			q.add(sc.nextInt());
		}

		for (int i = 0; i < m; i++) {
			q.add(q.poll() / 2);
		}
		System.out.println(q.stream().mapToLong(val -> Integer.toUnsignedLong(val)).sum());
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
            return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
            }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
            }
        }

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
        }

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 30652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>=13){
    cout<<b<<endl;
    return 0;
  }
  else if(a>=6&&12>=a){
    cout<<b/2<<endl;
    return 0;
  }
  else {
    cout<<0<<endl;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define PI 3.14159265358979323846264338327
#define NUM 1000000007
#define ss second
#define ff first
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	int n, k;
	string s;
	cin >> n >> k;
	//getline(cin >> ws, s);
	double chance = 0;
	for (int i = 1; i <= n; i++){
		int r = 0;
		int t = i;
		while (t < k){
			t *= 2;
			r++;
		}
		chance += (double) 1.0 / n * pow(0.5, r);
		//cout << r << "\n";
	}
	cout << fixed << setprecision(20) << chance <<"\n";
	
	//cout << s << "\n";
	return 0;
}

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

using namespace std;
  int A, B, C, D;
void pre(){
    int X = (A + D - 1) / D;
  int Y = (C + B - 1) / B;
  
  cout << (X >= Y ? "Yes" : "No") << "\n";
  
}
int main (){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);

  cin >> A >> B >> C >> D;
  
  pre();
  
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int fact(int i){
    if(i == 0) return 1;
    if(i == 1) return 1;
    else return i*fact(i-1);
}
int main()
{
    int N;
    int P[10];
    int Q[10];
    
    cin >> N;
    
    for(int i=0; i<N; i++){
        cin >> P[i];
    }
    for(int i=0; i<N; i++){
        cin >> Q[i];
    }
    
    int p_count=1;
    for(int i=0; i<N; i++){
        int counter=0;
        for(int j=i; j<N; j++){
            if(P[i]>P[j]) counter++;
        }
        if(counter>0){
            p_count += counter*fact(N-i-1);
        }
    }
    int q_count=1;
    for(int i=0; i<N; i++){
        int counter=0;
        for(int j=i; j<N; j++){
            if(Q[i]>Q[j]) counter++;
        }
        if(counter>0){
            q_count += counter*fact(N-i-1);
        }
    }
    
    cout << abs(p_count-q_count) << endl;
    return 0;
}


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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, a[125252];
	cin>>n;
	int sum=0;
	REP(i, n){
		cin>>a[i];
		sum+=abs(a[i]);
	}
	if(n==2){
		if((a[0]-a[1])<(a[1]-a[0])){
			cout<<a[1]-a[0]<<'\n';
			cout<<a[1]<<' '<<a[0]<<'\n';
		}
		else{
			cout<<a[0]-a[1]<<'\n';
			cout<<a[0]<<' '<<a[1]<<'\n';
		}
		return 0;
	}
	sort(a, a+n);
	if(a[n-2]>=0 && a[n-1]>=0){
		if(a[0]>=0){
			cout<<sum-2*a[0]<<'\n';
		}
		else{
			cout<<sum<<'\n';
		}
		int tmp=0;
		cout<<a[0]<<' '<<a[n-1]<<'\n';
		tmp=a[0]-a[n-1];
		int idx=0;
		FORR(i, 1, n-2){
			if(a[i]<0){
				idx=i;
				break;
			}
			cout<<tmp<<' '<<a[i]<<'\n';
			tmp-=a[i];
		}
		cout<<a[n-2]<<' '<<tmp<<'\n';
		tmp=a[n-2]-tmp;
		FOR(i, 1, idx+1){
			cout<<tmp<<' '<<a[i]<<'\n';
			tmp-=a[i];
		}
	}
	else if(a[n-1]>=0){
		cout<<sum<<'\n';
		cout<<a[n-1]<<' '<<a[0]<<'\n';
		int tmp=a[n-1]-a[0];
		FOR(i, 1, n-1){
			cout<<tmp<<' '<<a[i]<<'\n';
			tmp-=a[i];
		}
	}
	else{
		cout<<sum+2*a[n-1]<<'\n';
		int tmp=0;
		cout<<a[n-1]<<' '<<a[n-2]<<'\n';
		tmp=a[n-1]-a[n-2];
		FORR(i, 0, n-2){
			cout<<tmp<<' '<<a[i]<<'\n';
			tmp-=a[i];
		}
	}
	return 0;
}


Measured memory_bytes: 2304
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 100005

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

int main()
{
	ll a,b,c;
	scanf("%lld %lld %lld",&a,&b,&c);
	printf("%lld\n",min(c,a+b+1)+b);
	return 0;
}


Measured memory_bytes: 128
//
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false)
using namespace std;

string gs(char x){
    string s(1,x);
    return s;
}

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

	if(a>8 ||b>8)
		cout<<":(";
	else
		cout<<"Yay!";




	
	return 0;
}

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

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> vec(h);
  for (auto &v : vec)
    cin >> v;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (vec[i][j] == '.')
        vec[i][j] = '0';
      if (vec[i][j] != '#')
        continue;
      for (int k = 0; k < 3; ++k) {
        for (int l = 0; l < 3; ++l) {
          if (k == 1 && l == 1)
            continue;
          int x = i - 1 + k;
          int y = j - 1 + l;
          if (x < 0 || h <= x || y < 0 || w <= y || vec[x][y] == '#')
            continue;
          if (vec[x][y] == '.')
            vec[x][y] = '1';
          else
            vec[x][y] = char(int(vec[x][y] - '0' + 1) + '0');
        }
      }
    }
  }

  for (auto &v : vec)
    cout << v << endl;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1e18;

int main() {
  ll n,k;
  cin >> n >> k;
  n%=k;
  cout << min(n,k-n) << endl;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    int m = 100001;
    vi imos(m+1, 0), sum(m+1, 0), rsum(m+1, 0);
    vp data(n);
    rep(i, n) {
        int2(a, b);
        a--; b--;
        data[i].fir = a; data[i].sec = b;
        imos[a]++; imos[b]--;
        sum[b]++; rsum[a]++;
    }

    Rep(i, imos.size()) {
        imos[i] += imos[i-1];
        sum[i] += sum[i-1];
    }

    for (int i = rsum.size()-1; i > 0; i--) {
        rsum[i-1] += rsum[i];
    }

    int ans = 0;
    rep(i, n) {
        ans = max(ans, n - rsum[data[i].sec] - sum[data[i].fir]);
    }

    cout << ans << " " << *max_element(all(imos)) << endl;



    return 0;
}



Measured memory_bytes: 8272
import math
a,b,C=map(int,input().split())

h=b*math.sin(math.radians(C))
S=a*h*(1/2)
L=a+b+math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(math.radians(C)))
print(f'{S:.5f}')
print(f'{L:.5f}')
print(f'{h:.5f}')



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

const int maxn = 1000010, P = 1000000007;
int n, f[maxn];

int main() {
    scanf("%d", &n);
    f[1] = n, f[2] = 1LL * n * n % P;
    for (int i = 3, s = 0; i <= n; i++) {
        (s += f[i - 3]) %= P;
        f[i] = (f[i - 1] + s + 1LL * (n - 1) * (n - 1) + n - i + 2) % P;
    }
    printf("%d\n", f[n]);
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
	string s;
  cin >> s;
  int d = s.size()/2;
  string l,r;
  rep(i,d) {
    l += s[i];
  }
  for(int i=s.size()-1; i>=d; --i){
    r += s[i];
  }
  int cnt = 0;
  rep(i,d) {
    if (l[i] != r[i]) cnt++;
  }
  cout << cnt << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>

#include <sstream>
const int MOD = 1000000007;
using namespace std;

int main()
{
    int n;
    cin >> n;
    auto data = vector<int>(n, 0);
    for (int i = 0; i < n; i++) {
        scanf("%d", &data[i]);
    }

    vector<int> ans;
    for (int i = 0; i < n; i++) {
		int x=MOD-data[i];
		auto it=upper_bound(ans.begin(),ans.end(),x);
		if (it==ans.end()) ans.push_back(x);
		else *it=x;
    }
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 1276
import sys
sys.setrecursionlimit(100000000)
n=int(input())
ab=[]
root=[[] for i in range(n)] 
for i in range(n-1):
    a,b=map(int,input().split())
    root[a-1].append((i,b-1))
    root[b-1].append((i,a-1))
c=0
for i in range(n):
    c=max(c,len(root[i]))
print(c)
color=[0]*(n-1)

def dfs(node,par,c):
    if c!=1:
        i=1
    else:
        i=2
    for idx,x in root[node]:
        if x==par:
            continue
        if color[idx]==0:
            color[idx]=i
            dfs(x,node,i)
            i+=1
            if i==c:
                i+=1
dfs(0,-1,0)
for i in range(n-1):
    print(color[i])

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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin>>n>>k;
    
    int a[n+1];
    f1(i,1,n+1)
    cin>>a[i];

    int ans = 0;
    int temp = 0, curr = 1;

    int vis[n+1];
    memset(vis, -1, sizeof vis);
    vis[1] = 0;
    int cyc = -1,start = -1, base = -1;
    while(1)
    {
        curr = a[curr];
        temp++;
        if(temp == k)
        {
            cout<<curr<<endl;
            return 0;
        }
        else if(curr == a[curr])
        {
            cout<<curr<<endl;
            return 0;
        }
        if(vis[curr] >= 0)
        {
            k -= (vis[curr]);
            base = vis[curr];
            cyc = temp - vis[curr];
            start = curr;
            break;
        }
        vis[curr] = temp;
    }
    k %= cyc;

    f1(i,1,n+1)
    if(vis[i] == base + k) cout<<i<<endl;

    return 0;
}

Measured memory_bytes: 6744