akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll cnt = 0;
    rep(i,0,3){
        if(s[i] == '1') cnt++;
    }
    print(cnt);

}


Measured memory_bytes: 256
n=int(input())
S=[]
for i in range(n):
    s=int(input())
    S.append(s)
if sum(S)%10!=0:
    ans=sum(S)
else:
    ans=0
for i in range(n):
    if ans<sum(S)-S[i] and (sum(S)-S[i])%10!=0:
        ans=sum(S)-S[i]
print(ans)

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int A, B, C, X, Y; scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);
  ll ans = 1LL * A * X + B * Y;

  ll val = X * (2 * C) + max(0, Y - X) * B;
  ans = min(ans, val);
  val = Y * (2 * C) + max(0, X - Y) * A;
  ans = min(ans, val);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
using namespace std;
int main(void){
	int h,w,i,j;
	cin>>h>>w;
	char ma[h+3][w+3];
	for(i=0;i<h+2;i++){
		for(j=0;j<w+2;j++) ma[i][j]='#';
	}
	for(i=1;i<h+1;i++){
		for(j=1;j<w+1;j++) cin>>ma[i][j];
	}
	for(i=0;i<h+2;i++){
		for(j=0;j<w+2;j++) cout<<ma[i][j];
		cout<<endl;
	}
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int M = N-2;
  int count = 0;
  for (int i = 0; i < M; i++) {
    if (S[i] =='A'&&S[i+1] =='B'&&S[i+2] =='C')
      count++;
    }
  cout << count << endl;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  int ans = 0;
  rep(i,k) ans += a[i];
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

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

  vector<ll> a(n+1);
  vector<ll> b(n);

  rep(i, n+1) cin >> a.at(i);
  rep(i, n) cin >> b.at(i);

  ll mon=0;
  rep(i,n){
    ll first = min(a.at(i), b.at(i));
    ll second = min(a.at(i+1), b.at(i)-first);
    a.at(i+1) -= second;

    mon += (first+second);
    
  }

  cout << mon;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  N %= K;
  cout<<min(abs(N), abs(N-K))<<endl;
}



Measured memory_bytes: 3556
N = gets.to_i
A = gets.split.map(&:to_i)

cost = 0

([0] + A + [0]).each_cons(2) do |from, to|
  cost += (from - to).abs
end

def f(skip, from, to)
  (from - skip).abs + (to - skip).abs - (from - to).abs
end

A.each_with_index do |a, i|
  if i == 0
    puts cost - f(a, 0, A[i + 1])
  elsif i == N - 1
    puts cost - f(a, A[i - 1], 0)
  else
    puts cost - f(a, A[i - 1], A[i + 1])
  end
end


Measured memory_bytes: 12556
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

N = int(input())

for i in range(N):
    S = input()
    M = []

    for s in S:
        M.append(int(s))
    
    M.sort()

    minnum = 0
    maxnum = 0

    #print(M)

    for j, n in enumerate(M[::-1]):
        minnum += (n*10**(j))

    for j, n in enumerate(M):
        maxnum += (n*10**(j))

    #print(minnum)
    #print(maxnum)

    print(maxnum-minnum)



Measured memory_bytes: 5684
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        long[] Az = new long[N];
        long maxA = 0;
        for (int i = 0; i < N; i++){
            Az[i] = sc.nextLong();
            if (maxA < Az[i]){
                maxA = Az[i];
            }
        }
        long left = 0;
        long right = maxA;
        long mid = 0;
        int cutCnt = 0;
        long minNo = maxA+1;
        long ans = maxA;
        long nextToAns = maxA;
        int cnt = 0;
        int cannotFindFlg = 0;
        while (left < right){
            mid = (left + right)/2;
            if (mid == 0) break;
            cutCnt = 0;
//            System.out.println(left +" "+right+" mid "+mid+" "+cnt+" ans "+ans+" "+(cutCnt > K)+" "+cutCnt);
            for (int i = 0; i < N; i++){
//                System.out.println(mid +" Az[i] "+Az[i]+" "+(Math.ceil((double) Az[i] / mid)));
                cutCnt += Math.ceil((double) Az[i] / mid) - 1;
            }
//            System.out.println("cutCnt "+cutCnt);
            if (cutCnt > K){
                minNo = mid;
//                right = mid;
                left = mid + 1;
            } else {
                ans = mid;
//                if (minNo == ans + 1){
//                    System.out.println("aa");
//                    cannotFindFlg = 1;
//                    nextToAns = mid;
//                    break;
//                }
//                left = mid + 1;
                right = mid;
            }
//            System.out.println(left +" "+right+" mid "+mid+" "+cnt+" ans "+ans+" "+(cutCnt > K)+" "+cutCnt);
            cnt++;
//            if (cnt == 10) break;
        }
