akhauriyash/Code-Regression huggingface dataset:
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $n = <STDIN>);
chomp (my @b = split / /, <STDIN>);

my @res;
for my $i (1..$n) {
  my $pivot = -1;
  for (my $j=@b; $j>=1; $j--) {
    if ($b[$j-1] == $j) {
      $pivot = $j;
      last;
    }
  }
  if ($pivot == -1) {
    say -1;
    exit;
  }
  unshift @res, $pivot;
  splice @b, $pivot-1, 1;
}
say $res[$_] for 0..$#res;

Measured memory_bytes: 896
#include <iostream>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int x,y,s,ans,a,b,aoff,boff;
int main() {
  while(true){
    cin >> x >> y >> s;
    if(x==0&&y==0&&s==0) return 0;
    ans = 0;
    REP(i,1,s/2+1){
      a = i;
      b = s-i;
      aoff = a*100/(100+x)-1;
      rep(j,3){
        if(aoff*(100+x)/100==a) break;
        aoff++;
      }
      if(aoff*(100+x)/100!=a) continue;
      boff = b*100/(100+x)-1;
      rep(j,3){
        if(boff*(100+x)/100==b) break;
        boff++;
      }
      if(boff*(100+x)/100!=b) continue;
      int on = aoff*(100+y)/100+boff*(100+y)/100;
      if(on>ans) ans = on;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdlib>

using namespace std;

int main(void)
{
    int x, y, z;
    cin >> x >> y >> z;

    int temp;
    temp = x;
    x = y;
    y = temp;

    temp = x;
    x = z;
    z = temp;

    cout << x << " " << y << " " << z << endl;

    return 0;
}

Measured memory_bytes: 256
n,a,b,k=map(int,input().split())
mod=998244353
ans=0
fact=[1]*(n+1)
rev=[1]*(n+1)
fx=lambda a,b:(fact[a]*rev[a-b]*rev[b])%mod
for i in range(1,n+1):
    fact[i]=i*fact[i-1]%mod
    rev[i]=pow(fact[i],mod-2,mod)
for i in range(n+1):
    j,r=divmod((k-a*i),b)
    if r==0 and 0<=j<=n:
      ans+=(fx(n,i)*fx(n,j))%mod
print(ans%mod)


Measured memory_bytes: 46060
def check(_a):
    for i in range(0, len(_a)):
        if N <= _a[i]:
            return True
    else:
        return False


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    divide_num = [0 for i in range(N)]
    ans = 0
    while check(a):
        sum_num = 0
        for i in range(0, N):
            tmp = a[i] // N
            divide_num[i] = tmp
            sum_num += tmp
            ans += tmp

        a = [(a[i] % N + sum_num - divide_num[i]) for i in range(0, N)]

    print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
	#include<stdlib.h>
	#include<string.h>
	#include<math.h>
	#include<vector> 
	#include<iostream>
	using namespace std;
	char a[200000+100];
	char b[200000+100];
	vector<int>aa[30];
	vector<int>bb[30];
	int main()
	{
		cin>> a>> b;
		int lena=strlen(a); 
		int lenb=strlen(b);
		for(int i=0;i<lena;i++)
			aa[a[i]-'a'].push_back(i);
		for(int i=0;i<lenb;i++)
			bb[b[i]-'a'].push_back(i);
		bool flag=false;
		for(int i=0;i<26;i++)
		{
			for(int k=1;k<bb[i].size();k++)
				 if(a[bb[i][k]]!=a[bb[i][k-1]])
				 {
				 	flag=true;
				 	break;
				 }
			if(flag)
				break;
		}
		for(int i=0;i<26;i++)
		{
			for(int k=1;k<aa[i].size();k++)
				 if(b[aa[i][k]]!=b[aa[i][k-1]])
				 {
				 	flag=true;
					break; 
				}
			if(flag)
				break;
		}
		if(!flag)
			printf("Yes\n");
		else
			printf("No\n");
		return 0;
	 } 

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

int main(){
	double num1[10000];
	double num2[10000];
	double ans1=0.0;
	double ans2=0.0;
	int i=0,j;
	
	while((scanf("%lf,%lf",&num1[i],&num2[i]))!=EOF){
		ans1+=num1[i]*num2[i];
		ans2+=num2[i];
		i++;
	}
	printf("%.0f\n%.0f\n",ans1,floor((ans2)/i+0.5));
	
	return 0;
}

Measured memory_bytes: 648
n = input()
for _ in xrange(n):
    s = raw_input()
    cur = 1
    def parse():
        global cur
        result = []
        num = None
        while 1:
            c = s[cur]; cur += 1
            if c is '[':
                result.append(parse())
            elif c is ']':
                break
            else:
                num = num or 0
                num = 10*num + int(c)
        if num is not None:
            return num/2+1
        l = len(result)
        result.sort()
        return sum(result[:l/2+1])

    print parse()

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

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

    vector<int> road(4, 0);
    rep(i, 3){
        int a, b;
        cin >> a >> b;
        ++road[a-1];
        ++road[b-1];
    }

    rep(i, 4){
        if(road[i] > 2){
            puts("NO");
            return 0;
        }
    }

    puts("YES");

    return 0;
}

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	int H, W, K;
	std::vector<std::string> S;
	std::cin >> H >> W >> K;
	S.resize(H);
	for (auto& s : S)
		std::cin >> s;

	std::vector<std::string> Suniq;
	std::vector<int> cpref;
	std::vector<std::vector<int>> areaid;
	cpref.resize(H);

	int idx = -1;
	for (int i = 0; i < H; ++i) {
		if (S[i].find('#') != std::string::npos) {
			++idx;
			Suniq.push_back(S[i]);
		}
		cpref[i] = idx;
	}
	for (int i = 0; i < H; ++i) {
		if (cpref[i] == -1)
			cpref[i] = 0;
	}

	idx = 0;
	areaid.resize(Suniq.size());
	for (int i = 0; i < Suniq.size(); ++i) {
		++idx;
		areaid[i].resize(W);
		const auto& Su = Suniq[i];
		bool first = true;
		for (int j = 0; j < W; ++j) {
			if (Su[j] == '#') {
				if (first)
					first = false;
				else if (j != 0)
					++idx;
			}
			areaid[i][j] = idx;
		}
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (j != 0) {
				std::cout << " ";
			}
			std::cout << areaid[cpref[i]][j];
		}
		std::cout << "\n";
	}
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    REP(i,h)cin >> s[i];
    int32 ans = INF;
    for(int32 mask = 0; mask < (1 << h-1);++mask){
        int32 curans = bitset<32>(mask).count();
        vector<int32> cnt(h,0);
        bool hflg = false;
        REP(i,w){
            vector<int32> cnt2(h,0);
            if(s[h-1][i] == '1')cnt2[h-1]++;
            FORR(j,h-2,0){
                if(s[j][i] == '1')cnt2[j]++;
                if(!(mask & (1 << j)))cnt2[j] += cnt2[j+1];
            }
            bool flg = false;
            REP(j,h){
                if(cnt[j] + cnt2[j] > k){
                    flg = true;
                }
                // cout << cnt[j] + cnt2[j] << " ";
            }
            // cout << endl;
            if(flg){
                curans++;
                cnt = cnt2;
            }else{
                REP(j,h)cnt[j] += cnt2[j];
            }
            REP(j,h){
                if(cnt2[j] > k)hflg = true;
            }
            if(hflg)break;
        }
        // cout << bitset<16>(mask) << " " << curans << endl;
        if(!hflg)
            ans = min(ans, curans);
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

int main()
{
  int N,M,D,Y;
  P p[100001],q[100001];
  cin >> N >> M;
  REP(i,M){
    cin >> D >> Y;
    p[i].first = D;
    p[i].second = Y;
    q[i] = p[i];
  }
  sort(p,p+M);
  map<P,string> nin;
  map<int,int> num;
  for(int i=0;i<M;i++){
    char st[30];
    sprintf(st,"%06d%06d",p[i].first,++num[p[i].first]);
    string a(st,12);
    nin[p[i]] = a;
  }
  REP(i,M){
    cout << nin[q[i]] << endl;
  }
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 18688
# -*- coding: utf-8 -*-

def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\n
        int: 標準入力
    """
    N = int(input())

    return N


def main(N: int) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 整数（1 <= N <= 10000）
    """
    # 求解処理
    ans = (1000 - (N % 1000)) % 1000

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N = get_input()

    # メイン処理
    main(N)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(int i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	cout<<n*800-(n/15)*200<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	int N = S.size();

	int dp[200010][2] = {};
	dp[0][0] = 1;
	dp[1][1] = 1;

	rep(i, N) {
		if (dp[i][0]) {
			if (S[i] != S[i + 1]) dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + 1);
			dp[i + 2][1] = max(dp[i + 2][1], dp[i][0] + 1);
		}
		if (dp[i][1]) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + 1);
		}
	}

	co(max(dp[N - 1][0], dp[N - 1][1]));

	Would you please return 0;
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, k; cin >> n >> k;
  if(k > (n - 1) * (n - 2) / 2) {
    cout << -1 << endl;
  } else {
    vector<pair<int, int>> p;
    for(int i=1;i<n;++i) {
      p.push_back({0, i});
    }
    for(int i=1;i<n;++i) {
      for(int j=i+1;j<n;++j) {
        if(k == 0) {
          p.push_back({i, j});
        } else {
          k--;
        }
      }
    }
    cout << p.size() << endl;
    for(int i=0;i<(int)(p.size());++i) {
      cout << p[i].first + 1 << " " << p[i].second + 1 << endl;
    }
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;
static const int MAX_A = 100000;

int N;
int a[MAX_N];

int num[MAX_A + 3];

void solve(){
	for(int i = 0; i < MAX_A + 3; i++) num[i] = 0;
	for(int i = 0; i < N; i++){
		num[a[i]]++;
	}
	int max = 0;
	for(int i = 0; i < MAX_A + 3; i++){
		int sum = num[i] + num[i + 1] + num[i + 2];
		if(sum > max) max = sum;
	}
	printf("%d\n", max);
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &a[i]);
	solve();
	return 0;
}


Measured memory_bytes: 1024
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max

local n, m, rnum = io.read("*n", "*n", "*n")
local r = {}
for i = 1, rnum do r[i] = io.read("*n") end
local edge = {}
for i = 1, n do edge[i] = {} end
for i = 1, m do
  local u, v, l = io.read("*n", "*n", "*n")
  edge[u][v] = l
  edge[v][u] = l
end

local inf = 30000001

local function getlength(start_idx, dst_idx)
  local taskstate = {}
  for i = 1, n do taskstate[i] = false end
  local tasks = {}
  local tasknum = 0
  local done = 0

  local len = {}
  for i = 1, n do len[i] = inf end
  len[start_idx] = 0

  local function addtask(idx)
    if(not taskstate[idx]) then
      taskstate[idx] = true
      tasknum = tasknum + 1
      tasks[tasknum] = idx
    end
  end
  addtask(start_idx)

  while(done < tasknum) do
    done = done + 1
    local src = tasks[done]
    taskstate[src] = false
    for dst, cost in pairs(edge[src]) do
      if len[src] + cost < len[dst] then
        len[dst] = len[src] + cost
        addtask(dst)
      end
    end
  end
  return len[dst_idx]
end

local function heldkarp_prepare(n)
  local tot = 1
  local alltask = {}
  local stagetask = {}
  for i = 1, n do
    tot = tot * 2
    alltask[i] = {}
    stagetask[i] = {}
  end
  for i = 1, n do
    for j = 1, tot - 1 do
      alltask[i][j] = 160000001
    end
  end
  for i = 1, tot - 1 do
    local ti = i
    local cnt = 0
    for j = 1, n do
      if ti % 2 == 1 then
        cnt = cnt + 1
        ti = ti - 1
      end
      ti = ti / 2
    end
    table.insert(stagetask[cnt], i)
  end
  -- set first state
  local tmp = 1
  for i = 1, n do
    alltask[i][tmp] = 0
    tmp = tmp * 2
  end
  return tot, alltask, stagetask
end

local function heldkarp_doall(n, alltask, stagetask, len)
  for stage = 1, n - 1 do
    local stlen = #stagetask[stage]
    for i_stagetask = 1, stlen do
      local used = stagetask[stage][i_stagetask]
      local t_used = used
      for i = 1, n do
        if t_used % 2 == 1 then
          local val = alltask[i][used]
          local mul = 1
          local tmp = used
          for j = 1, n do
            if tmp % 2 == 0 then
              alltask[j][used + mul] = mmi(alltask[j][used + mul], val + len[(i - 1) * n + j])
            else
              tmp = tmp - 1
            end
            tmp = tmp / 2
            mul = mul * 2
          end
          t_used = t_used - 1
        end
        t_used = t_used / 2
      end
    end
  end
end

local function heldkarp_getresult(n, tot, alltask)
  local ret = alltask[1][tot - 1]
  for i = 2, n do
    ret = mmi(ret, alltask[i][tot - 1])
  end
  return ret
end


local len = {}
for i = 1, rnum * rnum do
  len[i] = 0
end
for i = 1, rnum - 1 do
  for j = i + 1, rnum do
    local l = getlength(r[i], r[j])
    len[(i - 1) * rnum + j] = l
    len[(j - 1) * rnum + i] = l
  end
end
local t1, t2, t3 = heldkarp_prepare(rnum)
heldkarp_doall(rnum, t2, t3, len)
print(heldkarp_getresult(rnum, t1, t2))


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

n = int(input())
nums = [int(x) for x in input().split()]
alice = 0
bob = 0
while nums != []:
    alice += max(nums)
    nums.remove(max(nums))
    if nums != []:
        bob += max(nums)
        nums.remove(max(nums))
print(alice - bob)

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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int suma,sumb,sumc=1000000000,sumd=1000000000;
    suma = 2*c*max(x,y);
    sumb = a*x+b*y;
    if(x-y > 0) sumc = a*(x-y) + 2*c*y;
    if(y-x > 0) sumd = 2*c*x + b*(y-x);
    int minimum = min(sumd,min(sumc,min(suma,sumb)));
    cout << minimum << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class MainClass
{
    public struct DataSet
    {
        public int x,y;

        public DataSet(int n1,int n2)
        {
            x=n1;
            y=n2;
        }

        public void Swap()
        {
            int tmp=x;
            x=y;
            y=tmp;
        }
    }

    public static void Main(string[] args)
    {
        List<DataSet> inputs=new List<DataSet>(3000){};

        while(true)
        {
            string[] str=Console.ReadLine().Split(' ');

            int x=Convert.ToInt32(str[0]);
            int y=Convert.ToInt32(str[1]);
            
            if(x==0&&y==0) break;

            inputs.Add(new DataSet(x,y));
        }

        foreach(DataSet ds in inputs)
        {
            if(ds.x>ds.y)
            {
                ds.Swap();
            }

            Console.WriteLine("{0} {1}",ds.x,ds.y);
        }
    }
}

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

using namespace std;

long long MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] %= MOD;
    sum += a[i];
  }

  long long s = 0;
  for (int i = 0; i < n; i++) {
    sum -= a[i];
    s += (a[i] * (sum % MOD)) % MOD;
  }

  cout << s % MOD << '\n';


  return 0;
}


