akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define mp make_pair
typedef long long Int;

int of[200000];

int main() {
    int N, M;
    scanf("%d%d", &N, &M);
    vector<pair<int, int> > v[2];
    rep(i, N) {
        int s, t;
        scanf("%d%d", &s, &t);
        v[s<t].push_back(mp(s, i+1));
        v[s<t].push_back(mp(t, -(i+1)));
    }
    rep(_, M) {
        int p;
        scanf("%d", &p);
        rep(k, 2) v[k].push_back(mp(p, 0));
    }
    rep(k, 2) sort(v[k].begin(), v[k].end());
    reverse(v[0].begin(), v[0].end());
    Int ans = 0;
    rep(k, 2) {
        int nc=0, cc=0, pc=0;
        rep(i, v[k].size()) {
            if(i>0) ans += (Int)nc*abs(v[k][i].first-v[k][i-1].first);
            if(v[k][i].second==0) {
                pc++;
                swap(nc, cc);
            }
            else if(v[k][i].second>0) {
                const int ix = v[k][i].second-1;
                nc++;
                of[ix] = pc;
            }
            else {
                const int ix = -v[k][i].second-1;
                if((pc-of[ix])%2==0) nc--;
                else cc--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4604
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

int main(){
	long long n, i;
	cin>>n;
	long long x = floor(sqrt(n));
	for(i = x; i>=1; i--){
		if(n%i == 0){
			break;
		}
	}
	i = n/i;
	int ans = 0;
	while(i != 0){
		i/=10;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,W; cin >> N >> W;
	const int MC = 1010*100+2;
	vector<LL> dp(MC,W+5);
	dp[0] = 0;
	repp(i,0,N){
		LL w; LL v; cin >> w >> v;
		repm(k,MC,v-1) dp[k] = min(dp[k],dp[k-v]+w);
	}
	LL ans = 0; repp(i,0,MC) if(dp[i] <= W) ans = i;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vi a(m), b(m);
    vvi c(m);
    vl cbit(m, 0);
    // set<int> canopen;
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        for (int j = 0; j < b[i]; ++j) {
            cin >> c[i][j];
            c[i][j]--;
            cbit[i] += (1 << c[i][j]);
            // canopen.insert(c[i][j]);
        }
    }
    vvl dp(m + 1, vl((1 << 12), INF));
    dp[0][0] = 0;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < (1 << 12); ++j) {
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][j | cbit[i]], dp[i][j] + a[i]);
        }
    }
    if (dp[m][(1<<n)-1] == INF)
        cout << -1 << "\n";
    else
        cout << dp[m][(1<<n)-1] << "\n";
    return 0;
}

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

