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

int q1,b,c1,c2,q2;

int main() {
    while (cin >> q1, q1) {
        cin >> b >> c1 >> c2 >> q2;
        bool ok = false;
        int x, y;
        for (x=min(b/c1,q2); x>=1; --x) {
            y = (b - c1 * x) / c2;
            if (q1 <= x + y) {
                ok = true;
                break;
            }
        }
        if (ok) {
            cout << x << " " << y << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
import collections
def slove(n, s):
    counter = collections.Counter()
    for i in s:
        counter[i] += 1


    ans = len(counter.keys())
    return ans

if __name__ == "__main__":

    n = int(input())
    s = [input() for i in range(n)]
    print(slove(n, s))

Measured memory_bytes: 38776
#include<iostream>
using namespace std;
long long int MOD = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);

int main() {
	//C
	int n;
	cin >> n;
	int x[100];
	int i;
	for (i = 0; i < n; i++) {
		cin >> x[i];
	}
	int sum, j, summin = 100000000;
	for (i = 0; i <= 100; i++) {
		sum = 0;
		for (j = 0; j < n; j++) {
			sum = sum + (x[j] - i) * (x[j] - i);
		}
		if (sum < summin)summin = sum;
	}
	cout << summin << endl;
	return 0;

	//D
	/*
	long long int n;
	cin >> n;
	long long int a, b;
	cin >> a >> b;
	if (n == 2) {
		cout << 0 << endl;
		return 0;
	}
	long long int sum = 1;
	int i;
	long long int x = 2, m = n;
	//2^nを計算
	while (m > 0) {
		if (m % 2 == 1) {
			sum = (sum * x) % MOD;
		}
		m = (int)(m / 2);
		x = (x * x) % MOD;
	}

	//cout << 1 << endl;
	
	long long int sum1 = 1;
	for (i = 1; i <= a; i++) {
		sum1 = (sum1 * (n + 1 - i)) % MOD;
	}
	for (i = 1; i <= a; i++) {
		sum1 = (sum1 * modinv(i, MOD)) % MOD;
	}
	sum = (sum - sum1 + MOD) % MOD;
	//cout << 2 << endl;

	sum1 = 1;
	for (i = 1; i <= b; i++) {
		sum1 = (sum1 * (n + 1 - i)) % MOD;
	}
	for (i = 1; i <= b; i++) {
		sum1 = (sum1 * modinv(i, MOD)) % MOD;
	}
	sum = (sum - sum1 + MOD) % MOD;
	sum = (sum + MOD - 1) % MOD;
	cout << sum << endl;
	return 0;
	*/
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}

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

int main(){
	int a,b;
	while(1){
		a=-1;
		int ret = 0;
		int data[100]={0};
		while(cin >> a >> b && a || b){
			a--;b--;
			data[a]++;
			data[b]++;
		}
		if(data[0]%2==0 || data[1]%2==0)ret = 10000;
		for(int i=0;i<100;i++){
			if(data[i]%2==1 && data[i]){
				ret++;
			}
		}
		if(a==-1)return 0;
		cout << (ret>2?"NG":"OK") << endl;
	}
	
	
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		if (N == 0) {
			System.out.println(1);
		} else {
			if (N == 1) {
				System.out.println(1);
			} else {
				ans = 2;
				int a = 1;
				int b = 1;
				while (N > 2) {
					int temp = b;
					b = ans;
					ans = ans + temp;
					a = temp;
					N = N - 1;
				}
				System.out.println(ans);
			}
		}
	}

}

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

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

	vector<pair<int, int>> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i].first;
        a[i].second=i+1;
	}
    sort(a.begin(), a.end());
    
    for(auto i : a) cout << i.second << " ";
    cout << endl;
}

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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 100010;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int N,K;
	cin>>N>>K;
	vector<int> a(N);
	int ind = -1;
	for(int i = 0;i < N;i++) cin>>a[i], ind = a[i] == 1?i:ind;
	cout<<(N-1 + K - 2)/(K-1)<<'\n';
	return 0;
}


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

const int mod = 1e9 + 7;
int H, W;
vector<vector<char>> grid;
vector<vector<ll>> dp;

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> H >> W;
	grid.resize(H, vector<char> (W));
	dp.resize(H, vector<ll> (W, 0));
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			cin >> grid[i][j];
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (i == 0 && j == 0)
				continue;
			if (grid[i][j] == '#')
				continue;
			if (i - 1 >= 0)
				dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
			if (j - 1 >= 0)
				dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
		}
	}
	cout << dp[H - 1][W - 1];

	return 0;
}

Measured memory_bytes: 12240
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
using namespace std;