Measured memory_bytes: 4440
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
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;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}
int k(ll n) {
	int x=0;
	while (n) {
		x+=n % 10;
		n /= 10;
	}
	return x;
}
ll max(ll x, ll y) {
	if (x < y)return y;
	return x;
}

int main() {
	int n;
	cin>>n;
	hei(llint) a(n), b(n);
	rep(i, 0, n)cin >> a[i] >> b[i];
	llint A = a[0];
	llint B = b[0];
	rep(i, 1, n) {
		if (A <= a[i] && B <= b[i]) {
			A = a[i];
			B = b[i];
		}
		else {
			if (A <= a[i]) {
				ll x=(B + b[i] - 1) / b[i];
				A = a[i] * x;
				B = b[i] * x;
			}
			else {
				if (B <= b[i]) {
					ll x = (A + a[i] - 1) /a[i];
					A = a[i] * x;
					B = b[i] * x;
				}
				else {
					ll x = max((A + a[i] - 1) / a[i], (B + b[i] - 1) / b[i]);
					A = a[i] * x;
					B = b[i] * x;
				}
			}
		}
	}
	ll ans = A + B;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n,k = gets.chomp.split(' ').map(&:to_i)
h = gets.chomp.split(' ').map(&:to_i)

h.sort!

k.times do
  h.delete_at(-1)
end

if (h == [])
  puts 0
  exit
end

result = h.inject do |sum, n|
  sum + n
end
puts result


Measured memory_bytes: 19824
#include <bits/stdc++.h>
using namespace std;
int n, c, d[32][32] = {}, cnt[3][32] = {}, ans = 1145141919;

int calc(int x[3]) {
  int ret = 0;
  
  for (int i  = 0; i < 3; i++) {
    for (int j = 0; j < c; j++) {
      
      ret += d[j][x[i]] * cnt[i][j];
    }
  }
  
  return ret;
}

int main(void) {
  cin >> n >> c;
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      cin >> d[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int in;
      cin >> in;
      cnt[(i + j) % 3][in - 1]++;
    }
  }
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      for (int k = 0; k < c; k++) {
        if (i == j || j == k || k == i)
          continue;
        int arg[3] = {i, j, k};
        int tmp = calc(arg);
        ans = min(ans, tmp);
      }
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,k,temp,ans,suma,sumb,tempa,tempb,a,b,c,d;
	cin>>a>>b>>c>>d;
	int i=0;
	while((a>0)&&(c>0)){
		if(i%2)
		a=a-d;
		else c=c-b;
		i++;
	}
	if(a<=0)
	cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	ll n,k;
	cin >> n >> k;
	vector<pair<int,ll>> v;
	rep(i,n){
		int a,b;
		cin >> a >> b;
		v.push_back({a,b});
	}
	sort(v.begin(),v.end());
	ll cnt = 0;
	rep(i,n){
		if(cnt + v[i].second >= k){
			cout << v[i].first << endl;
			return 0;
		}
		cnt += v[i].second;
	}
	return 0;
}