int main(){
	while(true){
		int m, f, r;
		char s;
		
		cin >> m >> f >> r;
		
		if(m==-1 && f==-1&& r==-1) break;
		
		if(m==-1 || f==-1) s = 'F';
		else if(m+f>=80) s = 'A';
		else if(m+f>=65) s = 'B';
		else if(m+f>=50) s = 'C';
		else if(m+f>=30){
			if(r>= 50) s = 'C';
			else s = 'D';
		}
		else s = 'F';
		
		cout << s << "\n";
	}
	return 0;
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[3][4];
  cin >> s[0] >> s[1];
  if(s[0][0]==s[1][2]&&s[0][1]==s[1][1]&&s[0][2]==s[1][0])cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
ABCD=input()
ABCD=ABCD.split()
A=int(ABCD[0])
B=int(ABCD[1])
C=int(ABCD[2])
D=int(ABCD[3])
while(1):
    C=C-B
    if(C<=0):
        print('Yes')
        break
    A=A-D
    if(A<=0):
        print('No')
        break


Measured memory_bytes: 9188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
typedef long long lint;
const int N=1005;
int n,val[N];
std::bitset <N> use;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	std::vector <int> step;
	n=nxi();
	{
		lint v[2]={0};
		bool all_neg=1;
		int xpos=1;
		for(int i=1; i<=n; ++i){
			val[i]=nxi();
			if(val[i]>0) v[i&1]+=val[i];
			all_neg&=val[i]<0;
			if(val[xpos]<val[i]) xpos=i;
		}
		bool p=v[1]>v[0];
		printf("%lld\n",all_neg?(lint)val[xpos]:v[p]);
		for(int i=1; i<=n; ++i){
			use[i]=(i&1)==p&&val[i]>=0;
		}
		if(all_neg) use[xpos]=1;
	}
	for(int x=n; n>1; apn(x,n)){
		for(; x&&(use[x]||(x!=1&&x!=n&&use[x-1]!=use[x+1])); --x);
		assert(x);
		step.push_back(x);
		const int p=2-(x==1||x==n);
		n-=p;
		use=(use>>(x+p)<<x)|(use^(use>>x<<x));
	}
	printf("%d\n",(int)step.size());
	for(std::vector <int> ::iterator it=step.begin(); it!=step.end(); ++it){
		printf("%d\n",*it);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

typedef struct {
  int before;
  int next;
  int count;
} conn;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> path(N);
  int a, b;
  rep(i, M) {
    cin >> a >> b;
    a--;
    b--;
    path[a].push_back(b);
    path[b].push_back(a);
  }

  vector<std::pair<int, int>> post(N);
  rep(i, N) {
    post[i].first = -1;
  }

  std::queue<conn> q;
  conn first = {0, 0, 0};
  q.push(first);

  while(!q.empty()) {
    conn p = q.front();
    q.pop();

    int now = p.next;
    if (post[now].first == -1 || post[now].second > p.count) {
      post[now].first = p.before;
      post[now].second = p.count;
    }

    rep(i, path[now].size()) {
      int next = path[now][i];
      conn tmp = {now, next, p.count + 1};
      q.push(tmp);
    }
    rep(i, path[now].size()) {
      int next = path[now][i];
      path[now].erase(path[now].begin() + i);
      path[next].erase(std::remove(path[next].begin(), path[next].end(), now), path[next].end());
    }
  }

  for(int i = 1; i < N; i++) {
    if (post[i].first == -1) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for(int i = 1; i < N; i++) {
    cout << post[i].first + 1 << endl;
  }

  return 0;
}


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

# define ll long long
ll mod=pow(10,9)+7;

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

    map<int,int> mp;
    for(int i=1;i<=100;i++)
        for(int j=1;j<=100;j++)
        for(int k=1;k<=100;k++){
            int temp=i*i + j*j + k*k + i*j + j*k + i*k;
            if(temp>pow(10,4))
                continue;
            mp[temp]++;
    }
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cout<<mp[i]<<endl;
}


Measured memory_bytes: 4084
#include<stdio.h>
int main(){
	long long a,b,c,d;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	long long ans;
	ans=a*c;
	if (a*d>ans) ans=a*d;
	if (b*c>ans) ans=b*c;
	if (b*d>ans) ans=b*d;
	printf("%lld",ans);
}

Measured memory_bytes: 1732
n = int(input())
xy = [[] for _ in range(n)]
ans = -float("inf")

for i in range(n):
	a = int(input())
	for _ in range(a):
		x, y = map(int, input().split())
		xy[i].append(tuple([x-1, y]))

for i in range(2**n):
	flag = False
	cnt = 0
	for j in range(n):
		if (i >> j) & 1:
			cnt += 1
			for x, y in xy[j]:
				if y == 1:
					if (i >> x & 1) == 0:
						flag = True
				elif y == 0:
					if (i >> x & 1) == 1:
						flag = True
	if not flag:
		ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 43256
import fractions as fc

a,b,c,d = map(int, input().split())

tmp = (c * d) // fc.gcd(c, d)

all_num = b//c + b//d - b//tmp
a_num = (a-1)//c + (a-1)//d - (a-1)//tmp

ans = (b-a+1) - (all_num - a_num)
print(ans)

Measured memory_bytes: 5984
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0;
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0)
using namespace std;
vector<int>V,L;
vector<string>Ans;
map<int,int>M;
set<ll>S;
set<char>:: iterator it;
ll n,m,a,b,c,d,e,f,x,y,z,t,l=100,r,ans,cnt,score;
string   s,winner,temp,p;
ll   arr[1001][1001];
bool xy=0;
char bd;
float ans1;
int main()
{
    TIME;
    cin>>a>>b;
    cnt=a*4;
    ans=a*2;
    if (b%2==0 and b>=ans and b<=cnt)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#define inlien inline
#define retrun return
#define cpnst const
int N;
#include<vector>
typedef long long ll;
cpnst ll mod=1e9+7;

std::vector<int>v[111111];
ll dp[5555][5555],siz[5555],pr[5555];
void dfs(int p=1,int f=0)
{
	dp[p][1]=1,siz[p]=1;
	register int i,ii;
	for(auto t:v[p])
	{
		if(t==f)continue;
		dfs(t,p);
		for(i=siz[p];i;(dp[p][i]*=dp[t][0])%=mod,i--)
			for(ii=1;ii<=siz[t];ii++)
				(dp[p][i+ii]+=dp[t][ii]*dp[p][i])%=mod;
		siz[p]+=siz[t];
	}for(i=1;i<=siz[p];i++)
		(dp[p][0]+=(mod*mod-dp[p][i]*pr[i]))%=mod;
}
int main()
{
	scanf("%d",&N);
	register int i;
	pr[0]=1;
	for(i=2;i<=N;i++)pr[i]=pr[i-2]*(i-1)%mod;
	int x,y;
	for(i=1;i<N;i++)
		scanf("%d%d",&x,&y),v[x].push_back(y),v[y].push_back(x);
	dfs(),printf("%lld\n",(mod-dp[1][0])%mod);
}
/*
Giving the world a better yourself is giving yourself a better world. 
*/

Measured memory_bytes: 223104
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k, total, tmp int
	fmt.Scanf("%d %d\n", &n, &k)
	dic := map[int]int{}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		dic[tmp]++
	}

	var counts []int
	for _, value := range dic {
		counts = append(counts, value)
	}

	sort.IntSlice(counts).Sort()

	for i := 0; i < len(counts)-k; i++ {
		total += counts[i]
	}

	fmt.Println(total)

}