int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    map<int ,int >mp;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int a;
            cin>>a;
            mp[a]++;
        }
    }
    int count=0;
    for(auto it=mp.begin();it!=mp.end();it++){
        //cout<<(*it).first<<endl;
        if((*it).second==n)count++;
    }
    cout<<count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n, m, a, b, c;
  cin >> n >> m;

  map<ll, ll> cnt;
  vl num;

  rep(_, n) {
    cin >> a;
    cnt[a]++;
    num.push_back(a);
  }

  rep(_, m) {
    cin >> b >> c;
    cnt[c] += b;
    num.push_back(c);
  }

  sort(all(num), greater<ll>());

  ll ans=0;
  rep(i, num.size()) {
    if(n - cnt[num[i]] >= 0) {
      ans += num[i] * cnt[num[i]];
      n -= cnt[num[i]];
      cnt[num[i]] = 0;
    }else {
      ans += num[i] * n;
      n = 0;
      break;
    }
  }

  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 17292
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int main(){
	map<string,int> mp;
	mp["SUN"]=0;mp["MON"]=1;mp["TUE"]=2;mp["WED"]=3;
	mp["THU"]=4;mp["FRI"]=5;mp["SAT"]=6;
	string s;cin>>s;
    if(s=="SUN"){ cout<<7<<endl; return 0; }
	cout<<(mp["SUN"]+7-mp[s])%7<<endl;
}
/*タスクを並列に行う 二分探索
sorted
auto it=lower_bound(v.begin(),v.end(),w) v[it-v.begin()]>=w
auto it=upper_bound(v.begin(),v.end(),w) v[it-v.begin()]>w
void func(int* vec){}
puts(string) cout<<string<<endl;
1.*a/b int to double
(int)a-48 char to int
(char)(i+97) int to char
stoi(s) string to int
stoll(s)
cout.precision(16);
cout<<fixed<<a;
printf("%.6lf\n",a);
accumulate(a,a+n,0);
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int mod = 1000000007;
long long dp[100005];

int main() {
  vector<pair<int, int>> g;
  long long n;
  cin >> n;
  int a,b;
  for(int i =0;i<n;i++){
    cin >> a >> b;
    g.push_back({b,a});
  }
  sort(g.begin(), g.end());
  
  long long sa,sb;
  sa = 0;
  sb = 0;
  string flg = "Yes";
  for(int i = 0;i<n;i++){
    sa += g[i].second;
    sb = g[i].first;
    
    if(sa > sb){
      flg = "No";
      break;
    }
  }
  
  cout << flg << endl;
}


Measured memory_bytes: 2420
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

int main()
{
  int a;
  int count;
  int max=0;

  cin >> a;
  int total[a];
  for(int i=0;i<a;i++)
  {
    cin>>total[i];
  }
  for(int i=0;i<a;i++)
  {
    int tmp;
    while(1)
    {
      tmp = total[i] % 2;
      if(tmp==1)break;
      total[i]/=2;
      count++;
    }
    if(max<count)max=count;
  }
  cout << count<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	int sum1,sum2;
	sum1 = x-a;
	sum2 = x-b;
	sum1 < 0 ? sum1 *= -1 : sum1;
	sum2 < 0 ? sum2 *= -1 : sum2;
	sum1 < sum2 ? printf("A\n") : printf("B\n");
	return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

vp pos;
int n;
int ans;

ll gcd(ll a,ll b)
{
    if(a == 0 || b == 0){
        return max(a,b);
    }
    if(a % b == 0){
        return b;
    }else{
        return gcd(b,a%b);
    }
}

P trans(int i,int j)
{
    int nx = pos[i].fi-pos[j].fi;
    int ny = pos[i].se-pos[j].se;
    int g = gcd(abs(nx),abs(ny));
    if(nx < 0 || (nx == 0 && ny < 0)){
        g = -g;
    }
    return P(nx/g,ny/g);
}

void dfs(int u,int used,int par,vp& kp)
{
    if(par == n/2){
        map<P,int> mp;
        rep(i,len(kp)){
            mp[kp[i]]++;
        }
        int cri = 0;
        each(it,mp){
            if(it.se >= 2){
                cri += it.se*(it.se-1)/2;
            }
        }
        cmx(ans,cri);
        return;
    }
    if((used >> u) & 1){
        dfs(u+1,used,par,kp);
    }else{
        srep(i,u+1,n){
            if(!((used >> i) & 1)){
                kp.push_back(trans(u,i));
                used ^= (1 << i);
                dfs(u+1,used,par+1,kp);
                used ^= (1 << i);
                kp.pop_back();
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    pos.resize(n);
    rep(i,n){
        int u,v;
        cin >> u >> v;
        pos[i] = P(u,v);
    }
    vector<P> kp;
    ans = 0;
    dfs(0,0,0,kp);
    cout << ans << "\n";
    return 0;
}

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

int main()
{
    int a, b;
    cin>>a>>b;
    string s;
    cin>>s;
    if(s[a] != '-')
    {
        cout<<"No\n";
        return 0;
    }
    for(int i = 0; i < (int)s.length(); i++)
    {
        if(i == a)
            continue;
        if(s[i] > '9' || s[i] < '0')
        {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC051B
{
    static class Program
    {
        static void Main()
        {
            int[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            int times = 0;

            for (int i = 0; i <= nbrs[0]; i++)
                for (int j = 0; j <= nbrs[0]; j++)
                {
                    int z = nbrs[1] - i - j;
                    if(z >= 0 && z <= nbrs[0])
                        times++;
                }
                    

            Console.WriteLine(times);
        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	double x,y;
	bool erased;
};

typedef Info Vector;

int N;

double calc_dist(double from_x,double from_y,Info to){
	return sqrt((from_x-to.x)*(from_x-to.x)+(from_y-to.y)*(from_y-to.y));
}

double calc(Vector v){
	return sqrt((v.x)*(v.x)+(v.y)*(v.y));
}

double dot(Vector a,Vector b){
	return a.x*b.x + a.y*b.y;
}

double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

void func(){

	Info info[N];

	for(int i = 0; i < N; i++){
		scanf("%lf %lf",&info[i].x,&info[i].y);
		info[i].erased = false;
	}

	double sum_dist = 0.0,min_dist,min_angle,tmp_dist,tmp_angle;
	double current_x = 0.0,current_y = 0.0;
	double naiseki,gaiseki;

	Vector current,tmp,next;
	current.x = 0;
	current.y = 500;


	int next_index;

	for(int loop = 0; loop < N; loop++){

		min_dist = DBL_MAX,min_angle = DBL_MAX;
		for(int i = 0; i < N; i++){
			if(info[i].erased)continue;

			tmp.x = info[i].x - current_x;
			tmp.y = info[i].y - current_y;

			naiseki = dot(current,tmp);
			gaiseki = cross(current,tmp);

			tmp_angle = atan2(gaiseki,naiseki);

			if(tmp_angle <= 0.0+EPS && fabs(tmp_angle) < fabs(min_angle)){
				min_angle = tmp_angle;
				min_dist = calc_dist(current_x,current_y,info[i]);
				next_index = i;
				next = tmp;
			}else if(fabs(min_angle-tmp_angle) < EPS){
				tmp_dist = calc_dist(current_x,current_y,info[i]);
				if(tmp_dist < min_dist){
					min_dist = tmp_dist;
					next_index = i;
					next = tmp;
				}
			}
		}

		info[next_index].erased = true;

		sum_dist += min_dist;

		current_x = info[next_index].x;
		current_y = info[next_index].y;

		current = next;
	}

	printf("%.1lf\n",sum_dist);
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int k, n;
    cin >> k >> n;
    vector<ll> a(n), rev(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        rev[i] = k - a[i];
    }
    a.push_back(a[0] + k);
    ll ans = 1e+15;
    for(int i = 0; i < n; ++i){
        chmin(ans, k - (a[i + 1] - a[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 7552
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N;
    cin >> N;
    auto good_mod = [N](ll x){
        return (x%N + N) % N;
    };
    vector<ll> As(N);
    rep(i,0,N) {
        cin >> As[i];
    }
    vector<ll> Bs(N);
    rep(i,0,N) {
        Bs[i] = As[(i+1)%N] - As[i];
    }
    vector<ll> Cs(N);
    rep(i,0,N) {
        Cs[i] = Bs[(i+1)%N] - Bs[i];
    }
    // N == 1 or 2?
    rep(i,0,N) {
        if (Cs[i] % N != 0) {
            cout << "NO" << endl;
            return 0;
        }
        Cs[i] /= N;
    }
    ll cs_sum = 0;
    rep(i,0,N) {
        cs_sum += Cs[i];
    }
    if (cs_sum != 0) {
        cout << "NO" << endl;
        return 0;
    }
    ll as_sum = 0;
    rep(i,0,N) {
        as_sum += As[i];
    }
    ll inc = (N*(N+1))/2;
    if (as_sum % inc != 0) {
        cout << "NO" << endl;
        return 0;
    }
    ll op_cnt = as_sum / inc;
    ll Nx0 = op_cnt;
    rep(i,0,N) {
        Nx0 -= Cs[good_mod(-1+i)] * (i+1);
    }
    if (Nx0 % N != 0) {
        cout << "NO" << endl;
        return 0;
    }
    if (Nx0 < 0) {
        cout << "NO" << endl;
        return 0;
    }
    ll x0 = Nx0 / N;
    vector<ll> cs_sums(N+1);
    rep(n,1,N+1) {
        cs_sums[n] = cs_sums[n-1] + Cs[n-1];
    }
    vector<ll> xs(N);
    xs[0] = x0;
    rep(i,1,N) {
        xs[i] = cs_sums[N-1] - cs_sums[i-1] + x0;
        if (xs[i] < 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    ll ans = As[0];
    rep(i,1,N+1) {
        ans += (op_cnt - xs[good_mod(i)]) - (N-1) * xs[good_mod(i)];
        if (ans != As[good_mod(i)]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
// #include <math.h>
// #include <cmath>
#include <vector>
#include <utility> 
// #include <unordered_map>

using namespace std;
typedef long long int lli;

#define M_PI_H  3.14159265358979323846/2  /* pi by two*/
#define rep(i, start, end) for(int i = start; i < end; i++) 
#define repr(i, start, end) for(int i = s; i >= end; i--)   //INCLUSIVE


