akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#define SIZE 100005
#define LINF 1000000000000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
typedef pair <P,ll> PP;

int main()
{
	int n,q;
	scanf("%d %d",&n,&q);
	set <PP> st;
	set <PP>::iterator it;
	st.insert(PP(P(0,n-1),0));
	PP dm=PP(P(-1,-1),-1);
	for(int i=0;i<q;i++)
	{
		int a;
		ll b;
		scanf("%d %lld",&a,&b);a--;
		while(1)
		{
			it=st.lower_bound(PP(P(a+1,-1),-1));
			it--;
			PP p=*it;
			PP q=dm;
			if(it!=st.begin())
			{
				it--;
				q=*it;
				it++;
			}st.erase(it);
			if(p.first.second>a) st.insert(PP(P(a+1,p.first.second),p.second));
			p.first.second=a;
			if(q!=dm&&(q.second-p.second)*(ll) (p.first.second-p.first.first+1)<=b)
			{
				b-=(q.second-p.second)*(ll) (p.first.second-p.first.first+1);
				st.erase(q);
				st.insert(PP(P(q.first.first,p.first.second),q.second));
			}
			else
			{
				p.second+=b/(ll) (p.first.second-p.first.first+1);
				b%=(ll) (p.first.second-p.first.first+1);
				if(b>0)
				{
					st.insert(PP(P(p.first.first,p.first.first+(int) b-1),p.second+1));
					p.first.first+=(int) b;
				}st.insert(p);
				break;
			}
		}
	}
	for(it=st.begin();it!=st.end();it++)
	{
		PP p=*it;
		P s=p.first;
		for(int i=s.first;i<=s.second;i++) printf("%lld\n",p.second);
	}
	return 0;
}


