akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)


const int inf = (1<<21);

class state{
public:
  int y,x,c;
};

int cost[100][100];
bool iswall[100][100][4];

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

int bfs(int r,int c){
  /*
  rep(i,r){
    rep(j,c){
      cout << iswall[i][j][0];
    }
    cout << endl;
  }
  */

  rep(i,r)rep(j,c)cost[i][j]=inf;
  queue<state > Q;
  Q.push((state){0,0,0});
  while(!Q.empty()){
    state now = Q.front();Q.pop();
    if (cost[now.y][now.x] != inf)continue;
    cost[now.y][now.x]=now.c;
    
    if (now.x == c-1 && now.y == r-1)return now.c+1;
    //cout << now.x <<" " << now.y << " " <<now.c <<" " <<  c-1 <<" " << r-1 << endl;
    
    rep(i,4){
      int nex=now.x+dx[i],ney=now.y+dy[i];
      if (nex == -1 || nex == c || ney == -1 || ney == r || iswall[now.y][now.x][i])continue;
      Q.push((state){ney,nex,now.c+1});
    }
    
  }
  return 0;
}


main(){
  int r,c;
  while(cin>>c>>r && c){
    rep(i,100)rep(j,100)rep(k,4)iswall[i][j][k]=false;

    rep(i,r-1){
      bool tmp;
      rep(j,c-1){
	cin>>tmp;iswall[i][j][0]=iswall[i][j+1][1]=tmp;
      }
      rep(j,c){
	cin>>tmp;iswall[i][j][2]=iswall[i+1][j][3]=tmp;
      }
    }

    rep(j,c-1){
      bool tmp;	cin>>tmp;iswall[r-1][j][0]=iswall[r-1][j+1][1]=tmp;
    }
    cout << bfs(r,c) << endl;
  }

}

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

int main()
{
   string a, b;
   string x, y;
   cin >> a >> b;
   for (int i = 0; i < b[0]-'0'; i++) {
        x += a;
   }
   for (int i = 0; i < a[0]-'0'; i++) {
        y += b;
   }
   if (x < y) cout << x << "\n";
   else cout << y << "\n";
}


Measured memory_bytes: 256
//14
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
#include<cstdlib>

using namespace std;

vector<int> prm;

void mfd(vector<pair<int,int> > &v,vector<int> &r,int x,int p){
  if(x==v.size()){
    r.push_back(p);
  }else{
    int f=1;
    for(int i=0;i<=v[x].second;i++,f*=v[x].first){
      mfd(v,r,x+1,p*f);
    }
  }
}

vector<int> mf(int a){
  vector<pair<int,int> > v;
  for(int i=0;a!=1;i++){
    int nd=0;
    while(a%prm[i]==0){
      nd++;
      a/=prm[i];
    }
    if(nd){
      v.push_back(make_pair(prm[i],nd));
    }
  }
  vector<int> r;
  mfd(v,r,0,1);
  sort(r.begin(),r.end());
  return r;
}

int main(){
  bool cmp[10001]={};
  for(int i=2;i<=10000;i++){
    if(!cmp[i]){
      prm.push_back(i);
      for(int j=2;j*i<=10000;j++){
	cmp[i*j]=true;
      }
    }
  }
  for(int a,b,c;cin>>a>>b>>c,a|b|c;){
    if(c==0){
      pair<int,int> ra(1,0),rb(a,b);
      if(ra<rb){
	swap(ra,rb);
      }
      cout<<ra.first<<' '<<ra.second<<' '<<rb.first<<' '<<rb.second<<endl;
    }else{
      vector<int> af=mf(abs(a)),cf=mf(abs(c));
      for(int i=0;i<af.size();i++){
	for(int j=0;j<cf.size();j++){
	  for(int sn=0;sn<2;sn++){
	    int p=af[i],q=cf[j];
	    int r=a/p,s=c/q;
	    if(sn){
	      q=-q;
	      s=-s;
	    }
	    //	    cout<<p<<' '<<q<<' '<<r<<' '<<s<<endl;
	    //	    cout<<p*s+q*r<<' '<<b<<endl;
	    if(p*s+q*r==b){
	      pair<int,int> ra(p,q),rb(r,s);
	      if(ra<rb){
		swap(ra,rb);
	      }
	      cout<<ra.first<<' '<<ra.second<<' '<<rb.first<<' '<<rb.second<<endl;
	      goto next;
	    }
	  }
	}
      }
      cout<<"Impossible"<<endl;
    next:
      ;
    }
  }
  return 0;
}

    

Measured memory_bytes: 1256
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;
const double eps=1e-10;

