akhauriyash/Code-Regression huggingface dataset:
#include<string>
#include <iostream>
#include<math.h>

using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int N, K;
int a, b;
string s;
int d[100000 + 1];

int main(void) {
    int x, c;
    cin >> a >> b >> c >> x;
    int m = 0;
    for (int i = 0;i<=a; i++) {
        for (int j = 0;j<=b; j++) {
            for (int k = 0;k<=c;k++) {
                if (500 * i + 100 * j + 50 * k == x) {
                    m++;
                }
                if (500 * i + 100 * j + 50 * k > x) break;
            }
            if (500 * i + 100 * j > x) break;
        }
        if (500 * i > x) break;
    }


    cout << m << endl;
    return 0;
}




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

int main(){
  int a, b, c, d, e, k;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> k;

  if ((e - a) > k){
    cout << ":(" << endl;
  } else{
    cout << "Yay!" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}


int n;

ll a[100100];

int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i];
	ll tl=2,th=2;
	for(int i=n-1;i>=0;i--){
		//cout<<i<<endl;
		tl=((tl+a[i]-1)/a[i])*a[i];
		if(tl>th){
			cout<<"-1"<<endl;
			return 0;
		}
		th=((th/a[i])*a[i])+a[i]-1;
	}
	cout<<tl<<" "<<th<<endl;
	return 0;
}
	

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
#define inf 0x7fffffff
using namespace std;
char s[55], t[55];
int lens, lent;
bool check(int pos) {
	for(int i = pos; i <= pos + lent - 1; i++) {
		if(s[i] != t[i - pos + 1] && s[i] != '?') return false;
	}
	return true;
}
int main() {
	scanf("%s%s", s + 1, t + 1);
	lens = strlen(s + 1);lent = strlen(t + 1);
	for(int i = lens - lent + 1; i >= 1; i--) {
		if(check(i)) {
			for(int k = 1; k < i; k++) {
				if(s[k] == '?')printf("a");
				else printf("%c", s[k]);
			}
			printf("%s", t + 1);
			for(int k = i + lent; k <= lens; k++)
				if(s[k] == '?')printf("a");
				else printf("%c", s[k]);
			printf("\n");
			return 0;
		}
	}
	printf("UNRESTORABLE\n");
	return 0;
}

Measured memory_bytes: 128
d,n = map(int,input().split())
 
if d == 0:
  if n == 100:
    print(101)
  else:
    print(n)
elif d == 1:
  if n == 100:
    print(10100)
  else:
    print(100*n)
elif d == 2:
  if n == 100:
    print(1010000)
  else:
    print(10000*n)

Measured memory_bytes: 3060
import heapq
X,Y,Z,K=map(int,input().split())
A=sorted([-int(i) for i in input().split()])
B=sorted([-int(i) for i in input().split()])
C=sorted([-int(i) for i in input().split()])
q=[]
heapq.heappush(q,(A[0]+B[0]+C[0],0,0,0))
S={(0,0,0)}
for n in range(K):
    p,i,j,k=heapq.heappop(q)
    if i+1<X and not((i+1,j,k) in S):
        S.add((i+1,j,k))
        heapq.heappush(q,(A[i+1]+B[j]+C[k],i+1,j,k))
    if j+1<Y and not((i,j+1,k) in S):
        S.add((i,j+1,k))
        heapq.heappush(q,(A[i]+B[j+1]+C[k],i,j+1,k))
    if k+1<Z and not((i,j,k+1) in S):
        S.add((i,j,k+1))
        heapq.heappush(q,(A[i]+B[j]+C[k+1],i,j,k+1))
    print(-p)


Measured memory_bytes: 4976
#include<bits/stdc++.h>
using namespace std;
#define ll "%I64d"
const int max1=100010;
//long long a[max1],b[max1];
int main()
{
    // string s1,s2;
    int a,b,x=0,y=0,z=0;
    cin>>a;
    int c[a+5];
    for(int i=0; i<a; i++)
    {
        cin>>c[i];
        if(x>0)
        {
            if(c[i-1]>=c[i])
            {
                y++;
               // cout<<y<<"\n";
                if(z<=y)
                {
                    z=y;
                   // y=0;
                }
            }
            else
            {
                y=0;
            }
        }
        x++;

    }
    cout<<z<<"\n";
}



Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

double p;
constexpr int MN = 100001;
int N;
vector<pii> g[MN];

double poi;

double dfs1(int cur,int pre){
    double ret=0;
//    for(int i=0;i<g[cur].size();i++){ <- ok
    for(pii v : g[cur]){
        if(v.first==pre) continue;
        ret += p*(double)(v.second+dfs1(v.first,cur));
    }
    return ret;
}

