akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 500;
ll N, C[MAX_N], S[MAX_N], F[MAX_N];
ll t[MAX_N]; // t[i]: 

void solve() {
    REP(i, N - 1) {
        fill(t, t + N, 0);
        FOR(j, i, N - 1) {
            if (j == i) {
                t[j + 1] = S[j] + C[j];
            } else {
                if (S[j] - t[j] > 0) {
                    t[j + 1] = t[j] + S[j] - t[j] + C[j];
                } else {
                    ll temp = (abs((S[j] - t[j])) % F[j]);
                    if (temp == 0) t[j + 1] = t[j] + C[j];
                    else t[j + 1] = t[j] + F[j] - temp + C[j];
                }
            }
        }
        cout << t[N - 1] << endl;
    }
    cout << 0 << endl;
}

int main() {
    cin >> N;
    REP(i, N - 1) cin >> C[i] >> S[i] >> F[i];
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


int a[300001];

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

	int N; cin >> N;
	for (int i = 0; i < 3 * N; i++) cin >> a[i];
	sort(a, a + 3 * N, greater<int>());

	ll ans = 0LL;
	for (int i = 0; i < N; i++) ans += a[2 * i + 1];
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main()
{
    long long int a, b, p;
    scanf("%lld%lld", &a, &b);
    if(b==0)
    {
        p = 0;
    }
    else if(b>1)
    {
        p = a-b;
    }
    printf("%lld\n", p);
    return 0;
}


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

int main(void)
{
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    int f = 1;
    if (v[0] > v[1])
        f = -1;
    else if (v[0] == v[1])
        f = 0;
    int ans = 1;
    for (int i = 1; i < n - 1; i++)
    {
        if (f == 1 && v[i] > v[i + 1])
            f = 0, ans++;
        else if (f == -1 && v[i] < v[i + 1])
            f = 0, ans++;
        else if (f == 0)
        {
            if (v[i] < v[i + 1])
                f = 1;
            else if (v[i] > v[i + 1])
                f = -1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
#define md 1000000007
#define ll long long 
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fastmap mp.reserve(1024);mp.max_load_factor(0.25);
#define fastset st.reserve(1024);st.max_load_factor(0.25);
ll int mpw(ll int a,ll int b,ll int m)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%m;
		}
		a=(a*a)%m;
		b>>=1;
	}
	return ans;
}

ll int pw(ll int a,ll int b)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans*=a;
		}
		a*=a;
		b>>=1;
	}
	return ans;
}

ll int mn(ll int a,ll int b)
{
	if(a<=b)
	{
		return a;
	}
	return b;
}

ll int mx(ll int a,ll int b)
{
	if(a>=b)
	{
		return a;
	}
	return b;
}
vector<vector<ll int>>D;
int main()
{
	fio
	int n,k;
	cin>>n>>k;
	vector<int>nm(n);
	for(int i=0;i<n;++i)
	{
		cin>>nm[i];
	}
	vector<int>D(n,-1);
	D[0]=0;
	for(int i=1;i<n;++i)
	{
		for(int j=1;i-j>=0 && j<=k;++j)
		{
			if(D[i]==-1)
			{
				D[i]=D[i-j]+abs(nm[i]-nm[i-j]);	
			}
			else{
				D[i]=min(D[i-j]+abs(nm[i]-nm[i-j]),D[i]);		
			}
		}
	}
	cout<<D[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 3844
#include <bits/extc++.h>
using namespace std;
using i64 = int64_t;

main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  i64 ans = -1e18;
  for (i64 x : {a, b}) {
    for (i64 y : {c, d}) {
      ans = max(x * y, ans);
    }
  }
  cout << ans;
}


Measured memory_bytes: 3564
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define ALL(v) v.begin(), v.end()
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	vector<ll> a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	ll cnt = 0;
	rep(i, n) {
		if (a[i]<b[i]) {
			int tmp = (b[i]-a[i]+1)/2;
			cnt += tmp;
			a[i] += tmp*2;
		}
	}
	rep(i, n) {
		if (a[i]>b[i]) cnt -= (a[i]-b[i]);
	}
	if (cnt >= 0) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 384
//sieu nhan
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inp "test.inp"
#define out "test.out"
#define oo 105
#define ii 100005
#define inf 1e15
#define mod 1000000007
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define y1 hungdzno1
int n,w,a[oo],b[oo],f[oo][ii];
void nhap(){
  cin>>n>>w;
  for(int i=1;i<=n;++i) cin>>a[i]>>b[i];
}
void xuly(){
  for(int i=1;i<=n;++i){
    for(int j=0;j<=w;++j){
      if(j-a[i]<0) f[i][j]=f[i-1][j];
      else f[i][j]=max(f[i-1][j],f[i-1][j-a[i]]+b[i]);
    }
  }
  cout<<f[n][w];
}
main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //freopen(inp,"r",stdin);
  //freopen(out,"w",stdout);
  nhap();
  xuly();
}


