akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	A := make([][]int, N)
	b := make([][]int, N)
	for i := 0; i < N; i++ {
		A[i] = ReadInts(N)
		b[i] = append([]int{}, A[i]...)
	}
	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				if k == i || k == j {
					continue
				}
				if A[i][k]+A[k][j] < A[i][j] {
					fmt.Println(-1)
					return
				}
				if A[i][k]+A[k][j] == A[i][j] {
					b[i][j] = 0
				}
			}
		}
	}
	ans := 0
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			ans += b[i][j]
		}
	}
	fmt.Println(ans)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 4936
#include<stdio.h>
#include<algorithm>

#define MAX 1000
#define WMAX 10000

int main() {
    int n;
    int A[MAX], B[MAX], V[MAX], T[WMAX+1];

    scanf("%d", &n);
    int min = WMAX;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
        B[i] = A[i];
        V[i] = false;
        min = std::min(min, A[i]);
    }
    std::sort(B, B+n);
    for (int i = 0; i < n; ++i) T[B[i]] = i;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (V[i]) continue;

        int cur = i;
        int num = 0;
        int sum = 0;
        int m = WMAX;
        while (true) {
            V[cur] = true;
            num++;
            sum += A[cur];
            m = std::min(m, A[cur]);
            cur = T[A[cur]];
            if (V[cur]) break;
        }
        ans += std::min(sum + (num - 2) * m, sum + (num - 2) * m + (m + min) * 2 - (m - min) * (num - 1));
    }
    printf("%d\n", ans);

    return 0;
}

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

using namespace std;

const int ms = 311;

int memo[ms][ms][ms][2];

string s;

int dp(int k, int l, int r, int b) {
  if (l == s.size() or r < 0) return 0;
  if (r - l + 1 == b) return 0;
  if (r - l + 1 < b) return -10000;
  int &ans = memo[k][l][r][b];
  if (ans != -1) return ans;
  ans = max(dp(k, l + 1, r, b), dp(k, l, r - 1, b));
  ans = max(ans, 0);
  if (s[l] == s[r] and l < r) ans = max(ans, 1 + dp(k, l + 1, r - 1, b));
  if (k and l < r) ans = max(ans, 1 + dp(k - 1, l + 1, r - 1, b));
  // cout << k << ' ' << l << ' ' << r << ' ' << b << ' ' << ans << endl;
  return ans;
}

int main() {
  cin >> s;
  int k;
  cin >> k;
  int ans = 0;
  if (k >= s.size() / 2) ans = s.size();
  memset(memo, -1, sizeof memo);
  ans = max(ans, 2 * dp(k, 0, s.size() - 1, 0));
  ans = max(ans, 2 * dp(k, 0, s.size() - 1, 1) + 1);
  cout << min(ans, (int)s.size()) << endl;
}


Measured memory_bytes: 235392
#include<iostream>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
using namespace std;

int main(){
    int n,q;
    vector<int> a(100001,0);
    int inp;
    long long int wa=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> inp;
        a.at(inp)++;
        wa+=inp;
    }
    // cout << "a" << endl;
    cin >> q;
    int inpb,inpc;
    for(int i=0;i<q;i++){
        cin >> inpb >> inpc;
        wa+= a.at(inpb)*(inpc-inpb);
        cout << wa << endl;
        a.at(inpc)+=a.at(inpb);
        a.at(inpb)=0;
    }
    
    
    
    return 0;

}

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

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

  vector<int> data(N);
  int counter = 0;

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

  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());

  for(int i = 0;i < K;i++){
    counter += data.at(i);
  }

  cout << counter << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