Measured memory_bytes: 7680
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A < B) {
		int i = A;
		A = B;
		B = i;
	}
	if (A>C && C>B) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n;
	cin >> n;
	vector<int> b(n-1);
	rep(i, 0, n-1) {
		cin >> b[i];
	}
	int ans = b[0];
	rep(i, 0, b.size()) {
		if (i == b.size() - 1) {
			ans += b[i];break;
		}
		if (b[i] <= b[i + 1]) {
			ans += b[i];
		}
		else if (b[i] > b[i + 1]) {
			ans+= b[i + 1];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int i,j,n,now;
int ans[105][105];
int main()
{
	scanf("%d",&n);
	for (i=1;i<=2;i++)
		for (j=1;j<=n;j++)
		{
			scanf("%d",&now);
			ans[i][j]=max(ans[i-1][j],ans[i][j-1]);
			ans[i][j]+=now;
		}
	printf("%d",ans[2][n]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int N,a,b,ans;
int fac[10000005],inv[10000005];
const int fish=998244353;
int Pow(int x,int y){
    int ans=1;
    for (;y;y>>=1,x=1ll*x*x%fish) if (y&1) ans=1ll*ans*x%fish;
    return ans;
}
void Pre(){
    fac[0]=1;
    for (int i=1;i<=10000000;i++)
        fac[i]=1ll*fac[i-1]*i%fish;
    inv[10000000]=Pow(fac[10000000],fish-2);
    for (int i=9999999;i>=0;i--)
        inv[i]=1ll*inv[i+1]*(i+1)%fish;
}
int C(int n,int r){return 1ll*fac[n]*inv[r]%fish*inv[n-r]%fish;}
int catalan(int x,int y){return ((C(x+y,y)-C(x+y,y-1))+fish)%fish;}
int main(){
    Pre();
    scanf("%d%d%d",&N,&a,&b);
    if (b==0){
        cout<<1;
        return 0;
    }
    for (int i=0;i<=min(min(a,N-b),b-1);i++){
        int tot=catalan(b-1,i);
        if (i+b==N){
            if (a==i)
                (ans+=tot)%=fish;
        }
        else {
            int x=N-b-i-1;
            int y=b-i-(b-a)+1;
            (ans+=1ll*tot*C(x+y-1,x)%fish)%=fish;
        }
    }
    cout<<ans;
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;
ll ans = -INF*INF, ansi;
vector<int> a;

int main() {
    cin >> n;
    rep(i,n) {
        int tmp;
        cin >> tmp; a.push_back(tmp);
    }
    rep(i,n) {
        ll cnt = a[i];
        for (int j = i-2; j >= 0; j -= 2) {
            if (a[j] > 0) cnt += a[j];
        }
        for (int j = i+2; j < n; j += 2) {
            if (a[j] > 0) cnt += a[j];
        }
        if (ans < cnt) {
            ans = cnt;
            ansi = i;
        }
    }
    cout << ans << endl;
    vector<int> out;
    while (a.size() != 1) {
        int j = ansi-2;
        if (j >= 0) {
            if (a[j] > 0) {
                out.push_back(j+2);
                a.erase(a.begin()+j);
                a.erase(a.begin()+j);
                ansi -= 2;
            } else {
                out.push_back(j+1);
                a.erase(a.begin()+j);
                ansi--;
                if (j != 0) { a.erase(a.begin()+j-1); ansi--; }
            }
            continue;
        }
        j = ansi+2;
        if (j < a.size()) {
            if (a[j] > 0) {
                out.push_back(j);
                a.erase(a.begin()+j-1);
                a.erase(a.begin()+j-1);
            } else {
                out.push_back(j+1);
                a.erase(a.begin()+j);
                if (j != a.size()) a.erase(a.begin()+j-1);
            }
            continue;
        }
        if (ansi != 0) {
            out.push_back(1);
            a.erase(a.begin());
            ansi--;
            continue;
        }
        if (ansi != a.size()-1) {
            out.push_back(a.size());
            a.erase(a.begin()+a.size()-1);
            continue;
        }
    }
    cout << out.size() << endl;
    rep(i,out.size()) cout << out[i] << endl;
}
































Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  string S;
  cin>>S;
  if(S[S.size()-1]=='s') cout<<S<<"es"<<endl;
  else cout<<S<<"s"<<endl;
}




Measured memory_bytes: 3628
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int num = N;
    switch(num%10){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
string s,st;
int f[3005][3005],n;
string truyvet(int x, int y){
    if(x==0||y==0){
        return "";
    }
    if(s[x-1]==st[y-1]){
        return truyvet(x-1,y-1)+s[x-1];
    }
    else
    if(f[x][y-1]>f[x-1][y]){
        return truyvet(x,y-1);
    }
    else{
        return truyvet(x-1,y);
    }
}
int main(){
    cin >> s >> st;
    for(int i=0;i<s.size();++i){
        for(int j=0;j<st.size();++j){
            if(s[i]==st[j]){
                f[i+1][j+1]=f[i][j]+1;
            }
            else{
                f[i+1][j+1]=max(f[i][j+1],f[i+1][j]);
            }
        }
    }
    cout << truyvet(s.size(),st.size());
    return 0;
}

Measured memory_bytes: 35968
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V, string sep = " ", string end_ = "endl") {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << sep;
    }
    if(end_ == "endl")
        cout << endl;
    else
        cout << end_;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, x = 0, M = 0;
    string S;
    cin >> N >> S;
    auto e = S.begin();
    while(e != S.end()) {
        if(*e++ == 'I')
            M = max(M, ++x);
        else
            x--;
    }
    cout << M << endl;
}


Measured memory_bytes: 256
using System;

class main
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());        
        for( int i = 0; i < n; i++ )
        {
            string[] s1 = Console.ReadLine().Split(' ');
            double x1 = double.Parse(s1[0]);
            double y1 = double.Parse(s1[1]);
            double x2 = double.Parse(s1[2]);
            double y2 = double.Parse(s1[3]);
            double x3 = double.Parse(s1[4]);
            double y3 = double.Parse(s1[5]);
            double a = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
            double b = Math.Sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
            double c = Math.Sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
            double r = (a * b * c) / Math.Sqrt((a + b + c) * (-a + b + c) * (a - b + c) * (a + b - c));
            double x = (((x1 * x1 + y1 * y1) * (y2 - y3)) + ((x2 * x2 + y2 * y2) * (y3 - y1)) + ((x3 * x3 + y3 * y3) * (y1 - y2))) / ((x1 * (y2 - y3)) + (x2 * (y3 - y1)) + (x3 * (y1 - y2))) * 0.5;
            double y = (((x1 * x1 + y1 * y1) * (x2 - x3)) + ((x2 * x2 + y2 * y2) * (x3 - x1)) + ((x3 * x3 + y3 * y3) * (x1 - x2))) / ((y1 * (x2 - x3)) + (y2 * (x3 - x1)) + (y3 * (x1 - x2))) * 0.5;
            r = ToHalfAdjust(r, 3);
            x = ToHalfAdjust(x, 3);
            y = ToHalfAdjust(y, 3);
            Console.WriteLine("{0:F3} {1:F3} {2:F3}", x, y, r);
        }
    }
    public static double ToHalfAdjust(double dValue, int iDigits)
    {
        double dCoef = System.Math.Pow(10, iDigits);

        return dValue > 0 ? System.Math.Floor((dValue * dCoef) + 0.5) / dCoef :
                        System.Math.Ceiling((dValue * dCoef) - 0.5) / dCoef;
    }
}