Measured memory_bytes: 2420
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [ list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N):
    summ = 0
    for j in range(M):
        #print(A[i][j], B[j])
        summ += A[i][j] * B[j]
    #print(summ)
    if summ + C > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;
int A[123];
int ud[123];

int main() {

	cin >> N;
	rep(i, N) cin >> A[i];
	rep(i, N) {
		if (!i) ud[i] = -1;
		else {
			if (A[i] > A[i - 1]) ud[i] = 1;
			else ud[i] = -1;
		}
	}

	rep(i, N) {
		if (ud[N - 1 - i] == -1) ud[N - 1 - i] = 0;
		else break;
	}

	ll M = 1000, K = 0;

	rep(i, N) {
		if (!ud[i]) break;
		if (ud[i] == -1 && ud[i + 1] == 1) {
			K = M / A[i];
			M -= A[i] * K;
		}
		if (ud[i] == 1 && ud[i + 1] != 1) {
			M += A[i] * K;
			K = 0;
		}
	}

	cout << M << endl;

	return 0;
}


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

template<typename C>
inline void out_vector(const C& v){
  bool isFirst = true;
  for(const auto& e : v){
    if(isFirst) { isFirst = false; }
    else { cout << " "; }
    
    cout << e;
  }
  cout << endl;
}