Measured memory_bytes: 19684
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,Q = Is()
S = S()
lis = [0]
t = 0
for i in range(N):
    if S[i:i+2] == "AC":
        t += 1
    lis.append(t)
for q in range(Q):
    l,r = Is()
    print(lis[r-1]-lis[l-1])


Measured memory_bytes: 6628
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
	io;
	int n;
  	cin>>n;
  	int a[n];
  int ans=0;
 	int b[n];
  	int c[n];
  	for(int i=0;i<n;i++) cin>>a[i];
  	for(int i=0;i<n;i++){
  	cin>>b[i];
	}
	c[0]=0;
  for(int i=1;i<n;i++) cin>>c[i];
  for(int i=0;i<n;i++){
  	if(a[i]!=n&&i!=n-1&&a[i]+1==a[i+1]){
		ans+=b[a[i]-1]+c[a[i]];
  	}
  	else ans+=b[a[i]-1];
  }
  	cout<<ans;
	return 0;
}

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n,k=MI()
	V=LI()

	ans=0

	for a in range(min(n+1,k+1)):
		for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	print(ans)










if __name__ == "__main__":
	main()


Measured memory_bytes: 9308
mod = 10**9+7


def main():
    H, W = map(int, input().split())
    a = [input() for _ in range(H)]
    dp = [[0 for _ in range(W)] for _ in range(H)]
    dp[0][0] = 1
    for i in range(H):
        for j in range(W):
            if a[i][j] == ".":
                if j+1 < W:
                    dp[i][j + 1] += dp[i][j]
                    dp[i][j+1] %= mod
                if i+1 < H:
                    dp[i + 1][j] += dp[i][j]
                    dp[i+1][j] %= mod
    print(dp[-1][-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 44608
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
    }
    // annotate for rust-analyzer
    let mut s: &str = &s;

    let mut r = "YES";
    while s.len() > 0 {
        s = match s {
            e if e.ends_with("dream") => &s[..(s.len() - 5)],
            e if e.ends_with("dreamer") => &s[..(s.len() - 7)],
            e if e.ends_with("erase") => &s[..(s.len() - 5)],
            e if e.ends_with("eraser") => &s[..(s.len() - 6)],
            _ => {
                r = "NO";
                break;
            }
        };
    }

    println!("{}", r);
}


Measured memory_bytes: 2360
import math
 
def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())

if n == k:
  for i in range(1, k+1):
    if i == 1:
      print(1)
    else:
      print(0)
else:
  for i in range(1,k+1):
    if i <= n-k+1:
      p1 = combinations_count(n-k+1, i)
      p2 = combinations_count(k-1, i-1)
      ans = p1*p2
      ans = ans%(10**9+7)
      print(ans)
    else:
      print(0)
  
  

Measured memory_bytes: 3316
import sys
import numpy as np
import math

def ReadInputNum():
    input_num=[]
    for i in range(5):
        input_num.append(int(input()))
    return tuple(input_num)

def CheckRangeInput(*argv):
    for num in argv:
        if 1<=num<=123 and isinstance(num,int):
            pass
        else:
            print("input"+ num +"is unexpected.")
            sys.exit()


def SumTotalTime(Tuple_Input):
    list_input=list(Tuple_Input)
    amari=[]
    # use numpy #                                                                                                                                                                        
    # list_tmp=np.array(list_input)                                                                                                                                                      
    # amari=(list_tmp-1)%10                                                                                                                                                              

    for i in list_input:
        amari.append((i-1) % 10)

    # amari=amari.tolist()                                                                                                                                                               
    last_one=min(amari)
    last_one=list_input.pop(amari.index(last_one))
    # print(last_one)                                                                                                                                                                    
    # print(list_input)                                                                                                                                                                  

    out_put=0
    for i in list_input:
        out_put += math.ceil(i/10)*10
    # print(out_put)                                                                                                                                                                     
    print(out_put+last_one)