template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline bool _cmp(const _Tp &a,const _Tp &b){return abs(a-b)<=eps;}
template <typename _Tp>Finline void read(_Tp &x)
{
	register char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	register char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	register char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=100005;
ll d[N];
struct node{
	int u;
	ll d;
	Finline bool operator < (const node &o)const
	{
		return d<o.d;
	}
};
std::priority_queue<node> q;
std::map<ll,int> mp;
int siz[N];
std::vector<int> e[N];
int main()
{
	int n;
	read(n);
	for(int i=1;i<=n;++i)
	{
		read(d[i]);
		mp[d[i]]=i;
		q.push((node){i,d[i]});
		siz[i]=1;
	}
	if(n==1)
	{
		if(d[1]!=1)
		{
			printf("-1\n");
		}
		return 0;
	}
	if(n==2)
	{
		if(d[1]==1&&d[2]==1)
		{
			printf("1 2\n");
		}
		else
		{
			printf("-1\n");
		}
		return 0;
	}
	std::vector<std::pair<int,int> > v;
	int qwq=0;
	while(!q.empty())
	{
		node x=q.top();
		q.pop();
		if(q.empty())
		{
			qwq=x.u;
			break;
		}
		if(mp.find(x.d+2*siz[x.u]-n)==mp.end())
		{
			printf("-1\n");
			return 0;
		}
		int id=mp[x.d+2*siz[x.u]-n];
		v.push_back(std::make_pair(x.u,id));
		siz[id]+=siz[x.u];
	}
	for(auto it:v) e[it.second].push_back(it.first);
	ll ans=0;
	std::function<void(int,int)> dfs=[&](int x,int dep)
	{
		ans+=dep;
		for(auto it:e[x]) dfs(it,dep+1);
	};
	dfs(qwq,0);
	if(ans!=d[qwq])
	{
		printf("-1\n");
	}
	else
	{
		for(auto it:v) printf("%d %d\n",it.first,it.second);
	}
	return 0;
}


Measured memory_bytes: 19696
#include <stdio.h>
#include <string.h>

long ans = 0;

void dfs(char s[], int array[], int len){
  if(array[0] == len){
    long num = (long)(s[0]-'0');
    long sum = 0;
    for(int i=1; i<=len; i++){
      if(array[i]){
	sum += num;
	num = 0;
      }
      num = num*10 + (long)(s[i]-'0');
    }
    sum += num;
    ans = ans + sum;
    return;
  }

  for(int i=0; i<=1; i++){
    array[++array[0]] = i;
    dfs(s, array, len);
    array[0]--;
  }
}

int main(){
  char s[12];  scanf("%s", s);
  int array[12] = {0}, len = strlen(s);

  dfs(s, array, len-1);

  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 128
def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        _a = list(map(lambda x: int(x)-1, input().split()))
        A.append(_a)
    ptrs = [0 for _ in range(N)]
    day = 0
    players = set([i for i in range(N)])
    finished = set()
    yest_players = set([i for i in range(N)])
    while True:
        todays_players = set()
        matched = False
        if len(finished) == N:
            break
        #print("------")
        for home in yest_players:
            if home in finished:
                continue
            away = A[home][ptrs[home]]
            if away in finished:
                continue
            #print(home, away)
            away_opp = A[away][ptrs[away]]
            if home in todays_players or away in todays_players:
                continue
            if home == away_opp:
                ptrs[home] += 1
                ptrs[away] += 1
                todays_players.add(home)
                todays_players.add(away)
                matched = True
                if ptrs[home] == N-1:
                    finished.add(home)
                if ptrs[away] == N-1:
                    finished.add(away)
        yest_players = todays_players
        #print(ptrs)
        if matched:
            day += 1
        else:
            day = -1
            break
    print(day)





if '__main__' == __name__:
    resolve()


Measured memory_bytes: 84532
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,n = LI()
print((a * min(n,b-1)) // b)


Measured memory_bytes: 65424
def main(s):
    n = len(s)
    l = []
    i = 0
    while i < n:
        if s[i] == 'A':
            i += 1
            l.append('a')
        elif i < n-1 and s[i] == 'B' and s[i+1] == 'C':
            l.append('bc')
            i += 2
        else:
            l.append('b')
            i += 1
    n = len(l)
    cum = [0] * (n+1)
    ans = 0
    for i in range(n):
        if l[i] == 'a':
            cum[i+1] = cum[i] + 1
        elif l[i] == 'bc':
            cum[i+1] = cum[i]
            ans += cum[i]
        else:
            cum[i+1] = 0
    print(ans)
    # ans = 0
    # flag = True
    # s = [i for i in s]
    # while flag:
    #     flag = False
    #     for i in range(n-2):
    #         if s[i:i+3] == ['A', 'B', 'C']:
    #             s[i] = 'B'
    #             s[i+1] = 'C'
    #             s[i+2] = 'A'
    #             flag = True
    #             ans += 1
    # 
    # print(ans)

s=input()
main(s)
# import random
# for i in range(1000):
#     s = [''] * random.randint(1, 100)
#     for j in range(len(s)):
#         s[j] = 'ABC'[random.randint(0, 2)]
#         a,b=main(''.join(s))
#         if a != b:
#             print(''.join(s))
#             print(a, b)

Measured memory_bytes: 12936
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
int N;
int A;
int B;
int C;
int D;
char S[200002];
int main(){
  int i, j, k;
  rd(N);
  rd(A);
  rd(B);
  rd(C);
  rd(D);
  rd(S);
  A--;
  B--;
  C--;
  D--;
  k =max_L(C, D);
  for(i=A;i<k;i++){
    if(S[i]=='#' && S[i+1]=='#'){
      wt_L("No");
      wt_L('\n');
      return 0;
    }
  }
  if(C > D){
    for(i=B;i<D+1;i++){
      if(S[i-1]=='.' && S[i]=='.' && S[i+1]=='.'){
        break;
      }
    }
    if(i==D+1){
      wt_L("No");
      wt_L('\n');
      return 0;
    }
  }
  wt_L("Yes");
  wt_L('\n');
  return 0;
}
// cLay varsion 20190601-1

// --- original code ---
// int N, A, B, C, D;
// char S[200002];
// {
//   int i, j, k;
//   rd(N,A,B,C,D,S);
//   A--; B--; C--; D--;
// 
//   k = max(C, D);
//   rep(i,A,k){
//     if(S[i]=='#' && S[i+1]=='#'){
//       wt("No");
//       return 0;
//     }
//   }
// 
//   if(C > D){
//     rep(i,B,D+1) if(S[i-1]=='.' && S[i]=='.' && S[i+1]=='.') break;
//     if(i==D+1){
//       wt("No");
//       return 0;
//     }
//   }
// 
//   wt("Yes");
// }


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int N;
bool f( int n )
{
    int tmp{};
    for( int i = 1; i <= n; ++i )
    {
        if( n % i == 0 && i % 2 != 0 )
        {
            tmp++;
        }
    }
    return tmp == 8 ? 1 : 0;
}
int main()
{
    cin >> N;
    int res{};
    for( int i = 1; i <= N; ++i )
    {
        res += f( i );
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	B := make([]int, N-1)
	for i := 0; i < N-1; i++ {
		B[i] = sc.nextInt()
	}
	A := make([]int, N)
	A[0] = B[0]
	A[N-1] = B[N-2]
	before := B[0]
	for i := 1; i < N-1; i++ {
		current := B[i]
		A[i] = min(before, current)
		before = current
	}
	count := 0
	for _, v := range A {
		count += v
	}
	fmt.Println(count)
}


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

int main() {
  long long n, a, b, syuuki, ans, amari;
  cin >> n >> a >> b;
  syuuki = n / (a + b);
  ans = a * syuuki;
  amari = n % (a + b);
  ans += min(amari, a);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 10001
int linearserach(int*,int,int);

int main(){
  int i,n,S[N],q,t,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    if(linearserach(S,n,t))sum++;
  }

  printf("%d\n",sum);

  return 0;
}
int linearserach(int* S,int n,int t){
  int i=0;
  S[n]=t;
  while(S[i]!=t){
    i++;
  }
  if (i==n)return 0;
  return 1;
    
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int u1000, u100, u10, u1;
  u1000 = N / 1000;
  u100 = (N % 1000) / 100;
  u10 = (N % 100) / 10;
  u1 = N % 10;
  if(u100 == u10) {
    if(u1000 == u100 || u10 == u1){
    	cout << "Yes" << endl;
    }
    else {
    	cout << "No" << endl;
    }
  }
  else {
  	cout << "No" << endl;
  }

}

Measured memory_bytes: 3624
n = int(input())

a = {}
b = []
for i in range(n):
  s = input()
  b.append(s)
  if s in a:
    a[s] += 1
  else:
    a[s] = 1

b = sorted(list(set(b)))
p = max(a.values())

for i in b:
  if a[i] == p:
    print(i)

Measured memory_bytes: 43908
#include<bits/stdc++.h>
using namespace std;
int ans=0,ans2=0;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='I')
			ans2++;
		else
			ans2--;
		ans=max(ans,ans2);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

alias E = Tuple!(int, "d", long, "c");

void main()
{
    auto wh = readln.split.to!(long[]);
    auto W = wh[0];
    auto H = wh[1];
    E[] es;
    foreach (_; 0..W) {
        es ~= E(0, readln.chomp.to!long);
    }
    foreach (_; 0..H) {
        es ~= E(1, readln.chomp.to!long);
    }
    sort!"a.c < b.c"(es);

    auto X = (W+1) * (H+1) - 1, w = W+1, h = H+1;
    long r;
    foreach (e; es) {
        if (X == 0) break;
        if (e.d == 1) {
            r += w * e.c;
            X -= w;
            --h;
        } else {
            r += h * e.c;
            X -= h;
            --w;
        }
    }
    writeln(r);
}

Measured memory_bytes: 6880
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func incrementByte(b byte) byte {
	if b >= 97 && b < 122 {
		return b + 1
	} else if b == 122 {
		return 97
	}
	return b
}

func main() {
	scanner.Split(bufio.ScanLines)

	for {
		line := nextString()
		if len(line) == 0 {
			break
		}
		for i := 0; i <= 26; i++ {
			decoded := []byte{}
			for j := 0; j < len(line); j++ {
				decoded = append(decoded, incrementByte(line[j]))
			}
			line = string(decoded)
			if strings.Contains(line, "the") || strings.Contains(line, "this") || strings.Contains(line, "that") {
				fmt.Println(line)
				break
			}
		}
	}
}



Measured memory_bytes: 1072
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n;ll t;
ll x,y;
int ans;
int main(){
//	freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>t;
    rep(i,1,n){
    	cin>>x>>y;
    	if(x*x+y*y<=t*t)++ans;
	}
	cout<<ans;
    
 
 
 
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    int i;
    int count=0;
    int sayac=0;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]%6==0 || a[i]%10==0)
            count++;
        if(a[i]%2==0)
            sayac++;
    }
    if(sayac==count)    puts("APPROVED");
    else    puts("DENIED");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

#define N 1000000
#define INI -1

typedef struct node{
  int p;
  int right;
  int left;
}Node;


int main(){

  int n,i,j,l,c,k,id,P,depth,r;
  Node a[N],tmp;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    a[i].p = INI;
    a[i].right = INI;
    a[i].left = INI;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);

    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0) a[id].left = c;
      else a[r].right = c;
      a[c].p = id;
      r=c;
    }
  }

  for(i=0;i<n;i++){
    depth = 0;
    P = a[i].p;

    while(P != INI){
      P = a[P].p;
      depth++;
    }

    if(a[i].p == INI){
      printf("node %d: parent = %d, depth = %d, root, [",
       i,a[i].p,depth);
    }
    else if(a[i].left == INI) printf("node %d: parent = %d, depth = %d, leaf, [",i,a[i].p,depth);
    else printf("node %d: parent = %d, depth = %d, internal node, [",i,a[i].p,depth);

    P = a[i].left;
    if(P != INI) printf("%d",P);

    while(P != INI){
      P = a[P].right;
      if(P != INI) printf(", %d",P);
    }
    printf("]\n");
  }

  return 0;
}

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