Measured memory_bytes: 5736
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

















int main(){
    double r;
    cin >> r;
    printf("%.4lf\n", 2 * acos(-1) * r);
}

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

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;


int main(){
	int n; string s; cin >> n >> s;
	vector<int> dp(n+1);
	dp[1] = 1;
	for(int len = 2; len <= n; ++len){
		vector<int> new_dp(n+1);
		bool ok = (s[len-2] == '<');
		for(int ld = 1; ld < len; ++ld){//ld means last digit
			if(ok){
				new_dp[ld+1] += dp[ld]; new_dp[ld+1] %= mod;
			}
			else{
				new_dp[1] += dp[ld]; new_dp[1] %= mod;
				new_dp[ld+1] -= dp[ld];
				if(new_dp[ld+1] < 0) new_dp[ld+1] += mod;
			}
		}
		for(int i = 1; i <= len; ++i){
			new_dp[i] += new_dp[i-1];
			new_dp[i] %= mod;
		}
		dp = new_dp;
	}
	ll ans = 0;
	for(int i = 1; i <= n; ++i){
		ans += dp[i]; ans %= mod;
	}
	cout << ans;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  vector<int> A(H), B(H);
  for (int i = 0; i < H; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
  }
  map<int, int> mp;
  multiset<int> res;
  for (int i = 0; i < W; i++) {
    mp[i] = i;
    res.insert(0);
  }
  for (int i = 0; i < H; i++) {
    auto it = mp.lower_bound(A[i]);
    int s = -1;
    while (it != mp.end() && it->first < B[i] + 1) {
      int x = it->first - it->second;
      s = max(s, it->second);
      res.erase(res.find(x));
      mp.erase(it++);
    }
    if (s != -1 && B[i] < W) {
      res.insert(B[i] - s);
      mp[B[i]] = s;
    }
    if (!res.empty()) {
      cout << *res.begin() + i + 1 << '\n';
    } else {
      cout << -1 << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 23516
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;

int main(){
	while(1){
		int n,ans=0;
		cin>>n;
		if(n==0)break;
		rep(i,1,1000){
			rep(j,i+1,1001){
				if(n*2==(j-i+1)*(i+j))ans++;
			}
		}
		print(ans);
	}
	return 0;
}


Measured memory_bytes: 2992
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long A, B;
  string S;
  cin >> A >> B >> S;

  for (long i = 0; i < A + B + 1; i++) {
    if (i < A) if (S[i] < '0' or '9' < S[i]) { cout << "No" << endl; return; }
    if (i == A) if (S[i] != '-') { cout << "No" << endl; return; }
    if (i > A) if (S[i] < '0' or '9' < S[i]) { cout << "No" << endl; return; }
  }

  cout << "Yes" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep0(i,b) for(int i=0 ; i< b ;i++)
#define rep1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007
# define M_PI     3.14159265358979323846

using namespace std;


int main()
{

  ll x,res=100,rep=0;
  cin >> x;

  while(res<x){
    res +=  res/100;
    rep++;
  }
  cout<< rep;


  return 0 ;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep2(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const ll mod = 1e9+7;
int gcd(int a, int b){if(a<b) swap(a,b); if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

double N, M, K, H, W, L, R;

int main(){
  cin >> W >> H;
  double x, y; cin >> x >> y;
  cout << fixed << setprecision(10);
  cout << H*W/2 << " ";
  if(W/2 == x && H/2 == y) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

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

#define V vector
#define P pair
typedef long long ll;

int main() {
    int n; cin >> n;
    bool zero = false;
    V<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 0) zero = true;
    }


    bool flag = true;
    ll ans = a[0];
    for(int i = 1; i < n; i++){
        if(ans <= 1000000000000000000 / a[i]){
            ans *= a[i];
        }else{
            flag = false;
            break;
        }
    }

    if(zero){
        cout << 0 << endl;
    }else if(!flag){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

}


Measured memory_bytes: 4048
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())
S = list(map(lambda s: s.strip(), sys.stdin.readlines()))

x = {}

for s in S:
    x[s] = True

print(len(x.keys()))


Measured memory_bytes: 147280
#include<stdio.h>
int func(int *A,int n,int i,int num) {
	int ans;
	if (num == 0) {
		return 1;
	}
	if (i >= n) {
		return 0;
	}
	if ((func(A, n, i + 1, num) == 1) || (func(A, n, i + 1, num - A[i]) == 1)) {
		return 1;
	}
	return 0;
	
}

int main(void) {
	int n, q,i;
	int A[20], m[200];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &m[i]);
	}
	for (i = 0; i < q; i++) {
		if (func(A, n, 0, m[i])==1) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}
}


Measured memory_bytes: 2052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();

			if (H == 0 && W == 0) {
				return;
			}

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.printf("%n");
			}
			System.out.printf("%n");		
		}
		
		
	}
}