int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	
	long long a;
	long double b;
	cin>>a>>b;

	long double c = (long double)(a) * (b);

	cout<<(long long)c;
    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N; cin >> N;
  long long sum = 0;
  vector<long long> A(N);
  for(long long i = 0; i < N; ++i){
    cin >> A.at(i);
    sum += A.at(i);
  }
  
  long long center, f, l;
  long long x = 0;
  for(long long i = 0; i < N; ++i){
    x += A.at(i) * 2;
    if(x == sum){
      cout << 0 << endl;
      return 0;
    }
    if(x > sum){
      center = i;
      l = x - sum;
      f = sum - x + A.at(i) * 2;
      break;
    }
  }
  
  cout << min(f, l) << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

int dp[201][201];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,d;
	//dp[last][day]
	cin>>d>>n;
	vi t(d),a(n),b(n),c(n);
	rep(i,d)cin>>t[i];
	rep(i,n)cin>>a[i]>>b[i]>>c[i];
	rep(i,201){
		rep(j,201){
			dp[j][i]=-1;
		}
	}
	rep(i,d){
		rep(j,n){
			rep(k,n){
				if(a[k]<=t[i]&&t[i]<=b[k]){
					dp[k][i+1]=max(dp[k][i+1],dp[j][i]+((dp[j][i]!=-1)?abs(c[j]-c[k]):1));
				}
			}
		}
	}
	int ans=0;
	rep(i,n){
		ans=max(ans,dp[i][d]);
	}
	cout<<ans<<endl;
}


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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    double r, are, circ, p=3.141592653589;
    cin >> r;

    are = r * r * p;
    circ = (r + r) * p;

    printf("%f %f\n", are, circ);
}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll ai, bi;
    vector<vector<ll>> G(N, vector<ll>());
    for(int i=0;i<N-1;i++){
        cin >> ai >> bi;
        ai--; bi--;
        G[ai].push_back(bi);
        G[bi].push_back(ai);
    }
    if(N==1){
        cout<<K<<endl;
        return 0;
    }
    ll res = K * (K-1);
    res %= 1000000007;
    set<ll> s;
    queue<ll> q;
    ll u0 = -1;
    for(ll i=0;i<N;i++){
        if(G[i].size()>1) continue;
        u0 = i;
        break;
    }
    s.insert(u0);
    s.insert(G[u0].front());
    q.push(G[u0].front());
    while(!q.empty()){
        auto t = q.front(); q.pop();
        ll cN = 0;
        for(auto v : G[t]){
            if(s.count(v)) continue;
            s.insert(v);
            q.push(v);
            res *= max(K-2-cN, (ll)0);
            res %= 1000000007;
            cN++;
        }
    }
    cout<<res<<endl;

    return 0;
}


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