int main()
{
    ll H;
    cin >> H;
    ll count = 0;

    while(H > 0)
    {
        H /= 2;
        count++;
    }

    vector<ll> two(42);
    two.at(0) = 0;

    for(ll i = 1; i <= 41; i++)
    {
        two.at(i) = pow(2,i-1);
    }

    ll sum = 0;

    for(ll i = 0; i <= count; i++)
    {
        sum += two.at(i);
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	int n,p=0,q=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=n-1;i>=0;i--){
		if((n-i)%2) p+=a[i];
		else q+=a[i];
	}
	cout<<p-q<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 10;

vector<int>e[maxn];
int n,ret,m;

bool vis[maxn];
void dfs(int u,int fa,int cnt){
  if(cnt==n){
    ret++;
    return;
  }
  for(int i=0;i<e[u].size();i++){
    int v = e[u][i];
    if(v==fa||vis[v])continue;
    vis[v]=1;
    dfs(v,u,cnt+1);
    vis[v]=0;
  }
}

int main() {
//  freopen("in.cpp","r",stdin);
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  vis[1]=1;
  dfs(1,0,1);
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 256
import scipy.fftpack as f;input();m=200003;t=[0]*m;a=[0]*2*m;s=0
for i in range(m):t[pow(2,i,m)]=i
for i in map(int,input().split()):
	if i:a[t[i]]+=1;s-=i*i%m
for i,j in enumerate(f.ifft(f.fft(a)**2)):s+=int(round(j.real))*pow(2,i,m)
print(s//2)

Measured memory_bytes: 144116
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int digit(int n){
  int ans=0;
  while(n>0){
    ans++;
    n=n/10;
  }
  return ans;
}
int main(){
  int n,i;
  cin >> n;
  int ans=0;
  for(i=1;i<=n;i++){
    if(digit(i)%2==1){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int a, b;
    char n[5] = "";
    int c = 0;
    int t = 0;

    scanf("%s %d %d", n, &a, &b);

    int i;
    for (i = 1;i <= atoi(n);i++) {
        int tmp = i;
        int j = 10000;
        int s = 0;
        while (0 < j) {
            s += tmp / j;
            tmp = tmp % j;
            j /= 10;
        }
        if (a <= s && s <= b) {
            t += i;
        }
    }
    printf("%d\n", t);

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
using namespace std;
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a*b>=c*d)  printf("%d",a*b);
    else  printf("%d",c*d);
    return 0;
}

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

using namespace std;
#define ll long long


int main(){
    int N, W;
  	cin >> N >> W;
    int w[N], v[N];
    for(int i = 0; i < N; i++)
        cin >> w[i] >> v[i];

    ll dp[N+1][W+1];
    memset(dp, 0, sizeof(dp));

    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= W; j++){
          if(i == 0 || j == 0)
              dp[i][j] = 0;
          else{
              dp[i][j] = dp[i-1][j];
              if(j-w[i-1] >= 0)
                  dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
          }
          //cout << dp[i][j] << " ";
		}//cout << endl;
	}

cout << dp[N][W];
}


Measured memory_bytes: 82444
package main

import (
	"fmt"
	"regexp"
)

var (
	idMatch = regexp.MustCompile(`^[a-z]+$`)
)

func registration(s, t string) string {
	if !idMatch.MatchString(s) || !idMatch.MatchString(t) {
		return "No"
	}
	if len(s) < 1 || len(s) > 10 {
		return "No"
	}
	if len(t) != len(s)+1 {
		return "No"
	}
	if s != string([]rune(t)[:len(t)-1]) {
		return "No"
	}
	return "Yes"
}

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	r := registration(s, t)
	fmt.Println(r)
}

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

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

        static void Solve()
        {
            var N = Sarray()[0];
            var Ai = Slist();
            Ai.Insert(0, 0);
            Ai.Add(0);
            var Nd = N + 2;
            var sum = 0L;
            for (var i = 1; i < Nd; ++i)
                sum += Abs(Ai[i] - Ai[i - 1]);
            for (var i = 1; i < 1 + N; ++i)
            {
                var diff = Abs(Ai[i + 1] - Ai[i - 1]) - Abs(Ai[i] - Ai[i - 1]) - Abs(Ai[i + 1] - Ai[i]);
                WriteLine(sum + diff);
            }
        }

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

Measured memory_bytes: 37388
#include <iostream>

using namespace std;

int main() {
  int n, k, a = 0, r = 0;
  cin >> n >> k;

  for (int i = 1; i <= n; i++) {
    a++;
    if (a == k) {
      r++;
      a = 0;
      i = i - (k - 1);
    }
  }

  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define mk  make_pair
#define pb  push_back
#define mx 200009
#define mod 1000000007
ll pf[mx+10],sf[mx+10];


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll n,k;
    cin>>n>>k;
    for(ll i=1;i<=n+2;i++){
        pf[i]=pf[i-1]+i;
    }
    sf[n]=n;
    for(ll i=n-1;i>=0;i--){
        sf[i]=sf[i+1]+i;
    }
    ll ans=0;
    for(ll i=k-1;i<=n;i++){
        ll lo=pf[i];
        ll hi=sf[n-i];
        //cout<<hi<<" "<<lo<<endl;
        ans= ((ans%mod)+(hi-lo+1)%mod)%mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}


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

using namespace std;
#define int int64_t
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   int n, cnt = 0;
   cin >> n;
   vector<int> x(n), y(n);

   rep(i, n) cin >> x[i];
   rep(i, n) cin >> y[i];

   rep(i, n)
   {
      if (x[i] > y[i])
      {
         cnt += (x[i] - y[i]);
      }
   }

   cout << cnt << '\n';
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int n;lint a,out=0,N;
	vector<lint> v;
	cin>>n;N=n;
	rep(i,n){
		cin>>a;v.pb(a);
	}
	sort(All(v));
	while(v[n-1]>=N){
		lint sum=0;
		vector<lint> x,ne;
		rep(i,n){
			if(v[i]>N-1) x.pb(v[i]/N);
			else x.pb(0);
			sum+=x[i];
		}
		rep(i,n){
			v[i]-=N*x[i];
			v[i]+=(sum-x[i]);
		}
		out+=sum;sort(All(v));
	}
	cout<<out<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
vector<string> m;
int h,w;
int Ans[30][30];
int ove[]={0,1,0,-1};
int Move[]={1,0,-1,0};

int main(){
    cin >> h >> w;
    m.resize(h);
    rep(i,h) cin >> m[i];
    
    int ans=0;
    queue<pair<int,int> > next;

    rep(i,h)rep(j,w){
        if(m[i][j]=='#') continue;
        rep(k,h)rep(l,w) Ans[k][l]=-1;
        next.push(pair<int,int>(i,j));
        Ans[i][j]=0;
        while(!next.empty()){
            pair<int,int> ne;
            ne=next.front();
            next.pop();
            int nowi=ne.first;
            int nowj=ne.second;
            rep(k,4){
                int ni=ne.first+ove[k];
                int nj=ne.second+Move[k];
                if(ni>=h || ni<0 || nj>=w || nj<0) continue;
                if(Ans[ni][nj]>=0) continue;
                if(m[ni][nj]=='#') continue;
                next.push(pair<int,int>(ni,nj));
                Ans[ni][nj]=Ans[nowi][nowj]+1;
            }
        }
        rep(k,h)rep(l,w) ans=max(ans,Ans[k][l]);
    }
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n + 1];
        for(int i = 0 ; i < n ; i++ ){
            h[i] = sc.nextInt();
        }
        h[n] = h[n - 1] + 1;
        sc.close();
        int s = 0 , a = 0;
        for(int i = 0 ; i < n ; i++){
            if(h[i] >= h[i + 1]){
                a++;
            }else{
                if(s < a){
                    s = a;
                }
                a = 0;
            }
        }
        System.out.println(s);
    }
}