Measured memory_bytes: 39056
x = input()
count_s = 0
ans = 0
for i in range(len(x)):
    if x[i] == 'S':
        count_s += 1
    if x[i] == 'T':
        if count_s == 0:
            ans += 1
        else:
            count_s -= 1
ans += count_s
print(ans)

Measured memory_bytes: 3500
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		int[] a = {1,0,0};
		while (in.hasNext()) {
			String s = in.next();
			swap(a,s.charAt(0)-'A',s.charAt(2)-'A');
		}

		out.println(a[0] == 1 ? "A" : (a[1] == 1 ? "B" : "C"));
	}

	static void swap(int[] a, int i, int j) {
		int t = a[i];
		a[i] = a[j];
		a[j] = t;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 25956
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		String s = stdIn.next();
		
		String initial = s.substring(0,2);
		
		int a = Integer.parseInt(initial); //前2文字を数字化
		
		String finish = s.substring(2,4);
		int b = Integer.parseInt(finish); //後ろ2文字を数字化
		
		
		if((1 <= a && a<= 12 ) && (1 <= b && b<= 12 ) ) {
			System.out.println("AMBIGUOUS");
		}else if(1 <= a && a<= 12 ) {
			System.out.println("MMYY");
		}else if(1 <= b && b<= 12 ){
			System.out.println("YYMM");
		}else {
			System.out.println("NA");
		}
			
			
			
		
		
		
		
	}

}


Measured memory_bytes: 21844
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 998244353, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

ll dp[3001][3001];
Pa arr[3000];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> T;
	rep(i, N) {
		cin >> A >> B;
		arr[i] = Pa(A, B);
	}
	sort(arr, arr + N);
	rep(i, N + 1) {
		rep(j, T + 1) {
			dp[i][j] = 0;
		}
	}
	ll maxv = 0;
	rep(i, N) {
		rep(j, T) {
			if (j + arr[i].first <= T) dp[i + 1][j + arr[i].first] = max(dp[i + 1][j + arr[i].first], dp[i][j] + arr[i].second);
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		}
	}
	rep(i, N + 1) {
		rep(j, T) {
			maxv = max(maxv, dp[i][j] + arr[i].second);
		}
	}
	cout << maxv;
}


