akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, k;
	int x;
	cin >> n >> k;
	vector<int>a(k);
	for (int i = 0;i < k;i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int b = 0;
	for (int i = n;i < 100000;i++) {
		for (int j = 0;j < k;j++) {
			if (a[j] == 0 && i < 10000) {
				if (i >= 1000) {
					if (i / 1000 != a[j] && (i - i / 1000 * 100) / 100 != a[j] && 
						(i - i / 100 * 100) / 10 != a[j] && (i - i / 10 * 10) != a[j]) {
						continue;
					}
					else {
						b = 1;
						break;
					}
				}
				else if (i >= 100) {
					if (i / 100 != a[j] &&
						(i - i / 100 * 100) / 10 != a[j] && (i - i / 10 * 10) != a[j]) {
						continue;
					}
					else {
						b = 1;
						break;
					}
				}
				else if (i >= 10) {
					if (i / 10 != a[j] && (i - i / 10 * 10) != a[j]) {
						continue;
					}
					else {
						b = 1;
						break;
					}
				}
			}
			else if (i / 10000 != a[j] && (i - i / 10000 * 10000) / 1000 != a[j] && (i - i / 1000 * 1000) / 100 != a[j] &&
				(i - i / 100 * 100) / 10 != a[j] && (i - i / 10 * 10) != a[j]) {
				continue;
			}
			else {
				b = 1;
				break;
			}
		}
		if (b == 1) {
			b = 0;
			continue;
		}
		else {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

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

#define MAX 10000

void initialize();
int isEmpty();
int isFull();
void  push(int x);
int pop();

int top;
int S[10000];

int main()
{
  int i,n,n1,n2,n3,ans,b;
  char c[1000000];

  initialize();

  while(1){
    // scanf("%s",c);
    if(scanf("%s",c)==EOF) break;

    if(c[0]=='+' || c[0]=='-' ||c[0]=='*'){
      n1 = pop();
      n2 = pop();
      if(c[0]=='+') n3 = n1 + n2;
      if(c[0]=='-') n3 = n2 - n1;
      if(c[0]=='*') n3 = n1 * n2;
      push(n3);

    }
    else{
      n = atoi(c);
      push(n);
    }
  }

  printf("%d\n",pop());
  return 0;
}

void initialize(){
  top = 0;
}

int isEmpty(){
  return top == 0;
}

int isFull(){
  return top >= MAX - 1;
}

void  push(int x){
  if (isFull()) fprintf(stderr,"overflow\n");
  top++;
  S[top] = x;
}

int pop(){
  if (isEmpty()) fprintf(stderr,"underflow\n");
  top--;
  return S[top+1];
}

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

using namespace std;

int main(void)
{
	int a,b;

	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> a;
	cin >> b;

	if(a<=8 && b<=8)
	{
		cout << "Yay!" << '\n';
	}
	else
	{
		cout << ":(" << '\n';
	}
	
	return 0;
}

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

struct query{
  ll type;//0=empty, 1=add-sum ,2=set-max
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// max-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=max(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return -inf; // max
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return max(lv,rv); // max
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmax(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n);
  for(ll i=0;i<n;i++) {
    ll x,d;
    cin >> x >> d;
    a[i]={x,d};
  }
  sort(a.begin(),a.end());
  segtree d(n+10);
  d.Set(0,n+1,-inf);
  vec dp(n+1);
  dp[0]=1;
  for(ll i=0;i<n;i++) {
    ll x=a[n-i-1].first+a[n-i-1].second;
    ll it=upper_bound(a.begin(),a.end(),pll(x,0))-a.begin();
    d.Set(n-i-1,n-i,it);
    d.Set(n-i-1,n-i,d.Getmax(n-i-1,it));
    ll id=n-d.Getmax(n-i-1,n-i);
    (dp[i+1]=dp[i]+dp[id])%=mod;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 21376
#include <iostream>
#include <algorithm>
using namespace std;
int main() 
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int N;
	int sum[2][101];
	cin>>N;
	sum[0][0]=sum[1][0]=0;
	int a;
	for(int j=0;j<2;++j)
	{
		for(int i=1;i<=N;++i)
		{
			cin>>a;
			sum[j][i]=a+sum[j][i-1];
		}
	}
	int max_cnt=-1;
	for(int i=1;i<=N;++i)
	{
		int cnt=sum[0][i]+(sum[1][N]-sum[1][i-1]);
		max_cnt=max(cnt,max_cnt);
	}
	cout<<max_cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

B = list(map(int,input().split()))

ans = B[0] + B[N-2]



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

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const ll INF = 1e18;


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

int n;
cin >> n;
vl a(n);
rep(i,n) cin >> a[i];

vl s(n+1);
rep(i,n) s[i+1] = s[i] + a[i];
ll res = INF;
for(int i = 1; i < n; i++) {
    chmin(res, abs(s[n]-2*s[i]));
}
cout << res << endl;
return 0;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
  ll n ;cin>> n ;
  vector<ll> A(n) ;
  vector<ll> B(n) ;
  rep(i,n) cin>>A[i]>>B[i] ;
  ll x=A[0] ;ll y=B[0] ;
  ll baia=0 ; ll baib=0 ;
  rep(j,n-1){
  ll i= j+1 ;
  if(x<=A[i]) baia=1 ;
  else{
  ll syo= x/A[i] ; ll ama= x%A[i] ;
  if(ama==0) baia= syo ;
  else baia=syo+1 ;
  }
  if(y<=B[i]) baib=1 ;
  else{
  ll syo= y/B[i] ; ll ama= y%B[i] ;
  if(ama==0) baib= syo ;
  else baib=syo+1 ;
  }
  baia=max(baia,baib) ;
  x= A[i]*baia ;
  y= B[i]*baia ;
  }
   ll ans= x+y ;
   cout<<ans<<endl ;
  return 0;
  }

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

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int n, l;
  cin >> n >> l;
  int sa = 0;
  if(l + n - 1 <= 0) sa = l + n - 1;
  else if(l >= 0) sa = l;
  else sa = 0;
  
  int sum = 0;
  for(int i = 1; i <= n; i++) {
    sum += l+i-1;
  }
   
  int ans = sum - sa;
  cout << ans << endl;
}

Measured memory_bytes: 3584
a,b=map(int,input().split())
d=[["#"]*100 for i in range(100)]
a-=1
b-=1
for i in range(50,100):
    for j in range(100):
        d[i][j]="."
for i in range(0,50,2):
    for j in range(0,100,2):
        if a==0:
            break
        d[i][j]="."
        a-=1
    if a==0:
        break
for i in range(99,49,-2):
    for j in range(0,100,2):
        if b==0:
            break
        d[i][j]="#"
        b-=1
print(100,100)
for i in d:
    print(*i,sep="")

Measured memory_bytes: 4468
n, k = map(int, input().split())
h = [int(x) for x in input().split()]

dp = [0]*n

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    dp[i] = abs(h[i] - h[i-1]) + dp[i-1]
    for j in range(2,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i], abs(h[i]-h[i-j])+dp[i-j])

print(dp[-1])

Measured memory_bytes: 52832
fn input_pair<T: std::str::FromStr + Copy> () -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let arr: Vec<_> = s.trim().split_whitespace().flat_map(str::parse).collect();
    (arr[0], arr[1])
}

fn gcd(a: usize, b: usize) -> usize {
    if a == 0 {
        b
    } else {
        gcd(b % a, a)
    }
}

fn main() {
    let (a, b) = input_pair::<usize>();
    println!("{}", a * b / gcd(a, b));
}


Measured memory_bytes: 2032
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int N = 100010;
int n;
struct Dish {
    ll a, b;
    Dish(int x, int y) {
        a = x;
        b = y;
    }
    Dish() {
        a = 0;
        b = 0;
    }
    bool operator < (const Dish & other) const {
        if(a + b > other.a + other.b) return true;
        return false;
    }
}Dishes[N];
int main() {
    cin >> n;
    for(int i = 0; i < n; i ++) {
        int x, y;
        cin >> x >> y;
        Dishes[i] = Dish(x, y);
    }
    sort(Dishes, Dishes+n);
    ll taka = 0;
    ll aoki = 0;
    for(int i = 0; i < n; i ++) {
        if(i % 2) {
            aoki += Dishes[i].b;
        } else {
            taka += Dishes[i].a;
        }
    }
    cout << taka - aoki << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int sum = 0;
		for(int i = 1; i <= num; i++)
			sum += i;
		System.out.println(sum);
	}
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000007
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 


int main()
{
    int k,n;
    cin >> k >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin >> v[i];
    sort(v.begin(),v.end());
    int ans=k*10;
    for(int i=0;i<n;i++)
    {
        int a,b;
        if(i==0)
        {   
            a=v[n-1]-v[0];
            b=k-(v[1]-v[0]);
            ans=min({ans,a,b});
        }
        else if(i==n-1)
        {
            a=v[n-1]-v[0];
            b=k-(v[n-1]-v[n-2]);
            ans=min({ans,a,b});
        }
        else
        {
            a=k-(v[i]-v[i-1]);
            b=k-(v[i+1]-v[i]);
            ans=min({ans,a,b});      
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
let () =
    let main () =
        let n = Scanf.scanf "%d" (fun n -> n) in
        let m = 1000000000 + 7 in
        let ( +@) a b = (a + b) mod m in
        let ( *@) a b = ((a mod m) * (b mod m)) mod m in
        let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
        let rec loop i acc =
            if i = 60 then acc else
                let d0, d1 = Array.fold_left (fun (acc1, acc2) v ->
                    if v land (1 lsl i) = 0 then acc1 + 1, acc2 else acc1, acc2 + 1) (0, 0) a
                in
                loop (i + 1) (acc +@ d0 *@ d1 *@ (1 lsl i))
        in
        Printf.printf "%d\n" (loop 0 0)
    in
    main ()

Measured memory_bytes: 6144
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N, K; cin >> N >> K;
		if (!N)break;
		vector<vector<int>>diss(N, vector<int>(N, 1e9));
		for (int i = 0; i < N; ++i)diss[i][i] = 0;
		for (int i = 0; i < K; ++i) {
			int a; cin >> a;
			if (a) {
				int c, d, e; cin >> c >> d >> e; c--; d--;
				diss[c][d] = min(diss[c][d],e);
				diss[d][c] = min(diss[d][c],e);
				for (int j = 0; j < N; ++j) {
					for (int k = 0; k < N; ++k) {
						diss[j][k] = min(diss[j][k],diss[j][c] + diss[c][d] + diss[d][k]);
						diss[j][k] = min(diss[j][k],diss[j][d] + diss[d][c] + diss[c][k]);
					}
				}
			}
			else {
				int a, b; cin >> a >> b; a--; b--;
				if (diss[a][b] >= 1e9) {
					cout << -1 << endl;
				}
				else {
					cout << diss[a][b] << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3152
#include<iostream>
#include<iomanip>
#include<fstream>
#include<sstream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
#include<valarray>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<list>
#include<utility>
#include<bitset>
#include<algorithm>
#include<functional>
using namespace std;
int n,x[110][20],ans=-1000000000,u[100][100];
int main()
{
	cin>>n;
	for (int i=0;i<n;i++)
		for (int j=0;j<10;j++)
			cin>>x[i][j];
	for (int i=0;i<n;i++)
		for (int j=0;j<11;j++)
			cin>>u[i][j];
	for (int a=0;a<2;a++)
		for (int b=0;b<2;b++)
			for (int c=0;c<2;c++)
				for (int d=0;d<2;d++)
					for (int e=0;e<2;e++)
						for (int f=0;f<2;f++)
							for (int g=0;g<2;g++)
								for (int h=0;h<2;h++)
									for (int i=0;i<2;i++)
										for (int j=0;j<2;j++)
											if (a==1||b==1||c==1||d==1||e==1||f==1||g==1||h==1||i==1||j==1){
												int y=0;
												for (int l=0;l<n;l++){
													int z=0;
													if (x[l][0]==a&&a==1) z++;
													if (x[l][1]==b&&b==1) z++;
													if (x[l][2]==c&&c==1) z++;
													if (x[l][3]==d&&d==1) z++;
													if (x[l][4]==e&&e==1) z++;
													if (x[l][5]==f&&f==1) z++;
													if (x[l][6]==g&&g==1) z++;
													if (x[l][7]==h&&h==1) z++;
													if (x[l][8]==i&&i==1) z++;
													if (x[l][9]==j&&j==1) z++;
													y+=u[l][z];
												}
												//if (y==0) cout<<a<<b<<c<<d<<e<<f<<g<<h<<i<<j<<endl;
												ans=max(y,ans);
											}
	cout<<ans;
	return 0;
}

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

// 1 ^ 2n ^ 2n+1 = 0

// 2^i <= x を満たす最大の i
int log_x(int x){
    return 31 - __builtin_clz(x);
}

int main() {
    int N;
    cin >> N;
    int t = __builtin_ctz(N);
    int m = N >> t;
    if (m == 1) {
        cout << "No" << "\n";
        return 0;
    }
    cout << "Yes" << "\n";
    int ub = N;
    if (N % 2 == 0) {
        ub--;
    }
    for (int i = 2; i <= ub; ++i) {
        cout << 1 << " " << i << "\n";
    }
    for (int i = 2; i < ub; i += 2) {
        cout << i << " " << i+1+N << "\n";
        cout << i+1 << " " << i+N << "\n";
    }
    // 余った1+Nは任意のi+Nと繋げてよい
    cout << 1+N << " " << 2+N << "\n";
    if (N != ub) {
        int k = 1 << log_x(N);
        cout << k << " " << N << "\n";
        k = k ^ N ^ 1;
        cout << k << " " << N+N << "\n";
    }
    return 0;
}

Measured memory_bytes: 2304
#include<iostream>
int main(){
	int n,b, m=0;
	while (true){
		std::cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n/4; i++){
			std::cin >> b;
			m += b;
		}
		std::cout << m << "\n";
		m = 0;
	}
}

Measured memory_bytes: 1160
a, b, k = map(int, input().split())
if k < a:
    print(str(a - k) + " " + str(b))
elif a <= k and k < a + b:
    print(str(0) + " " + str(b - k + a))
elif k >= a + b:
    print(str(0) + " " + str(0))

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

int main() {
  int64_t n, k;
  std::cin >> n >> k;

  if (k % 2 == 1) {
    const auto t = n / k;
    std::cout << t * t * t << std::endl;
  } else {
    const auto t = n / k;
    const auto u = (n + k / 2) / k;
    std::cout << t * t * t + u * u * u << std::endl;
  }
  return 0;
}


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

int main(void) {
	int n; cin >> n;
	int mx = 0, x = 0;
	string s; cin >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') { x += 1; }
		if (s[i] == 'D') { x -= 1; }
		mx = max(mx, x);
		}

	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

ll F[90];
ll fibonacchi(ll n) {
    if (n == 0)
        return F[n] = 2;
    if (n == 1)
        return F[n] = 1;
    if (F[n] != -1)
        return F[n];
    else
        return F[n] = fibonacchi(n - 1) + fibonacchi(n - 2);
}

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

    ll N;
    cin >> N;
    memset(F, -1, sizeof(F));
    cout << fibonacchi(N) << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef int64_t ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N;
    vec a(N);
    ll ans=0,ma=-100000,mi=100000;
    bool hu = false,sei = false;
    rep(i,N) {
        cin>>a[i];
        ma = max(ma,a[i]);
        mi = min(mi,a[i]);
        ans += abs(a[i]);
        if(a[i]<=0) hu = true;
        if(a[i]>=0) sei= true;
    }
    if(hu&&sei) {
        cout<<ans<<endl;
    }else if(hu&&!sei){
        cout<<ans+2*ma<<endl;
    }else{
        cout<<ans-2*mi<<endl;
    }
        
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll la = a.size();
    reps(i,1,la-1){//N=2なら行わない
        if(a.at(i)>=0){
            printf("%lld %lld\n", mi, a.at(i));
            mi -= a.at(i);
        }else{            
            printf("%lld %lld\n", ma, a.at(i));
            ma -= a.at(i);
        }
    }
    cout<<ma<<' '<<mi<<endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int A, B, C; 
  cin >> A >> B >> C;

  cout << C << " " << A << " " << B << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

SUM = sum(A)
ans = 0

for i in range(N+1):
    SUM -= A[i]
    if i == 0:
        res = min(1 - A[0], SUM)
    else:
        res = min(2*B-A[i], SUM)
    if res < 0:
        ans = -1
        break
    ans = ans + res + A[i] 
    B = res
    
print(ans)

Measured memory_bytes: 20148
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    char str[4];
    map<char,int>m;
    while(cin>>str){
        for(int i=0;i<strlen(str);i++){
            m[str[i]]++;
        }
        map<char,int>::iterator it;
        int flag=1;
        for( it=m.begin();it!=m.end();it++){
            //cout<< it->first <<" "<< it->second <<endl;
            if((it->second) !=2){
                cout<<"No"<<endl;
                flag=0;
                break;
            }
        }
        if(flag)cout<<"Yes"<<endl;
        m.clear();
    }
    return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int n, r;
  cin >> n >> r;
  cout << (n<10 ? (r+100*(10-n)) : r) << endl;
  return 0;
}

Measured memory_bytes: 256
use strict;
use warnings;

my ($h, $w, $k);
{
  my $in = <STDIN>;
  ($h, $w, $k) = split(" ", $in);
}
my (@s, @t);
{
  for (my $i=0; $i<$h; $i++) {
    my $in = <STDIN>;
    my @b = split("", $in);
    my @c;
    for (my $j=0; $j<$w; $j++) {
      push @c, 0;
    }
    $s[$i] = \@b;
    $t[$i] = \@c;
  }
}
my $c = 0;
my $b = 0;
for (my $i=0; $i<$h; $i++) {
  $b = 0;
  for (my $j=0; $j<$w; $j++) {
    if ($s[$i][$j] eq '#') {
      $c++;
      $t[$i][$j] = $c;
      $b = 1;
    }
    if ($b && $s[$i][$j] eq '.') {
      $t[$i][$j] = $c;
    }
  }
}
for (my $i=$h-1; $i>=0; $i--) {
  my $c = -1;
  for (my $j=$w-1; $j>=0; $j--) {
    if ($t[$i][$j]>0) {
      $c = $t[$i][$j];
    } elsif ($c>0) {
      $t[$i][$j] = $c;
    }
  }
}
for (my $j=0; $j<$w; $j++) {
  for (my $i=0; $i<$h; $i++) {
    if ($t[$i][$j]==0) {
      if ($i>0) {
        $t[$i][$j] = $t[$i-1][$j];
      }
    }
  }
}
for (my $j=0; $j<$w; $j++) {
  for (my $i=$h-1; $i>=0; $i--) {
    if ($t[$i][$j]==0) {
      if ($i<$h-1) {
        $t[$i][$j] = $t[$i+1][$j];
      }
    }
  }
}

for (my $i=0; $i<$h; $i++) {
  for (my $j=0; $j<$w; $j++) {
    print $t[$i][$j] . " ";
  }
  print "\n";
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6 1");
            WillReturn.Add("3");
            //4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("10 2");
            WillReturn.Add("4");
            WillReturn.Add("5");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("100 5");
            WillReturn.Add("1");
            WillReturn.Add("23");
            WillReturn.Add("45");
            WillReturn.Add("67");
            WillReturn.Add("89");
            //608200469
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int N = wkArr[0];

        var AArr = new HashSet<int>();
        foreach (string EachStr in InputList.Skip(1)) {
            AArr.Add(int.Parse(EachStr));
        }

        //場合の数[現在位置]なDP表
        int[] DPArr = new int[N + 1];
        DPArr[0] = 1;
        int UB = N;

        for (int I = 0; I <= UB; I++) {
            int NextDan;

            //1段あがる場合
            NextDan = I + 1;
            if (NextDan <= UB && AArr.Contains(NextDan) == false) {
                DPArr[NextDan] = DPArr[NextDan] + DPArr[I];
                DPArr[NextDan] %= 1000000007;
            }

            //2段あがる場合
            NextDan = I + 2;
            if (NextDan <= UB && AArr.Contains(NextDan) == false) {
                DPArr[NextDan] = DPArr[NextDan] + DPArr[I];
                DPArr[NextDan] %= 1000000007;
            }
        }
        Console.WriteLine(DPArr[UB]);
    }
}


Measured memory_bytes: 21728
#include <iostream>
#include <vector>
#include <algorithm>

#include <numeric>
using namespace std;

typedef long long ll;

ll dp[101010];
ll MOD = 1000000007;
bool ban[101010];


int main() {
    int N, M;
    cin>>N>>M;
    
    ll ans;
    for(int i=0;i<M;i++){
        int x;
        cin>>x;
        ban[x] = true;
    }
    dp[0]=1;
    
    for(int i=1;i<=N;i++){
        if(!ban[i]) (dp[i] = dp[i-1]+dp[i-2])%=MOD;
    }
    cout<<dp[N]<<endl;

}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


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

int t[210],v[210];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,x;
    cin>>N>>x;
    vector<ll> a(N),c(N);
    ll ans=0;
    REP(i,N){
        cin>>a[i];
        c[i]=a[i];
        ans+=a[i];
    }
    for(ll t=1;t<N;t++){
        ll cost=t*x;
        for(int i=0;i<N;i++){
            c[i]=min(c[i],a[(i+N-t)%N]);
            cost+=c[i];
        }
        ans=min(ans,cost);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

bool x[maxN];
vector <pii> G[maxN];

void DFS(int v, int p = 0, int w = 0){
	x[v] = x[p] ^ (w % 2);
	for (auto e : G[v]){
		if (e.first == p) continue;
		int u = e.first;
		int wt = e.second;
		DFS(u, v, wt);
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, u, v, w; cin >> n;
	for (int i = 1; i < n; i++){
		cin >> u >> v >> w;
		G[u].push_back({v, w});
		G[v].push_back({u, w});
	}
	x[0] = false;
	DFS(1);
	for (int i = 1; i <= n; i++){
		cout << x[i] << "\n";
	}
	return 0;
}



Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
    	cin>>s[i];
    }
    ll dp[h][w];
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		dp[i][j]=1e9;
    	}
    }
    dp[0][0]=0;
    if(s[0][0]=='#')dp[0][0]++;
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		if(i+1<h)dp[i+1][j]=min(dp[i+1][j],dp[i][j]+((s[i][j]==s[i+1][j])?0:1));
    		if(j+1<w)dp[i][j+1]=min(dp[i][j+1],dp[i][j]+((s[i][j]==s[i][j+1])?0:1));
    	}
    }
    cout << (dp[h-1][w-1]+1)/2 <<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
const int mod=1e9+7;
using namespace std;
char c[5000005];
int n;
int fail[5000005];
int rfail[5000005];
char rc[5000005];

void build()
{
	int j=fail[0]=-1;
	for(int i=1;i<=n;i++)
	{
		while(j>=0 && c[i-1]!=c[j]) j=fail[j];
		j++;
		fail[i]=j;
	}
}

void rbuild()
{
	int j=rfail[0]=-1;
	for(int i=1;i<=n;i++)
	{
		while(j>=0 && rc[i-1]!=rc[j]) j=rfail[j];
		j++;
		rfail[i]=j;
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	scanf("%s",c);
	n=strlen(c);
	for(int i=0;i<n;i++)
	{
		rc[i]=c[n-i-1];
	}
	bool f=true;
	for(int i=0;i<n;i++)
	{
		if(c[i]!=c[0]) f=false;
	}
	if(f)
	{
		cout<<n<<endl<<1<<endl;
		return 0;
	}
	build();
	rbuild();
	int p=n-fail[n];
	if(n%p==0 && n!=p)
	{
		int res=0;
		for(int i=1;i<n;i++)
		{
			if((i)%(i-fail[i])==0 && (i)!=(i-fail[i]) || (n-i)%(n-i-rfail[n-i])==0 && n-i!=n-i-rfail[n-i]) continue;
			res++;
		}
		cout<<2<<endl<<res<<endl;
//		cout<<2<<endl;
//		cout<<(1LL*(n/p)*(p-1)+(n/p==2?1:0))%mod<<endl;
	}
	else
	{
		cout<<1<<endl<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 11008
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//a??¨b?????§?????????

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//a??¨b????°??????????

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//a??¨b???????????¶??????

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//p????´???°,a???b??????p??§?????£?????????

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//p????´???°,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//?????§??¬?´???°

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//????°???¬?????°

int main() {
	
	double r, a1, a2;

	cin >> r;

	a1 = r*r*M_PI;
	a2 = 2 * r*M_PI;

	printf("%f %f\n", a1, a2);

	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int x, y, z; cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z << '\n';
	return 0;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    cout << max({ A + B, A - B, A * B });
    return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    bool equal = true;
    for(int i = 0; i < s.length(); i++) {
        if(s[i] != t[i]) {
            equal = false;
            break;
        }
    }
    cout << (equal ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    Map<Integer, List<Integer>> map = new HashMap<>();
    for(int i = 0; i < m; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(!map.containsKey(a)){
        map.put(a, new ArrayList<Integer>());
      }
      if(!map.containsKey(b)){
        map.put(b, new ArrayList<Integer>());
      }
      List<Integer> list = map.get(a);
      list.add(b);
      map.put(a, list);
      list = map.get(b);
      list.add(a);
      map.put(b, list);
    }
    List<Integer> list = map.get(1);
    for(int i : list){
      List tmp = map.get(i);
      if(tmp.contains(n)){
        System.out.println("POSSIBLE");
        System.exit(0);
      }
    }
    System.out.println("IMPOSSIBLE");
  }
}


Measured memory_bytes: 161980
n = int(input())
s = input()

# ( と )　の数を数える。差の分だけ (→左から追加。 )→右から追加
l=0
r=0
ans = ""

for i in s:
  ans += i
  if i == "(":
    l += 1
  else:
    r += 1
  
  if l - r < 0:
    ans = "(" + ans
    l += 1
    
diff = l - r
ans += ")" * diff
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
#define ALL(X) X.begin(), X.end()
using lint = long long;
template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

int main()
{
    lint n;
    scanf("%lld", &n);

    std::vector<lint> a(n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
    }

    std::vector<lint> ref(1000001, 0);

    for (int i = 0; i < n; ++i)
    {
        ref[a[i]]++;
    }

    lint ans = 0;

    if (ref[1] == 1)
    {
        std::cout << 1 << "\n";
    }
    else if (ref[1] > 1)
    {
        std::cout << 0 << "\n";
    }
    else
    {
        for (int i = 0; i < n; ++i)
        {
            lint cur = a[i];
            lint ok = 1;
            if (ref[cur] == 1)
            {
                for (int j = 2; j < sqrt(cur) + 0.005; ++j)
                {
                    if (cur % j == 0 && (ref[j] != 0 || ref[cur / j] != 0))
                    {
                        ok = 0;
                        break;
                    }
                }
                if (ok == 1)
                {
                    ans++;
                }
            }
        }
        std::cout << ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 12392
# -*- coding: utf-8 -*-
N=input()
dp=[ float("inf") for _ in range(N+1) ]
dp[0]=0

#6円
for k in range(1,10**5):
    yen=6**k
    for i in range(N+1):
        if i+yen<=N:
            dp[i+yen]=min(dp[i+yen],dp[i]+1)
    if N<=yen:break

#9円
for k in range(1,10**5):
    yen=9**k
    for i in range(N+1):
        if i+yen<=N:
            dp[i+yen]=min(dp[i+yen],dp[i]+1)
    if N<=yen:break


#1円
for i in range(N+1):
    if i+1<=N:
        dp[i+1]=min(dp[i+1],dp[i]+1)


print dp[N]


Measured memory_bytes: 33900
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<pair<string,int>,int>mm1,mm2;

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(0);   

  #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout);
      }
  #endif  

  int n;
  cin>>n;
  string s;
  cin>>s;
  string a=s.substr(0,n);
  string b=s.substr(n,n);

  for(int i=0;i<(1<<n);i++)
  {
    string str1="",str2="";
    for(int j=0;j<n;j++)
    {
      if((i&(1<<j)))
      {
        str1+=a[j];
      }
      else
      {
        str2+=a[j];
      }      
    }
    reverse(str2.begin(),str2.end());
    int m=str1.length();
    str1+=str2;
    mm1[{str1,m}]++;
  }

  reverse(b.begin(),b.end());
  for(int i=0;i<(1<<n);i++)
  {
    string str1="",str2="";
    for(int j=0;j<n;j++)
    {
      if((i&(1<<j)))
      {
        str1+=b[j];
      }
      else
      {
        str2+=b[j];
      }      
    }
    reverse(str2.begin(),str2.end());
    int m=str1.length();
    str1+=str2;
    mm2[{str1,m}]++;
  }

  int ans=0;
  for(auto i:mm1)
  {
    ans+=i.second*mm2[i.first];
  }
  cout<<ans;

}

Measured memory_bytes: 87040
#include <iostream>
#include <vector>
#include <algorithm>
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define SUM(X,Y) (acc[Y+1]-acc[X])
using namespace std;

long long a[500], dp[500][500];
long long acc[500];

int main(){
  int n;
  int ans;
  
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> a[i];
    dp[i][0] = 0; // 0初期化されてるけど明示しておく
    acc[i+1] = a[i] + acc[i];
  }  
  for (int len=1; len<n; len++){
    for (int left=0; left+len<n; left++){
      dp[left][len] = dp[left][0] + dp[left+1][len-1] + SUM(left, left) + SUM(left+1, left+len);
      for (int i=0; i<=len; i++){
        long long tmp;
        tmp = dp[left][i] + dp[left+i+1][len-i-1]  + SUM(left, left+i) + SUM(left+i+1, left+len);
        dp[left][len] = MIN(dp[left][len],tmp);
      }
      //cout << left << " to " << (left+len) << ": " << dp[left][len] << endl;
    }
  }
  cout << dp[0][n-1] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 211;

ll n, k, i, cnt;
ll ans;

void brute() {
    int i, cnt, j, k, n;
    int sg[maxN];
    vector<int> aux;

    k = 5;
    n = 80;

    for (i = 0; i < k; i++) sg[i] = 0;
    for (i = k; i <= n; i++) {
        cnt = i / k;
        aux.clear();
        for (j = 1; j <= cnt; j++) aux.pb(sg[i - j]);
        sort(aux.begin(), aux.end());
        aux.resize(unique(aux.begin(), aux.end()) - aux.begin());
        aux.pb(-1);

        sg[i] = 0;
        while (aux[sg[i]] == sg[i]) sg[i]++;
    }

    for (i = 0; i <= n; i++) cerr << sg[i] << ' ';
}

ll slow(ll n, ll k) {
    if (n < k) return 0;
    if (n % k == 0) return n / k;
    return slow(n - (n / k) - 1, k);
}

ll solve(ll n, ll k) {
    ll dif, low, tms;

    while (true) {
        if (n < k) return 0;
        if (n % k == 0) return n / k;

        dif = (n / k) + 1;
        low = (n / k) * k + 1;

        tms = ((n - low) / dif) + 1;
        n -= tms * dif;
    }

}

int main()
{
    //freopen("test.in","r",stdin);

    //brute();

    /*int i, j;
    for (i = 1; i <= 100; i++)
        for (j = 1; j <= 100; j++)
            if (slow(i, j) != solve(i, j))
                cerr << i << ' ' << j << '\n';*/

    cin >> cnt;
    for (i = 1; i <= cnt; i++) {
        cin >> n >> k;
        ans ^= solve(n, k);
    }

    if (ans != 0)
        cout << "Takahashi";
    else
        cout << "Aoki";


    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
    
    private static BufferedReader br;
    private static StringTokenizer strz;
    
	public static void main (String[] args) throws java.lang.Exception {
		br=  new BufferedReader(new InputStreamReader(System.in));
		strz = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(strz.nextToken());
		int k = Integer.parseInt(strz.nextToken());
		
		int[] arr = new int[n];
		
		strz = new StringTokenizer(br.readLine());
		for(int i= 0; i < n; ++i)
		    arr[i] = Integer.parseInt(strz.nextToken());
		    
		Arrays.sort(arr);
		    
		int cost = 0;
		for(int i = 0; i < k; ++i)
		    cost += arr[i];
		System.out.println(cost);
	}
}


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

int main(void) {
	int n, i;
	int ayaneru = 0, asumisu = 0;
	char tomatu[128], sumipe[128];
	if (scanf("%d", &n) != 1) return 1;
	for (i = 0; i < n; i++) {
		int mareitaso;
		if (scanf("%127s%127s", tomatu, sumipe) != 2) return 1;
		mareitaso = strcmp(tomatu, sumipe);
		if (mareitaso > 0) ayaneru += 3;
		else if (mareitaso < 0) asumisu += 3;
		else ayaneru++, asumisu++;
	}
	printf("%d %d\n", ayaneru, asumisu);
	return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
//#define sort(x) sort(x.begin(), x.end())
#define MAX 1000005


int main()
{
 //O_O ;
   ll n,k;
   cin>>n>>k;
   if(n>=k){
     ll ans=n%k;
   if(ans!=0)
   {
     ll temp=abs(ans-k);
     ll mi=min(ans,temp);
     cout<<mi<<nn;
      }
    else
        cout<<0<<nn;


   }

 else
 {

         ll temp=abs(k-n);
         if(temp<n)
            cout<<temp<<nn;
         else
            cout<<n<<nn;



 }



    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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


Measured memory_bytes: 2112
///

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll N = 750002;
const int mod = 1000000007;
const long long int inf = INT64_MAX;
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++)    
void fastIO(void);
 
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);

int main()
{  
  ll a,b;
  cin>>a>>b;
  ll c = a-2*b;
  if(c>0) cout<<c<<endl;
  else cout<<0<<endl;
  
  
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   return ((a%mod)+(b%mod)+mod)%mod;
}
ll modpower(ll a, ll n){
   if(n==0)
      return 1;
   ll result = 1;
   while(n>0){
      if(n%2==1)
         result = modmulti(result,a);
      a = modmulti(a,a);
      n = n/2;
   }
   return result;
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}
 

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define MAX 2000
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2


int A[N][N], n;

int min();

int main(){
  int i, j, a;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &a);
      A[i][j]=a;
      if(A[i][j] ==-1)  A[i][j]=INFTY;
    }
  }

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

  return 0;
}

int min(){
  int i,j,b, min, sum = 0;
  int B[N], C[N], color[N];

  for(i = 0; i < n; i++){
    B[i] = INFTY;
    C[i] = -1;
    color[i] = WHITE;
  }

  B[0] = 0;

  while(1){
    min = INFTY;
    b = -1;
    for(i = 0; i < n; i++){
      if(min > B[i] && color[i] != BLACK){
        b = i;
        min = B[i];
      }
    }
    if(b == -1) break;
    color[b] = BLACK;
    for(j = 0; j < n; j++){
      if(color[j] != BLACK && A[b][j] != INFTY){
        if(B[j] > A[b][j]){
          B[j] = A[b][j];
          C[j] = b;
          color[j] = GRAY;
        }
      }
    }
  }

   for(i = 0; i < n; i++){
    if(C[i] != -1) sum += A[i][C[i]];
  }

  return sum;
}



Measured memory_bytes: 2112