using namespace std;
using llint = long long int;

#define mod (1000000000 + 7)

int main() {
  __int128 ans = 0;
  int N;
  cin >> N;
  llint A[N];
  for(llint &a : A)
    cin >> a;
  
  llint sum = 0;
  for(int i = 0; i < N; i++)
    sum += A[i];
  
  for(int i = 0; i < N - 1; i++) {
    sum -= A[i];
    ans += ((__int128)A[i]) * sum;
  }
  
  cout << (unsigned int)(ans % mod) << endl; 
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

char s[5];

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    scanf("%s", &s);
    int a = s[0] -'0', b = s[1] -'0', c = s[2] -'0', d = s[3] -'0';
    if (a - b - c - d == 7)
        printf("%d-%d-%d-%d=7\n", a, b, c, d);
    else if (a - b - c + d == 7)
        printf("%d-%d-%d+%d=7\n ", a, b, c, d);
    else if (a - b + c - d == 7)
        printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if (a - b + c + d == 7)
        printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if (a + b - c - d == 7)
        printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if (a + b - c + d == 7)
        printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if (a + b + c - d == 7)
        printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if (a + b + c + d == 7)
        printf("%d+%d+%d+%d=7\n", a, b, c, d);

    return 0;
}

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

int main(void) {
  int N, A, B;
  cin >> N >> A >> B;
  if (abs(A - B) % 2 == 0) {
    cout << "Alice" << endl;
  } else {
    cout << "Borys" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
nStr = str(N)
digit = int(nStr[-1])
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if digit in hon:
	print('hon')
elif digit in pon:
	print('pon')
else:
	print('bon')

Measured memory_bytes: 61624
# -*- coding: utf-8 -*-
#ABC122C
import sys

n = int(input())

minn = int(input())
minn = min(minn,int(input()))
minn = min(minn,int(input()))
minn = min(minn,int(input()))
minn = min(minn,int(input()))

#print(minn)

print(((n-1)//minn)+5)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fore(i,a,b) for(int i=a,to=b;i<to;++i)
using namespace std;
typedef long long ll;

int n;
int a[100005];

int main(){
	scanf("%d",&n);
	fore(i,0,n)scanf("%d",a+i);
	ll r=0;
	fore(i,0,n){
		r+=a[i]/2;
		a[i]%=2;
		if(a[i]&&a[i+1])r++,a[i+1]--;
	}
	printf("%lld\n",r);
	return 0;
}

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

#define ll long long
#define pll pair<ll,ll> 
vector<ll> M;
ll  func(ll A[],ll n,ll p, ll x){
	if(p==n-1)
		return 0;
	if(p>=n-1)
		return INT_MAX;
	ll &ans=M[p];
	if(ans==-1)
		ans=min(func(A, n,p+1,A[p])+abs(A[p]-A[p+1]), func(A,n, p+2, A[p])+abs(A[p]-A[p+2]));
	return ans;
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n,k;
	cin>>n;
	ll A[n];
	M.resize(n,-1);
	for(ll i=0;i<n;i++)
		cin>>A[i];
	
	cout<<func(A,n,0, 0);



}


Measured memory_bytes: 8672
import java.util.Scanner;

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

		System.out.println(sum-N);
	}
}


Measured memory_bytes: 40492
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn is_palindrome(chars: &Vec<char>) -> bool{
    for i in 0..chars.len()/2 {
        if chars[i] != chars[chars.len()-i-1] {
            return false;
        }
    }
    return true;
}

fn main() {
    let s = read::<String>();
    let chars = s.chars().collect::<Vec<char>>();

    if !is_palindrome(&chars) {
        println!("No");
        return;
    }

    let sub_chars = s.chars().take(chars.len()/2).collect::<Vec<char>>();
    if !is_palindrome(&sub_chars) {
        println!("No");
        return;
    }
    let sub_chars = s.chars().skip((chars.len()+1)/2).collect::<Vec<char>>();
    if !is_palindrome(&sub_chars) {
        println!("No");
        return;
    }

    println!("Yes");
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <sstream>
#include <map>
#include <algorithm>
using namespace std;

int toInt(const char *a){
  stringstream ss;
  int b;
  string s(a);
  ss<<s;
  ss>>b;
  return b;
}

string toStr(int a){
  stringstream ss;
  ss<<a;
  string s;
  ss>>s;
  return s;
}

int main(void){
  string a;
  int l;
  while(cin>>a>>l,a!="0"||l){
    map<string,int> v;
    for(int i=0;;++i){
      for(;a.size()<l;)a="0"+a;
      if(v.find(a)!=v.end()){cout<<v[a]<<" "<<toInt(a.c_str())<<" "<<i-v[a]<<endl;break;}
      v[a]=i;
      char *min,*max;
      min=(char *)malloc((l+1)*sizeof(char));
      max=(char *)malloc((l+1)*sizeof(char));
      strcpy(min,a.c_str());
      strcpy(max,a.c_str());
      sort(min,min+l);
      sort(max,max+l,greater<char>());
      a=toStr(toInt(max)-toInt(min));
      free(min);
      free(max);
    }
  }
  return 0;
}

Measured memory_bytes: 1268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NL = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var a = Enumerable.Range(NL[1], NL[0]).Select(x => x).ToArray();
            var min = a.First(x => x < 0 ? -1*x == a.Min(y => Math.Abs(y)) :  x == a.Min(y => Math.Abs(y)));
            Console.WriteLine(a.Where(x => x != min).ToArray().Sum());

        }




       

    }
}