Measured memory_bytes: 74056
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  int n;
  cin>>n;
  long long a[n];
  long long ans[n]={};
  REP(i,n){
    cin>>a[i];
    if(i%2==0){
      ans[0] += a[i];
    }else{
      ans[0] -= a[i];
    }
  }
  
  REP(i,n){
    if(i==0){
      continue;
    }else{
      ans[i] = 2*a[i-1]-ans[i-1];
    }
  }
  
  REP(i,n){
    cout<<ans[i]<<' ';
  }
  cout<<endl;
  return 0;
}


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

int main(){
    int n,*X,*Y;
    double dis1 = 0,dis2 = 0,dis3 =0,disM = 0;
    scanf("%d",&n);
    X = (int *)malloc(sizeof(int)*n);
    Y = (int *)malloc(sizeof(int)*n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&X[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&Y[i]);
    }
    for(int i =0;i<n;i++)
    {
    	dis1 = dis1 + sqrt(pow((X[i] - Y[i]), 2));
    	dis2 = dis2 + pow((X[i] - Y[i]), 2);
    	dis3 = dis3 + pow((fabs(X[i] - Y[i])),3);
    	if(disM < fabs(X[i] - Y[i])) disM = fabs(X[i] - Y[i]);
    }
    printf("%.8f\n%.8f\n%.8f\n%.8f\n",dis1,sqrt(dis2),pow(dis3,0.3333333333333),disM);
}


Measured memory_bytes: 2104
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

main {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  set<string> a;
  while (n--) {
    string cmd;
    string s;
    cin >> cmd >> s;
    if (cmd == "insert") a.insert(s);
    if (cmd == "find") cout << (a.count(s) ? "yes" : "no") << endl;
  }
}

Measured memory_bytes: 29020
package main

import (
    "fmt"
)

func main() {
    var n, a, b, sum int
    fmt.Scan(&n, &a, &b)
    for i := 1; i < n+1; i++ {
        i1 := i % 10
        i10 := (i % 100) / 10
        i100 := (i % 1000) / 100
        i1000 := (i % 10000) / 1000
        i10000 := i / 10000 //1≤N≤10^4
        if v := i1 + i10 + i100 + i1000 + i10000; a <= v && v <= b {
            sum += i
        }
    }
    fmt.Println(sum)
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end(),greater<int>());
    int ans=0;
    for(int i=0; i<k; i++){
        ans+=l[i];
    }
    cout << ans <<endl;

}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

bool is_kaibun(string s) {
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != s[s.size() - i - 1]) return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (!is_kaibun(s)) {
        cout << "No" << endl;
        ret();
    }

    string p = s.substr(0, (n - 1) / 2);
    string q = s.substr((n + 3) / 2 - 1, n-1);
    if (is_kaibun(p) && is_kaibun(q)) {
        cout << "Yes" << endl;
        ret();
    }
    cout << "No" << endl;

}





Measured memory_bytes: 256
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(m)]
ans = min(A)+min(B)
for x, y, c in xyc:
  x -= 1
  y -= 1
  ans = min(ans, A[x]+B[y]-c)

print(ans)

Measured memory_bytes: 38488
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <queue>
#include <tuple>

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  std::vector<std::pair<size_t, intmax_t>> S(N);
  for (auto& si: S)
    scanf("%zu %jd", &si.first, &si.second);

  std::sort(S.rbegin(), S.rend());

  std::priority_queue<std::pair<intmax_t, size_t>> pq;
  intmax_t res = 0;
  for (size_t i = M; i--;) {
    while (!S.empty() && S.back().first + i <= M) {
      pq.emplace(S.back().second, S.back().first);
      S.pop_back();
    }
    while (!pq.empty()) {
      size_t a;
      intmax_t b;
      std::tie(b, a) = pq.top();
      pq.pop();
      res += b;
      break;
    }
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 3956
n = gets.to_i
ans = {"AC" => 0,"WA" => 0, "TLE" => 0,"RE" => 0}
arr = ["AC","WA","TLE","RE"]

n.times do 
  s = gets.chomp
  ans[s] += 1
end

arr.each do |c|
  puts "#{c} x #{ans[c]}"
end


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

typedef long long int lli;
typedef long int li;

void solve(){
}

int main(){
	
    ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    
    string s, t;
    cin >> s >> t;
    
    t.pop_back();
    puts(t == s ? "Yes" : "No");
}	

/*
	check for corner cases.
	When using log check for zeros.
	Use queues and stacks if they are helping.           
                            
    (___)           
    . . )____________ 
   _|__/\           |\
  (o_o_) \__________| \
           /|     ||   )     
          < |     ||  
*/



Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	maxN = 50
)