//        if (cannotFindFlg == 0){
        System.out.println(ans);
//        } else {
//            System.out.println(nextToAns);
//        }

    }
}


Measured memory_bytes: 61628
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n;
    cin>>n;
    cout<<n*n;}

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

using pii = pair<int, int>;

constexpr int INF = 1e9;

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> p(n);
        for(int i=0; i<n; ++i) {
            cin >> p[i];
        }
        vector<vector<pii>> dp(n+1, vector<pii>(500*n, make_pair(INF, INF)));
        dp[0][0] = make_pair(0, 0);
        for(int i=0; i<n; ++i) {
            for(int j=0; j<500*n; ++j) {
                if(dp[i][j].first == INF) {
                    continue;
                }
                int noguti = ((p[i] + 999) / 1000) * 1000;
                if(1 <= p[i] % 1000 && p[i] % 1000 <= 500) {
                    int coin = noguti - p[i] - 500;
                    pii next = make_pair(dp[i][j].first - 1, dp[i][j].second + p[i]);
                    dp[i+1][j+coin] = min(dp[i+1][j+coin], next);
                } else {
                    dp[i+1][j] = min(dp[i+1][j], dp[i][j]); // not buy
                    int cost = ((p[i] % 1000) + 500) % 1000;
                    if(cost <= j) { // use coin
                        pii next = make_pair(dp[i][j].first - 1, dp[i][j].second + p[i]);
                        dp[i+1][j-cost] = min(dp[i+1][j-cost], next);
                    } else { // only noguti
                        pii next = make_pair(dp[i][j].first, dp[i][j].second + p[i]);
                        int coin = noguti - p[i];
                        dp[i+1][j+coin] = min(dp[i+1][j+coin], next);
                    }
                }
            }
        }
        auto res = *min_element(dp[n].begin(), dp[n].end());
        cout << -res.first << ' ' << res.second << endl;
    }
}