Measured memory_bytes: 13524
loop do
m,f,r = gets.split.map(&:to_i)

if m == -1 && f == -1 && r == -1 then
exit
else
if m == -1 || f == -1 then
puts "F"
else
d = m+f
if d >= 80 then
puts "A"
else
if d >= 65 then
puts "B"
else
if d >= 50 then
puts "C"
else
if d >= 30 then
if r >= 50 then
puts "C"
else
puts "D"
end
else
puts "F"
end
end
end
end
end
end
end



Measured memory_bytes: 6868
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int p, q, r;
  cin >> p >> q >> r;
  cout << min({p + q, p + r, q + r}) << endl;
  return 0;
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 lcm(u64 a, u64 b) { return (a / gcd(a, b)) * b; }

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

  vector<double> P(N);
  for (u32 i = 0; i < N; ++i) {
    double p;
    cin >> p;
    P[i] = (p + 1) / 2;
  }
  vector<double> K_res(N - K + 1, 0);
  double tmp_res = 0;
  for (u32 i = 0; i < K; ++i) tmp_res += P[i];
  K_res[0] = tmp_res;
  for (u32 i = K; i < N; ++i) {
    tmp_res -= P[i - K];
    tmp_res += P[i];
    K_res[i - K + 1] = tmp_res;
  }
  cout << setprecision(15) << *max_element(K_res.begin(), K_res.end()) << endl;

  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define inf 10000000000000ll
using namespace std;
int read();
int n, a, b;