var edges [maxN][]int
var visited [maxN]bool

func dfs(pos int, a, b int) {
	visited[pos] = true
	for _, nxt := range edges[pos] {
		if visited[nxt] {
			continue
		}
		if pos == a && nxt == b {
			continue
		}
		dfs(nxt, a, b)
	}
}

func clear() {
	for i := 0; i < maxN; i++ {
		visited[i] = false
	}
}
func check() int {
	res := 0
	for i := 0; i < maxN; i++ {
		if visited[i] {
			res++
		}
	}
	return res
}
func main() {
	fsc := NewFastScanner()
	N, M := fsc.NextInt(), fsc.NextInt()
	for i := 0; i < M; i++ {
		a, b := fsc.NextInt(), fsc.NextInt()
		a--
		b--
		edges[a] = append(edges[a], b)
		edges[b] = append(edges[b], a)
	}
	result := 0
	for a := 0; a < N; a++ {
		for _, b := range edges[a] {
			clear()
			dfs(0, a, b)
			res := check()
			if res != N {
				result++
			}
		}
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 640
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

bool cmp(pair<int,int> &a,pair<int,int> &b){
	return a.F<b.F;
}

void solve(int test_case) {//233
	int k,n;
	cin>>k>>n;
	k--;
	REP(i,n-k,n+k)cout<<i<<" ";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  int N, K, input;
  cin >> N >> K;
  vector<int> prices;
  for (int i = 0; i < N; ++i) {
  	cin >> input;
    prices.push_back(input);
  }
  sort(prices.begin(), prices.end());
  int cost = 0;
  for (int i = 0; i < K; ++i)
    cost += prices[i];
  cout << cost << '\n';
  return 0;
}

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

int main() {
  int n; cin >> n;
  int m; cin >> m;
  
  vector<int> count(n, 0);
  for (int i = 0; i < m; i++) {
    int a; cin >> a;
    int b; cin >> b;
    
    for (int j = 0; j < n; j++) {
      count.at(j) += (a == j + 1 or b == j + 1); 
    }
  }
  
  for (int j = 0; j < n; j++) {
    cout << count.at(j) << endl;
  }
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};

int rui[100001];
int N, A[100000];
int ans[100000];

void debug1(){
	for(int i = 0; i <= N; i++){
		cout << rui[i] << " ";
	}
	exit(0);
}
void debug2(){
	for(int i = 0; i < N; i++){
		cout<< ans[i] << " ";
	}
	exit(0);
}

void solve(){
	rui[0] = 0;
	rui[1] = abs(A[0]);
	for(int i = 1; i < N; i++){
		rui[i + 1] = rui[i] + abs(A[i] - A[i-1]);
	}
	// debug1();
	for(int i = 0; i < N; i++){
		if(i == 0){
			ans[i] = rui[N]-rui[2] + abs(A[1]) + abs(A[N-1]);
		}else if(i == N-1){
			ans[i] = rui[N-1] + abs(A[N-2]);
		}else{
			ans[i] = rui[i] + rui[N]-rui[i+2] + abs(A[i+1] - A[i-1]) + abs(A[N-1]);
		}
	}
	// debug2();
	return;
}

int main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		cin>> A[i];
	}
	solve();
	for(int i = 0; i < N; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

vv d;
vector<vector<bool>> use;
bool ok = true;

void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = i+1; j < n; j++) {  // 終点
        if(k == i || k == j)continue;
        if(d[i][j] == d[i][k] + d[k][j]){
            use[i][j] = false;
        }
        else if(d[i][j] >= d[i][k] + d[k][j]){
            ok = false;
        }
      }
    }
  }
}