Measured memory_bytes: 42552
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<int> > g(N);
	vector<vector<int> > rev(N);
	int a, b;
	vector<int> cnt(N, 0);
	for (int i = 0; i < N - 1 + M; i++) {
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		rev[b].push_back(a);
		cnt[b]++;
	}
	vector<int> res(N);
	queue<int> qu;
	for (int i = 0; i < N; i++) {
		if (cnt[i] == 0) {
			res[i] = 0;
			qu.push(i);
			break;
		}
	}
	vector<int> d(N, 0);
	while (qu.size()){
		a = qu.front(); qu.pop();
		int mx = -1;
		for (int i : rev[a]) {
			if (mx < d[i]) {
				mx = d[i];
				res[a] = i + 1;
			}
		}
		d[a] = mx + 1;
		for (int i : g[a]) {
			cnt[i]--;
			if (cnt[i] == 0) {
				qu.push(i);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << res[i] << endl;
	}
}

Measured memory_bytes: 14080
import sys
s = list(input())
k = int(input())

if len(set(s))==1:
	print((len(s)*k)//2)
	sys.exit()
    
def counter(string):
    count = 0
    answer = 0
    prev = ""
    for index,sss in enumerate(string):
        if prev == "" or sss == prev:
            count+=1
            if count == 2: 
                answer+=1
                count=0
                string[index] = "1"
        else:
            count=1
        prev = sss
    return answer,string

answer, string = counter(s.copy())

if string[0] != string[-1]:
    print(answer*k)
else:
    count = 0
    l = len(s)
    for i in range(l):
        if s[i] == s[0]:
            count += 1
        else:
            break
    for i in range(l):
        if s[-1-i] == s[0]:
        	count += 1
        else:
        	break

    if count % 2 ==0:
        print(answer*k + k-1)
    else:
        print(answer*k)


Measured memory_bytes: 3064
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int n, k, s; cin >> n >> k >> s && n;) {
		vector<vector<int>> dp(k + 1, vector<int>(s + 1, 0));
		dp[0][0] = 1;
		for(int i = 1; i <= n; ++i) {
			for(int j = s; j >= i; --j) {
				for(int l = k - 1; l >= 0; --l) {
					dp[l + 1][j] += dp[l][j - i];
				}
			}
		}
		cout << dp[k][s] << endl;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1232
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A >= B && A >= C) {
        cout << A * 10 + B + C << endl;
    } else if(B >= A && B >= C) {
        cout << B * 10 + A + C << endl;
    } else {
        cout << C * 10 + B + A << endl;
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0; i<n; i++){
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  cout << d[n/2]-d[(n/2)-1] << endl;
  return 0;
}


Measured memory_bytes: 640
# sはありったけ使うほうがいい（cから作るとコストがかかる）
# ありったけ = m//2
# 残ったcからsccを作るには4つ必要

n, m = map(int, input().split())
c = min(n, m // 2)
c += max(0, (m-2*n) // 4)
print(c)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
ll dp[16][1LL<<16];
ll s[200], t[200], d[200];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll dist[20][20] = {};
    rep(i,0,N){
        rep(j,0,N){
            if(i == j) dist[i][j] = 0;
            else dist[i][j] = INF;
        }
    }
    rep(i,0,M){
        cin >> s[i] >> t[i] >> d[i];
        dist[s[i]][t[i]] = d[i];
    }
    rep(i,0,N){
        rep(j,0,(1LL<<N)){
            dp[i][j] = INF;
        }
    }
    dp[0][1] = 0; //dp[i][j]: 今iにいて訪れたことのある頂点集合がjの時の最短距離
    rep(bit,0,(1LL<<N)){
        rep(i,0,N){
            if(dp[i][bit] == INF) continue;
            rep(j,0,N){
                if((bit>>j) & 1) continue;
                dp[j][bit | (1LL<<j)] = min(dp[j][bit | (1LL<<j)], dp[i][bit] + dist[i][j]);
            }
        }
    }
    ll ans = INF;
    rep(i,0,N){
        ans = min(ans, dp[i][(1LL<<N)-1] + dist[i][0]);
    }
    if(ans == INF){
        print(-1);
    }else{
        print(ans);
    }

    
}


Measured memory_bytes: 7128
#include <iostream>

using namespace std;

class Dice {
    public:
    int face[6];
    Dice() {}
    void rotateX () {
        rotate(0, 1, 5, 4);
    }
    void rotateY () {
        rotate(0, 2, 5, 3);
    }
    void rotateZ () {
        rotate(1, 2, 4, 3);
    }
    void rotate (int a, int b, int c, int d) {
        int t = face[a];
        face[a] = face[b];
        face[b] = face[c];
        face[c] = face[d];
        face[d] = t;
    }
};

bool eq(Dice d1, Dice d2) {
    for (int i = 0; i < 6; i++)
        if (d1.face[i] != d2.face[i]) return false;
    return true;
}

bool equal(Dice d1, Dice d2) {
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 4; j++) {
            if (eq(d1, d2)) return true;
            d1.rotateZ();
        }
        if (i % 2 == 0) d1.rotateY();
        else d1.rotateX();
    }
    return false;
}