#define root 0, n, 1
#define ls l, mid, k << 1
#define rs mid + 1, r, k << 1 | 1
struct Seg {
    long long tmn[400005], tag[400005];
    void Tag(int k, long long v) { tmn[k] += v, tag[k] += v; }
    void psd(int k) {
        Tag(k << 1, tag[k]), Tag(k << 1 | 1, tag[k]), tag[k] = 0;
    }
    void update(int k) { tmn[k] = min(tmn[k << 1], tmn[k << 1 | 1]); }
    void build(int l, int r, int k) {
        if (l == r) return tmn[k] = l ? inf : 0, void();
        int mid = l + r >> 1;
        build(ls), build(rs), update(k);
    }
    void modi(int l, int r, int k, int p, long long v) {
        if (l == r) return tmn[k] = v, void();
        psd(k);
        int mid = l + r >> 1;
        p <= mid ? modi(ls, p, v) : modi(rs, p, v), update(k);
    }
    long long qry(int l, int r, int k, int st, int en) {
        if (st > r || en < l) return inf;
        if (st <= l && en >= r) return tmn[k];
        psd(k);
        int mid = l + r >> 1;
        return min(qry(ls, st, en), qry(rs, st, en));
    }
    void add(int l, int r, int k, int st, int en, int v) {
        if (st > r || en < l) return;
        if (st <= l && en >= r) return Tag(k, v);
        psd(k);
        int mid = l + r >> 1;
        add(ls, st, en, v), add(rs, st, en, v), update(k);
    }
} seg;

int main() {
    n = read(), a = read(), b = read();
    seg.build(root);
    for (int i = 1, x; i <= n; ++i) {
        x = read(), seg.modi(root, x, seg.qry(root, 0, x));
        seg.add(root, 0, x - 1, a), seg.add(root, x + 1, n, b);
    }
    printf("%lld\n", seg.qry(root, 0, n));
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}

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

int main(){
  
  int N;
  cin >> N;
  vector<int64_t> L(N+1);
  
  L.at(0)=2;
  L.at(1)=1;
  
  for(int i=2; i<=N; i++){
    L.at(i)=L.at(i-1)+L.at(i-2);
  }
  cout << L.at(N) << endl;
}

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

int N, L;
vector<int> s, t, u;

bool is_ok(const double p, double &tank) {
    bool is_ok = true;
    for (int i = 1; is_ok && i < s.size(); i++) {
        tank = min((double)L, tank + (s[i] - t[i-1]) * p);
        tank = min((double)L, tank + (t[i] - s[i]) * (p - u[i]));
        if (tank < 0) is_ok = false;
    }
    return is_ok;
}

int main() {
    while (cin >> N >> L, N + L) {
        s.clear(); t.clear(); u.clear();
        s.resize(N + 2); t.resize(N + 2); u.resize(N + 2);
        s[0] = t[0] = u[0] = 0;
        for (int i = 1; i <= N; i++)
            cin >> s[i] >> t[i] >> u[i];
        s[N + 1] = t[N + 1] = 86400;
        u[N + 1] = 0;

        double left = 0, right = 1e6;
        while (right - left > 1e-8) {
            double mid = (right + left) / 2;

            bool flag = true;
            double first = L;
            flag = flag && is_ok(mid, first);
            double second = first;
            flag = flag && is_ok(mid, second) && (first <= second);

            if (flag)
                right = mid;
            else
                left = mid;
        }
        printf("%.12lf\n", left);
    }
}



Measured memory_bytes: 3904
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		 try {
	            InputStreamReader isr = new InputStreamReader(System.in);
	            BufferedReader br = new BufferedReader(isr);
	            String buf = br.readLine();
	            StringTokenizer st=new StringTokenizer(buf," ");
	            int W = Integer.parseInt(st.nextToken());   //??????(H)???height
	            int H = Integer.parseInt(st.nextToken());   //???(W)???wide
	            int x = Integer.parseInt(st.nextToken());   //x???????¨? ????????¢???
	            int y = Integer.parseInt(st.nextToken());   //y????????? ???????????¢???
	            int r = Integer.parseInt(st.nextToken());   //??????
	 
	            if(-100 <=x && x<=100 && -100 <=y && y<=100 && 0<W && W <=100 && 0<H && H <=100 && 0<r && r <=100){
	 
	                if( (x-r) >= 0 && (x+r) <= W && (y-r) >=0 && (y+r) <= H ){
	 
	                    System.out.println("Yes");
	                } else{
	                    System.out.println("No");
	                }
	            }
	 
	        } catch(IOException e) {
	            System.err.println(e);
	        }

	}

}

Measured memory_bytes: 24444
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String value = sc.nextLine();
		
		switch (value) {
		case "22": System.out.println("Christmas Eve Eve Eve");
			break;
		case "23": System.out.println("Christmas Eve Eve");
		break;
		case "24": System.out.println("Christmas Eve");
		break;
		case "25": System.out.println("Christmas");
		break;
		default: System.out.println("input again");
			break;
		}
	}
}


Measured memory_bytes: 21972
def c(n, i, j)
	k = 1
	digits = 1
	count = 0
	while true
		k = 10 ** (digits - 1) * i
		while k / (10 ** (digits - 1)) == i and k <= n
			count += 1 if k % 10 == j
			k += 1
		end
		break if k > n

		digits += 1
	end
	count
end

def handstand(n)
	array = Array.new(9) {Array.new(9, -1)}
	count = 0
	(1..9).each do |i|
		(1..9).each do |j|
			if array[i - 1][j - 1] == -1
				array[i - 1][j - 1] = c(n, i, j)
			end
			if array[j - 1][i - 1] == -1
				array[j - 1][i - 1] = c(n, j, i)
			end
			count += array[i - 1][j - 1] * array[j - 1][i - 1]
		end
	end
	count