int main(){
    ll N;
    cin>>N;
    d.resize(N,v(N));
    rep(i,0,N)rep(j,0,N){
        cin>>d[i][j];
    }
    use.resize(N,vector<bool>(N,true));
    warshall_floyd(N);
    ll ans = 0;
    if(!ok)cout<<-1;
    else{
        rep(i,0,N)rep(j,i+1,N){
            if(use[i][j])ans += d[i][j];
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {


	int n;
	cin >> n;

	COUT((n - 2) * 180);


	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt(s *bufio.Scanner) int {
	if s.Scan() {
		t := s.Text()
		v, err := strconv.Atoi(t)
		if err == nil {
			return v
		}
		panic(err)
	} else {
		panic(s.Err())
	}
}

func scanString(s *bufio.Scanner) string {
	if s.Scan() {
		return s.Text()
	}
	panic(s.Err())
}

func main() {
	sc := newScanner()
	n, m := scanInt(sc), scanInt(sc)

	if n == m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// random {{{ 1
ll rnd(){
    static ll x = time(0);
    x = x ^ (x << 13); x = x ^ (x >> 7);
    return x = x ^ (x << 17);
}
// }}}
// }}} 0

int main() {

    ll N;
    Scll(N);

    ll M = sqrt(N)+114;

    ll ans = N;
    while( M ){
        if( N%M == 0 ){
            ans = min(N/M+M-2,ans);
        }
        M--;
    }

    printf ("%lld\n", ans );

    return 0;
}




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

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

  vector<int> P_inv(N + 1);
  for(int i = 1; i <= N; i++){
    int tmp;
    cin >> tmp;
    P_inv[tmp] = i;
  }

  long long ans = 0;
  set<int> indices;
  indices.insert(0);
  indices.insert(N + 1);
  for(int i = N; i >= 1; i--){
    //cout << P_inv[i] << endl;
    auto larger1 = indices.lower_bound(P_inv[i]);
    //auto larger1 = lower_bound(indices.begin(), indices.end(), P_inv[i]);
    auto smaller1 = prev(larger1);
    //cout << (*smaller1) << ' ' << (*larger1) << endl;
    if((*larger1) != N + 1){
      auto larger2 = next(larger1);
      ans += static_cast<long long>(i) * (P_inv[i] - *smaller1) * (*larger2 - *larger1);
    }
    if((*smaller1) != 0){
      auto smaller2 = prev(smaller1);
      ans += static_cast<long long>(i) * (*smaller1 - *smaller2) * (*larger1 - P_inv[i]);
    }
    indices.insert(P_inv[i]);
    //cout << ans << endl;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <math.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  vi a(3);
  map<int,int> mp;
  rep(i,3) {
    cin>>a[i];
    mp[a[i]]++;
  }
  bool ja=true;
  for(auto x:mp){
    if(x.second==2)ja=false;
  }
  if(ja) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3528
s=int(input())
tmp=[s]
for m in range(2,1000000):
  if tmp[-1]%2 == 0:
    if tmp[-1]/2 in tmp:
      print(m)
      exit()
    else:
      tmp.append(tmp[-1]/2)
  else:
    if 3*tmp[-1]+1 in tmp:
      print(m)
      exit()
    else:
      tmp.append(3*tmp[-1]+1)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
bool f(int x)
{
	int xx=x;
	int xxx=0;
	while(xx>0)
	{
		xxx=xxx*10+xx%10;
		xx/=10;
	}
	if(xxx==x)
		return 1;
	else return 0;
}
int main(){
	int a,b;
	cin>>a>>b;
	int s=0;
	for(int i=a;i<=b;i++)
		if(f(i))
			s++;
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
program main
  implicit none

  integer :: x, p, b, ans, i, j

  read(*,*) x


  if(x <= 3) then
     ans = 1
     write(*,*) ans
     stop
  end if
  
  ans = 0
  do i = 2, x
     do j = 2, 10
        b = i
        p = j
        if(x >= b**p) then
           ans = max(ans, b**p)
        end if
     end do
  end do

  write(*,*) ans

end program main

     
  


Measured memory_bytes: 2876
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
// #define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};

int cnt[10000001];
 bool is[10000001];
void pre() {
    fori(i,10000001) {
        cnt[i] = 2;
        is[i] = true;
    }
    cnt[1] = 1;
    for(ll i = 2; i<10000001; i++) {
        for(ll j = 2; j*i<10000001; j++) {
            cnt[i*j]++;
            // if(is[j*i]) {
            //     is[j*i] = 0;
            //     cnt[j*i] = 2ll*cnt[j]; 
            //     if(i == j) cnt[i*j]--;
            // }
        }
    }
}



int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    pre();
    while(t--) {
        int n;
        cin>>n;
        ll ans = 0;
        for(int i = 1; i<=n; i++) {
            ans += (1ll*i)*1ll*cnt[i];
            // cout<<cnt[i]<<"  ";
        }
        // cout<<endl;
        cout<<ans;
    }
    
    return 0;
}

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


int main() {
    string s;
    cin >> s;
    int m = numeric_limits<int>::max();
    for(int i = 0; i< s.size() -2; i++){
        int num = atoi(s.substr(i,3).c_str());
//        cout << "num is: " << num << endl;
        if(num == 753){
            cout << 0 << endl;
            exit(0);
        }
        int diff = abs(num - 753);
        m  = min(m,diff);
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
#include <cmath>
 
using namespace std;
 
typedef string::const_iterator iter;
typedef long long lint;
 
#define DEBUG(s,x) // cerr << s << " : " << x << endl
 
lint term(iter &it);
lint number(iter &it);
 
lint expr(iter &it) {
    lint res = term(it);
    while('>' == *it && '>' == *(it + 1) && (isdigit(*(it + 2)) || *(it + 2) == 'S')) {
        it++;
        it++;
        int res2 = term(it);
        res = res / pow(2.0, res2);
    }
    return res;
}
 
lint term(iter &it) {
    if(isdigit(*it)) return number(it);
    it++; // skip S
    it++; // skip <
    lint res = expr(it);
    it++; // skip >
    res = (res * res) % 1000000007LL;
    return res;
}
 
lint number(iter &it) {
    lint res = 0;
    while(isdigit(*it)) {
        res *= 10;
        res += (*it - '0');
        it++;
    }
    return res;
}
 
string replaceAll(string s, string f, string t) {
    string r;
    for(size_t p = 0; (p = s.find(f)) != string::npos; ){
        r += s.substr(0, p) + t;
        s = s.substr(p + f.size());
    }
    return r + s;
}
 
int main() {
    while(true) {
        string s;
        getline(cin, s);
        if(s == "#") break;
        s = replaceAll(s, " ", "");
        s += "@@@";
        iter it = s.begin();
        lint res = expr(it);
        cout << res << endl;
    }
}

Measured memory_bytes: 3100
let get_4_ints () = Scanf.scanf "%d %d %d %d" (fun u v w x -> u,v,w,x)
module Rep = struct
	let __range ?(stride=1) u v =
		let rec f0 i = if i>v then [] else i::(f0 (i+stride))
    in f0 u
  let __ls_product l r =
    List.map (fun u -> List.map (fun v -> u,v) r) l
    |> List.concat
	let init f = f ()
	let rep ?(stride=1) f t = __range ~stride f t
	let (=+>) v p = (v,p)
	let (=>) (v,p) q = (v,__ls_product p q)
	let (=>>) (v,p) f = List.fold_left (fun x y -> f x y) v p
end

let () = 
  let (a,b,c,x) = get_4_ints ()
  in let open Rep in
  init (fun () -> 0)
  =+> rep 0 a => rep 0 b => rep 0 c =>>
  (fun a ((u,v),w) -> if u*500+v*100+w*50=x then a+1 else a)
  |> Printf.printf "%d\n"

Measured memory_bytes: 10880
#include<stdio.h>
int main(void){
  int b,f,r,v,n;
  int A[4][3][10]={0};
  int i,j,k;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    A[b-1][f-1][r-1]+=v;
  }

  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
       for(k=0;k<10;k++){
        printf(" %d",A[i][j][k]);
        if(k==9){
              printf("\n");
              if(j==2&&i<3){
                printf("####################\n");
             }
          }
       }
    }
  }
  return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int X, Y, ans=2e9+5;

void go (int i, int j, int k) {
        if (i<=j) ans = min(ans, j-i+k);
}

int main () {
        cin >> X >> Y;
        go(X, Y, 0);
        go(-X, Y, 1);
        go(X, -Y, 1);
        go(-X, -Y, 2);
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256