int main() {
  string s;
  cin >> s;
  
  auto p = 0;
  auto len = s.size();
  map<int, tuple<char, int, int>> tokens;
  vector<int> result(len);
  
  while(p < len){
    auto i = s.find("RL", p);
    if(i == string::npos) { i = len; }
    else { result[i] = result[i + 1] = 1; }
    
    auto pr = p;
    while(s[pr] == 'L' && pr < i) { pr++; }
    if(pr != p) { // 'L'
      tokens[p] = make_tuple(s[p], pr - p, p - 2);
    }
    if(pr < i){ // 'R'
      tokens[pr] = make_tuple(s[pr], i - pr, i);
    }
    p = i + 2;
  }
  
  for(auto t : tokens){
    auto p = t.first;
    
    auto cl = t.second;
    char c; int l, a;
    tie(c, l, a) = cl;
    
    if(c == 'R'){
      // R
      result[a] += l / 2;
      // L
      result[a + 1] += (l + 1) / 2;
    } else { //'L'
      // L
      result[a] += (l + 1) / 2;
      // R
      result[a + 1] += l / 2;
    }
  }
  
  out_vector(result);
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;

const int INF = 1145141919;
int n;
vector<int> et[100000];			//et[i] = 頂点iから行ける頂点の集合
int num[100000];				//num[i] = 頂点iに書かれている値 (なければINF)
pair<int, int> range[100000];	//range[i] = 頂点i以下で矛盾を無くしたいときに頂点iに書ける値の範囲 (閉区間)

//開始頂点の番号を返す
int input() {
	int i;
	cin >> n;
	for (i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v; u--; v--;
		et[u].push_back(v);
		et[v].push_back(u);
	}
	for (i = 0; i < n; i++) { num[i] = INF; }
	
	int k;
	int ret = -1;
	cin >> k;
	for (i = 0; i < k; i++) {
		int v, p;
		cin >> v >> p; v--;
		num[v] = p;
		ret = v;
	}
	return ret;
}

//偶奇チェック
bool dfs(int parent, int v, int mod) {
	if (num[v] != INF && num[v] % 2 != mod) { return false; }
	for (int i = 0; i < et[v].size(); i++) {
		if (et[v][i] == parent) continue;
		if (!dfs(v, et[v][i], (mod + 1) % 2)) return false;
	}
	return true;
}

//値範囲決め (頂点v以下で矛盾がないようにしたとき, 頂点vに入る値の集合は1つの区間になる)
pair<int, int> dfs2(int parent, int v) {
	pair<int, int> ret = pair<int, int>(-INF, INF);
	
	if (num[v] != INF) ret = pair<int, int>(num[v], num[v]);
	
	for (int i = 0; i < et[v].size(); i++) {
		if (et[v][i] == parent) continue;
		pair<int, int> res = dfs2(v, et[v][i]);
		ret.first = max(ret.first, res.first - 1);
		ret.second = min(ret.second, res.second + 1);
	}
	return (range[v] = ret);
}

//値を根から決めていく
void dfs3(int parent, int v) {
	if (parent == -1) { num[v] = range[v].first; }
	else {
		if (range[v].first <= num[parent] - 1 && num[parent] - 1 <= range[v].second) { num[v] = num[parent] - 1; }
		else { num[v] = num[parent] + 1; }
	}
	for (int i = 0; i < et[v].size(); i++) {
		if (parent == et[v][i]) continue;
		dfs3(v, et[v][i]);
	}
}

signed main() {
	int start = input();
	if (!dfs(-1, start, num[start] % 2)) { cout << "No" << endl; return 0; }
	pair<int, int> res = dfs2(-1, start);
	
	for (int i = 0; i < n; i++) { if (range[i].first > range[i].second) { cout << "No" << endl; return 0; } }
	
	cout << "Yes" << endl;
	dfs3(-1, start);
	for (int i = 0; i < n; i++) {
		cout << num[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 15360
n, x, y = list(map(int, input().split()))

count = [0]*n

for i in range(n-1):
    for j in range(i+1, n):
        ans_1 = j-i
        ans_2 = abs(x-(i+1))+1+abs(y-(j+1))
        
        count[min(ans_1,ans_2)] += 1

# print(count)

[print(k) for k in count[1:]]

Measured memory_bytes: 3444
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;

class Main{
        public static void main(String[] args){
                Scanner scanner=new Scanner(System.in);
                int n=scanner.nextInt();
                int[] a=new int[n];
                for(int i=0;i<n;i++){
                        a[i]=scanner.nextInt();
                }
                Arrays.sort(a);

                int j=a[n-1];
                int k=0;
                int[] h=new int[2];
                for(int i=1;i<n;i++){
                        if(a[n-1-i]==j){
                                i++;
                                h[k]=j;
                                k++;
                                if(k==2){
                                        System.out.println((long)h[0]*h[1]);
                                        return;
                                }
                        }
                        if(i>=n-1){
                                break;
                        }
                        j=a[n-1-i];
                }
                System.out.println(0);
        }
}

Measured memory_bytes: 50652
while True:
    
    m, f, r = map(int, input().split())
    
    if m == f == r == -1:
        break
        
    if m == -1 or f == -1:
        print("F")
        
    elif m + f >= 80:
        print("A")
        
    elif m + f >= 65:
        print("B")
        
    elif m + f >= 50:
        print("C")
        
    elif m + f >= 30 and r >= 50:
        print("C")
        
    elif m + f >= 30 and r < 50:
        print("D")
        
    else:
        print("F")


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

int main()
{
	string A;
	cin >> A;
	reverse(A.begin(), A.end());
	int N = A.size();
	vector<vector<int>> cnt(N + 1, vector<int>(26));
	vector<int> var(N + 1), mi(N + 1);
	for (int i = 0; i < N; i++) {
		cnt[i + 1] = cnt[i];
		var[i + 1] = var[i];
		mi[i + 1] = mi[i];
		if (cnt[i + 1][A[i] - 'a'] == mi[i + 1]) {
			cnt[i + 1][A[i] - 'a']++;
			var[i + 1]++;
			if (var[i + 1] == 26) {
				mi[i + 1]++;
				var[i + 1] = 0;
			}
		}
	}
	string res;
	int tmp = N, now = mi[tmp];
	char ta;
	for (int i = 0; i < 26; i++) {
		if (cnt[tmp][i] == now) {
			ta = 'a' + i;
			res.push_back('a' + i);
			break;
		}
	}
	while (now) {
		while (tmp >= 0 && A[tmp] != ta) {
			tmp--;
		}
		if (tmp < 0) {
			break;
		}
		now = mi[tmp];
		for (int i = 0; i < 26; i++) {
			if (cnt[tmp][i] == now) {
				ta = 'a' + i;
				res.push_back('a' + i);
				tmp--;
				break;
			}
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 28548
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] lr = s.toCharArray();
        int[] children = new int[s.length()];

        int border = 0;
        char now = 'R';
        for (int i = 0; i < s.length(); i++) {
            if (lr[i] == now) {
                continue;
            }
            if (lr[i] != now) {
                int r = i - border;
                if (now == 'R') {
                    children[i - 1] += r / 2 + r % 2;
                    children[i] += r / 2;
                }
                if (now == 'L') {
                    children[border - 1] += r / 2;
                    children[border] += r / 2 + r % 2;
                }
                border = i;
                now = lr[i];
            }
        }
        int l = s.length() - border;
        children[border - 1] += l / 2;
        children[border] += l / 2 + l % 2;
        for (int i = 0; i < children.length; i++) {
            System.out.print(children[i] + " ");
        }
    }
}

Measured memory_bytes: 42900
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;

int main(){
	int A,B;
  	cin >> A >> B;
  if (A+B>=10){
    cout <<"error"<<endl;
  } else {
    cout << A + B <<endl;
  }
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc129/tasks/abc129_e
# 桁DPの理解が深まる一問
# 詳しくはeditorial参照

import sys
read = sys.stdin.readline
ra = range
enu = enumerate


class ModInt:
    def __init__(self, x, MOD=10 ** 9 + 7):
        '''
        pypyじゃないと地獄みたいな遅さなので注意
        '''
        self.mod = MOD
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x, self.mod)
        else:
            return ModInt(self.x + other, self.mod)

    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x, self.mod)
        else:
            return ModInt(self.x - other, self.mod)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x, self.mod)
        else:
            return ModInt(self.x * other, self.mod)

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(self.x * pow(other, self.mod - 2, self.mod), self.mod)

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, self.mod), self.mod)
        else:
            return ModInt(pow(self.x, other, self.mod), self.mod)

    __radd__ = __add__

    def __rsub__(self, other):  # 演算の順序が逆
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x, self.mod)
        else:
            return ModInt(other - self.x, self.mod)

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x * pow(self.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(other * pow(self.x, self.mod - 2, self.mod), self.mod)

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, self.mod), self.mod)
        else:
            return ModInt(pow(other, self.x, self.mod), self.mod)