end

n = gets.chomp.to_i
puts handstand(n)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector<bool> memo(n, false);
	ll counter = 0;
	for (int i = 0; i < n; i++) {
		if (memo[i])
			continue ;
		ll tmp = a[i];
		while (tmp <= a[n-1])
		{
			auto it = equal_range(a.begin() + i + 1, a.end(), tmp);
			if (tmp == a[i] && it.first == it.second)
				counter++;
			while (it.first != it.second)
			{
				memo[it.first - a.begin()] = true;
				(it.first)++;
			}
			tmp += a[i];
		}
	}
	cout << counter << endl;
}


Measured memory_bytes: 4016
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define sz(v) (ll)v.size()
#define inf 1000000000000000000
#define vll vector<ll>
using namespace std;
const int N=100005;

void solve()
{
	ll n,a[N],i,ans,pre1,pre2;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	ans=-a[0]+a[n-1];
	for(i=1;i<n-1;i++)
		ans+=abs(a[i]);
	cout<<ans<<"\n";
	pre1=a[n-1];
	for(i=1;i<n-1;i++)
	{
		if(a[i]<0)
		{
			cout<<pre1<<" "<<a[i]<<"\n";
			pre1-=a[i];
		}
		else
			break;
		
	}
	pre2=a[0];
	for(i=n-2;i>0;i--)
		if(a[i]>=0)
		{
			cout<<pre2<<" "<<a[i]<<"\n";
			pre2-=a[i];
		}
	cout<<pre1<<" "<<pre2<<"\n";
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

Measured memory_bytes: 2688
def main():
	A, B, C, D, E, F = map(int, input().split())
	water = set()
	sugar = set()

	for i in range(F // (100 * A) + 1):
		for j in range(F // (100 * B) + 1):
			water_amount = 100 * A * i + 100 * B * j
			if 0 < water_amount and water_amount <= F:
				water.add(water_amount)

	for i in range(F // C + 1):
		for j in range(F // D + 1):
			sugar_amount = C * i + D * j
			if sugar_amount <= F:
				sugar.add(sugar_amount)

	# print(water)
	# print(sugar)

	max_c = -1
	max_w = 0
	max_s = 0

	for w in water:
		for s in sugar:
			if w + s <= F:
				if s / w <= E / 100:
					if s * 100 / (w + s) > max_c:
						max_c = s * 100 / (w + s)
						max_w = w
						max_s = s

	print(max_w + max_s, max_s)

 
if __name__ == "__main__":
  	main()

Measured memory_bytes: 9252
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
#[macro_use] extern crate text_io;
use proconio::marker::*;
use std::mem::*;
use std::collections::*;
use std::cmp::*;

#[fastout]
fn main() {
    input!{
        d:i32,t:i32,s:i32
    }
    if s*t>=d{
        println!("Yes");
    }else{
        println!("No");
    }
}

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

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

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

ll a,b,x;
ll f(ll n){
  if(n==-1){
    return 0ll;
  }
  return n/x+1;
}
int main(){
  cin >>a>>b>>x;
  cout << f(b)-f(a-1)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
main()
{
	int i,n,a,b,A,B;
	while(scanf("%d",&n)){
		if(n==0) break;
		A=0;
		B=0;
		for(i=0;i<n;i++){
			scanf("%d %d",&a,&b);
			if(a>b){
				A+=a+b;
			}
			else if(a<b){
				B+=a+b;
			}
			else{
				A+=a;
				B+=b;
			}
		}
		printf("%d %d\n",A,B);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int N, D;
    cin >> N >> D;
    
    cout << (N % (2*D + 1) ? N / (2*D + 1) + 1 : N / (2*D + 1)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import bisect

INF = 1e+11
A,B,Q=map(int, input().split())
s = [-INF]+[int(input()) for _ in range(A)]+[INF]
t = [-INF]+[int(input()) for _ in range(B)]+[INF]
x = [int(input()) for _ in range(Q)]

for i in range(Q):
    a,b= bisect.bisect_right(s,x[i]), bisect.bisect_right(t,x[i])
    ans = INF
    for S in [s[a-1], s[a]]:
        for T in [t[b-1], t[b]]:
            d1 = abs(S-x[i])+abs(S-T)
            d2 = abs(T-x[i])+abs(S-T)
            ans = min(ans, d1, d2)
    print(ans)



Measured memory_bytes: 81244
#include<iostream>
#include<vector>
#include<utility>
using namespace std;

string itos(int a){
  string s;
  int k = 1000;
  for(int i=0;i<4;i++){
    s.push_back(a/k+'0');
    a -= (a/k)*k;
    k/=10;
  }
  return s;
}

pair<int,int> hitblow(string a,string b){
  pair<int,int> res;
  int c = 0;
  bool ca[10],cb[10];
  for(int i=0;i<10;i++){
    ca[i] = false;
    cb[i] = false;
  }
  for(int i=0;i<(int)a.size();i++){
    if(a[i] == b[i])c++;
    ca[a[i]-'0'] = true;
    cb[b[i]-'0'] = true;
  }

  res.first = c;
  c = 0;
  for(int i=0;i<10;i++){
    if(ca[i] && cb[i])c++;
  }
  res.second = c - res.first;

  return res;
}

int main(){
  bool check[10000],hoge[10000];
  string str;
  int h,b,n;

  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
	for(int l=0;l<10;l++){
	  if(i==j || i== k|| i==l || j==k || j==l || k==l){
	    hoge[i*1000+j*100+k*10+l] = false;
	  }else{
	    hoge[i*1000+j*100+k*10+l] = true;
	  }
	}
      }
    }
  }

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<10000;i++)check[i] = hoge[i];

    for(int i=0;i<n;i++){
      cin >> str >> h >> b;
      for(int i=0;i<10000;i++){
	if(check[i]){
	  pair<int,int> tmp;
	  tmp = hitblow(itos(i),str);
	  check[i] = (tmp.first == h) && (tmp.second == b);
	}
      }
    }
 
    int c = 0;
    for(int i=0;i<10000;i++){
      if(check[i])c++;
    }
    if(c==1){
      for(int i=0;i<10000;i++){
	if(check[i])cout << itos(i) << endl;
      }
    }else{
      vector<int> can;
      for(int i=0;i<10000;i++){
	if(check[i])can.push_back(i);
      }
      int i;
      for(i=0;i<10000;i++){
	if(hoge[i]){
	  int hb[5][5];
	  for(int j=0;j<5;j++){
	    for(int k=0;k<5;k++)hb[j][k] = 0;
	  }
	  bool f = true;
	  for(int j=0;j<(int)can.size();j++){
	    pair<int,int> tmp;
	    tmp = hitblow(itos(i),itos(can[j]));
	    hb[tmp.first][tmp.second]++;
	    if(hb[tmp.first][tmp.second]>=2){
	      f = false;
	      break;
	    }
	  }

	  if(f){
	    cout << itos(i) << endl;
	    break;
	  }
	}
      }
      if(i==10000)cout << "????" << endl;
    }
  }
}

Measured memory_bytes: 952
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  char s[11];
  scanf("%s", s);
  int l=strlen(s);
  if (s[0] == 'A') {
    int boo = 0;
    for (int i=1; i<l; i++) {
      if (s[i]-'a' >= 0 && s[i]-'a' <26) continue;
      else if (s[i] == 'C' && boo == 0 && i>1 && i<l-1) boo = 1;
      else {
        printf("WA\n");
        return 0;
      }
    }
    if (boo == 1) {
      printf("AC\n");
      return 0;
    }
  }
  printf("WA\n");
  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import math
import datetime
import itertools
import sys
import copy

# 入力
#N = int(input())
#S = str(input())
#N, A, B = map(int, input().split())

N, W = map(int, input().split())
H = []
for _ in range(N) :
  H.append(list(map(int, input().split())))
#print(H)

#N(i+1)個目の品物を追加したときにWjとなる場合のWj地点の最大価値
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(1, N+1) :
  for j in range(W+1) :
    dp[i][j] = max(dp[i-1][j], dp[i][j])
    if dp[i-1][j] > 0 and j+H[i-1][0] <= W:
      dp[i][j+H[i-1][0]] = max(dp[i-1][j+H[i-1][0]], dp[i-1][j] + H[i-1][1])
    
  dp[i][H[i-1][0]] = max(dp[i-1][H[i-1][0]], H[i-1][1])
  #print (dp[i])      
#print (dp)

print (max(dp[N]))

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

int main(){
    string s;
    cin >> s;
    bool flag_g = true, flag_k = true;
    string gu = "", ki = "";

    rep(i, int(s.length())) {
        if (i%2 == 0 && s[i] == 'L') {
            cout << "No" << endl;
            return 0;
        } else if (i%2 != 0 && s[i] == 'R') {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    

    return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	ll val = 1;
	ll digit = 1;
	while (true) {
		val *= K;
		if (val > N){
			break;
		}
		digit++;
	}

	cout << digit << endl;

	return 0;
}


Measured memory_bytes: 256
import sys

line = sys.stdin.readline()
inp = []
for i in line.split(" "):
    inp.append(int(i))
a = inp[0]
b = inp[1]

if a<b:
    print("a < b")
elif a==b:
    print("a == b")
elif a>b:
    print("a > b")

Measured memory_bytes: 7584
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  string S; cin >> S;
  int n = S.length();

  string s_ans1, s_ans2;
  rep(i, n){
    s_ans1 += '0';
    s_ans2 += '1';
    if (s_ans1.length() == n) break;
    s_ans1 += '1';
    s_ans2 += '0';
    if (s_ans1.length() == n) break;
  }
  int ans1 = 0, ans2 = 0;
  rep(i, n){
    if (S[i] != s_ans1[i]) ans1++;
    if (S[i] != s_ans2[i]) ans2++;
  }
  cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 768