# tuple_input= ReadInputNum()                                                                                                                                                            
# CheckRangeInput(tuple_input)                                                                                                                                                           
A,B,C,D,E = ReadInputNum()
CheckRangeInput(A,B,C,D,E)
tuple_input = (A,B,C,D,E)
SumTotalTime(tuple_input)


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

const int64_t M = 1'000'000'007;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);

    int n;
    cin >> n;
    int a[21];
    for(int i=0;i<n;i++){
        a[i] = 0;
        for(int j=0;j<n;j++){
            int x;
            cin >> x;
            a[i] |= x<<j;
        }
    }

    static uint32_t dp[1<<21][22];
    for(int j=0;j<=n;j++){
        for(uint ptn=0;ptn<(1<<n);ptn++){
            if(j == 0){
                dp[ptn][j] = 1;
                continue;
            }
            dp[ptn][j] = 0;
            uint mask = ptn & a[j-1];
            mask |= 1<<n;
            for(uint k=(mask & -mask);k<(1<<n);k=(mask & -mask)){
                dp[ptn][j] += dp[ptn & ~k][j-1];
                dp[ptn][j] %= M;
                mask &= ~k;
            }
        }
    }

    cout << dp[(1<<n)-1][n] << endl;
    
    return 0;
}

Measured memory_bytes: 180480
MOD = 10 ** 9 + 7
def choose(n,r):
  num = 1
  den = 1
  for i in range(r):
    num *= n-i
    num %= MOD
  for i in range(r):
    den *= i+1
    den %= MOD
  return num * pow(den, MOD-2, MOD) % MOD
def solve(x,y):
  if (x+y)%3!=0:
    return 0
  k = (x+y)//3
  if x<k or y<k:
    return 0
  return choose(k, min(y-k, x-k))
print(solve(*map(int, input().split())))