MOD = 10 ** 9 + 7

L = read()[:-1]
n = len(L)

# a+bの各桁についてDPで組み合わせの総和を数え上げる
# dp[i][j]...上位[0,i)桁まで見たときのa,bの組み合わせの総数。j=0→L[:i]まで一致している場合の通り数、j=1→未満が確定している状態の通り数

dp = [[0] * 2 for _ in ra(n + 1)]
dp[0][0] = ModInt(1)
for i in ra(n):
    # i桁目が0の場合→a+bのi桁目はどちらも必ず0となるはず(通りの数は増えない)
    if L[i] == '0':
        # 未満の状態は未満の状態に
        # ちょうどの状態もちょうどの状態に遷移する
        dp[i + 1][0] += dp[i][0]
        dp[i + 1][1] += dp[i][1]
    else:
        # ちょうどの数も未満に遷移する
        dp[i + 1][1] += dp[i][0] + dp[i][1]

    # i桁目が1の場合→a+bのi桁目はどちらかが1となるはず(通りの数2倍になる)
    if L[i] == '0':
        # 未満は未満のままだけど
        # ちょうどだった状態は超えてしまう虚無に帰す
        dp[i + 1][1] += dp[i][1] * 2
    else:
        # 未満は未満のままで、ちょうどはちょうどのまま
        dp[i + 1][0] += dp[i][0] * 2
        dp[i + 1][1] += dp[i][1] * 2