int main () {
    Dice d1, d2;

    for (int i = 0; i < 6; i++) cin >> d1.face[i];
    for (int i = 0; i < 6; i++) cin >> d2.face[i];

    if (equal(d1, d2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int x,y;
    for (int i=0;i<10000;i++){
        x = (int)(i*2/25);
        y = (int)(i*0.1);
        if(x == a && y == b){
            cout << i;
            return 0;
        }
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 256
n = input()
a = map(int, raw_input().split())

for i in range(n):
    key = a[i]
    j = i - 1
    while j >= 0 and a[j] > key:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = key
    print(" ".join(map(str, a)))

Measured memory_bytes: 4212
#include <iostream>
#define llint long long

using namespace std;

llint r0, w0, c, r;

int main(void)
{
  while(1){
    cin >> r0 >> w0 >> c >> r;
    if(r0 == 0 && w0 == 0 && c == 0 && r == 0) break;
    if(c*w0-r0+r-1 <= 0) cout << 0 << endl;
    else cout << (c*w0-r0+r-1)/r << endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int n,d;
    cin>>n>>d;
    int x[n][d];
    int ans=0;
    rep(i,0,n-1){
        rep(j,0,d-1){
            cin>>x[i][j];
        }
    }
    int diff;
    int hoge=0;
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            hoge = 0;
            rep(k,0,d-1){
                diff = abs(x[i][k]-x[j][k]);
                hoge += diff*diff;
            }
            bool flag = false;
            rep(k,0,hoge){
                if(k*k==hoge){
                    flag = true;
                    break;
                }
            }
            if(flag==true)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var count = 0;
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var L = int.Parse(line[0]);
            var r = int.Parse(line[1]);
            count += r - L + 1;
        }
        Console.WriteLine(count);
    }
}

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

#define Inf ll(1e18)
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=20;
int n;
int a[maxn];
map<pii,ll>dp[maxn][maxn];

ll solve(int l,int r,int xl,int xr){
	if(l>r)return 0;
	if(dp[l][r].count(mp(xl,xr)))return dp[l][r][mp(xl,xr)];
	ll res=Inf;
	for(int i=l;i<=r;i++)
		res=min(res,solve(l,i-1,xl,xl+xr)+solve(i+1,r,xl+xr,xr)+1LL*a[i]*(xl+xr));
	return dp[l][r][mp(xl,xr)]=res;
}

int main(){
	scanf("%d",&n);
	REP(i,n)scanf("%d",&a[i]);
	printf("%lld\n",a[1]+a[n]+solve(2,n-1,1,1));
	return 0;
}

Measured memory_bytes: 16640
n = int(input())
li1 = list(map(int,input().split()))
li2 = []
count = 0
for i in range(n):
    li2.append(i+1)
for i in range(n):
    if li1[i] != li2[i]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
n, m = map(int, input().split())
MOD = 1000000007
def comb(x, y):
    ret = 1
    for a in range(x, x - y, -1):
        ret *= a
    for b in range(y, 0, -1):
        ret //= b
    return ret

ans = 1
for i in range(2, 100000):
    if i > m:break
    cnt = 0
    while m % i == 0:
        cnt += 1
        m //= i
    ans *= comb(cnt + n - 1, cnt)
if m != 1:
    ans *= comb(n, 1)

print(ans % MOD)

Measured memory_bytes: 39920
#include <iostream>
   #include <string>
  #include <algorithm>
  #include <cmath>
  using namespace std;
  
  int main() {
      int n, m;
      cin >> n >> m;
    int s, length;
    s = (n*m);
    length = 2*(n+m);
      cout << s << " " << length << endl;
}



Measured memory_bytes: 3052
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    auto b  = a;
    sort(all(b));
    int cnt = 0;
    rep(i, n) if(a[i] != b[i]) cnt++;
    string yes = "YES", no = "NO";
    if(cnt <= 2) cout << yes << endl;
    else cout <<  no << endl;;
    return 0;
}

Measured memory_bytes: 256
A = int(input())
if A == 2:
    print(2)
    exit()
sosu = [2] #素数が入る
sosu_2 = [4] #素数の2乗の数が入る
sosu_2_index = 1
for num in range(3, 100010, 2):
    if  num > sosu_2[sosu_2_index-1]:
        sosu_2_index += 1
    flag =  True
    for i in range(1,sosu_2_index):
        if num % sosu[i] == 0:
            flag = False
            break
    if flag:
        sosu.append(num)
        if num >= A:
            print(num)
            exit()
        sosu_2.append(num**2)

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

using namespace std;

#define f0r(a, b) for (long long a = 0; a < b; a++)
#define f1r(a, b, c) for (long long a = b; a < c; a++)
#define f0rd(a, b) for (long long a = b; a >= 0; a--)
#define f1rd(a, b, c) for (long long a = b; a >= c; a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define f first
#define s second

#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << endl;}

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const ll inf = 1e12;
const ll mod = 1e9 + 7;


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

    string s;

    cin >> s;

    if (s[0] == s[s.length() - 1]) {
        if (s.length() % 2 == 0) {
            cout << "First" << endl;
        } else {
            cout << "Second" << endl;
        }
    } else {
        if (s.length() % 2 == 0) {
            cout << "Second" << endl;
        } else {
            cout << "First" << endl;
        }
    }

}


Measured memory_bytes: 3784
#include<stdio.h>
int main(){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0)break;
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				printf("%c",'#');
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define LL long long 
using namespace std;
const int maxn=1e5+5;
struct node
{
    LL a, b, c;
    bool operator <(const node & A) const
    {
        return (a-b)<A.a-A.b;
    }
}p[maxn];
LL lef[maxn];

priority_queue<LL, vector<LL>, greater<LL> >q;



int main()
{
    int x, y, z;
    cin>>x>>y>>z;
    int i, j, n=x+y+z;
    LL base=0;
    for(i=1; i<=n; i++)
    {
        scanf("%lld%lld%lld", &p[i].a, &p[i].b, &p[i].c);
        base+=p[i].c;
    }
    sort(p+1, p+1+n);
    LL ans=0, sum=0;
    for(i=1; i<=y; i++)
    {
        sum+=p[i].b-p[i].c;
        q.push(p[i].b-p[i].c);
    }
    for(i=y+1; i<=n-x+1; i++)
    {
        lef[i]=sum;
        sum+=p[i].b-p[i].c;
        q.push(p[i].b-p[i].c);   
        sum-=q.top();
        q.pop();
    }

    while(q.empty()==0)q.pop();
    sum=0;
    for(i=n; i>=n-x+1; i--)
    {
        sum+=p[i].a-p[i].c;
        q.push(p[i].a-p[i].c);
    }

    for(; i>=y; i--)
    {
        ans=max(ans, base+lef[i+1]+sum);
   //     printf("%d %lld %lld %lld\n", i, base, lef[i+1], sum);
        sum+=p[i].a-p[i].c;
        q.push(p[i].a-p[i].c);
        sum-=q.top();
        q.pop();
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3960
/*　　　＿
　 '´　　 ヽ
 ./ ﾉﾉ））)）〉＜そーなのかー
〈《.! ﾟ ヮﾟﾉ》
　⊂!::V::!つ
　 く::::::::〉
　　 し'ﾉ*/
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,m;
  int l=0;
  int a=1;
  cin >> n >> m;
  for(int i=0;i<100;i++){
  l++;
  a*=m;  
    if(n<a){
    break;
    }
  }
  cout << l << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;

int main(){
    int n,count=0;
    cin>>n;
    int a[10000]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int q;
    cin>>q;
    int b[10000]={};
    for(int j=0;j<q;j++){
        cin>>b[j];
        for(int i=0;i<n;i++){
            if(b[j]==a[i]){
                count++;
                break;
            }
        }
        
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3180
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int n; cin >> n;
  vector<int> h(n);
  int ren = 0;
  int maxi = 0;
  for(int i = 0; i < n ; i++){
    cin >> h[i];
    if(i == 0) continue;
    if(h[i] <= h[i-1]) ren++;
    else{
      maxi = max(maxi, ren);
      ren = 0;
    }
  }
  cout << max(maxi, ren) << endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

int main() {
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 != m2 and d2 == 1) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){
	
	int H,W,K;
	cin>>H>>W>>K;
	
	vector<string> A(H);
	
	for(int i=0;i<H;i++)cin>>A[i];
	
	vector<vector<int>> ans(H,vector<int>(W,0));
	int now = 1;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(ans[i][j]!=0)continue;
			if(A[i][j]!='#')continue;
			int r = W;
			int c = 0;
			for(int k=j;k<W;k++){
				if(ans[i][k]!=0){
					r=k;
					break;
				}
				if(c==1&&A[i][k]=='#'){
					r = k;
					break;
				}
				if(A[i][k]=='#'){
					c++;
				}
				ans[i][k]=now;
			}
			int l = 0;
			for(int k=j-1;k>=0;k--){
				if(ans[i][k]!=0){
					l=k+1;
					break;
				}
				if(c==1&&A[i][k]=='#'){
					l = k+1;
					break;
				}
				if(A[i][k]=='#'){
					c++;
				}
				ans[i][k]=now;
			}
			
			
			int b = i;
			while(true){
				b++;
				if(b==H)break;
				bool f = true;
				for(int k=l;k<r;k++){
					if(ans[b][k]!=0){
						f=false;
						break;
					}
					if(c==1&&A[b][k]=='#'){
						f=false;
						break;
					}
					if(A[b][k]=='#')c++;
				}
				if(!f){
					break;
				}
			}
			
			int u = i;
			while(true){
				u--;
				if(u<0){
					u++;
					break;
				}
				bool f = true;
				for(int k=l;k<r;k++){
					if(ans[u][k]!=0){
						f=false;
						break;
					}
					if(c==1&&A[u][k]=='#'){
						f=false;
						break;
					}
					if(A[u][k]=='#')c++;
				}
				
				if(!f){
					u++;
					break;
				}
			}
			
			
			
			for(int a=u;a<b;a++){
				for(int k=l;k<r;k++){
					ans[a][k]=now;
				}
			}
			
			now++;
		}
	}
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(j!=0)cout<<' ';
			cout<<ans[i][j];
		}
		cout<<endl;
	}
	
	return 0;
	
}

Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * 入力された数字を構成する数字の組み合わせ数を計算して出力する。
	 *
	 * @param args
	 */
	public static void main(String[] args) throws IOException {

		// 入力がある限り処理を行う
        String line = null;
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        while ((line = reader.readLine()) != null) {

        	int input = Integer.parseInt(line);
        	System.out.println(calculateNumberOfCombination(input));

        }

        if (reader != null) {
            reader.close();
        }
	}

	/**
	 * 入力された数値を構成する4つの数字の組み合わせの数を求める。
	 *
	 * @param input 入力された数値
	 * @return 組み合わせの数
	 */
	protected static int calculateNumberOfCombination(int input) {

		// 全パターンを試す
		int count = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						if (i + j + k + l == input) {
							count++;
						}
					}
				}
			}
		}

		return count;
	}
}