Measured memory_bytes: 79360
from __future__ import division
import math

while True:
    n = int(raw_input())
    if n == 0:
        break
    data = map(float, raw_input().split())
    m = sum(data) / n
    var = sum([(i-m)**2 for i in data]) / n
    std = math.sqrt(var)
    print "{:.5f}".format(std)

Measured memory_bytes: 6564
(function(stdin) {
  // Define Function
  function splitCols(line, sep) {
    return line.split(sep);
  }
  function Squire(width, height) {
    this.height = height;
    this.width = width;
    this.getArea = function() {
      return this.width * this.height;
    };
    this.getPeriphery = function() {
      return (this.width + this.height) * 2;
    };
  }
  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const cols    = splitCols(inputs[0], ' ').map(Number);
  // Main Procedure
  const result = (function(a, b) {
    const squire = new Squire(a, b);
    return [squire.getArea(), squire.getPeriphery()].join(' ');

  }(cols[0], cols[1]
  ));

  // Display
  console.log(result);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int parseTime(string s)
{
    //hh:mm:ss
    int res = 0;
    res += (s[0] - '0') * 10 * 3600;
    res += (s[1] - '0') * 3600;
    res += (s[3] - '0') * 600;
    res += (s[4] - '0') * 60;
    res += (s[6] - '0') * 10;
    res += s[7] - '0';

    return res;
}

const int TMAX = 24 * 60 * 60;
int c[TMAX + 1];

int main()
{
    int n;
    while (cin >> n, n)
    {
        memset(c, 0, sizeof(c));
        rep(i, n)
        {
            string s;
            cin >> s;
            int t = parseTime(s);
            c[t]++;
            cin >> s;
            t = parseTime(s);
            c[t]--;
        }

        int ans = 0;
        int now = 0;
        rep(i, TMAX + 1)
        {
            now = now + c[i];
            ans = max(ans, now);
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3488
#include <iostream>

using namespace std;

int main(){
  int testnum;
  cin >> testnum;
  for(int t = 0; t < testnum ; ++t){
    int gx,gy;
    cin >> gx >> gy;
    int p;
    cin >> p;
    //movex[y][x] : (x,y)????????´???????????????????????????
    //movey[y][x] : (x,y)????????´???????????????????????????
    bool movex[16][16]={},movey[16][16]={};
    //????????????????????¨???????????´???????????????????????????????????¨??????
    for(int i=0;i<16;++i){
      movey[0][i] = true;
      movex[i][0] = true;
    }
    for(int i=0;i<p;++i){
      int x1,y1,x2,y2;
      cin>>x1>>y1>>x2>>y2;
      if(x1==x2) movey[max(y1,y2)][x1] = true;
      else movex[y1][max(x1,x2)] = true;
    }

    unsigned long route[16][16]={0};
    route[0][0] = 1;
    for(int y=0;y<=gy;++y){
      for(int x=0;x<=gx;++x){
        if(!movey[y][x]) route[y][x] += route[y-1][x];
        if(!movex[y][x]) route[y][x] += route[y][x-1];
      }
    }
    /*
    for(int i=0;i<=gy;++i){
      for(int j=0;j<=gx;++j){
        cout << "(" << movex[i][j] << "," << movey[i][j] << ") " ;
      }
      cout << endl;
    }
    
    for(int i=0;i<=gy;++i){
      for(int j=0;j<=gx;++j){
        cout << route[i][j] << " ";
      }
      cout << endl;
    }*/
    if(route[gy][gx]!=0){
      cout << route[gy][gx] << endl;
    }else{
      cout << "Miserable Hokusai!" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <string>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int r = n%10;
  string name = "hon";
  if(r == 0 || r == 1 || r == 6 || r == 8) name = "pon";
  else if(r == 3) name = "bon";
  
  cout << name<< endl;
}


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

#define ll long long

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

    ll n, k;
    cin >> n >> k;

    ll ans = n / k + 3 * (n / k) * (n / k - 1) + (n / k) * (n / k - 1) * (n / k - 2);

    if (k % 2 == 0)
        ans += (n + k / 2) / k + 3 * ((n + k / 2) / k) * ((n + k / 2) / k - 1) + ((n + k / 2) / k) * ((n + k / 2) / k - 1) * ((n + k / 2) / k - 2);
    
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int gcd(int a,int b,int c){
  while(a%b != 0){
    int a2 = a;
    a = b;
    b = a2 % b;
  }
  while(b%c != 0){
    int b2 = b;
    b = c;
    c = b2 % c;
  }
  return c;
}

int main()
{
  int K,a,b,c;
  long sum=0;
  cin >> K;

  for(a=1;a<=K;a++){
    for(b=1;b<=K;b++){
      for(c=1;c<=K;c++){
        sum += gcd(a,b,c);
      }
    }
  }

  cout << sum << endl;
  return 0;

}


Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        long k = in.nextLong();
        in.nextLine();
        final int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        in.nextLine();
        if (k <= n) {
            int res;
            for (res = 1; k > 0; k--) {
                res = arr[res - 1];
            }
            System.out.println(res);
            return;
        }
        int slow = 1;
        int fast = 1;
        int cycle = 0;
        int initial = 0;
        do {
            slow = arr[slow - 1];
            fast = arr[arr[fast - 1] - 1];
        } while (slow != fast);
        do {
            slow = arr[slow - 1];
            cycle++;
        } while (slow != fast);
        slow = 1;
        while (slow != fast) {
            slow = arr[slow - 1];
            fast = arr[fast - 1];
            initial++;
        }
        k -= initial;
        k = Math.floorMod(k, cycle);
        int res;
        for (res = slow; k > 0; k--) {
            res = arr[res - 1];
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 60064
#include <stdio.h>
#define MIN(a,b) ((a>b)?(b):(a))
int main(void) {
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  printf("%d\n",MIN(a+b,MIN(b+c,a+c)));
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
 
char a[101];
 
int main(){
 
 int n;
 cin>>n;
int p=0;
int w=0;
int g=0;
int y=0;
 
 for(int i=0;i<n;i++){
 	cin>>a[i];
    if(a[i]=='P'){
    	p++;
    }else if(a[i]=='W'){
    	w++;
    }else if(a[i]=='G'){
    	g++;
    }else if(a[i]=='Y'){
    	y++;
    }
 }
 
 if(p>0 && w>0 && g>0 && y>0){
 	cout<<"Four";
 }else if(p>0 && w>0 && g>0 ){
 	cout<<"Three";
 }
 
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int A,B;

int main(){
    cin>>A>>B;

    cout<<max(A+B,max(A-B,A*B))<<endl;    
}

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

int main(){
	int N; cin>>N;
	int64_t p[N], m[N];
	for(int i=0; i<N; ++i){
		int x, y; cin>>x>>y;
		p[i] = x + y;
		m[i] = x - y;
	}
	sort(p, p + N);
	sort(m, m + N);
	cout<< max(p[N-1] - p[0], m[N-1] - m[0]) <<endl;
}


Measured memory_bytes: 6760
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> ch(h + 1, 0), cw(w + 1, 0);
    unordered_map<int, unordered_set<int>> um, res;
    for (int i = 0; i < m; i++) {
        int hh, ww;
        cin >> hh >> ww;
        um[hh].insert(ww);
        ch[hh]++;
        cw[ww]++;
    }
    int max_h = *max_element(ch.begin() + 1, ch.end());
    int max_w = *max_element(cw.begin() + 1, cw.end());
    vector<int> vh, vw;
    for (int i = 1; i <= h; i++) {
        if (ch[i] == max_h) {
            vh.push_back(i);
        }
    }
    for (int i = 1; i <= w; i++) {
        if (cw[i] == max_w) {
            vw.push_back(i);
        }
    }
    for (auto hh : vh) {
        for (auto ww : vw) {
            if (um[hh].find(ww) == um[hh].end()) {
                cout << max_w + max_h << endl;
                return 0;
            }
        }
    }
    cout << max_w + max_h - 1 << endl;

}


Measured memory_bytes: 56140
import itertools
abcd = input()
symbol = ["+", "-"]
list_cand = [(i, j, k) for i in symbol for j in symbol for k in symbol]
for cand in list_cand:
  temp_str = abcd[0] + cand[0] + abcd[1] + cand[1] + abcd[2] + cand[2] + abcd[3]
  if eval(temp_str) == 7:
    print(temp_str + "=7")
    exit()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

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

    vector<int> S;

    int i, j;

    /* 判定フラグ */
    int flag;

    /* 素数かどうかを判定 */
    for (i = 2; i <= 55555; ++i)
    {
        flag = 0;
        for (j = 2; j < i; ++j)
        {
            if (i % j == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag == 0)
            if (i % 10 == 1)
                S.push_back(i);
    }

    for (int i = 0; i < N; i++)
    {
        cout << S[i] << " ";
    }

    return 0;
}

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

int h, w, n, a[10005], ans[105][105];
int main()
{
	std::cin >> h >> w >> n;
	for (int i = 0; i < n; ++i)
		std::cin >> a[i];

	int nh = 0, nr = 0, idx = 0, num = 0;
	bool turn = true;
	while (idx < n) {
		ans[nh][nr] = idx + 1;
		if (turn&&nr < w - 1)
			++nr;
		else if (!turn&&nr > 0)
			--nr;
		else {
			++nh;
			turn = !turn;
		}
		++num;
		if (num >= a[idx]) {
			++idx;
			num = 0;
		}
	}

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			std::cout << ans[i][j];
			if (j != w - 1)
				std::cout << " ";
		}
		std::cout << std::endl;
	}

	return 0;
}


Measured memory_bytes: 384
N, M = map(int, input().split())
xy = []
for _ in range(M):
    xy.append(tuple(map(int, input().split())))

num = [1] * N
red = [False] * N
red[0] = True

for el in xy:
    x, y = el
    x, y = x - 1, y - 1
    if red[x]:
        red[y] = True
    num[x] -= 1
    if num[x] == 0:
        red[x] = False
    num[y] += 1
# print(num, red)
cnt = 0
for el in red:
    if el:
        cnt += 1
print(cnt)


Measured memory_bytes: 60632
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int n, m; cin >> n >> m;
    vector<string> A(n), B(m);
    string res;
    bool flag = true;

    rep(i, n) cin >> A[i];
    rep(i, m) cin >> B[i];
    if(n == 1 and m == 1){
        if(A[0][0] == B[0][0]){
            cout << "Yes" << endl;
                return 0;
        }
        else goto no;
    }
    rep(i, n){
        if(i + m > n - 1) break;
        rep(j, n){
            if(j + m > n - 1) break;
            flag = true;
            rep(x, m){
                if(!flag) break;
                rep(y, m){
                    if(A[i+x][j+y] != B[x][y]){
                        flag = false;
                        break;
                    }
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
no:
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n;
cin >> n;
ll t[n] = {};

cout << (n-2)*180 << endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
long long x;
int k, y;
int main(){
  int N,M;
  cin >> N >> M;
  vector<tuple<long long,long long>> V;
  for(int i = 0; i < N; i ++){
    long long a, b;
    cin >> a >> b;
    V.emplace_back(a, b);
  }
  sort(V.begin(), V.end());
  while(1){
    long long a, b;
    tie(a,b) = V[k];
    if((M - y) <= b){
      x = x + a * (M - y);
      break;
    }else{
      x = x + a * b;
      y = y + b;
      k = k + 1;
    }
  }
  cout << x <<endl;
  return 0;
}

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

int main() {
    int N,K,i;
     string S;
     cin >> N>>S>>K;
     for (int i = 0; i < N; ++i){

       if(S[i] != S[K-1]){
          S[i] = '*';
       }
     }

     cout << S;
}



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

typedef struct List {
	struct List *next;
	int v;
} list;

void merge_sort(int x[], int n)
{
	static int y[10001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, u, w, N, c[10001], deg[10001] = {};
	scanf("%d", &N);
	list **adj = (list**)malloc(sizeof(list*) * (N + 1)), *d = (list*)malloc(sizeof(list) * (N - 1) * 2);
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		d[i*2].v = w;
		d[i*2+1].v = u;
		d[i*2].next = adj[u];
		d[i*2+1].next = adj[w];
		adj[u] = &(d[i*2]);
		adj[w] = &(d[i*2+1]);
		deg[u]++;
		deg[w]++;
	}
	for (i = 0; i < N; i++) scanf("%d", &(c[i]));
	merge_sort(c, N);
	
	int M = 0;
	for (i = 0; i < N - 1; i++) M += c[i];
	
	int q[10001], head, tail, ans[10001] = {};
	list *p;
	for (i = 1, tail = 0; i <= N; i++) if (deg[i] == 1) q[tail++] = i;
	for (head = 0; head < tail; head++) {
		u = q[head];
		ans[u] = c[head];
		for (p = adj[u]; p != NULL; p = p->next) {
			if (ans[p->v] == 0) {
				deg[p->v]--;
				if (deg[p->v] == 1) q[tail++] = p->v;
			}
		}
	}
	
	printf("%d\n%d", M, ans[1]);
	for (i = 2; i <= N; i++) printf(" %d", ans[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}

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

using namespace std;
#define ll  long long
#define ld  long double

#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN=1e5+5;
int n;
vector<int>v[MAXN];
bool vis[MAXN];
map<int,int> m1;
map<int,int> mlast;

void dfs1(int a,int sum)
{
    vis[a]=1;
    for(int i=0;i<v[a].size();i++)
    {
        if(!vis[v[a][i]]){
        m1[v[a][i]]=sum+1;
        dfs1(v[a][i],sum+1);
        }
    }
}
void dfslast(int a,int sum)
{
    vis[a]=1;
    for(int i=0;i<v[a].size();i++)
    {
        if(!vis[v[a][i]]){
        mlast[v[a][i]]=sum+1;
        dfslast(v[a][i],sum+1);
        }
    }
}
int main()
{
    cin>>n;
    for(int i=0; i<n-1; i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs1(1,0);
    memset(vis,0,sizeof vis);
    dfslast(n,0);
    int c1=0,c2=0;
    for(int i=1;i<=n;i++)
    {
        if(m1[i]<=mlast[i])
            c1++;
        else
            c2++;
    }
    if(c1>c2)
        cout<<"Fennec"<<endl;
    else
        cout<<"Snuke"<<endl;

    return 0;
}


Measured memory_bytes: 23040
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

        System.out.println(solve(a, b));

        sc.close();
    }

    static String solve(int a, int b) {
        return (a * b % 2 == 0) ? "Even" : "Odd";
    }
}

Measured memory_bytes: 21844
w,h,n=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
ue=h
sita=0
migi=w
hidari=0
for i in range(n):
    if li[i][2]==1:
        if li[i][0]>hidari:
            hidari=li[i][0]

    if li[i][2]==2:
        if li[i][0]<migi:
            migi=li[i][0]

    if li[i][2]==3:
        if li[i][1]>sita:
            sita=li[i][1]

    if li[i][2]==4:
        if li[i][1]<ue:
            ue=li[i][1]
print(max(0,(ue-sita))*max(0,(migi-hidari)))

Measured memory_bytes: 3064
N = int(input())
W = list(map(int, input().split()))
left = [0 for i in range(N)]
right = [0 for i in range(N)]
for i in range(N):
    left[i] = left[i-1] + W[i]
    right[i] = right[i-1] + W[N-i-1]
minsa = 10 ** 16
for i in range(N-1):
    sa = abs(left[i] - right[N-2-i])
    minsa = min(minsa, sa)

print(minsa)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;

ll X,T;

int main(){
	cin>>X;
	T=100;
	for(int i=1;;i++){
		T*=1.01;
		if(X<=T){
			cout<<i<<endl;
			return 0;
		}
	}
}


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

int main()
{
	int N;
	std::cin >> N;

	std::vector<std::string> words;
	words.resize(N);

	for (int i = 0; i < N; ++i)
	{
		std::cin >> words[i];
	}

	for (auto& word : words)
	{
		auto count = std::count(words.cbegin(), words.cend(), word);
		if (count > 1)
		{
			std::cout << "No" << std::endl;
			return 0;
		}
	}

	for (int i = 0; i < N - 1; ++i)
	{
		bool ok = words[i][words[i].size() - 1] == words[i + 1][0];
		if (!ok)
		{
			std::cout << "No" << std::endl;
			return 0;
		}
	}

	std::cout << "Yes" << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <chrono>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pldll;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<ld> vld;
#define newl '\n'
const ll M = 1e9 + 7;
const ll N = 1e2;
const ll INF = LONG_MAX;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define LOG_TWO_N 10

template <class T>
void print(vector<T> &vec, int inc = 0, bool lb = true)
{
    for (auto v : vec)
        cout << v + inc << " ";
    if (lb)
        cout << newl;
}

void solve(ll t)
{
    int n; cin >> n;
    int a[100];
    REP(i, 0, n) {
        cin >> a[i];
    }

    sort(a, a+n);
    int ans=0;
    REP(i, 0, n) {
        // if(i > 0 && a[i]==a[i-1]) continue;
        REP(j, i+1, n) {
            if(a[j]==a[i]) continue;
            REP(k, j+1, n) {
                // if(k > j+1 && a[k]==a[k-1]) continue;
                if(a[k]==a[i] || a[k]==a[j]) continue;
                if(a[i] > a[k]-a[j]) ans++;
            }
        }
    }

    cout << ans << newl;
}

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

    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve(t);
    }

    return 0;
}

Measured memory_bytes: 3632
# 個数制限なしナップザック問題
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]
# i番目までの魔法を使った時にjを削るために必要な最小のコスト
dp = [[10**10]*(H+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(H+1):
        # 使わない場合
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        # 使う場合
        dp[i+1][min(j+magic[i][0], H)] = min(dp[i+1][min(j+magic[i][0], H)], dp[i+1][j] + magic[i][1])
print(dp[N][H])

Measured memory_bytes: 120668
#include <stdio.h>

int main(void);

int main(void)
{
    int  x, y;
    while(1){
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0) break;
        if (x > y){
        printf("%d %d\n", y, x);
        }
        else {
        printf("%d %d\n", x, y);
        }
    }
    return(0);
}


Measured memory_bytes: 2052
use std::cmp::{max, min};

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let _ = scan!(usize);
    let vs = scan!(i64;;);

    let mut ans0 = 0;
    let mut sum = 0;
    for (i, &v) in vs.iter().enumerate() {
        sum += v;
        if i % 2 == 0 && sum <= 0 {
            ans0 += 1 - sum;
            sum = 1;
        } else if i % 2 == 1 && sum >= 0 {
            ans0 += sum + 1;
            sum = -1;
        }
    }

    let mut ans1 = 0;
    sum = 0;
    for (i, &v) in vs.iter().enumerate() {
        sum += v;
        if i % 2 == 1 && sum <= 0 {
            ans1 += 1 - sum;
            sum = 1;
        } else if i % 2 == 0 && sum >= 0 {
            ans1 += sum + 1;
            sum = -1;
        }
    }

    println!("{}", min(ans0, ans1));
}


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

signed main () {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0, lr = 0, rl = 0;
	for (int i = 0; i < n - 1; ++i) {
		ans += (s[i] == s[i + 1]);
		lr += (s[i] != s[i + 1] && s[i] == 'L');
		rl += (s[i] != s[i + 1] && s[i] == 'R');
	}
	while (k && lr && rl) {
		--lr;
		--rl;
		--k;
		ans += 2;
	}
	if (s[0] == 'L') {
		while (k && lr) {
			--k;
			++ans;
			--lr;
		}
	}
	else {
		while (k && rl) {
			--k;
			++ans;
			--rl;
		}
	}
	if (s.back() == 'R') {
		while (k && lr) {
			--k;
			++ans;
			--lr;
		}
	}
	else {
		while (k && rl) {
			--k;
			++ans;
			--rl;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>
#include <cassert>
#include <deque>
#include <queue>
#include <map>
#include <utility>
#include <set>
// g++ -std=c++11 <filename>
#define FOR(j,k,n) for (int j = k; j < (int)(n); j++)
#define MAXN 10000000000000000
#define realMAXN 1000000000000000000
#define newl printf("\n")
#define fi first
#define se second
#define pb push_back
#define test(t)  int t; cin>>t; for(int tes = 0; tes < t; tes++)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
typedef pair<lli,lli> plli;
void inn(long long int &ix) {scanf("%lld",&ix);}
void inn(long long int &ix,long long int &iy) {scanf("%lld%lld",&ix,&iy);}
void inn(int &ix) {scanf("%d",&ix);}
void inn(int &ix,int &iy) {scanf("%d%d",&ix,&iy);}
void inn(long double & ix) {scanf("%LF",&ix);}
void outt(long long int ix) {printf("%lld",ix);}
void outt(long long int ix, char cx) {printf("%lld%c",ix,cx);}
void outt(int ix) {printf("%d",ix);}
void outt(int ix, char cx) {printf("%d%c",ix,cx);}
void outt(long double ix, char cx){printf("%.9LF%c",ix,cx);}
void outt(long double ix){printf("%.9LF",ix);}
void pline() {printf("\n");}

const int MM = 1200000;
lli m,n,k,p1,p2,p3,p,f,a[MM];
string s,s1,s2;
lli c1,c2,c4;

int main(){
	// Have you solved the problem completely?    
  	
  	cin>>c1>>c2>>c4>>p;
  	c1 *= 4;
  	c2 *= 2;
  	cin>>n;
  	p2 = p;
  	p1 = min(c1,min(c2,c4));
  	if(p1*2 <= p2)
  	{
  		cout<<n*p1;
  	}
  	else if(n%2 == 0)
  	{
  		cout<<(p2*(n/2));
  	}
  	else
  	{
  		cout<<p1 + (p2 * (n/2));
  	}


	return 0;
}







Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
ll combi(ll a, ll b)
{
    if (a < b)
        return 0;
    ll res = 1;
    for (ll i = a; i >= a - b + 1; i--)
    {
        res *= i;
        res %= MOD;
    }
    rep3(i, 1, b + 1)
    {
        res *= modinv(i, MOD);
        res %= MOD;
    }
    return res;
}
//a,m=MOD MOD逆元
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin>>s;
    sort(all(s));
    map<int, ll> mp;
    rep(i,n){
        mp[s[i] - 'a']++;
    }
    ll res = 1;
    rep(i,26){
        res *= (mp[i] + 1);
        res %= MOD;
    }
    cout << (res+MOD-1)%MOD << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
int n,m;
vector<int> ga[300100];
int u,v;
int dist[300100];
queue<int> q;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		ga[u*3].push_back(v*3+1);
		ga[u*3+1].push_back(v*3+2);
		ga[u*3+2].push_back(v*3);
	}
	memset(dist,63,sizeof(dist));
	int s,t;
	cin>>s>>t;
	dist[s*3]=0;
	q.push(s*3);
	while(!q.empty()){
		int uu=q.front();
		q.pop();
		for(int i=0;i<ga[uu].size();i++)
		{
			int vv=ga[uu][i];
			if(vv==t*3){
				cout<<(dist[uu]+1)/3<<endl;
				return 0;
			}
			if(dist[vv]>=1e9){
				dist[vv]=dist[uu]+1;
				q.push(vv);
			}
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 17792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
const int MOD = 1e9+7;
const ll INF =1e18;

int main(){
    ll n;cin >> n ;
    vl a(n), b(n), c(n);
    fr(i,n) cin >> a[i] >> b[i] >> c[i];
    vl dpa(n),dpb(n),dpc(n);
    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];
    fr(i,n-1){
        dpa[i+1] = max(dpb[i],dpc[i]) + a[i+1];
        dpb[i+1] = max(dpc[i],dpa[i]) + b[i+1];
        dpc[i+1] = max(dpa[i],dpb[i]) + c[i+1];
    }
    ll ans = max(dpa[n-1], max(dpb[n-1], dpc[n-1]));
    cout << ans << endl;
}

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

int n, a, cnt[200005];

int main() {
    cin >> n;
    for (int i = 2; i <= n; i++){
        cin >> a;
        cnt[a]++;
    }
    for (int i = 1; i <= n; i++){
        cout << cnt[i] << "\n";
    }
}


Measured memory_bytes: 4376
#include<iostream>

using namespace std;

const static int MAX_N = 100;
int N;
int A[MAX_N];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int min_a = 1000000001, max_a = 0;
  for (int i = 0; i < N; i++) {
    max_a = max(max_a, A[i]);
    min_a = min(min_a, A[i]);
  }

  int ans = max_a - min_a;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
typedef long long int lli;

using namespace std;

int main(){
  int N;
  cin >> N;
  lli T = 1, A = 1;
  REP(i, 0, N) {
    lli t, a;
    cin >> t >> a;
    lli tt = (T + t - 1) / t;
    lli aa = (A + a - 1) / a;
    lli m = max(tt, aa);
    T = m * t;
    A = m * a;
  }
  cout << T + A <<endl;
  return 0;
}


Measured memory_bytes: 384
import math

a, b, C = map(int, input().split())
S = a * b * math.sin(math.radians(C)) / 2
L = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C)))
h = 2 * S / a
print(S)
print(L)
print(h)


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

int abc[3];
int dp[100001][3];
bool memo[100001][3];

int main() {
    ll N,K,R,S,P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    ll ans = 0;

    abc[0] = R;
    abc[1] = S;
    abc[2] = P;
    
    for(int i=0;i < N;i++){
        ll pre = i - K;
        if(T[i]=='r'){
            if(pre >= 0 && T[pre] == 'r' && memo[pre][2])continue;
            memo[i][2] = true;
            ans += abc[2];
        }else if(T[i] == 's'){
            if(pre >= 0 && T[pre] == 's' && memo[pre][0])continue;
            memo[i][0] = true;
            ans += abc[0];
        }else{
            if(pre >= 0 && T[pre] == 'p' && memo[pre][1])continue;
            memo[i][1] = true;
            ans += abc[1];
        }
    }


    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define MOD 1000000007

int main() {
  long long n, r = 1;
  cin >> n;
  rep(i, n) {
    r = (i + 1) * r;
    r = r % MOD;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  int H, W, D;
  cin >> H >> W >> D;
  vector<vector<int>> A(H, vector<int>(W));
  rep(i,H)rep(j,W) cin >> A[i][j];
  int Q;
  cin >> Q;
  vector<int> l(Q), r(Q);
  rep(i,Q){
    cin >> l[i] >> r[i];
    l[i]--; r[i]--;
  }
  vector<pair<int, int>> num(H*W);
  rep(i,H)rep(j,W) num[A[i][j]-1] = {i, j};
  vector<int> sum(H*W+1);
  for(int i=D; i<=H*W; i++){
      sum[i] = sum[i-D]+abs(num[i].first-num[i-D].first)+abs(num[i].second-num[i-D].second);
  }
  rep(i,Q)
    cout << sum[r[i]]-sum[l[i]] << endl;
  return 0;
}

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

int main() {
  int k, n;
  int a[200000 + 1];
  cin >> k >> n;
  for (int i = 0; i < n; i++) cin >> a[i];

  int md = 0;
  a[n] = k + a[0];
  for (int i = 0; i < n; i++) {
    md = max(md, a[i + 1] - a[i]);
  }
  cout << (k - md) << endl;
}

Measured memory_bytes: 1024
arr = [0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
p arr[gets.to_i]


Measured memory_bytes: 14376
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

void solve(void)
{
  int a, b; cin >> a >> b;
  int m = std::min(a, b);
  int l = std::max(a, b);
  string s = std::to_string(m);
  string ans{};
  for (int i = 0; i < l; ++i) {
    ans += s;
  }
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 2e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

int solve()
{
	ll n ;
	cin >> n ;
	ll ans = 1e15 ;
	for(ll i = 1 ; i*i <= n ; i++)
	{
		if(n%i==0)
		{
			ll a = i , b = n/i ;
			ll mov = (a-1)+(b-1);
			ans = min(ans , mov);
		}
	}
	cout << ans ;



}
int main()
{
	fast;
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}

	return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
# とけてない
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import heapq

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()
A.sort(reverse=True)
B = [-x for x in A]

l = 0
r = 2*10**5+1

ans = 0

def count(x):  # 和がx以上になる組み合わせの個数
	cnt = 0
	for y in A:  # 左手
		left = -(x-y)
		cnt += bisect(B, left)

	return cnt

while l+1 != r:
	m = (l+r)//2
	if count(m) < M:
		r = m
	else:
		l = m
ans = 0

A_acc = list(accumulate([0]+sorted(A, reverse=True)))
cnt = 0
for y in A:
	left = -(l-y)
	idx = bisect(B, left)
	ans += A_acc[idx]+idx*y
	cnt += idx
ans -= (cnt-M)*l

print(ans)


Measured memory_bytes: 18988
using System;

namespace ABC161
{
    class Program
    {
        static void Main()
        {
            /*
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            */
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            var x = a;
            var y = b;
            var z = c;
            
            x = b;
            y = a;
            z = x;
            x = c;
            Console.Write(x);
            Console.Write(" ");
            Console.Write(y);
            Console.Write(" ");
            Console.Write(z);
            
        }
    }
}

Measured memory_bytes: 11092
// ------------------------------------
// Date:2018/ 3/20
// Problem:A - Shrinking re_a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int INF = 1e9 + 1;
static const int MAX_N = 1;

int main()
{
  SCIN(s);
  int ans = INF;
  REP(i, 26) {
    // OK(true);
    char ch = i + 97;
    string tmp = s;
    int cnt = 0;
    bool ok = false;
    REP(i, s.size()) {
      if (s[i] != ch) break;
      if (i == s.size() - 1) ok = true;
    }
    while(!ok) {
      // OK(false);
      REP(j, tmp.size() - 1) {
	if (tmp[j] == ch or tmp[j + 1] == ch) {
	  tmp[j] = ch;
	}
      }
      tmp.pop_back();
      REP(j, tmp.size()) {
	if (tmp[j] != ch) break;
	if (j == tmp.size() - 1) ok = true;
      }
      if (tmp.size() == 0) ok = true;
      cnt++;
    }
    ans = min(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256