print(dp[-1][0] + dp[-1][1])


Measured memory_bytes: 71200
#include  <stdio.h>

int main(void)
{		
  int n,i,j,temp,x[100],count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
  }
  for (i = 0; i < n - 1; i++) {
    for (j = n - 1; j > i; j--) {
      if (x[j - 1] > x[j]) {  /* 前の要素の方が大きかったら */
	temp = x[j];        /* 交換する */
	x[j] = x[j - 1];
	x[j - 1]= temp;
	count++;
      }
    }	
  }
  for(i=0;i<n;i++){
    if(i==n-1)
      printf("%d\n",x[i]);
    else
      printf("%d ",x[i]);
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#include <cstdint>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18
const long MOD = 998244353;


long power(long a, long b, long MOD){
    a %= MOD;
    if(b == 0){
        return 1l;
    }else if(b % 2 == 1){
        return a * power(a, b-1, MOD) % MOD;
    }else{
        long r = power(a, b/2, MOD);
        return r * r % MOD;
    }
}

long n, s;
long a[3005];

long dp[3005][3005];

int main(){
    scanf("%ld%ld", &n, &s);
    for(int i = 0; i < n; i++){
        scanf("%ld", a+i+1);
    }
    long m_init = power(2, n, MOD);
    long div = power(2, MOD-2, MOD);
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= s+1; j++){
            dp[i][j] = 0;
        }
    }
    for(int i = 0; i <= n; i++){
        dp[i][0] = m_init;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= s; j++){
            dp[i][j] = dp[i-1][j];
            if(j - a[i] >= 0){
                dp[i][j] += dp[i-1][j-a[i]] * div % MOD;
                dp[i][j] %= MOD;
            }
        }
    }
    /*
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= s; j++){
            printf("%4ld ", dp[i][j]);
        }
        printf("\n");
    }
    //*/
    printf("%ld\n", dp[n][s]);
}