double dfs2(int cur,int pre){
    double ret=poi;
    for(int i=0;i<g[cur].size();i++){
        if(g[cur][i].first==pre) continue;
        ret += p*(g[cur][i].second+dfs2(g[cur][i].first,cur));
    }
    return ret;
}

int main(){
    cin >> p;
    cin >> N;
    rep(i,N-1){
        int x,y,c;cin>>x>>y>>c;
        x--;y--;
        g[x].pb(MP(y,c));
        g[y].pb(MP(x,c));
    }
    poi = dfs1(0,-1);
    cout << Double(dfs2(0,-1)) << endl;
}

Measured memory_bytes: 14960
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int dp[100010];
int N, K;
int h[100010];

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

	cin >> N >> K;
	rep(i, 0, N)cin >> h[i];

	rep(i, 0, N)dp[i] = INF;
	dp[0] = 0;

	rep(i, 1, N)
	{
		rep(j, 1, K + 1)
		{
			if (i - j >= 0)
			{
				chmin(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
			}
		}
	}

	cout << dp[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD               1000000007
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
bool cmp(ll x,ll y)
{
   return x>y;
}
int main(void)
{
   optimize
   //long long int t,n,m,k,x,y,a[200001];
   vector<ll> v,v1,v2;
   vector< pair <ll,ll> >p,p1,p2;
   set<ll> st;
   priority_queue<ll> pq;
   priority_queue< ll,vector<ll>,greater<ll> > lpq;
   priority_queue< pair<ll,ll> > phpq;
   priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair <ll,ll> > > plpq;
   //string s;
   //cin>>t;
   //while(t--)
   //{
   float t,d,s,str;
      cin>>d>>t>>s;
      str=d/s;
      if(str<=t)
         cout<<"Yes"<<endl;
      else
         cout<<"No"<<endl;
   //}
   return 0;
}


Measured memory_bytes: 3760
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var NX = ReadSplitInt();
            var N = NX[0];
            var X = NX[1];
            var x = ReadSplitInt();

            var a = new int[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = Abs(X - x[i]);
            }

            var ans = a[0];
            for (int i = 1; i < N; i++)
            {
                ans = Gcd(ans, a[i]);
            }

            Println(ans);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 19680
//PLUS ULTRA

#include<bits/stdc++.h>
using namespace std;
     
     
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
/*
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)
*/
#define moder 1000000007
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define nfor(i,st,n) for(int i = st; i >= n ; i--)
#define pb push_back 
#define mp make_pair


ll moding( ll x , ll y ){
    ll ans = x % y;
    if(ans < 0)ans = ans + y ;
    return ans ;
}


bool isprime(ll n){
    if(n==2) return true;
    if(n==3) return true;
    if(n%2 == 0) return false;
    if(n%3 == 0) return false;

    ll i = 5,w=2;

    while(i*i <= n){
        if(n%i == 0)return false;
        i += w;
        w = 6 - w;
    }
    return true;
}

ll cmp(string s1 , string s2){
    // 1 for diff , 0 for same 
    int n = s1.size();
    int m = s2.size();
    if(n!=m)return 1;
    for(int i = 0 ; i < n ; i++)
        if(s1[i] != s2[i])return 1;
    return 0; // SAME
}

ll hcf(ll n1, ll n2) {
    if (n2 != 0)
        return hcf(n2, n1 % n2);
    else
        return n1;
}


int main(){

    SPEED;

    int a , b, c;

    cin >> a >> b >> c;

    int z = max(a,max(b,c));
    int x = min(a,min(b,c));
    int y = a + b + c - x - z;

    if((x == y && y != z) || (y==z && x != y) ){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;



           
     
     
        
    return 0;
}
      
       

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

void chmin(int& a, int b){
    a = min(a, b);
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N, Ma, Mb, a[40], b[40], c[40];
    cin >> N >> Ma >> Mb;
    for(int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i];

    // C[g][s] = グループgの選び方（1つ以上）で Mb*sumA - Ma*sumB = s となるときの最小コスト
    // sが負の値になり得るのでmap
    map<int, int> C[2];
    
    // グループgに属するのはインデックス [start[g], term[g]) の範囲のものとする
    int start[2] = {0, N/2}, term[2] = {N/2, N};
    
    for(int g=0; g<2; g++){
        int sz = term[g] - start[g];
        // 全列挙。1つ以上選ぶのでbits=0を見ない
        for(int bits=1; bits<(1<<sz); bits++){
            int s = 0, cost = 0;
            for(int i=0; i<sz; i++) if(nth_bit(bits, i)){
                s += Mb * a[i+start[g]] - Ma * b[i+start[g]];
                cost += c[i+start[g]];
            }
            if(C[g].count(s)){
                chmin(C[g][s], cost);
            }else{
                C[g][s] = cost;
            }
        }
    }

    // C[0][0], C[1][0], C[0][s] + C[0][-s] をそれぞれ調べる
    const int INF = 1e9;
    int ans = INF;
    for(int g=0; g<2; g++) if(C[g].count(0)) chmin(ans, C[g][0]);
    for(auto& p : C[0]){
        int s = p.first, c0 = p.second;
        if(C[1].count(-s)) chmin(ans, c0 + C[1][-s]);
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int n, x, max;
    cin >> n;
    x = 1;
    max = 0;
    
    for (int i = 0; i < n; i++) {
        int j = i + 1;
        int counter = 0;

        while (true) {
            bool flg = true;

            if (j % 2 == 0) {
                j = j / 2;
                ++counter;
            }
            else {
                break;
            }
        }

        if (counter > max) {
            max = counter;
            x = i + 1;
        }
    }

    cout << x << endl;
}


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

using namespace std;

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

  int p = 1;
  vector<int> ans;
  while (true) {
    if (n < p) {
      break;
    }
    n -= p;
    ans.push_back(p++);
  }

  for (int i = 0; i < n; i++) {
    ans[ans.size() - i - 1]++;
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    int ar[n];
    for(int i=0; i<n; i++) cin>>ar[i];
    sort(ar, ar+n);
    reverse(ar, ar+n);
    int x=0, y=0;
    for(int i=0; i<n; i++){
        if(i%2==0) x+=ar[i];
        else y+=ar[i];
    }
    cout<<x-y<<endl;
}


Measured memory_bytes: 256
n, m, x = gets.chomp.split(' ').map(&:to_i)
c = []
a = []
costs = []

n.times do
  tmp = gets.chomp.split(' ').map(&:to_i)
  c << tmp[0]
  a << tmp[1..m]
end

[0, 1].repeated_permutation(n) do |bits|
  cost = 0
  skills = Array.new(m, 0)
  
  bits.each_with_index do |v, i|
    if v == 1
      cost += c[i]
      skills = [skills, a[i]].transpose.map{|a| a.inject(:+) }
    end
  end
  
  costs << cost if skills.all? { |j| j >= x }
end

puts costs.empty? ? -1 : costs.min


Measured memory_bytes: 14404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(std::string b)
{
    if (b == "A")
    {
        cout << "T" << endl;
    }
    else if (b == "C")
    {
        cout << "G" << endl;
    }
    else if (b == "G")
    {
        cout << "C" << endl;
    }
    else
    {
        cout << "A" << endl;
    }
}

int main()
{
    std::string b;
    std::cin >> b;
    solve(b);
    return 0;
}


Measured memory_bytes: 256
#問題2
#https://qiita.com/drken/items/a5e6fe22863b7992efdb
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp
n, w = map(int,input().split())
value = []
weight = []

for i in range(n):
    val,wei = map(int,input().split())
    value.append(val)
    weight.append(wei)
    
#dp i <= 110, w <= 1010
dp = []
for i in range(110):
    o = [0 for i in range(10010)]
    dp.append(o)

#i = 0 何も入れない状態を初期化する

for ww in range(w):
    dp[0][ww] = 0

for i in range(0,n):
    for ww in range(w+1):
        #dp[i+1]に最終状態が格納される
        if ww >= weight[i] :
            dp[i+1][ww] = max(dp[i][ww-weight[i]] + value[i], dp[i][ww])
        else:
            dp[i+1][ww] = dp[i][ww]
print(dp[n][w])


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

int main(){
    int n;
    cin >> n;
    map<string, int> poll;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        if(poll.count(s)) poll[s]++;
        else poll[s]=1;
    }
    vector<string> maxs;
    int max = 0;
    for(auto pp:poll){
        string name = pp.first;
        int times = pp.second;
        if(times<max) continue;
        else if(times == max) maxs.push_back(name);
        else{
            max = times;
            maxs = {};
            maxs.push_back(name);
        }
    }
    for(string s:maxs) cout << s << endl;
}

Measured memory_bytes: 26868
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product#accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
from collections import deque
def run():
    N, M = map(int, sysread().split())
    to = [[] for _ in range(N+1)]
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    for a,b in zip(A,B):
        to[a].append(b)
        to[b].append(a)

    seen = [False] * (N+1)
    queue = deque([])
    seen[1] = True
    queue.append((1, 0))# (node, prev)
    mark = [0] * (N+1)

    while queue:
        current, prev = queue.popleft()
        for next in to[current]:
            if not seen[next]:
                queue.append((next, current))
                mark[next] = current
                seen[next] = True

    print('Yes')
    mark = [str(val) for val in mark]
    print('\n'.join(mark[2:]))

if __name__ == "__main__":
    run()

Measured memory_bytes: 59504
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  string S;
  cin>>N>>K>>S;
  
  if (S.at(K-1) == 'A') {
    S.at(K-1) = 'a';
  }
  else if (S.at(K-1) == 'B') {
    S.at(K-1) = 'b';
  }
  else if (S.at(K-1) == 'C') {
    S.at(K-1) = 'c';
  }
  
  cout<<S<<endl;
}

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

int f(long x,long y){
  long a;
  int cnt=0;
  if(x<y)
    a=y;
  else
    a=x;
  for(;a>=10;a/=10)
    cnt++;
  return cnt+1;
}

int main(){
  long n,r;
  int ans=100;
  cin>>n;
  r=sqrt(n);
  for(long i=1;i<=r;i++){
    if(n%i==0&&ans>f(i,n/i)){
      ans=f(i,n/i);
    }
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a[20][20]={0},num,n;
    char card;
    scanf("%d",&n);
    for(int x=0;x<n;x++)
    {
        scanf(" %c %d",&card,&num);
        if(card=='S') a[0][num]=1;
        if(card=='H') a[1][num]=1;
        if(card=='C') a[2][num]=1;
        if(card=='D') a[3][num]=1;
    }
    for(int i=0;i<=3;i++)
    {
        for(int j=1;j<=13;j++)
        {
            if(a[i][j]==1) continue;
            if(a[i][j]==0&&i==0) printf("S %d\n",j);
            if(a[i][j]==0&&i==1) printf("H %d\n",j);
            if(a[i][j]==0&&i==2) printf("C %d\n",j);
            if(a[i][j]==0&&i==3) printf("D %d\n",j);
             
        }
    }
    return 0;
}

Measured memory_bytes: 1028
N = int(input())
H = list(map(int, input().split()))


for i in range(N-1):
    if H[i+1] - H[i] > 0:
        H[i+1] -= 1

for i in range(N-1):
    if H[i+1] < H[i]:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 14396
x = input()
if len(x) < 3:
    print(0)
    exit()
k = int(x[0:-2])
x = int(x[-2:])

k -= x / 5
if x % 5 == 0 and k >= 0:
    print(1)
elif k > 0:
    print(1)
else:
    print(0)


Measured memory_bytes: 9004
#include<bits/stdc++.h>
using namespace std;
typedef long long lnt;
typedef pair<lnt, lnt> pll;
#define mk make_pair
#define pb push_back

int a, b, k;

signed main()
{
    cin >> a >> b >> k;
    int cnt = 0;
    for(int i = min(a, b); i >= 1; i--){
        if(a % i == 0 && b % i == 0){
            cnt++;
            //printf("%d\n", i);
            if(cnt == k){
                printf("%d\n", i);
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int               long long
#define ff                first
#define ss                second
#define md                1000000007
#define md1               998244353
#define inf               1000000000000000
#define minf              -1000000000000000
#define pb                push_back
#define in                insert
#define mkp               make_pair
#define mpll              map<ll,ll>
#define len(p)            (ll)p.size()
#define pll               pair<ll,ll>
#define all(v)            v.begin(),v.end()
#define mem(a,t)          memset(a,t,sizeof(a))
#define endl              "\n"
#define ar                array
#define vl                vector<ll>
#define vpll              vector<pair<ll,ll>>
#define f(i,yha,wha)      for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha)     for(ll i=wha;i>=yha;i--)
#define f0(n)             for(ll i=0;i<n;i++)
#define f1(n)             for(ll i=1;i<=n;i++)
#define fg(i,yha,wha,gap) for(ll i=yha;i<wha;i+=gap)


void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


void solve()
{
    ll n, k;
    cin >> n >> k;
    ll a[n + 10] = {0};
    f(i, 0, k)
    {
        ll d;
        cin >> d;
        f(j, 0, d)
        {
            ll tmp;
            cin >> tmp;
            a[tmp] = 1;
        }

    }
    ll cnt = 0;
    f(i, 1, n + 1)
    if (a[i] == 0)
        cnt++;
    cout << cnt << endl;
}

int32_t main()
{
    flash();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)


typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}


int main(){fastio
    ll n;cin>>n;
    string s;cin>>s;
    ll k=s.size();
    ll dp[2][n+1];memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    rep(i,0,n-1){
        rep(j,0,n)dp[(i+1)&1][j]=0;
        rep(j,0,n){
            Add(dp[(i+1)&1][j+1],dp[i&1][j]*2);
            if(j-1>=0)Add(dp[(i+1)&1][j-1],dp[i&1][j]);
            else Add(dp[(i+1)&1][j],dp[i&1][j]);
        }
        //rep(j,0,n)cout<<dp[(i+1)&1][j]<<" ";cout<<endl;
    }
    
    cout<<mod(dp[n&1][k]*bunbo(po(2,k)))<<endl;
    
    return 0;
}





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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> cnt(3, 0);
    for(char c : s){
        cnt[c - 'a']++;
    }
    rep(i, 3) {
        rep(j,3){
            if(abs(cnt[i] - cnt[j]) > 1){
                puts("NO");
                return 0;
            }
        }
    }
    puts("YES");
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>

int getGcd(int a, int b) {
    std::vector<int> po({a, b});
    int bigger = *std::max_element(po.begin(), po.end());
    int smaller = *std::min_element(po.begin(), po.end());
    while (bigger % smaller != 0) {
        int tmp;
        tmp = bigger % smaller;
        std::vector<int> po2({smaller, tmp});
        int bigger2 = *std::max_element(po2.begin(), po2.end());
        int smaller2 = *std::min_element(po2.begin(), po2.end());
        bigger = bigger2;
        smaller = smaller2;
    }
    return smaller;
}


int main()
{
    int n, x;
    std::cin >> n >> x;
    std::vector<int> xs;
    for (int i = 0; i < n; i++) {
        int x_i;
        std::cin >> x_i;
        xs.emplace_back(x_i);
    }
    for (int i = 0; i < n; i++) {
        xs[i] -= x;
        xs[i] = std::abs(xs[i]);
    }
    int gcd = xs.at(0);
    for (int i = 1; i < n; i++) {
        gcd = getGcd(gcd, xs.at(i));
    }
    std::cout << gcd << std::endl;

    return 0;
}

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

#define mp make_pair
#define X first
#define Y second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

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

int a, b, n;

int main(){
    if (fopen("inp.txt", "r")){
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> a >> b;
    n = a + b;

    if (b >= a) {
        cout << "Impossible";
        return 0;
    }

    function<int(int, int)> ask = [&](int x, int y) {
        char ch;
        cout << "? " << x << " " << y << endl;
        cin >> ch;
        return (ch == 'Y');
    };

    int unkind = b + 1;
    vector<int> honest;
    FOR(i, 0, n - 1){
        char ch;
        if (honest.size()) {
            if (ask(i, honest.back())) {
                honest.push_back(i);
                if (honest.size() >= unkind) break;
            } else {
                honest.pop_back();
                unkind--;
            }
        } else {
            honest.push_back(i);
            if (honest.size() >= unkind) break;
        }
    }

    string res = "";
    FOR(i, 0, n - 1)
        res += (char)(ask(honest[0], i) + '0');

    cout << "! " << res;

    return 0;
}


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

#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e6 + 41;
const int mod = 1e9 + 7;
const long long INF = 3e18 + 12;
const int inf = 1e9;

int d[N];

int ans[N];

vector <pair <int, int> > g[N];

void dfs (int v = 1, int p = -1, int c = -1) {
	int cur = 1;
	for (auto to : g[v]) if (to.first != p) {
		if (cur == c) cur++;
		ans[to.second] = cur;
		cur++;
		dfs (to.first, v, ans[to.second]);
	}
}

int main () {
	boost;
	int n, mx = 0;
	cin >> n;
	for (int i = 1 ; i < n ; ++ i) {
		int a, b;
		cin >> a >> b;
		d[a]++;
		d[b]++;
		g[a].push_back ({b, i});
		g[b].push_back ({a, i});
		mx = max (mx, d[a]);
		mx = max (mx, d[b]);
	}
	dfs();
	cout << mx << "\n";
	for (int i = 1;  i < n ; ++ i) cout << ans[i] << "\n";
}

Measured memory_bytes: 33408
import java.util.*;

public class Main{
  public static void main (String[] args){
    
    Scanner scanner = new Scanner(System.in);
    
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int X = scanner.nextInt();
    int Y = scanner.nextInt();
    int ans;
    
    if(N <= K){
      ans = N * X;
    }else{
      ans = K * X + (N - K) * Y;
    }
    
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
 
#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      cout<<"#x "<<x<<"\n";
#define trace(x,y)  cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          cout<<"\n";


bool SBF(const pair <int,int>&a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair<int,int>& a, const pair<int,int>& b){return a.S<b.S;}


const int maxn = 1e9+7;
int n;
int a[100000];

void solve(){
	int dp[n];
	memset(dp,0,sizeof(dp));
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	dp[2]=min(dp[1]+abs(a[2]-a[1]), abs(a[2]-a[0]));
        for(int i = 3 ; i< n ;i++){
		dp[i] = min(dp[i-2] + abs(a[i]-a[i-2]), dp[i-1] + abs(a[i]-a[i-1]));
	}
	cout<<dp[n-1]<<"\n";
return ;
}
int main(){
	cin >> n;
	for(int i = 0 ;i  < n ;i++)cin >> a[i];
	solve();
return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int64_t res = 0;
  vector<int64_t> A(N), X(100010, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    X[A[i]]++;
    res += A[i];
  }
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    int64_t b, c;
    cin >> b >> c;
    res -= b * X[b];
    res += c * X[b];
    X[c] += X[b];
    X[b] = 0;
    cout << res << '\n';
  }
  return 0;
}


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

int main()
{
	int n, m;
	long x[1000], y[1000];

	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i];

	int c = abs(x[0] + y[0]) % 2;
	bool f = 1;

	for (int i = 0; i < n; i++) {
		if (abs(x[i] + y[i]) % 2 != c) {
			cout << -1 << endl;
			f = 0;
			break;
		}
	}

	if (f) {
		long long d[32];

		m = 31;
		if(c % 2 == 0)
			m++;

		cout << m << endl;

		for (int i = 0; i < m - 1; i++) {
			d[i] = 1ull << (30 - i);
			cout << d[i] << " ";
		}

		d[m - 1] = 1;
		cout << d[m - 1] << endl;

		for (int i = 0; i < n; i++) {
			long long ax = 0, ay = 0; 
			if (c % 2 == 0) {
				x[i]--;
				m = 31;
			}
			for (int j = 0; j < m; j++) {
				if (y[i] - ay > x[i] - ax && y[i] - ay > -x[i] + ax) {
					cout << "U";
					ay += d[j];
				}
				else if (y[i] - ay > x[i] - ax && y[i] - ay < -x[i] + ax) {
					cout << "L";
					ax -= d[j];
				}
				else if (y[i] - ay < x[i] - ax && y[i] - ay < -x[i] + ax) {
					cout << "D";
					ay -= d[j];
				}
				else {
					cout << "R";
					ax += d[j];
				}
			}

			if (c % 2 == 0)
				cout << "R";

			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
S = input()
n = len(S)

for i in range(n//2):
  if S[i] == S[n-1-i]:
    pass
  else:
    print('No')
    break
else:
  s1 = S[0:(n//2)]
  s2 = S[(n//2+1):n]
  for j in range(len(s1)//2):
    if s1[j] == s1[len(s1)-1-j]:
      pass
    else:
      print('No')
      break
  else:
    for k in range(len(s2)//2):
      if s2[k] == s2[len(s2)-1-k]:
        pass
      else:
        print('No')
        break
    else:
      print('Yes')
     

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
     // String[] nyu=sc.nextLine().split(" ");

     String nyu=sc.nextLine();
//int[] num=new int[6];
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
int C=Integer.parseInt(nyu);
//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

int res=0;

if(C%2==0){
res=(C/2)*(C/2);
}else{
res=(C/2)*(C/2+1);
}

System.out.println(res) ;

	}
}

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

int main(){
  int N,i;
  scanf("%d",&N);
  int *a=malloc(sizeof(int)*N);
  int *b=malloc(sizeof(int)*N);
  for(i=0;i<N;i++){
  	scanf("%d",&a[i]);
     b[a[i]-1]=i+1;
  }
  for(i=0;i<N;i++)printf("%d ",b[i]);
}

Measured memory_bytes: 1536
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
string s,t;
int ls,lt,sum,ans=INT_MAX;
int main() {
    cin>>s>>t;
    ls=s.size(),lt=t.size();
    for(int l=0;l<=ls-lt;l++) {
        int r=l+lt-1;sum=0;
        for(int i=l;i<=r;i++)
            if(s[i]!=t[i-l])
                sum++;
        ans=min(ans,sum);
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 3260
#include <iostream>
#include <fstream>

#include <cmath>

using namespace std;


int Sort(int *a, int N);
void pp_sorting(int *a,int N);
int main(){

    int n, a[100];
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    int counter = Sort(a,n);
    pp_sorting(a,n);
    cout << counter << endl;

    return 0;
}

int Sort(int *a, int N){
    int counter = 0;
    for(int i=0;i<N;i++){
        int minj = i;
        for(int j=i;j<N;j++){
            if(a[j] < a[minj]) minj = j;
        }
        if(minj != i){
            int temp = a[i];
            a[i] = a[minj];
            a[minj] = temp;
            counter++;
        }
    }
    return counter;
}

void pp_sorting(int *a,int N){
    for(int i=0;i<N-1;i++) cout << a[i] << " ";
    cout << a[N-1] << endl;
}




Measured memory_bytes: 3112
program sample
  implicit none
  integer :: a,b,c,d,e,i,j
  integer :: s(4)

  read(*,*) a,b,c,d

  if(b<=c)then
     write(*,*) 0
     stop
  else if(d<=a)then
     write(*,*) 0
     stop
  else
     s(1)=a
     s(2)=b
     s(3)=c
     s(4)=d
     do i=1,3
        do j=i+1,4
           if(s(i)>s(j))then
              e=s(j)
              s(j)=s(i)
              s(i)=e
           endif
        enddo
     enddo
     write(*,*) s(3)-s(2)
  endif

end program sample

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> mp(H, vector<char>(W));
	vector<vector<int>> num(H, vector<int>(W,mod));
	for (size_t i = 0; i < H; i++)
	{
		for (size_t j = 0; j < W; j++)
		{
			cin >> mp.at(i).at(j);
		}
	}
	queue<pair<int, int>>chk;
	int painted=0,ans=0;

	for (size_t i = 0; i < H; i++)
	{
			for (size_t j = 0; j < W; j++)
			{
				if (mp.at(i).at(j) == '#')
				{
					chk.push({ i,j });
					num.at(i).at(j) = 0;

				}
			}
	}
		while (!chk.empty())
		{
			if (chk.front().first != 0 && mp.at(chk.front().first - 1).at(chk.front().second) == '.') {
				chk.push({ chk.front().first - 1,chk.front().second });
				mp.at(chk.front().first - 1).at(chk.front().second) = '#';
				num.at(chk.front().first - 1).at(chk.front().second) = num.at(chk.front().first).at(chk.front().second) + 1;
			}
			if (chk.front().first != H - 1 && mp.at(chk.front().first + 1).at(chk.front().second) == '.') {
				chk.push({ chk.front().first + 1,chk.front().second });
				mp.at(chk.front().first + 1).at(chk.front().second) = '#';
				num.at(chk.front().first + 1).at(chk.front().second) = num.at(chk.front().first).at(chk.front().second) + 1;
			}
			if (chk.front().second != 0 && mp.at(chk.front().first ).at(chk.front().second-1) == '.') {
				chk.push({ chk.front().first,chk.front().second-1 });
				mp.at(chk.front().first ).at(chk.front().second-1) = '#';
				num.at(chk.front().first).at(chk.front().second-1) = num.at(chk.front().first).at(chk.front().second) + 1;
			}
			if (chk.front().second!= W-1 && mp.at(chk.front().first).at(chk.front().second + 1) == '.') {
				chk.push({ chk.front().first,chk.front().second + 1 });
				mp.at(chk.front().first).at(chk.front().second + 1) = '#';
				num.at(chk.front().first).at(chk.front().second + 1) = num.at(chk.front().first).at(chk.front().second) + 1;
			}
			chk.pop();
		}
		int maxim = 0;
		for (size_t i = 0; i < H; i++)
		{
			sort(num.at(i).begin(), num.at(i).end(), greater<int>());
			if (maxim < num.at(i).at(0))maxim = num.at(i).at(0);
		}
		cout << maxim;

}

Measured memory_bytes: 13328
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int inp[100005];
vector<int> num[2];
int main () {
  int n;
  scanf("%d", &n);
  FOR(i, 1, n) {
    int t; scanf("%d", &t); inp[i] = t;
    if (t < 0) num[1].pb(t);
    else num[0].pb(t);
  }
  int tot = 0;
  if (!num[0].empty() && !num[1].empty()) {
    FOR(i, 1, n) tot += abs(inp[i]);
    printf("%d\n", tot);

    int v = num[1].back(); num[1].pop_back();
    while (num[0].size() > 1) {
      int w = num[0].back(); num[0].pop_back();
      printf("%d %d\n", v, w); v -= w;
    }
    int w = num[0][0];
    printf("%d %d\n", w, v); v = w - v;
    while (num[1].size()) {
      int w = num[1].back(); num[1].pop_back();
      printf("%d %d\n", v, w); v -= w;
    }
  } else if (num[0].empty()) {
    sort(inp + 1, inp + n + 1);
    tot = inp[n];
    FOR(i, 1, n - 1) tot += abs(inp[i]);
    printf("%d\n", tot);

    int v = inp[n];
    FORD(i, n - 1, 1) {
      printf("%d %d\n", v, inp[i]); v -= inp[i];
    }
  } else {
    sort(inp + 1, inp + n + 1);
    tot = -inp[1];
    FOR(i, 2, n) tot += inp[i];
    printf("%d\n", tot);
    
    int v = inp[1];
    FOR(i, 2, n - 1) {
      printf("%d %d\n", v, inp[i]); v -= inp[i];
    }
    printf("%d %d\n", inp[n], v); v = inp[n] - v;
  }
  return 0;
}

Measured memory_bytes: 2808
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    let n = s.len() + 1;
    let mut a = vec![0; n];
    for i in 0..n - 1 {
        if s[i] == '<' {
            a[i + 1] = a[i] + 1;
        }
    }
    for i in (0..n - 1).rev() {
        if s[i] == '>' {
            a[i] = max(a[i], a[i + 1] + 1);
        }
    }
    println!("{}", a.iter().cloned().sum::<usize>());
}


Measured memory_bytes: 11512
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define fr(i,start,end, inc) for(ll i=(start); i<(end); i+=inc)
#define rf(i,end,start, inc) for(ll i=(start-1); i>=(end); i-=inc)
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define pl pair<ll, ll>
#define pi pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;

bool compare(const pl &a, const pl &b){
    return a.fi<b.fi || (a.fi==b.fi && a.se<b.se);
}
ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}
inline vector<ll> allinv(ll n, ll p){
    vector<ll> arr(n);
    arr[1]=1;
    fr(i,2,n,1){
        arr[i] = (p - (p/i)*arr[p%i]%p)%p;
    }
    return arr;
}
vector<ll> inline allncr(ll n, ll p){
    vector<ll> nci(n+1);
    nci[0]=1;
    nci[n]=1;
    vector<ll> v = allinv(n,p);
    fr(i,1,n,1){
        nci[i]=(nci[i-1]*(n-i-1))%p;
    }
    return nci;
}
ll max3(ll a, ll b, ll c){
    return max(max(a,b),c);
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

void prt(int i){   
    i ? cout << "YES\n" : cout << "NO\n" ;
}

template<class T>
void printv(T &v){
    ll n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}
ll maxn = 100005;
vector<ll> f1(maxn), f2(maxn), b1(maxn), b2(maxn), parent(maxn,-1), tot(maxn,1), ans(maxn);

ll find_parent(ll u){
    if(parent[u]==-1)
        return u;
    return parent[u] = find_parent(parent[u]);
}

void merge(ll u, ll v){
    u = find_parent(u);
    v = find_parent(v);
    if(v==u)
        return;
    parent[v]=u;
    tot[u]+=tot[v];
}
int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        ll n,m,k,a,b;
        cin >> n >> m >> k;
        rep1(i,m){
            cin >> f1[i] >> f2[i];
            merge(f1[i], f2[i]);   
        }
        rep1(i,k)
            cin >> b1[i] >> b2[i];
        rep1(i,n)
            ans[i] = tot[find_parent(i)] - 1;
        rep1(i,m){
            ans[f1[i]]--;
            ans[f2[i]]--;
        }
        rep1(i,k){
            if(find_parent(b1[i]) == find_parent(b2[i]))
                ans[b1[i]]--, ans[b2[i]]--;
        }
        rep1(i,n)
            cout << ans[i] << " ";
        cout << "\n";
    }

}

Measured memory_bytes: 6912
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n,m = map(int, input().split())
    parent_dict = {}
    child_dict = {}
    len_tree = [0]*n
    for _ in range(n+m-1):
        a,b = map(int, input().split())
        try:
            parent_dict[b].add(a)
            len_tree[b-1]+=1
        except KeyError:
            parent_dict[b] = {a}
            len_tree[b-1] = 1
        try:
            child_dict[a].add(b)
        except KeyError:
            child_dict[a] = {b}
    parent_set = set(range(1,n+1))-set(parent_dict)
    root = list(parent_set)[0]
    check_list = [root]
    while len(check_list)>0:
        base = check_list[-1]
        check_list.pop(-1)
        try:
            for i in child_dict[base]:
                if len_tree[i-1]==1:
                    check_list.append(i)
                else:
                    len_tree[i-1]-=1
                    parent_dict[i]-={base}
        except KeyError:
            pass
    parent_dict[root] = [0]
    for i in range(1,n+1):
        print(list(parent_dict[i])[0])


Measured memory_bytes: 80992