Measured memory_bytes: 3064
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //入力
            string n = Console.ReadLine();


            //奇数なら(n+1)/2、偶数ならn/2。intは切り捨てなのでこれで解答可能
            if(n[0] == n[1] && n[1] == n[2])
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll k;cin>>k;
    For(i,1,k+1){
        For(j,1,k+1){
            ll g = gcd(i,j);
            For(t,1,k+1){
                ans += gcd(g,t);
            }
        }
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

int main()
{
    long long A, B;
    cin >> A >> B;
    if (A % 2 != B % 2)
    {
        cout << "IMPOSSIBLE" << endl;
    }
    else
    {
        cout << (A + B) / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#define pb push_back
     
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
     
bool debug = false;
     

struct state
{
    ll a,b,c;

    state(ll a, ll b, ll c) : a(a), b(b), c(c)
    {

    }

  bool operator==(const state &other) const
  { return (a == other.a
            && b == other.b
            && c == other.c);
  }
};


struct KeyHasher
{
    size_t operator()(const state& k) const
  {
    //using std::size_t;
    //using std::hash;
    //using std::string;

    return ((hash<ll>()(k.a)
               ^ (hash<ll>()(k.b) << 1)) >> 1)
               ^ (hash<ll>()(k.c) << 1);
  }
};  


void solve()
{
    ll res = 0;

   	ll n;
   	cin >> n;

   	vector<ll> a(n+1,0);
    vector<ll> suff(n+1,0);
   	//vector<ll> maxAvail(n+1, LLONG_MAX);


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

    suff[n] = a[n];

    for (int i = n-1; i >= 0; i--)
    {
        suff[i] = suff[i+1] + a[i];
    }



    ll numNonLeafsNodes = 1;

    for (int i = 0; i <= n; i++)
    {
        if (i == 0)
        {
            numNonLeafsNodes = 1;
        }
        else
        {
            numNonLeafsNodes *= 2;
        }

        ll numNodes = min(numNonLeafsNodes, suff[i]);

        if (numNodes < a[i])
        {
            //cout << "for i = " << i << ", numNodes = " << numNodes << ", a[i] = " << a[i] << endl;
            cout << -1 << endl;
            return;
        }

        numNonLeafsNodes = numNodes - a[i];

        res += numNodes;

    }

   	      /*
   		if (numOfNodes + a[i] <= maxAvail[i])
   		{
   			numOfNodes += a[i];
   		}
   		else if (numOfNodes > 1 and numOfNodes/2 + a[i] <= maxAvail[i])
   		{
   			numOfNodes = numOfNodes/2 + a[i];
   		}
   		else
   		{
   			res = -1;
   			break;
   		}
      */
   	

    cout << res << endl;
}

int main()
{
    // $ g++ -std=c++14 -Wshadow -Wall -o c C.cpp

    // !!! Here, unordered map was too slow!!!
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    solve();


    return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long int ll;
#define int long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define debug cout << "debug" << endl;
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;a<n?i<n:i>=n;a<n?i+=1:i-=1)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int>	vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<vector<ll>> matrix;
ll dx[] = {0, 1, 0, -1};
ll dy[] = {-1, 0, 1, 0};
const ll N = 1e7+5;
// ll a[N], b[N], dp[N], level[N], vis[N], in[N], out[N];
// vl g[N];
ll n, m;



void solve() {
	ll t, x, y, l, r;
	cin >> x >> n;
	map<ll, ll> mp;
	f(i, n) cin >> y, mp[y]++;
	ll mn = 100000;
	ll ans = -100;
	for(ll i=0; i<=101; i++){
		if(mp[i] == 0){
			if(abs(i - x) < mn){
				mn = abs(i - x);
				ans = i;
			}
		}
	}
	cout << ans << endl;
}

int32_t main() {
	IOS
	ll T;
	// cin >> T;
	// while(T--)
	solve();
	cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
	return 0;
}

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

using namespace std;

const double pi = M_PI;
int main() {
  double a, b, h, m, ans;
  cin >> a >> b >> h >> m;
  h = (60*h + m) * (pi / 360);
  m *=  (pi / 30);
  double ang = abs(h - m); 
  ans = sqrt(a*a + b*b - 2*a*b*cos(ang));
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


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

    int n, m, q; cin >> n >> m >> q;
    vector< vector<int> > x(510, vector<int>(510, 0)), cum(510, vector<int>(510, 0));

    for(int i=0; i<m; ++i){
        int l, r; cin >> l >> r;
        ++x[l][r];
    }

    for(int i=1; i<=n; ++i){
        for(int j=i; j<=n; ++j){
            cum[i][j] = cum[i][j-1] + x[i][j];
        }
    }

    vector<int> ans(q, 0);
    for(int i=0; i<q; ++i){
        int p, q; cin >> p >> q;
        for(int k=p; k<=q; ++k) ans[i] += cum[k][q];
    }

    for(auto e:ans) cout << e << endl;

	return 0;
}


Measured memory_bytes: 3456
n = int(input())
ls = list(map(int, input().split()))


def solve():
    if n < 3:
        return 0

    llen = len(ls)
    cnt = 0
    # c = set()

    for i in range(0, llen):
        for j in range(0, llen):
            for k in range(0, llen):
                if not (i < j < k):
                    continue

                xs = [ls[i], ls[j], ls[k]]
                xs.sort()
                ii, jj, kk = xs
                if len(set(xs)) < 3:
                    continue

                if ii + jj > kk and jj + kk > ii and kk + ii > jj:
                    # c.add(f"{ii}{jj}{kk}")
                    cnt += 1

    return cnt


print(solve())


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

      int x = sc.nextInt();
      int a = sc.nextInt();
      int b = sc.nextInt();

      if(b<=a){
        System.out.println("delicious");
      }else if((a<=b)&&(a+x>=b)){
        System.out.println("safe");
      }else if(a+x<b){
        System.out.println("dangerous");
  }
}
}


Measured memory_bytes: 21332
//繝・Φ繝励Ξ
#include <bits/stdc++.h>
//#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()
#define PAIR pair<int,int>
using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
//



signed main (){
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   int M;
   cin >> M;
   cout << 24 -M + 24 << endl;
}

//驛ｨ蛻・・譛蟆丞､
//譖ｴ譁ｰ縺励↑縺・ｴ蜷遺・邏ｯ遨阪ｏ
//莠梧ｬ｡蜈・↓縺励◆縺・・縺・ｂ縺呎ｳ・
//荳邂・園繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Segment Tree(縺溘□縺怜叙蠕涌(logN))
//遽・峇繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Lazy Segment Tree


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> A(N);
    for (int i=0;i<N;++i) cin >> A[i];
    vector<vector<ll>> dp(N+1,vector<ll>(4,-INF));
    dp[0][(N&1?0:2)]=0;
    for (int i=0;i<N;++i){
        dp[i+1][1]=max(dp[i+1][1],dp[i][0]);
        dp[(min(N,i+2))][0]=max(dp[(min(N,i+2))][0],dp[i][0]+A[i]);
        dp[(min(N,i+2))][2]=max(dp[(min(N,i+2))][2],dp[i][1]+A[i]);
        dp[(min(N,i+2))][2]=max(dp[(min(N,i+2))][2],dp[i][2]+A[i]);
        dp[(min(N,i+2))][3]=max(dp[(min(N,i+2))][3],dp[i][1]+A[i+1]);
        dp[(min(N,i+2))][3]=max(dp[(min(N,i+2))][3],dp[i][2]+A[i+1]);
        dp[(min(N,i+2))][3]=max(dp[(min(N,i+2))][3],dp[i][3]+A[i+1]);
    }
    cout << max({dp[N][1],dp[N][2],dp[N][3]}) << '\n';
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

i64 N;

int main() {
  cin >> N;
  cout << N * N * N << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 2000

int A[N], n;
int solve(int i, int m)
{
    int res;
    if(m == 0) return 1;
    if(i >= n) return 0;
    res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(void)
{
    int q, j, m;
    scanf("%d", &n);
    for(j=0; j<n; j++) scanf("%d", &A[j]);
    scanf("%d", &q);
    for(j=0; j<q; j++){
            scanf("%d", &m);
            if(solve(0,m)) printf("yes\n");
            else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2108
using System;

public class SmallOrLarge
{
    //?????????????????§?°????????????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int[] num = new int[3]; 
        string[] num_unit;
        /*---??£?¨???¨---*/

        /*??°???????????????????????§??????*/
        num_unit = Console.ReadLine().Split(' ');
        num[0] = int.Parse(num_unit[0]);
        num[1] = int.Parse(num_unit[1]);
        num[2] = int.Parse(num_unit[2]);

        /*?????????????????????????????????*/
        Array.Sort(num);

        /*???????????????*/
        Console.WriteLine("{0} {1} {2}", num[0], num[1], num[2]);

    }
}

Measured memory_bytes: 9312
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int a,b,total;
char op;


int main()
{
	cin >> a >> op >> b ;
	if (op == '+')
	{
		total = a + b;
	}
	else
	{
		total = a - b;
	}

	cout << total << endl;


	

	
	//system("pause");

}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!.map { it - '0' }
    (0..9).forEach {
        dic[it] = mutableMapOf()
        dic[it]!![n] = -1
    }
    for(i in (0 until n).reversed()) {
        (0..9).forEach {
            if(it == s[i]) {
                dic[it]!![i] = i
            } else {
                dic[it]!![i] = dic[it]!![i+1]!!
            }
        }
    }
    var ans = 0
    for(i in (0..9)) {
        val index100 = dic[i]!![0]!!
        if(index100 < 0) {
            continue
        }
        for(j in (0..9)) {
            val index10 = dic[j]!![index100+1]!!
            if(index10 < 0) {
                continue
            }
            for(k in (0..9)) {
                val index1 = dic[k]!![index10+1]!!
                if(index1 > 0) {
                    ans++
                }
            }
        }
    }
    println(ans)
}


val dic = mutableMapOf<Int, MutableMap<Int, Int>>()

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

using namespace std;

int main(){
  vector<int> vi;
  for(int i=0;i<10;i++){
    int buf;
    cin >> buf;
    vi.push_back(buf);
  }

  sort(vi.begin(),vi.end());

  for(int i=1;i<=3;i++){
    cout<< vi[vi.size()-i] << endl;
  }
}

Measured memory_bytes: 1216
#include <iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
   int n,zs=1,cs=0;
   double x[10],y[10];
   double sum=0;
   cin>>n;
   for(int i=1;i<=n;i++)
       cin>>x[i]>>y[i];
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
        {
            double ls=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
            ls=ls*1.0;
            sum+=sqrt(ls);
            cs++;
        }
    for(int i=2;i<=n;i++)
        zs*=i;
    int kk=zs*(n-1);
    //cout<<cs<<" "<<zs<<endl;
    cs=kk/cs;

    sum*=cs;
    sum=sum/zs;
    printf("%.10f",sum);
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	string s, t;
  	cin >> s >> t;
  	int ssz = s.size();
  	int tsz = t.size();
  	int flag;
  	int ansi = 100;
  	rep3rev(i,ssz-tsz,0){
      	flag = 1; // OK
    	rep(j,tsz){
        	// s[i+0] から s[i+tsz-1] までを見る
          	if(s[i+j] != '?' && s[i+j] != t[j]){
                	flag = 0; // NG
                  	break;
            }        
        }
    	if(flag == 1){
        	ansi = i;
          	break;
        }
    }
  	if(ansi == 100){
    	cout << "UNRESTORABLE" << endl;
    }
  	else{
  		rep(i,ssz){
  			if(ansi <= i && i <= ansi+tsz-1){
          		s[i] = t[i-ansi];
        	}
      		else if(s[i] == '?'){
            	s[i] = 'a';
        	}
    	}
  		cout << s << endl;
    }
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a == b && b != c){
        cout << "Yes" << endl;
    }else if(b == c && b != a){
        cout << "Yes" << endl;
    }else if(a == c && b != c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) throws IOException {
        long h = scanner.nextInt();
        long w = scanner.nextInt();
        long diff = Long.MAX_VALUE;

        long a = h * (w / 3);
        long b = h * ((w - a / h) / 2);
        long c = h * w - a - b;
        diff = Math.min(diff, Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

        a = h * (w / 3);
        b = (w - a / h) * (h / 2);
        c = h * w - a - b;
        diff = Math.min(diff, Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

        a = h * (w / 3 + 1);
        b = h * ((w - a / h) / 2);
        c = h * w - a - b;
        diff = Math.min(diff, Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

        a = h * (w / 3 + 1);
        b = (w - a / h) * (h / 2);
        c = h * w - a - b;
        diff = Math.min(diff, Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

        long t = h;
        h = w;
        w = t;

        a = h * (w / 3);
        b = h * ((w - a / h) / 2);
        c = h * w - a - b;
        diff = Math.min(diff, Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

        a = h * (w / 3);
        b = (w - a / h) * (h / 2);
        c = h * w - a - b;
        diff = Math.min(diff, Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

        a = h * (w / 3 + 1);
        b = h * ((w - a / h) / 2);
        c = h * w - a - b;
        diff = Math.min(diff, Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

        a = h * (w / 3 + 1);
        b = (w - a / h) * (h / 2);
        c = h * w - a - b;
        diff = Math.min(diff, Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

        System.out.println(diff);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 22996
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()


int main() {
    int n,m;
    cin>>n>>m;
    vector<pair<int, int> > as(m);
    rep(i,m) cin>>as.at(i).first>>as.at(i).second;
    
    for(auto x:as){
        for(auto y:as){
            if(x==y) break;
            else if(x.first==y.first&&x.second!=y.second){
                dunk(-1);
                return 0;
            }
        }
    }
    
    bool judge;
    rep(i,1000){
        judge=true;
        string s=to_string(i);
        
        if(s.size()!=n) continue;
        
        for(auto x:as){
            string second=to_string(x.second);
            if (s.at(x.first-1)!=second.at(0)){
                judge=false;
                break;
            }
        }
        if(judge){
            dunk(i);
            return 0;
        }
        
    }
    dunk(-1);
    return 0;
}



Measured memory_bytes: 384
N = int(input())
A = []
B = []
for i in range(N):
    AB = list(map(int, input().split()))
    A.append(AB[0])
    B.append(AB[1])
A = sorted(A)
B = sorted(B)

if N % 2 == 0:
    min1 = A[N//2-1]
    min2 = A[N//2]
    max2 = B[-N//2]
    max1 = B[-N//2-1]
    # print(min1, min2, max1, max2)
    ans = ((max2 + max1) / 2 - (min2 + min1) / 2) * 2 + 1
else:
    mini = A[N//2]
    maxi = B[-N//2]
    # print(mini, maxi)
    ans = maxi - mini + 1
print(int(ans))

Measured memory_bytes: 102860
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;

const int N=1e5+10;
char s[N];

int main(){
    char x;
    int ans=0;
    scanf("%s",s);
    int len=strlen(s);
    x = s[0];
    for(int i=0;i<len;i++)
    {
        if(x!=s[i]){
            x=s[i];
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 384
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

D = { 'SUN': 0,'MON': 1,'TUE': 2,'WED': 3,'THU': 4,'FRI': 5,'SAT': 6 }

S = input()

ans = (7-D[S])
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main() {
  int n;
  scanf("%d",&n);
  int ans=0;
  while(n--) {
    int x,i;
    scanf("%d",&x);
    for(i=2; i*i<=x; i++) {
      if(x%i==0) break;
    }
    if(i*i>x) ans++;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.time.chrono.MinguoChronology;

public class Main {
  static InputReader in;
  static PrintWriter out;
  
  static class Solution {
    void solve() throws IOException {
      int a = in.nextInt();
      int b = in.nextInt();
      int c = in.nextInt();
      
      if (a <= b) {
        if (b <= c) {
          out.println(a+" "+b+" "+c);
        } else if (c <= a) {
          out.println(c+" "+a+" "+b);
        } else {
          out.println(a+" "+c+" "+b);
        }
      } else {
        if (a <= c) {
          out.println(b+" "+a+" "+c);
        } else if (c <= b) {
          out.println(c+" "+b+" "+a);
        } else {
          out.println(b+" "+c+" "+a);
        }
      } 
    }
  }

  public static void main(String[] args) throws IOException {
//    ??????
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;
    
    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }
   
    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }
    
    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken()); 
    }
    
    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }
    
    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }
    
  }
  
}

Measured memory_bytes: 24496
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,M = inputMap()
	A = inputList()

	if len(A) == 1:
		print(A[0] // (2**M))
		sys.exit()

	A.sort()
	A = A[::-1]
	ans = 0
	A_new = []
	mimi = -1

	for i in range(10000000000000000000):
		for i,val in enumerate(A):
			if i == len(A)-1:
				A_new.append(val)
				break

			if mimi < val and M > 0:
				flg = False
				for j in range(1,M+1):
					if M - j != 0:
						tmp = val // (2**j)
						if tmp < A[i+1] or tmp < mimi:
							M -= j
							A_new.append(tmp)
							flg = True
							if mimi == -1:
								mimi = tmp
							break

				if flg == False:
					tmp = val // (2**M)
					M = 0
					A_new.append(tmp)

			else:
				A_new.append(val)

		#print(A_new)
		#A = copy.deepcopy(A_new)
		A = A_new
		A.sort()
		A = A[::-1]
		A_new = []
		mimi = -1

		if M == 0:
			break

	#print(A)

	ans = 0
	for i in A:
		ans += i

	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 70888
#if 0
date +%Y.%m.%d

首先有两个需要感性理解的结论：
1) 选择的向量的极角是连续的，不存在一个未选的向量夹在选了的向量中间。
2) 选择的向量一定在一条直线的一侧。

那么把向量按极角排序，然后复制一遍成环，于是选择的向量一定是长度不超过 n 的连续区间。
枚举左端点，最远右端点是可以尺取的，而且只需要考虑尺取中更新的向量和。
因为每次左端点 l 右移，相当与添了一条与 V[l] 相反的向量，
由结论 1) 可知最优解的右端点不会再往左移。
#endif
#include <cstdio>
#include <algorithm>
#include <cmath>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;

inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 100005;

struct Dot {
	int x, y;
	double a;
};

Dot d[maxn << 1];

inline bool cmp(Dot a, Dot b) {
	return a.a < b.a;
}

int main() {
	int n = input();

	for(int i = 1; i <= n; i ++) {
		d[i].x = input();
		d[i].y = input();
		d[i].a = atan2(d[i].y, d[i].x) + M_PI;
	}

	std::sort(d + 1, d + n + 1, cmp);

	for(int i = 1; i <= n; i ++) {
		d[i + n] = d[i];
		d[i + n].a += M_PI * 2;
	}

	lolong ans = 0;
	int x = 0, y = 0;

	/* for(int i = 1; i <= n * 2; i ++) */
	/* 	debug("%d %d %lf\n", d[i].x, d[i].y, d[i].a); */

	for(int l = 1, r = 0; l <= n; l ++) {
		while(r + 1 < l + n and d[r + 1].a < d[l].a + M_PI) {
			r ++;
			x += d[r].x;
			y += d[r].y;
			ans = std::max(ans, 1ll * x * x + 1ll * y * y);
			/* debug("%d %d\n", l, r); */
		}
		x -= d[l].x;
		y -= d[l].y;
		ans = std::max(ans, 1ll * x * x + 1ll * y * y);
	}

	printf("%.12lf\n", sqrt(ans));
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  map<int, int> m;
  vector<int> m_elem;

  rep(i, N) {
    if (m.find(a[i]) == m.end()) {
      m[a[i]] = 1;
      m_elem.pb(a[i]);
    } else
      m[a[i]]++;
  }

  int ans = 0;
  rep(i, m_elem.size()) {
    int num = m_elem[i];
    int cnt = m[num];

    if (cnt < num)
      ans += cnt;
    else
      ans += cnt - num;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5496
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU
import std.stdio      : readln, writeln;
import std.string     : chomp;
import std.conv       : to;

void main() {
    auto n = readln.chomp.to!uint;
    auto s1 = readln.chomp;
    auto s2 = readln.chomp;
    long ans, md = 1_000_000_007;
    uint i, pat;
    if (s1[0] == s2[0]) {
        ans = 3;
        i = 1;
        pat = 0;
    } else {
        ans = 6;
        i = 2;
        pat = 1;
    }
    while (i < n) {
        if (s1[i] == s2[i]) {
            if (pat == 0) {
                ans = (ans * 2) % md;
            }
            pat = 0;
            i += 1;
        } else {
            if (pat == 1) {
                ans = (ans * 3) % md;
            } else {
                ans = (ans * 2) % md;
            }
            pat = 1;
            i += 2;
        }
    }
    writeln(ans);
}

Measured memory_bytes: 256