Measured memory_bytes: 16976
from sys import stdin


def find_sum_of_digits(n, base=10):
    _sum = 0
    while n>0:
        _sum += n%base
        n //= base
    return _sum


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = float('inf')
    for A in range(1,N):
        B = N-A
        sum_ = find_sum_of_digits(A)+find_sum_of_digits(B)
        cnt = min(cnt,sum_)
    ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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


int main() {
	int H, W, sh, sw, gh, gw;
	cin >> H >> W >> sh >> sw >> gh >> gw;
	sh--; sw--; gh--; gw--;
	vector<string> v(H);
	rep(i, H) {
		cin >> v.at(i);
	}
	vector<vector<int>> vv(H, vector<int>(W));
	rep(i, H) {
		rep(j, W) {
			vv.at(i).at(j) = -1;
		}
	}
	vector<int> dy = {1, 0, -1, 0};
	vector<int> dx = {0, 1, 0, -1};
	vector<int> dw = {-2, -1, 0, 1, 2};
	queue<pint> Q;
	queue<pint> QW;
	pint S(sh, sw);
	vv.at(sh).at(sw) = 0;
	Q.push(S);
	int a=0, b=0, c=0, x, y, z;
	while (!Q.empty() || !QW.empty()) {
		while (!Q.empty()) {
			pint P = Q.front();
			Q.pop();
			x = P.first;
			y = P.second;
			QW.push(make_pair(x, y));
			if (x == gh && y == gw) {
				std::cout << a << '\n';
				return 0;
			}
			rep(i, 4) {
				if (x+dx[i] >= 0 && x+dx[i] < H && y+dy[i] >= 0 && y+dy[i] < W) {
					if (v.at(x+dx[i]).at(y+dy[i]) == '.'
					&& vv.at(x+dx[i]).at(y+dy[i]) == -1) {
						Q.push(make_pair(x+dx[i], y+dy[i]));
						vv.at(x+dx[i]).at(y+dy[i]) = a;
					}
				}
			}
		}
		a++;
		while (!QW.empty()) {
			pint P = QW.front();
			QW.pop();
			x = P.first;
			y = P.second;
			rep(i, 5) {
				rep(j, 5) {
					if (x+dw[i] >= 0 && x+dw[i] < H && y+dw[j] >= 0 && y+dw[j] < W) {
						if (v.at(x+dw[i]).at(y+dw[j]) == '.'
						&& vv.at(x+dw[i]).at(y+dw[j]) == -1) {
							Q.push(make_pair(x+dw[i], y+dw[j]));
							vv.at(x+dw[i]).at(y+dw[j]) = a;
							if (x+dw[i] == gh && y+dw[j] == gw) {
								std::cout << a << '\n';
								return 0;
							}
						}
					}
				}
			}
		}
	}
	cout << "-1" << '\n';
}


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