P = [[0] * n for i in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    P[a-1][b-1] = 1
    P[b-1][a-1] = 1

#dp[S][v] := 頂点０から出発し、集合Sに含まれる頂点を全て訪れるpathのうち、頂点vが最後になるようなpathの総数
dp = [[0] * n for _ in range(1 << n)]

#dpの初期化 dp({0}, 0) = 1
dp[1][0] = 1

for S in range(1 << n):
    for v in range(n):
        #vがSに含まれていないときはパスする
        if S & (1 << v) == 0:
            continue
        
        #sub = S - {v}
        sub = S ^ (1 << v)
        
        for u in range(n):
            #subにuが含まれており、かつuとvが辺で結ばれている
            if sub & (1 << u) and P[u][v]:
                dp[S][v] += dp[sub][u]

ans = sum(dp[(1 << n) - 1][u] for u in range(1, n))
print(ans)

Measured memory_bytes: 39920
import java.io.InputStreamReader;
import java.io.LineNumberReader;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_C
 * 
 * @author eitatsuro
 * 
 */
public class Main {
    private final static String SPACE = " ";
    public static void main(String[] args) {
        try {
            LineNumberReader stdReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            int r = 0;
            int c = 0;
            int an[] []= null;

            while ((sStr = stdReader.readLine()) != null) {
                // ??\???????????°
                if (stdReader.getLineNumber() == 1) {
                    String[] inputs = sStr.split(SPACE);
                    r = Integer.valueOf(inputs[0]);
                    c = Integer.valueOf(inputs[1]);
                    
                    // r??? x c?????????????¢????
                    // ??????????´???¨????´?????¢????.
                    an = new int[r+1][c+1];
                }

                // ???????????????
                // 0, 1, 2, 3, ....   x  0, 1, 2, 3, ... (0??????????????°??????)
                if (stdReader.getLineNumber() >= 2){
                    String[] matrix_row = sStr.split(SPACE);
                    int i = 0;
                    int row = stdReader.getLineNumber() - 2;
                    for (String temp : matrix_row) {
                        an[row][i] = Integer.valueOf(temp);
                        i++;
                    }
                    
                    if (stdReader.getLineNumber() == r+1) break;
                }

            }


            // ??¢????????????????¨????
            for (int i = 0; i<r; i++){
                int sumOfRow = 0;
                for (int j = 0; j<c; j++){
                    sumOfRow += an[i][j];
                }
                an[i][c] = sumOfRow;
            }

            for (int i = 0; i<=c; i++){
                int sumOfColumn = 0;
                for (int j = 0; j<r; j++){
                    sumOfColumn += an[j][i];
                }
                an[r][i] = sumOfColumn;
            }
            
            
            // ????????????
            for (int[] r_temp : an) {
                int i = 0;
                for (int c_temp : r_temp) {
                    System.out.print(c_temp );
                    if (i <c) {
                        System.out.print(SPACE);
                    }
                    i++;
                }
                System.out.println();
            }

            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    }
}

Measured memory_bytes: 33816
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n); i++)
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  scanf("%d",&N);
  int t[N+5],x[N+5],y[N+5];
  t[0] =0;
  x[0] = 0;
  y[0] = 0;
  for(int i = 1;i<N+1;++i){
    scanf("%d",&t[i]);
    scanf("%d",&x[i]);
    scanf("%d",&y[i]);
  }
  
  bool can = true;
  for(int i = 0;i<N;++i){
    if((x[i+1]-x[i] + y[i+1] - y[i]) > (t[i+1]-t[i])) can = false;
    if(((abs(x[i+1]-x[i] + y[i+1] - y[i]))%2) != (t[i+1]-t[i])%2) can = false;
  }
  if(can) printf("Yes\n");
  else printf("No\n");
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}

int main(){
    dcl(n);
    vi d(n);
    geti(d);
    int s=accumulate(all(d),0);
    sort(all(d));
    int diff=0;
    for(auto i:d){
        if(i%10){
            diff=i;
            break;
        }
    }
    cout<<(s%10==0?diff?s-diff:0:s)<<endl;
}


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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> Interval;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){
    os << v.first <<" "<<v.second<<endl;
    return os;
}

const int maxn = 1e5+5;
vector<int> G[maxn];
int N;

int solve(int u){
    if(G[u].size() == 0){
        return 0;
    }
    vector<int> vi;
    for(auto v:G[u]){
        vi.push_back(solve(v));
    }
    sort(ALL(vi),greater<int>());
    //cout << vi << endl;
    _for(i,0,vi.size()){
        vi[i] += (i+1);
    }
    return *max_element(ALL(vi));

}

int main()
{
    cin >> N;
    _rep(i,2,N){
        int num;
        scanf("%d",&num);
        G[num].pb(i);
    }

    cout << solve(1) << endl;

    return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    ll n, k;
    cin >> n >> k;

    ll sum_big[n+2], sum_small[n+2];
    sum_big[0] = sum_small[0] = 0;

    rep(i, n){
        sum_big[i+1] = sum_big[i] + n-i;
        sum_small[i+1] = sum_small[i] + i;
    }

    sum_big[n+1] = sum_small[n+1] = sum_big[n];

    ll ans = 0;
    for(ll i = k; i <= n+1; ++i){
        ans = (ans + (sum_big[i] - sum_small[i]) + 1) % MOD;
    }

    cout << ans << endl;

}

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

int main(){

  string a,s,t;
  char b;
  int n,an=0;
  cin >> s>>t;
  n=s.length();
  for(int i=0;i<n;i++){
    a=t.substr(0,n-1);
    b=t[n-1];
    t[0]=b;
    t = b + a;
    // for(int i=1;i<n;i++){
    //   t[i]=a[i-1];
    // }
    if(s==t){
      an++;
      cout << "Yes" << endl;
      break;
    }

  }
  if(an==0){
    cout << "No" << endl;
  }
  return 0;


}


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