Measured memory_bytes: 61740
def to_the_n(num,n)
  result = 1
  i = 0
  while i < n
    result *= num
    result %= (10**9 + 7)
    i += 1
  end
  result
end
n = gets.to_i
ans = to_the_n(10,n) - 2 * to_the_n(9,n) + to_the_n(8,n)
ans %= (10**9 + 7)
puts ans


Measured memory_bytes: 14316
a, b, c, d = map(int, input().split())

from fractions import gcd

def lcm(x, y):
    return (x*y) // gcd(x,y)

hoge = (b//c) + (b//d) - ((a-1)//c) - ((a-1)//d) - (b//lcm(c,d)) + ((a-1)//lcm(c,d))

print(b-a+1-hoge)

Measured memory_bytes: 5104
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
import itertools as it
from collections import Counter
#======================================================#
def main():
    n = II()
    aa = MII()
    cum = list(it.accumulate([0]+aa))
    c = Counter(cum)
    cnt = [n for n in c.values() if n > 1]
    ans = sum([(n*(n-1))//2 for n in cnt])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 41612
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	int n,i,x;
	cin>>n;
	vi a(n);
	for0(i,n) cin>>a[i];
	sort(a.begin(),a.end());
	x = a[n/2] - a[n/2 -1];
	cout<<x<<nw;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long N; string S; 
	cin >> N >> S; 
	long long P = 998244353; 
	long long ans = 0; 
	long long dp[200010][2] = {}; 
	long long odd = N; 
	while((odd & 1) == 0) odd >>= 1; 
	vector<long long> div; 
	for(long long i = 1; i * i <= odd; i+=2){
		if(odd % i == 0){
			div.push_back(i); 
			if(i * i != odd) div.push_back(odd / i); 
		}
	}
	sort(div.begin(), div.end()); 
	vector<long long> keisuu(div.size(), 0); 
	for(int i = 0; i < div.size(); i++){
		long long add = N * 2 / div.at(i); 		
		keisuu.at(i) = add - keisuu.at(i); 
		for(int j = i+1; j < div.size(); j++){
			if(div.at(j) % div.at(i) == 0) keisuu.at(j) += keisuu.at(i); 
		}
	}
	for(int i = 0; i < div.size(); i++){
		if(keisuu.at(i) < 0) keisuu.at(i) += P; 
	}
	for(int i = 0; i < div.size(); i++){
		string T = S.substr(0, N / div.at(i)); 
		string U = T; 
		for(int j = 0; j < U.size(); j++){
			if(U.at(j) == '0') U.at(j) = '1'; 
			else U.at(j) = '0'; 
		}
		string V; 
		for(int j = 0; j < N / T.size(); j++){
			if(j % 2 == 0) V += T; 
			else V += U; 
		}
		bool allzero = true; 
		for(int j = 0; j < T.size(); j++){
			if(T.at(j) == '1') allzero = false; 
		}
		if(V > S && allzero) continue; 
		else if(V > S){
			for(int j = T.size() - 1; j >= 0; j--){
				if(T.at(j) == '1'){
					T.at(j) = '0'; break; 
				}
				else T.at(j) = '1'; 
			}
		}
		dp[0][0] = 1; dp[0][1] = 0;
		for(int j = 1; j <= T.size(); j++){
			if(T.at(j-1) == '0'){
				dp[j][0] = dp[j-1][0]; 
				dp[j][1] = dp[j-1][1] * 2 % P; 
			}
			else{
				dp[j][0] = dp[j-1][0]; 
				dp[j][1] = dp[j-1][0] + dp[j-1][1] * 2 % P; 
			}
		}
			ans += keisuu.at(i) * (dp[T.size()][0] + dp[T.size()][1]) % P; 
			ans %= P; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 4228
import math
n=int(input())
ans=[]
for i in range(1,n+1,2):
    div=0
    for j in range(1,int(math.sqrt(i)//1)+1):
        if(i%j==0):
            div+=1

    if(div==4):
        ans.append(i)

print(len(ans))


Measured memory_bytes: 3060
/*
    author: Salam_35
    Created at :

*/

#include <bits/stdc++.h>
using namespace std;

/*        speed up       */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF    1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() _fastio;int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
template <typename T> T gcd(T a,T b){if(a < 0)return gcd(-a,b);if(b < 0)return gcd(a,-b);return (b == 0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a < 0)return lcm(-a,b);if(b < 0)return lcm(a,-b);return a*(b/gcd(a,b));}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    
    ll n ,q;
    cin >> n ;
    ll arr[n+10];
    mpll mp;
    ll sum=0;
    for (int i = 0; i < n; ++i)
    {
    	cin >> arr[i];
    	mp[arr[i]]++;
    	sum+=arr[i];
    }
    cin >> q;
    while(q--){
    	ll b,c;
    	cin >> b >> c;
    	ll cnt=mp[b];
    	mp[b]=0;
    	mp[c]+=cnt;
    	sum-=(b*cnt);
    	sum+=(c*cnt);
    	cout<<sum<<endl;
    }
}
/*
 		remember:
 		ll vs int
 		array size
 		case for 1 2 3 
*/


Measured memory_bytes: 10152
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]string, n)
	t := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i], &t[i])
	}
	var x string
	fmt.Scan(&x)

	flg := false
	ans := 0
	for i := 0; i < n; i++ {
		if flg {
			ans += t[i]
		}
		if x == s[i] {
			flg = true
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int n;
ld d0, x;

bool read() {
  double dd0, xx;
  if (scanf("%d%lf%lf", &n, &dd0, &xx) < 1) {
    return false;
  }
  d0 = dd0;
  x = xx;
  return true;
}

void solve() {
  ld res = 0;
  while (n) {
    res += d0 + (ld) (2 * n - 1) / 2 * x;
    d0 = (ld) (n + 1) / n * d0 + (ld) 5 / (2 * n) * x;
    x *= (ld) (n + 2) / n;
    n--;
  }
  printf("%.12f\n", (double) res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = [i for i in range(n)]
cnt = 0
for m in range(k,n+2):
    amin = (m*(m-1))/2
    amax = (n*(n+1))/2 - (n-m)*(n-m+1)/2
    cnt += amax-amin+1
print(int(cnt%(1e9+7)))

Measured memory_bytes: 16908
#include<bits/stdc++.h>
#pragma O3
#define int long long
using namespace std;
vector<int> r;
signed main(){
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,u;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>u;
		r.push_back(u);
	}
	sort(r.begin(),r.end());
	int en=r[n-1],st=r[0];
	for(int i=1;i<n-1;i++){
		if(r[i]<0) en-=r[i];
		else st-=r[i]; 
	}
	cout<<en-st<<endl;
	for(int i=1;i<n-1;i++){
		if(r[i]<0){
			cout<<r[n-1]<<" "<<r[i]<<endl;
			r[n-1]-=r[i];
		}
		else{
			cout<<r[0]<<" "<<r[i]<<endl;
			r[0]-=r[i];
		}
	}
	cout<<r[n-1]<<" "<<r[0];
}

Measured memory_bytes: 2804
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

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

  ll N, M;
  cin >> N >> M;

  vector<pair<ll, ll>> P(N);
  forn (i, N) cin >> P[i].first >> P[i].second;

  sort(all(P));

  ll sum = 0, ans = 0, cnt = 0;
  while (sum < M) {
    sum += P[cnt].second;
    ans += P[cnt].first * P[cnt].second;
    ++cnt;
  }
  ll over = sum - M;
  ans -= (over * P[cnt-1].first);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#define MAX 101
int main(){
  int i,j,k,n,a,b,A[MAX],B[MAX][MAX];
 
  scanf("%d",&n);
  for(i=1; i<=n; i++)
    scanf("%d%d",&A[i-1],&A[i]);
  
  for(i=1; i<=n; i++)
    B[i][i] = 0;
  
  for(j=2; j<=n; j++){
 
    for(i=1; i<=n-j+1; i++){
      a = i + j -1;
      B[i][a] = 1000000;
 
      for(k=i; k<=a-1; k++){
    b = B[i][k] + B[k+1][a] + A[i-1]*A[k]*A[a];
    if(B[i][a] >= b)
      B[i][a] = b;
      }
    }
  }
  
  printf("%d\n",B[1][n]);
    
  return 0;
}


Measured memory_bytes: 2140
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<iomanip>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
typedef long long int ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
//#define INF 931931114518101
using namespace std;
typedef pair<ll, ll>P;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
#define yo 100001
//------------------変数-----------------------//
ll n;
string s;
ll dp[100][2][10];
//-------------------関数----------------------//


int main(){
  cin>>n;
  ll a;cin>>a;
  cout<<n*n-a<<endl;;
	return 0;
}


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

int gcd(long long a, long long b){
  long long M = max(a, b), m = min(a, b);
  while(m != 0){
  	long long r = M%m;
    M = m; m = r;
  }
  return M;
}

int digit_sum(long long n){
  long long ans;
  while(n != 0){
  	ans += n%10;
  	n /= 10;
  }
  return ans;
}

int main(){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  int count = 1;
  
  for(int i = 0; i < 100; i++){
  	if(b <= count){
      	ans = i;
    	break;
    }
  
  	count += a-1;
  }
  cout << ans << endl;
}

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

const int N = 100005, H = 10004, INF = 1000000009;

int n, k, dp[N], h[N];

int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> h[i];
    for(int i = 2; i <= n; i++){
        dp[i] = INF;
        for(int j = 1; j <= k && i-j >= 1; j++){
            dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n] << "\n";
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		sc.close();
		
		int count = 0;
		for(int i=100;i>0;i--) {
			if(a%i==0 && b%i==0) {
				count++;
				if(count ==k) {
					System.out.println(i);
					return;
				}
			}
		}
	}

}


Measured memory_bytes: 23252
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var X = o.getValue(0);
    var rating = 1800;
    var diff = 200;
    var index = 1;
    while (rating >= 400) {
        if (rating <= X) return index;
        index++;
        rating -= diff;
    }
}

Measured memory_bytes: 29692
#include <bits/stdc++.h>
#include <string>
#include <vector>
#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(){
    int n;
    cin >>n;
    vector<int> c(n),s(n),f(n);
    rep(i,n-1) cin >> c[i+1] >> s[i+1] >> f[i+1];
    for(int i = 1;i<=n-1;i++){
        int temp = s[i]+c[i];
        for(int j = i+1;j<=n-1;j++){
            if(temp<s[j]) temp = s[j]+c[j];
            else if(temp%f[j]==0) temp = temp+c[j];
            else temp = (temp/f[j])*f[j] + f[j] + c[j];
        }
        cout << temp << endl;
    }
    cout << 0 << endl;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long H, long long W){
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return;
    }
    cout << (H * W - (H * W) / 2) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    solve(H, W);
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i).sort
i = 0
max = 0
while i < arr.size
  exceed_id = arr.bsearch_index {|num| num > arr[i] + 2 } || arr.size
  if max < exceed_id - i
    max = exceed_id - i
  end 
  i += 1