int main()
{
	string s, t;
	cin >> s >> t;
	vector<int> puni(26, -1), muni(26, -1);
	int n = s.size();
	for (int i = 0; i < n; i++)
	{
		int a = s[i] - 'a', b = t[i] - 'a';
		if (0 <= puni[a] || 0 <= muni[b])
		{
			if (puni[a] != b || muni[b] != a)
			{
				cout << "No" << endl;
				return 0;
			}
		}
		else
		{
			puni[a] = b;
			muni[b] = a;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  printf("%.20lf\n",in()*M_PI*2);
  return 0;
}


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

int main(){
  long long int N, K;

  cin >> N >> K;
  long long int r = N % K;

  if(r<(K-r)){
    cout << r << endl;
  }else{
    cout << (K-r) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(n);i++)
#define fori(a,b,i) for(int i=(a);i<=(b);i++)
#define ford(a,b,i) for(int i=(a);i>=(b);i--)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
typedef long long int llint;


 
int main () {
    llint n, m, x;
    cin>>n>>m>>x;
    llint cost[n];
    vector <llint> v[n];
    loop(i, n){
		cin>>cost[i];
		loop(j, m){
			llint t;
			cin>>t;
			v[i].pb(t);
		}
	}
	llint ans = INF;
	string ts, ps;
	loop(i, n) ps += '0';
	for(int mask = 0; mask < (1 << n); ++mask){
		llint tmp = mask, ind = 0;
		ts = ps;
		while(tmp){
			if(tmp & 1) ts[ind] = '1';
			++ind;
			tmp >>= 1;
		}
		vector <llint> tv(m, 0);
		llint tc = 0;
		for(int i = 0; i < n; ++i){
			if(ts[i] == '1'){
				loop(j, m){
					tv[j] += v[i][j];
				}
				tc += cost[i];
			}
		}
		bool flag = true;
		loop(i, m) if(tv[i] < x) flag = 0;
		if(flag) ans = min(ans, tc);
	}
	if(ans == INF) cout<<-1;
	else cout<<ans;
}


Measured memory_bytes: 3612
#include <iostream>

using namespace std;
int main() {
    int d, n;
    cin >> d >> n;
    int x = 1;
    while(d > 0) {
        x *= 100;
        d--;
    }
    int ans = x * n;
    if (n == 100) {
        ans += x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int a,b,c,cnt=0;
    cin >> a >> b >> c;
    for(int i=a; i<=b; i++){
        if(c%i==0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3084
# 62


h, w = map(int, input().split())
dp = [[int(x) for x in input().split()] for y in range(10)]
a_l = [[int(x) for x in input().split()] for y in range(h)]

for k in range(10):
    for j in range(10):
        for i in range(10):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
            
ans = 0
for i in range(h):
    for _a in a_l[i]:
        if _a == -1:
            continue
        ans += dp[_a][1]

print(ans)

Measured memory_bytes: 68148
#include <stdio.h>

int sum = 0;

void merge(int a[], int left, int mid, int right){
  int n1, n2;
  int l[500000], r[500000];
  int i, j, k, count;

  n1 = mid - left;
  n2 = right - mid;

  for (i = 0; i < n1; i++) {
    l[i] = a[left + i];
  }
  for (i = 0; i < n2; i++) {
    r[i] = a[mid + i];
  }
  l[n1] = 1000000000;
  r[n2] = 1000000000;
  i = 0;
  j = 0;
  for (k = left; k <= right - 1; k++) {
    sum++;
    if (l[i] <= r[j]) {
      a[k] = l[i];
      i = i + 1;
    }
    else {
      a[k] = r[j];
      j = j + 1;
    }
  }
}

void mergeSort(int a[], int left, int right) {
  int mid;
  if (left + 1 < right) {
    mid = (left + right) / 2;
    mergeSort(a, left, mid);
    mergeSort(a, mid, right);
    merge(a, left, mid, right);
  }
}

int main(void){
  int n, s[500000];
  int i;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }

  mergeSort(s, 0, n);

  for (i = 0; i < n; i++) {
    if (i <= n - 2) {
      printf("%d ", s[i]);
    }
    else if (i == n - 1) {
      printf("%d\n", s[i]);
    }
  }
  printf("%d\n", sum);

  return 0;
}



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

int main() {
    int a, b;
    cin >> a >> b;

    vector<int> l_a;
    vector<int> l_b;
    vector <int> ans;

    rep(i,1250) {
        if (int((i+1) * 0.08) == a) l_a.push_back(i+1);
    }
    rep(i,1000) {
        if (int((i+1) * 0.1) == b) l_b.push_back(i+1);
    }

    rep(i,l_a.size()) {
        rep (j,l_b.size()) {
            if (l_a[i] == l_b[j]) ans.push_back(l_a[i]);
        } 
    }
    if (ans.size()) cout << ans[0] << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;


int mul(int a, int b) { return (ll)a*b%MOD; }
void ad(int& a, int b) { a = (a+b)%MOD; }
void sub(int& a, int b) { a = (a-b+MOD)%MOD; }

template<int SZ> struct Combo {
    ll fac[SZ+1], ifac[SZ+1];
    
    Combo() {
        fac[0] = ifac[0] = 1;
    	FOR(i,1,SZ+1) {
    	    fac[i] = i*fac[i-1] % MOD;
    	    ifac[i] = inv(fac[i]);
    	}
    }
    
    ll po (ll b, ll p) { return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD; }
    ll inv (ll b) { return po(b,MOD-2); }
    
    ll comb(ll a, ll b) {
        if (a < b || b < 0 || a < 0) return 0;
        ll tmp = fac[a]*ifac[b] % MOD;
        tmp = tmp*ifac[a-b] % MOD;
        return tmp;
    }
    
    int perm(int a, int b) {
        if (a < b) return 0;
        return mul(fac[a],ifac[a-b]);
    }
};

Combo<1<<16> C;

int N,M;
vi A;

void naive() {
    bool a[1<<16];
    int dp[1<<16];
    F0R(i,M) a[A[i]] = 1;
    
    dp[0] = 1;
    FOR(i,1,1<<N) {
        FORd(j,i-1,1<<N) {
            F0R(k,N) if (!(j&(1<<k)) && !a[i]) ad(dp[j^(1<<k)],dp[j]<<k);
            mul(dp[j],j-i+1);
        }
    }
    
    mul(dp[(1<<N)-1],1<<N);
    cout << dp[(1<<N)-1];
}

array<int,1<<16> all, dp[17];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M; A.resize(M);
    F0R(i,M) { cin >> A[i]; A[i] --; }
    
    dp[M][0] = all[0] = 1;
    F0Rd(i,M) {
        F0R(j,1<<N) F0R(k,N) if (!(j&(1<<k))) 
            ad(dp[i][j|(1<<k)],mul(all[j],mul(1<<k,C.perm((1<<N)-1-A[i]-j,(1<<k)-1))));
        F0R(j,1<<N) ad(all[j],dp[i][j]);
    }
    
    int ans = 0;
    F0R(j,M+1) F0R(i,1<<N) {
        dp[j][i] = mul(dp[j][i],C.fac[(1<<N)-1-i]);
        if (__builtin_popcount(i)&1) sub(ans,dp[j][i]);
        else ad(ans,dp[j][i]);
    }
    cout << mul(1<<N,ans);
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 5888
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int a = tmp[0], b = tmp[1];
	WriteLine(((a&b&1) == 1) ? "Yes" : "No");
    }
}


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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define vec vector
#define countSetBits(x) __builtin_popcountll(x)
#define trailingz(x) __builtinctzll(x)
#define leadingz(x) __builtinclzll(x)
#define maxbit(x) __lg(x)
#define minbit(x) __builtin_ffs(x) //lsb index+1
#define debug(args...) cerr << "["#args"] = ["; dbg,args; cerr << "]" << endl;
struct debugger {
    template<typename T> debugger& operator , (const T& v) {    
        cerr<<v<<" ";    
        return *this;
    }
} dbg;
//debug(n, x, s, c);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,n,m,mx,mn,flag,sum=0;
    cin>>n;
    ll a[n],b[n],c[n],sa[n],sb[n],sc[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    sa[0]=a[0];
    sb[0]=b[0];
    sc[0]=c[0];
    for(i=1;i<n;i++)
    {
        sa[i]=max(a[i]+sb[i-1],a[i]+sc[i-1]);
        sb[i]=max(b[i]+sa[i-1],b[i]+sc[i-1]);
        sc[i]=max(c[i]+sb[i-1],c[i]+sa[i-1]);
    }
    mx=max(sc[n-1],max(sa[n-1],sb[n-1]));
    cout<<mx;
    return 0;
       
}

Measured memory_bytes: 8332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n;
  cin>>n;
  int a=n%1000;
  if(a==0)cout<<0<<endl;
  else cout<<1000-a<<endl;
  return(0);
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define pb push_back
#define pair pair<int,int>
#define ll long long
#define f first
#define se second
using namespace std;
double pi=acos(-1.0);
int main(){
int x;string s;
  cin>>x>>s;
  if(x<3200)
    cout<<"red";
  else
    cout<<s;
}

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

using namespace std;
const int MAX = 1e5+5;

long int A[MAX], DP[MAX];

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    DP[0] = 0; DP[1] = abs(A[1]-A[0]);
    for(int i = 2; i < N; i++) {
        DP[i] = 1e9;
        DP[i] = min(DP[i], DP[i-1] + abs(A[i] - A[i-1]));
        DP[i] = min(DP[i], DP[i-2] + abs(A[i] - A[i-2]));
    }

    cout << DP[N-1] << "\n";

    return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

  vector<bool> isUsed(k);
  int x = 7 % k;
  isUsed[x] = true;
  rep(i, k) {
    if (x == 0) {
      cout << i + 1 << endl;
      return 0;
    }

    x = (x * 10 % k + 7) % k;
    if (isUsed[x]) {
      cout << -1 << endl;
      return 0;
    }
    isUsed[x] = true;
  }

  cout << -1 << endl;
  return 0;
}


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

using namespace std;

pair<int,bool>a[1000001];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = false;
    }
    bool ch = false;
    int cnt = 0, r = a[0].first;
    a[0].second = true;
    int i = r - 1;
    while (i < n) {
        if (a[i].second == true) {
            break;
        }
        r = a[i].first;
        cnt++;
        a[i].second = true;
        if (i == 1) {
            ch = true;
            break;
        }
        i = r - 1;
    }
    if (ch) {
        cout << cnt << endl;
    } else {
        cout << "-1" << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
 int n;
  cin>>n;
  int a[n];
  for (int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  double s=a[0];
  for(int i=1;i<n;i++){ 
    //cout<<a[i]<<" ";
    s=(a[i]+s)/2;
  }
  cout<<s;
}

Measured memory_bytes: 256