Measured memory_bytes: 74196
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 100050;
int N;
int64_t A[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }

    std::vector<int64_t> pos_vec, neg_vec;

    for (int i = 1; i <= N; i++) {
        if (0 <= A[i]) {
            pos_vec.push_back(A[i]);
        } else {
            neg_vec.push_back(A[i]);
        }
    }

    if (pos_vec.size() == 0) {
        std::sort(neg_vec.begin(), neg_vec.end());
        assert(neg_vec.size() == N);
        int64_t ret = 0;
        ret = neg_vec[N-1];
        for (int i = 0; i < N - 1; i++) {
            ret = ret - neg_vec[i];
        }
        std::cout << ret << std::endl;
        ret = neg_vec[N-1];
        for (int i = 0; i < N - 1; i++) {
            std::cout << ret << " " << neg_vec[i] << std::endl;
            ret = ret - neg_vec[i];
        }
    } else if (neg_vec.size() == 0) {
        std::sort(pos_vec.begin(), pos_vec.end());
        assert(pos_vec.size() == N);
        int64_t ret = 0;
        for (int i = 0; i < N; i++) {
            ret += pos_vec[i];
        }
        ret -= pos_vec[0] * 2;
        std::cout << ret << std::endl;
        ret = pos_vec[0];
        for (int i = 1; i < N - 1; i++) {
            std::cout << ret << " " << pos_vec[i] << std::endl;
            ret = ret - pos_vec[i];
        }
        std::cout << pos_vec[N-1] << " " << ret << std::endl;
    } else {
        int64_t ret = 0;
        for (int i = 1; i <= N; i++) {
            ret += abs(A[i]);
        }
        std::cout << ret << std::endl;
        ret = neg_vec[0];
        for (int i = 0; i < pos_vec.size() - 1; i++) {
            std::cout << ret << " " << pos_vec[i] << std::endl;
            ret = ret - pos_vec[i];
        }
        std::cout << pos_vec.back() << " " << ret << std::endl;
        ret = pos_vec.back() - ret;
        for (int i = 1; i < neg_vec.size(); i++) {
            std::cout << ret << " " << neg_vec[i] << std::endl;
            ret = ret - neg_vec[i];
        }
    }

    return 0;
}

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