end
puts max

Measured memory_bytes: 22464
import java.util.Scanner;

public class Main {

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

    int c0 = 0;
    int c1 = 0;

    for (char c : s.toCharArray()) {
      if (c == '0')
        ++c0;
      else
        ++c1;
    }

    System.out.println(2 * Math.min(c0, c1));
  }
}

Measured memory_bytes: 29008
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] arr = reader.readLine().split(" ");
        Long N = Long.parseLong(arr[0]);
        Long A = Long.parseLong(arr[1]);
        Long B = Long.parseLong(arr[2]);
        Long div = N / (A + B);
        Long mod = N % (A + B);
        System.out.println(A * div + Math.min(A, mod));
    }
}

Measured memory_bytes: 24916
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int dp[100005][30];
int x[1000005];
int main(){
    int n;
    cin >> n;
    rep(i,n)cin >> x[i];
    int L;
    cin >> L;
    rep(i,n){
        dp[i][0] = (int)(upper_bound(x,x+n,x[i]+L)-x)-1;
    }
    for(int j = 1; j <= 29; j++){
        rep(i,n){
            dp[i][j] = dp[dp[i][j-1]][j-1];
        }
    }
    int q;
    cin >> q;
    while(q--){
        int a,b;
        cin >> a >> b;
        a--,b--;
        if(a>b)swap(a,b);
        int ans = 0;
        for(int i = 28; i >= 0; i--){
            if(dp[a][i] < b){
                ans += 1<<i;
                a = dp[a][i];
            }
            if(i==0 and dp[a][i] >= b)ans += 1<<i;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 14848