bool map[8][8];

void bomb(int x, int y) {
  map[x][y] = false;
  for (int xx=x-3; xx<=x+3; xx++) {
    if (xx<0) continue;
    if (xx>=8) break;
    if (map[xx][y]) bomb(xx, y);
  }
  for (int yy=y-3; yy<=y+3; yy++) {
    if (yy<0) continue;
    if (yy>=8) break;
    if (map[x][yy]) bomb(x, yy);
  }
}

int main() {
  int nds, x, y;
  char buf[10];

  scanf("%d", &nds);
  for (int i=1; i<=nds; i++) {
    for (int j=0; j<8; j++) {
      scanf("%s", buf);
      for (int k=0; k<8; k++) {
        map[j][k] = buf[k] - '0';
      }
    }
    scanf("%d %d", &x, &y);
    --x; --y;
    bomb(y, x);
    printf("Data %d:\n", i);
    for (int j=0; j<8; j++) {
      for (int k=0; k<8; k++) {
        printf("%d", (map[j][k] ? 1 : 0));
      }
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 1032
<?php
while ($input = fgets(STDIN)){
    $array[]  = trim($input);
}
$arrayed = explode(" ",$array[1]);
$count   = 0;
$N_count = $array[0];
for ($i=0;$i<$N_count;$i++){
    $n = $i*2;
    if ($N_count < $n){
        break;
    }
    $number = $arrayed[$n];
    if ($number%2 == 1){
        $count++;
    }
}

echo $count;
?>

Measured memory_bytes: 16192
#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 main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  vector<int> x,y;
  
  for(int i=0;100*a*i<=f;i++){
    for(int j=0;100*a*i+100*b*j<=f;j++){
      x.push_back(100*a*i+100*b*j);
    }
  }
  for(int i=0;c*i<=f;i++){
    for(int j=0;c*i+d*j<=f;j++){
      y.push_back(c*i+d*j);
    }
  }
  
  int x_len=x.size(),y_len=y.size();
  int X=100*a,Y=0;
  REP(i,x_len){
    REP(j,y_len){
      if(Y*(x[i]+y[j])<y[j]*(X+Y) && x[i]+y[j]<=f && 100*y[j]<=e*x[i]){
        X = x[i];
        Y = y[j];
      }
    }
  }
  cout<<X+Y<<' '<<Y<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include<stdio.h>

int main(void){
  int n,k; 
  int digits,m,power;
  int i = 0;
  
  scanf("%d %d", &n, &k);
  
  power = k;
  
  while(1){
    m = n / power;
    if(m >= 1)  power *= k;
    else break;
    i++;
  }
  
  digits = i + 1;
  
  printf("%d\n", digits);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

struct Vector2{
	double x;
	double y;
};

Vector2 rotate(Vector2 v){
	Vector2 vec;
	vec.x = -v.y;
	vec.y = v.x;
	return vec;
}

Vector2 shape[100][20];

Vector2 shape_origin[10][20];

int main(){
	
	int m_copy, n, m_origin;
	
	while(true){
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		for(int loop = 0; loop <= n; loop++){
			int x1_, y1_, x2_, y2_;
			if(loop == 0){
				cin >> m_origin;
				cin >> x1_ >> y1_;
				for(int i = 0; i < m_origin - 1; i++){
					cin >> x2_ >> y2_;
					shape_origin[0][i].x = x2_ - x1_;
					shape_origin[0][i].y = y2_ - y1_;
					x1_ = x2_;
					y1_ = y2_;
				}
				for(int num = 1; num <= 3; num++){
					for(int i = 0; i < m_origin - 1; i++){
						shape_origin[num][i] = rotate(shape_origin[num - 1][i]);
					}
				}
				for(int num = 4; num <= 7; num++){
					for(int i = 0; i < m_origin - 1; i++){
						shape_origin[num][i].x = -shape_origin[num - 4][m_origin - 2 - i].x;
						shape_origin[num][i].y = -shape_origin[num - 4][m_origin - 2 - i].y;
					}
				}
				/*
				for(int num = 0; num <= 7; num++){
					printf("%d\n", num);
					for(int i = 0; i < m_origin - 1; i++){
						printf("%f %f\n", shape_origin[num][i].x, shape_origin[num][i].y);
					}
				}
				*/
			}else{
				cin >> m_copy;
				cin >> x1_ >> y1_;
				for(int i = 0; i < m_copy - 1; i++){
					cin >> x2_ >> y2_;
					shape[loop][i].x = x2_ - x1_;
					shape[loop][i].y = y2_ - y1_;
					x1_ = x2_;
					y1_ = y2_;
				}
				if(m_copy != m_origin){
					continue;
				}
				bool checker = false;
				for(int num = 0; num <= 7; num++){
					for(int i = 0; i < m_copy - 1; i++){
						if(shape[loop][i].x != shape_origin[num][i].x || shape[loop][i].y != shape_origin[num][i].y){
							break;
						}
						if(i == m_copy - 2){
							checker = true;
						}
					}
				}
				if(checker){
					printf("%d\n", loop);
				}
			}
		}
		printf("+++++\n");
	}
	
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

struct Trie{
  struct node{
    vector<node*> ch;
  public:
    int count;
    node(){
      ch=vector<node*>(26,NULL);
      count=0;
    }
  };
  node* root;
  string dfs(node* now){
    string s="";
    rep(i,26){
      if(now->ch[i]!=NULL){
        if(now->ch[i]->count>1){
          string t = string(1,'A'+i)+dfs(now->ch[i]);
          if(s.length()<t.length()){
            s=t;
          }
        }
      }
    }
    return s;
  }
  void edfs(node* now){
    rep(i,26){
      if(now->ch[i]!=NULL){
        edfs(now->ch[i]);
      }
    }
    delete now;
  }
public:
  Trie(){
    root = new node;
  }
  void add(string &s){
    node* now = root;
    int n = s.length();
    rep(i,n){
      if(now->ch[s[i]-'A']==NULL){
        now->ch[s[i]-'A'] = new node;
      }
      now=now->ch[s[i]-'A'];
      now->count++;
    }
  }
  string solve(){
    return dfs(root);
  }
  ~Trie(){
    edfs(root);
  }
};

int main(){
  vector<int> vx={-1,-1,-1,0,0,1,1,1};
  vector<int> vy={-1,0,1,-1,1,-1,0,1};
  while(1){
    int h,w;
    cin >> h >> w;
    if(h==0) return 0;
    vector<string> f(h);
    rep(i,h) cin >> f[i];
    Trie tr;
    rep(i,h){
      rep(j,w){
        rep(k,8){
          vector<vector<bool>> usd(h,vector<bool>(w,false));
          string s;
          int nx=i,ny=j;
          while(!usd[nx][ny]){
            usd[nx][ny]=true;
            s.push_back(f[nx][ny]);
            nx=(nx+vx[k]+h)%h,ny=(ny+vy[k]+w)%w;
          }
          tr.add(s);
        }
      }
    }
    string ans = tr.solve();
    if(ans.length()<=1) cout << 0 << endl;
    else cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 40972
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort()
negative = deque([])
positive = deque([])

for n in A:
    if n < 0:
        negative.append(n)
    else:
        positive.append(n)

output = N-1

if negative and positive:
    print(abs(sum(negative)) + sum(positive))
elif not negative:
    print(sum(positive)-positive[0]*2)
    x = positive.popleft()
    y = positive.popleft()
    print(x, y)
    negative.append(x-y)
    output -= 1
else:
    print(abs(sum(negative)-negative[-1]*2))
    x = negative.pop()
    y = negative.pop()
    print(x, y)
    positive.append(x-y)
    output -= 1

for i in range(output):
    if len(negative) >= 2:
        y = negative.pop()
        x = positive.pop()
        print(x, y)
        positive.append(x-y)
    elif len(positive) >= 2:
        x = negative.pop()
        y = positive.pop()
        print(x, y)
        negative.append(x-y)
    else:
        print(positive.pop(), negative.pop())


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;
const int MAX = 1e5 + 1;
int prime[MAX];

using namespace std;

void era()
{
  prime[0] = prime[1] = 0;
  rep (i, 2, MAX)
    prime[i] = 1;

  rep (i, 2, MAX) {
    if (prime[i] == 1) {
      for (int j = i + 1; j < sqrt(MAX); j++) {
        if (j % i == 0)
          prime[j] = 0;
      }
    }
  }
}

bool judge(int x)
{
  if (x < 2)
    return false;

  rep (i, 2, x) {
    if (x % i == 0)
      return false;
  }
  return true;
}

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

  int x;
  cin >> x;

  era();

  rep (i, x, INF) {
    if (judge(i)) {
      cout << i << endl;
      break;
    }
  }

	return 0;
}


Measured memory_bytes: 640
#include <set>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <bitset>
#define ll long long
#define inf 0x3f3f3f3f
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
int a, b, c;
int main(void) {
    char n[1000];
    scanf("%s", n);
    int len = strlen(n);
    bool flag = 0;
    for(int i = 0; i < len/2; ++i) {
        if(n[i] != n[len-i-1]) {
            flag = 1;
            break;
        }
    }
    if(!flag) cout <<"Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  ll ans=MAXL,c=0,d=0;
  rep(i,n) d+=a[i];
  rep(i,n-1) {
    d-=a[i];
    c+=a[i];
    ans=min(ans,abs(d-c));
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <tuple> 
#include<memory>

using namespace std;

int main() {
	char first[4];
	char second[4];
	char third[4];
	cin >> first;
	cin >> second;
	cin >> third;

	cout << first[0];
	cout << second[1];
	cout << third[2];

	return 0;
}

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

#define int long long

using namespace std;

int a[100001];

 main () {   
 	int n;
 	cin >> n;
 	for (int i = 1;i <= n;i ++) cin >> a[i];
 	int odd = 0;
 	int even = 0;
 	for (int i = 1;i <= n;i ++) {
 		if (a[i] % 2) odd ++;
 		else even ++;
 	}        
 	if (odd % 2) cout << "NO";
 	else cout << "YES";
    return 0;           		
}

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

char incrementChar(char x){
    return static_cast<char>(x + 1);
}

int weekToInt(string x){
    int num;
    if(x == "SUN"){
        num = 1;
    }else if(x == "MON"){
        num = 2;
    }else if(x == "TUE"){
        num = 3;
    }else if(x == "WED"){
        num = 4;
    }else if(x == "THU"){
        num = 5;
    }else if(x == "FRI"){
        num = 6;
    }else if(x == "SAT"){
        num = 7;
    }else{
        num = 0;
    }

    return num;
}

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

    int ans = 0;
    for(int i=0; i<(int)S.size(); i++){
        if(S[i] == T[i]) ans += 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

bool mergiable(P a, P b) {
    return (a.se >= b.fi);
}

P merge(P a, P b) {
    return (make_pair(b.fi, min(a.se, b.se)));
}

int main() {
    int a, b;
    cin >> a >> b;
    vector<P> c;
    c.resize(b);
    REP(i, b) {
        int d, e;
        cin >> d >> e;
        c[i] = make_pair(d, e -1);
    }
    sort(ALL(c));
    int ans = 1;
    P d = c[0];
    REP(i, b) {
        if(mergiable(d, c[i])) {
            d = merge(d, c[i]);
        } else {
            ans++;
            d = c[i];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <string>

using namespace std;

const int maxn = 100000 + 50;
int N, A[maxn];

int bi_search_lb(int target) {
	int lp = 0, rp = N - 1;
	while (lp < rp) {
		int mid = lp + (rp - lp) / 2;
		if (A[mid] >= target)
			rp = mid;
		else
			lp = mid + 1;
	}
	return lp;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];

	sort(A, A + N);
	int mid = A[N - 1] / 2;

	int dist = 0x7fffffff, res = -1;
	for (int i = 0; i < N - 1; i++) {
		if (abs(mid - A[i]) < dist) {
			res = i;
			dist = abs(mid - A[i]);
		}
	}

	if (A[N - 1] % 2) {
		mid += 1;
		for (int i = 0; i < N - 1; i++) {
			if (abs(mid - A[i]) < dist) {
				res = i;
				dist = abs(mid - A[i]);
			}
		}
	}
	cout << A[N - 1] << " " << A[res] << endl;
	return 0;
}

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

int main(){
  string s,t,u;
  ll a,b;
  cin >> s >> t >> a >> b >> u;
  if(u==s){
    a-=1;
  }
  else{
    b-=1;
  }
  cout << a << " " << b;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
#define N 2500000
ll MOD=1e9+7;

ll modpow(ll a,ll n){
    if(n%2) return a*modpow(a*a%MOD,n/2)%MOD;
    else if(n==0) return 1ll;
    else modpow(a*a%MOD,n/2);
}

main(){
    ll n=in();
    vecll v;
    v.pb(1);
    rep(i,n)v.pb(in());
    vecll w=v;
    sort(all(w));
    vecll dp2;
    dp2.pb(0);dp2.pb(0);
    ll dp1=1;
    map<int,int> mp;
    vecll rev(n+2);
    int now=1;
    rep(i,n+1){
        if(mp[w[i]]==0) {
            mp[w[i]]=now;
            rev[now]=w[i];
            now++;
        }
    }
    rep(i,n){
        vecll newdp2(n+2);
        int a=mp[v[i]],b=mp[v[i+1]];
        if(v[i]<=v[i+1]){
            rep2(j,1,a){
                dp2[j]=(dp2[j]*modpow(2,v[i+1]-v[i]))%MOD;
            }
            rep2(j,a+1,b){
                dp2.pb(dp1*2%MOD*(modpow(2,v[i+1]-rev[j-1])-modpow(2,v[i+1]-rev[j])+MOD)%MOD);
            }
            dp1=dp1*2%MOD;
        }
        else{
            dp1=dp1*2%MOD;
            rep2(j,b+1,a){
                dp1=(dp1+2*dp2[j])%MOD;
            }
            dp2.erase(dp2.begin()+b+1,dp2.end());
        }
        // cout<<dp1<<" "; print(dp2);
        // cout<<endl;
        
    }
    ll ans=0;
    rep(i,dp2.size())ans=(ans+dp2[i])%MOD;
    cout<<(ans+dp1)%MOD<<endl;
}

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

using namespace std;

const int Nmax = 200005;

char a[Nmax], b[Nmax];

int n , v[27];

vector < int > L[30];


int main()
{
    cin >> (a + 1);
    cin >> (b + 1);
    n = strlen(a + 1);
    for(int i = 1 ; i <= n ; i++)
    {
        L[a[i] - 'a'] . push_back(i);
        if(!v[b[i] - 'a'])
            v[b[i] - 'a'] = a[i] - 'a';
        else if(v[b[i] - 'a'] != a[i] - 'a')
        {
            cout << "No\n";
            return 0;
        }
    }
    for(int i = 1 ; i <= n ; i++)
        if(a[i] != b[i])
            for(auto it : L[a[i] - 'a'])
            {
                if(b[it] != b[i])
                {
                    cout << "No\n";
                    return 0;
                }
                a[it] = b[i];
            }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define ld long double
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define ull unsigned long long
#define pdd pair <ld,ld>
#define pb push_back
#define mp make_pair
#define puu pair<ull,ull>
#define pvv pair<vector<int>, vector<int> >
#define _bp __builtin_popcount
#define ptt pair <Tree*,Tree*>
#define all(v) v.begin(),v.end()
#define en "\n"
//const long double pi = acos(-1);
void boos()
{
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file()
{
   freopen("robot.in","r",stdin);
   freopen("robot.out","w",stdout);
}
const ll INF = (ll)1e9 + 7ll;
const ll INF1 = 998244353;
const ll INF2 = (ll)1e9 + 9ll;
const ll LLINF = (ll)1e18 + 1;
const ll INTmx = (int)2e9;
const ld EPS = (ld)1e-15;
const int N = 3e5 + 100;
int main()
{
    //file();
    boos();
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	ll kol = 0;
	while(b <= a)
	{
		b *= 2ll;
		kol++;
	}
	while(c <= b)
	{
		c *= 2ll;
		kol++;
	}
	if(kol > k)
	{
		cout << "No";
	}else {
		cout << "Yes";
	}
}

Measured memory_bytes: 3648
#include<iostream>
#include<cmath>

int main(){
	int n,sum=100000;
	std::cin>>n;
	for(int i=0;i<n;i++){
		sum*=1.05;
		if(sum%1000!=0){
			sum+=1000-(sum%1000);
		}
	}
	std::cout<<sum<<std::endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef pair <long long, long long> pll;
 
ll mod = 998244353;
 
int main(){
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll a = 0, w = 0, t = 0, r = 0;
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    if (s[0] == 'A')
     a++;
    if (s[0] == 'W')
     w++;
    if (s[0] == 'T')
     t++;
    if (s[0] == 'R')
     r++;
  }
  cout << "AC x " << a << endl;
  cout << "WA x " << w << endl;
  cout << "TLE x " << t << endl;
  cout << "RE x " << r << endl;
}

Measured memory_bytes: 3660
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#define range(i,a,b) for(int i = (a); i <= (b); i++)
#define rrange(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,b) for(int i = 1; i <= (b); i++)
#define rrep(i,b) for(int i = (b); i >= 1; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=5e3+11,INF=~0u>>2;
struct Edge{int nxt,to;}edge[N];
int f[N],g[N][2],a[N],head[N],num_edge,n;
void add_edge(int from,int to){
	edge[++num_edge].nxt=head[from];
	edge[num_edge].to=to;
	head[from]=num_edge;
}
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
void dfs(int u){
	for(int i=head[u];i;i=edge[i].nxt) dfs(edge[i].to);
	int now=0,pre=1;
	g[0][now]=0;
	rep(i,a[u]) g[i][now]=INF;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		now^=1;pre^=1;
		range(j,0,a[u]) g[j][now]=INF;
		rrange(j,a[u]-a[v],0) g[j+a[v]][now]=min(g[j+a[v]][now],g[j][pre]+f[v]);
		rrange(j,a[u]-f[v],0) g[j+f[v]][now]=min(g[j+f[v]][now],g[j][pre]+a[v]);
	}
	f[u]=INF;
	range(i,0,a[u]) f[u]=min(f[u],g[i][now]);
} 
int main(){
//	freopen("ex.in","r",stdin);
	n=read();
	range(i,2,n){
		int tmp=read();
		add_edge(tmp,i);
	}
	rep(i,n) a[i]=read();
	dfs(1);
	rep(i,n) if(f[i]==INF){
		puts("IMPOSSIBLE");
		return 0;
	}
	puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve(){
    string str; cin>>str;
    map<char,int> m;
    for (int i = 0; i < 4; ++i)
    {
        m[str[i]]++;
    }
    if(m.size()==2) cout<<"Yes";
    else cout<<"No";
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

int main()
{
    char s[15];
    scanf("%s",s);
    int len=strlen(s);
    if(s[0]!='A'||s[len-1]=='C'||s[1]=='C')   cout<<"WA\n"<<endl;
    else
    {
        int cnt=0;  bool flag=true;
        for(int i=1;i<len;i++)
        {
            if(s[i]=='C')   cnt++;
            else if(s[i]>='A'&&s[i]<='Z')   flag=false;
        }
        if(flag&&cnt==1)    cout<<"AC\n"<<endl;
        else cout<<"WA\n"<<endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    vl x(5);
    cin >> x;
    rep(i, 5) {
        if (x[i] == 0) {
            cout << i + 1 << '\n';
            return;
        }
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 3624
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Int (Int64)
import Data.Coerce
import qualified Data.ByteString.Char8 as BS
import Control.Exception (assert)

main = do
  n <- readLn
  s <- BS.getLine
  assert (BS.length s == 2 * n) $ return ()
  let loop :: N -> Int -> Int -> N
      loop !acc !k !i | BS.length s == i = if k == 0 then acc else 0
                      | BS.index s i == 'W' = if even k
                                              then loop (acc * fromIntegral_Int_N k) (k-1) (i+1)
                                              else loop acc (k+1) (i+1)
                      | otherwise = if even k
                                    then loop acc (k+1) (i+1)
                                    else loop (acc * fromIntegral_Int_N k) (k-1) (i+1)
  print $ loop (product $ map fromIntegral_Int_N [1..n]) 0 0

--
-- Modular Arithmetic
--

modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger = fromInteger_N
  abs = undefined; signum = undefined
  {-# INLINE fromInteger #-}

fromInteger_N :: Integer -> N
fromInteger_N n = N (fromInteger (n `mod` fromIntegral modulo))
{-# INLINE [1] fromInteger_N #-}

fromIntegral_Int64_N :: Int64 -> N
fromIntegral_Int64_N n | 0 <= n && n < modulo = N n
                       | otherwise = N (n `mod` modulo)

fromIntegral_Int_N :: Int -> N
fromIntegral_Int_N n | 0 <= n && fromIntegral n < modulo = N (fromIntegral n)
                     | otherwise = N (fromIntegral n `mod` modulo)

{-# RULES
"^9/Int" forall x. x ^ (9 :: Int) = let u = x; v = u * u * u in v * v * v
"^9/Integer" forall x. x ^ (9 :: Integer) = let u = x; v = u * u * u in v * v * v
 #-}

{-# RULES
"fromIntegral/Int->N" forall x. fromInteger_N (fromIntegral x) = fromIntegral_Int_N x
"fromIntegral/Int64->N" forall x. fromInteger_N (fromIntegral x) = fromIntegral_Int64_N x
 #-}


Measured memory_bytes: 892
S = list(map(int, input()))

n = len(S)
ans = []
def f(ind, cnt, keta):
	if ind == 0:
		ans.append(cnt)
		return

	f(ind-1, cnt+S[ind-1], 0)
	f(ind-1, cnt+S[ind-1]*(10**(keta+1)), keta+1)


f(len(S)-1, S[-1], 0)

print(sum(ans))

Measured memory_bytes: 3060
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

input=sys.stdin.readline
l=int(input())
n=l.bit_length()
d=[]

for i in range(n-1):
    d.append((i+1,i+2,0))
    d.append((i+1,i+2,2**i))
res=l-2**(n-1)
for i in range(n-1):
    if 2**(n-1-i-1)>l-2**(n-1):
        continue
    x=l-2**(n-1-i-1)
    d.append((n-i-1,n,x))
    l=x
m=len(d)
print(n,m)
for i in d:
  print(*i)

Measured memory_bytes: 64108
q = int(input())
for _ in range(q):
    R = list(map(int, input().split()))
    a, b = min(R), max(R)
    if b - a <= 1:
        res = 2 * (a-1)

    else:
        c = int((a*b)**0.5)
        if c ** 2 == a * b:
            c -= 1
        if c * (c+1) < a * b:
            res = 2 * (c-1) + 1
        else:
            res = 2 * (c-1)
    print(res)

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

int main() {
  ll n, ans = 0;
  cin >> n;
  string s;
  map<string, int> mp;
  rep(i, n) {
    cin >> s;
    sort(s.begin(), s.end());
    ans += mp[s];
    mp[s]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>
#include<math.h>

double surface(double x);

double length(double x);

int main(void){
  double r;
  double s, l;

  scanf("%lf", &r);
  
  s = surface(r);
  l = length(r);

  printf("%lf %lf\n", s, l);
  
  return 0;
}

double surface(double x){
  double s;
  s = x*x*M_PI;
  return s;
}

double length(double x){
  double l;
  l = 2*x*M_PI;
  return l;
}

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

using namespace std;

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

	if(n*2<=m){
		ans+=n;
		m-=n*2;
		ans+=m/4;
	}else{
		ans+=m/2;
	}

	cout<<ans<<endl;

	return 0;
}


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

int sum[86401];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		memset(sum, 0, sizeof(sum));
		int h, m, s, h1, m1, s1;
		rep(i, n) {
			scanf("%d:%d:%d%d:%d:%d", &h, &m, &s, &h1, &m1, &s1);
			sum[h * 3600 + m * 60 + s]++; sum[h1 * 3600 + m1 * 60 + s1]--;
		}
		int Max = 0;
		rep(i, 86401) {
			if (i)sum[i] += sum[i - 1];
			Max = max(Max, sum[i]);
		}
		printf("%d\n", Max);
	}
}

Measured memory_bytes: 3420
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
  int n, m, e, j;

  while(1){
    cin >> n;
    if(n == 0){
      break;
    }
    for(int i = 0; i < n; i++){
      cin >> m >> e >> j;

      if(m == 100 || e == 100 || j == 100){
	cout << "A" << endl;
      } else if((m+e)/2 >= 90){
	cout << "A" << endl;
      } else if((m+e+j)/3 >= 80){
	cout << "A" << endl;
      } else if((m+e+j)/3 >= 70){
	cout << "B" << endl;
      } else if((m+e+j)/3 >= 50 && (m >= 80 || e >= 80)){
	cout << "B" << endl;
      } else {
	cout << "C" << endl;
      }
    }

  }


  return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    if ((a==b)and(c!=a))
        cout<<"Yes";
    else if ((a==c)and(b!=a))
        cout<<"Yes";
    else if ((b==c)and(b!=a))
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() { 
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    rep(i, M) cin >> a[i];

    cout << N - 1 - M << endl;
    
    return 0; 
}

Measured memory_bytes: 3100
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))

def binary_search(ng=0, ok=max(a)):
    if ok - ng < 2: return ok
    mid = (ok + ng) // 2
    cnt = 0
    for i in a:
        cnt += math.ceil(i / mid) - 1
    if cnt <= k:
        return binary_search(ng, mid)
    else:
        return binary_search(mid, ok)
print(binary_search())

Measured memory_bytes: 31096
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

double vs[55];

int main(void) {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> vs[i];
  }
  sort(vs, vs + n);
  double res = vs[0];
  REP(i, n-1) {
    res = (res + vs[i+1]) / 2;
  }
  printf("%.10f\n", res);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for(int i = 0; i < H; i++){
		cin >> S[i];
	}
	vector<vector<int>> V(H, vector<int>(W, 0));
	if(S[0][0] == '#')V[0][0] = 1;
	int a, b;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(i == 0 && j == 0)continue;
			if(i == 0){
				V[i][j] = V[i][j-1];
				if(S[i][j-1] == '.' && S[i][j] == '#')V[i][j]++;
			}
			else if(j == 0){
				V[i][j] = V[i-1][j];
				if(S[i-1][j] == '.' && S[i][j] == '#')V[i][j]++;
			}
			else{
				a = V[i][j-1];
				if(S[i][j-1] == '.' && S[i][j] == '#')a++;
				b = V[i-1][j];
				if(S[i-1][j] == '.' && S[i][j] == '#')b++;
				V[i][j] = min(a, b);
			}
		}
	}
	cout << V[H-1][W-1] << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String strArr[] = str.split(" ");

		int a, b;

		a = Integer.parseInt(strArr[0]);
		b = Integer.parseInt(strArr[1]);

		int d, r;
		double f;

		d = a/b;
		r = a%b;
		f = (double)a/b;

		System.out.printf("%d %d %.5f\n", d, r, f);
	}
}

Measured memory_bytes: 16924
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))

c = [0] * n

for i in range(n):
    c[i] = min(a[i] + a[i+1], b[i])
    if a[i] < b[i]:
        t = a[i+1] + a[i] - b[i]
        if t < 0:
            a[i+1] = 0
        else:
            a[i+1] = t

print(sum(c))


Measured memory_bytes: 17568