int main(){
  char s1[100], s2[100], p[100];

  scanf("%s", s1);
  scanf("%s", p);

  strcpy(s2 ,s1);
  strcat(s1, s2);

  if(strstr(s1, p)!=NULL) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin())
#define lc (v * 2)
#define rc (v * 2 + 1)
long long M = 998244353;
//>>>>>>>>>>>>>>>>>>>>>>>

#define int long long

const int N = 1e6 + 7;

int pw(int a, int b) {
	int rt = 1;
	while (b) {
		if (b % 2)
			rt = (rt * a) % M;
		a = (a * a) % M;
		b /= 2;
	}
	return rt;
}
int fc[N], rfc[N];

int chs(int a, int b) {
	return (((fc[b] * rfc[a]) % M) * rfc[b - a]) % M;
}

int32_t main() {
	fc[0] = rfc[0] = 1;
	for (int i = 1; i < N; i++) {
		fc[i] = (i * fc[i - 1]) % M;
		rfc[i] = pw(fc[i], M - 2);
	}
	makefast;
	int res, n, m;
	cin >> n >> m;
	res = max(n, m);
	for (int i = 2; i <= min(n + 1, m + 1); i++) {
		int way = (chs(i - 1, 2 * (i - 1)) * chs(m + 1 - i, n + m + 2 - 2 * i)) % M;
		int p = ((way * pw(chs(n, n + m), M - 2)) % M);
	//	cout << " p : " << i << " > " << p << endl;
		p = (p * pw(2, M - 2)) % M;
		res = (res + p) % M;
	}
	cout << res;

}



Measured memory_bytes: 19324
/*#include<iostream>
using namespace std;
int main(){
	long long a,b,x;
	cin>>a>>b>>x;
	long long c=a;
	if (a!=0) a--;
	long long z=b/x-a/x;
	if (c==0) z++;
	cout<<z;
	return 0;
}
*/
//t2:
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a=0,ans=0;
    for (int i=0;i<s.length();i++){
    	int z=s[i]-48;
    	ans+=z;
    	a=a*10+z;
	}
	if (a%ans) cout<<"No"; else cout<<"Yes";
	return 0;
}

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

int main(){
  int a, b, c, ma, ans, k;
  scanf("%d%d%d%d", &a, &b, &c, &k);
  ma = max(max(a,b),c);
  ans = a + b + c - ma;
  for(int i = 0; i < k; i++) ma *= 2;
  printf("%d",ans + ma);
}


Measured memory_bytes: 128
use proconio::*;
use std::cmp::max;
use std::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut score = 0;
    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 40;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0, 3);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        score += max_score;
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
    l: usize,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let l = max(1, l - 1);
    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    let mut cands = BinaryHeap::new();
    for j in 0..26 {
        let tmp_score = calc_score(i + 1, j, &c, &s, lasts);
        cands.push((tmp_score, j));
    }
    for &(_, j) in cands.iter().take(l) {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score, l);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


Measured memory_bytes: 2396