akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    dbg_out(T...);
}
#ifdef LOCAL
    #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", dbg_out(__VA_ARGS__)
#else
    #define dbg(...) 42
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2e5+5;

void solve(){
    int n, k;
    cin >> n >> k;
    int h[n], ans = 0;
    fr(i, 0, n) cin >> h[i];
    sort(h, h+n, greater<int>());
    fr(i, k, n) ans += h[i];
    cout << ans;
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

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

int main(void){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    sum += A.at(i);
  }
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  int cnt=0;
  for(int i=0;i<M;i++){
    if(A.at(i) < sum*1.0/(4*M)){
      cout << "No" << endl;
      return(0);
    }
  }
  
  cout << "Yes" << endl;
  return(0);
}


Measured memory_bytes: 256
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e3 + 5;

char arr[MAXN][MAXN];

char sq[3][3] = {{'<', '>', '^'},
				 {'^', '.', 'v'},					
				 {'v', '<', '>'}};

int n, m, a, b;

void putAns(bool p) {
	if (!p) {
	 	printf("NO\n");
	}
	else {
		printf("YES\n");

		for (int i = 0; i < n; ++i) {
			printf("%s\n", arr[i]);
		}	
	}

	exit(0);
}

void solve() {                   
	scanf("%d %d %d %d", &n, &m, &a, &b);
	int S = (n * m) / 2;
	int aS = n * (m / 2);
	int bS = (n / 2) * m;

    if (a + b > S || a > aS || b > bS) {
    	putAns(0);    
   	}

    for (int i = 0; i < n; ++i) {
    	for (int j = 0; j < m; ++j) {
    		arr[i][j] = '.';
    	}
    }

	if (n == 1) {
		for (int i = 0; i + 1 < m; i += 2) {
			if (a > 0) {
				arr[0][i] = '<';
				arr[0][i + 1] = '>';
				--a;
			}
		}

		putAns(1);		
	}

	if (m == 1) {
		for (int i = 0; i + 1 < n; i += 2) {
			if (b > 0) {
				arr[i][0] = '^';
				arr[i + 1][0] = 'v';
				--b;
			}
		}

		putAns(1);
	}

	if ((aS - a) % 2) {
		if ((n * m) % 2 && a >= 2 && b >= 2) {
			for (int i = 0; i < 3; ++i) {
				for (int j = 0; j < 3; ++j) {
					arr[n - 3 + i][m - 3 + j] = sq[i][j];
				}
			}

			a -= 2;
			b -= 2;
		}
	}

	if (n & 1) {
		for (int i = 0; i + 1 < m; i += 2) {
			if (a > 0) {
				if (arr[n - 1][i] == '.' && arr[n - 1][i + 1] == '.') {
					arr[n - 1][i] = '<';
					arr[n - 1][i + 1] = '>';
					--a;
				}				
			}		
		}
	}

	if (m & 1) {
		for (int i = 0; i + 1 < n; i += 2) {
			if (b > 0) {
				if (arr[i][m - 1] == '.' && arr[i + 1][m - 1] == '.') {
					arr[i][m - 1] = '^';
					arr[i + 1][m - 1] = 'v';
					--b;
				}
			}
		}
	}

	for (int i = 0; i + 1 < n; i += 2) {
		for (int j = 0; j + 1 < m; j += 2) {
			if (arr[i][j] == '.' && arr[i + 1][j] == '.' && arr[i][j + 1] == '.' && arr[i + 1][j + 1] == '.') {
				if (a > 1) {
					arr[i][j] = arr[i + 1][j] = '<';
					arr[i][j + 1] = arr[i + 1][j + 1] = '>';
					a -= 2;
				}
				else if (b > 1) {
					arr[i][j] = arr[i][j + 1] = '^';
					arr[i + 1][j] = arr[i + 1][j + 1] = 'v';
					b -= 2;
				}
			}
		}
	}

	for (int i = 0; i + 1 < n; ++i) {
		for (int j = 0; j + 1 < m; ++j) {    
			if (a > 0 && arr[i][j] == '.' && arr[i][j + 1] == '.') {
				arr[i][j] = '<';
				arr[i][j + 1] = '>';
				--a;
			}

			if (b > 0 && arr[i][j] == '.' && arr[i + 1][j] == '.') {
				arr[i][j] = '^';
				arr[i + 1][j] = 'v';
				--b;
			}            
		}
	}	
                             
	putAns(a == 0 && b == 0);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define N 10
#define MAX 100000007

int main(void){
    int d,g,p[N],c[N];
    cin >> d >> g;
    for(int i=0;i<d;i++) cin >> p[i] >> c[i];

    int ans = MAX;
    for(int bit=0;bit<(1<<d);bit++){
        int s,num,reset_max;
        s = num = 0;
        reset_max = -1;
        for(int i=0;i<d;i++){
            if(bit & (1<<i)){
                s += 100*(i+1)*p[i]+c[i];
                num += p[i];
            }
            else{
                reset_max = i;
            }
        }

        if(s < g){
            int s1 = 100*(reset_max+1);
            int need = (g-s+s1-1)/s1;
            if(need >= p[reset_max]) continue;
            num += need;
        }
        ans = min(ans,num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n;
	cin >> n;
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];

	vector<vll> dp(n, vll(2));
	//a[i]まで，j:切り捨て，切り上げ
	dp[0][0] = 0;
	dp[0][1] = a[0];
	dp[1][0] = max(a[0], a[1]);
	dp[1][1] = max(a[0], a[1]);

    vll v(n, 0);
    //奇数項目まで見て切り上げ，のときの選び方は1通りなので先に求めておく．(*)
    v[0] = a[0];
    for (ll i = 2; i < n; i += 2) v[i] = v[i - 2] + a[i];

	for (ll i = 2; i < n; i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 2][0] + a[i]);
	    if (i % 2 == 0) dp[i][1] = v[i]; // ------------------ (*)
	    else dp[i][1] = dp[i][0]; //偶数項目まで見たときは切り上げも切り捨ても変わらない
	}
	cout << dp[n - 1][0] << endl;
}


Measured memory_bytes: 17252
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;

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

    int min_val = R[0];
    int max_val = R[1] - R[0];

    for(int i = 1; i < n; i++) {
        max_val = max(max_val, R[i] - min_val);
        min_val = min(min_val, R[i]);
    }

    cout << max_val << endl;
    return 0;
}



Measured memory_bytes: 3876
#nは札枚数
n,y = map(int,input().split())

for i in range(n+1):
  for j in range(n-i+1):
    if i*10000 + j*5000 + (n-i-j)*1000 == y:
      print(i,j, n-i-j)
      exit()
print('-1 -1 -1')
  

Measured memory_bytes: 2940
A, B, C = map(int, input().split())
A, B, C = sorted([A, B, C])

if C % 2 == 0:
    print(0)
else:
    d1, d2 = C // 2, (C // 2) + 1
    e = A * B
    print(abs(d1 - d2) * e)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    private int n;
    private int[] A;

    public Main(int n, int[] A) {
        this.n = n;
        this.A = A;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = in.nextInt();
        }
        Main test = new Main(n, A);
        int q = in.nextInt();
        for (int i = 0; i < q; i++) {
            int m = in.nextInt();
            if(test.solve(0, m)) System.out.println("yes");
            else System.out.println("no");

        }
    }

    public boolean solve(int i, int m) {
        if (m == 0) return true;
        if (i >= n) return false;
        boolean result = solve(i + 1, m) || solve(i + 1, m - A[i]);
        return result;
    }
}


Measured memory_bytes: 26844
/* Author: Newbie Abhishek Pandey */
                                       
#include<bits/stdc++.h>
#define Abhi_921 ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define fi(i,j,n) for(int i=j;i<n;i++)
#define fd(i,j,n) for(int i=j;i>n;i--)
#define print(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define inp(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define printe(v) for(auto &i:v){cout<<i<<' ';}cout<<endl;
#define deb(n1) cout<<n1<<endl;
#define pb push_back
#define eb emplace_back
#define vi vector<ll>
#define vll vector<pair<ll,ll>>
#define umap unordered_map<ll,ll>
using namespace std;
const long long mod=1e9+7;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
Abhi_921;
int t;
t=1;
while(t--){
string s;
cin>>s;
int n=s.length();
if(s[n-1]=='s'){
    s+='e';
    s+='s';
}
else{
    s+='s';
}
cout<<s<<endl;
}
return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int n;
  scanf("%d", &n);
  vector<int> A(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
  }
  int ans = 0;
  while (1) {
    bool ok = true;
    for (int i = 0; ok and i < n; ++i) {
      if (A[i] & 1) { ok = false; }
      else { A[i] >>= 1; }
    }
    if (not ok) { break; }
    ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


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

int main()
{
  int arr[33]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<arr[k];
return 0;
}
  


Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import product
N, M = map(int, input().split())
S = [list(map(int, input().split()))[1:] for _ in range(M)]

P = list(map(int, input().split()))

ret = 0
for p in product([0,1], repeat=N):
    f = True
    for i in range(M):
        c = 0
        for s in S[i]:
            c += p[s-1]
        if c%2 != P[i]:
            f = False
    if f: ret += 1

print(ret)




Measured memory_bytes: 9144
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef double db;
typedef vector<db> vd;
typedef vector<vd> vvd;
typedef pair<db, int> P;
int main() {
	ll xs, ys, xt, yt;
	int n;
	cin >> xs >> ys >> xt >> yt;
	cin >> n; 
	n += 2;

	vl X(n), Y(n), R(n);
	for (int i = 1; i < n-1; i++) {
		cin >> X[i] >> Y[i] >> R[i];
	}
	X[0] = xs;
	X[n - 1] = xt;
	Y[0] = ys;
	Y[n - 1] = yt;
	R[0] = 0;
	R[n - 1] = 0;
	vvd C(n, vd(n, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			double d = sqrt((db)(X[i] - X[j])*(X[i] - X[j]) + (Y[i] - Y[j])*(Y[i] - Y[j]));
			C[i][j] = max((db)0, d - R[i] - R[j]);
		}
	}
	vd ANS(n, (db)10000000000);
	priority_queue<P> que;
	que.push(P((db)0, 0));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		db d = -p.first;
		if (d > ANS[v]) {
			continue;
		}
		for (int i = 0; i < n; i++) {
			if (ANS[i] > d + C[v][i]) {
				ANS[i] = d + C[v][i];
				que.push(P(-ANS[i], i));
			}
		}
	}

	cout.precision(13);
	cout << ANS[n - 1] << endl;

	/*for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << C[i][j] << " ";
		}cout << endl;
	}*/
	return 0;
}

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


typedef long long ll;


int main() {
	string s;
	cin >> s;
	int ll = 0, rr = s.size() - 1;
	int ans = 0;
	while (ll < rr) {
		if (s[ll] != s[rr])
			ans++;
		ll++;
		rr--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cat = sc.nextInt();
        int dog = sc.nextInt();
        int x = sc.nextInt();
        if (cat <= x && dog + cat >= x) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21844
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    int A[] = new int[N];
    long sum[] = new long[N+1];
    sum[0] = 0;
    for(int i=0; i<N; i++){
      A[i] = sc.nextInt();
      sum[i+1] = sum[i] + A[i];
    }
    long ans = 1000000000000L;
    for(int i=1; i<N; i++){
      ans = Math.min(ans, Math.abs(sum[N] - sum[i] - sum[i]) );
    }
    out.println(ans);
  }

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

Measured memory_bytes: 87280
#include <iostream>
using namespace std;
int main(){


  int n,a[100000],m,b,result=0,i,j;

  cin>>n;
  for(i=0;i<n;i++) cin>>a[i];
  cin>>m;
  for(i=0;i<m;i++){
    cin>>b;
    for(j=0;j<n;j++) if(b==a[j]){
        result++;
        break;
      }
  }

  cout<<result<<endl;

  return 0;

}

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

using namespace std;

int n, m;
string a[50], b[50];

bool match(int x, int y)
{
    for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
            if(a[i+y][j+x] != b[i][j]) return false;
        }
    }

    return true;
}
int main()
{
    cin >> n >> m;

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

    if(n-m < 1){
        cout << (a[0]==b[0] ? "Yes" : "No") << endl;
        return 0;
    }

    bool cont;
    int j;
    for(i=0; i<n-m; i++){
        for(j=0; j<n-m; j++){
            cont = match(i, j);
            if(cont){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll m2 = 0, m4 = 0;
  for(ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if(a%4==0) m4++;
    else if(a%2==0) m2++;
  }
  cout << ( (n <= 2*m4+1 or n-m2 <= 2*m4) ?"Yes" :"No") << "\n";
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val t = readLine()!!.toInt()
    val (a, b) = readLine()!!.split(" ").map(String::toInt)
    var isContain = false
    for (i in a..b) {
        if (i % t == 0) {
            isContain = true
            break
        }
    }
    if (isContain) {
        println("OK")
    } else {
        println("NG")
    }
}

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

int main() {
	// your code goes here
	ll n;
	cin>>n;
	string str="";
	while(n>0){
		n--;
		char ch=((n%26)+'a');
		str=ch+str;
		n/=26;
	}
	cout<<str<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <cstdio>

int n;
int A[21];

constexpr int mod = 1000000007;

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      int x;
      scanf("%d", &x);
      if(x) A[i] |= 1 << j;
    }
  }

  long long int ans = 0;

  for(int x = 0; x < (1<<n); x++){
    int b = __builtin_parity(x);
    long long int r = 1;
    for(int i = 0; i < n; i++){
      r = r * __builtin_popcount(A[i] & x) % mod;
    }
    if(b) ans += mod - r;
    else  ans += r;
  }
  ans %= mod;

  if(n&1) ans = (mod - ans) % mod;
  printf("%lld\n", ans);
  return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,k,a[500],sum,ans;

bool kr(int x);

signed main() {
    cin >> n >> k;
    rep(i,n) cin >> a[i], sum += a[i];
    int b = sqrt(sum)+1;
    rep1(i,b) {
        if (kr(i)) ans = max(ans,i);
        if (kr(sum/i)) ans = max(ans,sum/i);
    }
    cout << ans << endl;
}

bool kr(int x) {
    vector<int> v;
    int sum=0,hoge=0;
    rep(i,n) {
        int b;
        b = a[i]%x;
        hoge += (x-b)%x;
        if (b) v.pb(b);
    }
    sort(all(v));
    if (hoge%x != 0) return false;
    rep(i,hoge/x) sum += v[i];
    if (sum <= k) return true;
    else return false;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
int f(int n){
    int ans = 0;
    while(n % 2 == 0){
        ans++;
        n /= 2;
    }
    return ans;
}

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 100000000;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        ans = min(ans,f(a[i]));
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll n;
  cin>>n;
  ll a[n][3];
  ll dp[n][3];
  fo(i,n)
  {
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    dp[i][0]=a[i][0];dp[i][1]=a[i][1];dp[i][2]=a[i][2];
  }
  for(ll i=1;i<n;i++)
  {
    dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
  }
  ll ans=max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
  cout<<ans;
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int main(void) {
    for (int c = 1; ; c++) {
        int W, N;
        cin >> W;
        if (W == 0) break;
        cin >> N;
        int v[N], w[N], dp[N + 1][W + 1];
        memset(dp, 0, sizeof(dp));
        for (int i = 0; i < N; i++) scanf("%d,%d", v + i, w + i);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= W; j++) {
                if (w[i] > j) {
                    dp[i + 1][j] = dp[i][j];
                } else {
                    dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
                }
            }
        }
        cout << "Case " << c << ":" << endl;
        for (int j = W; j > 0; j--) {
            if (dp[N][j] > dp[N][j - 1]) {
                cout << dp[N][j] << endl;
                cout << j << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define Rep(i, N) for(int i = 0; i < N; i++)

typedef pair<int, int> Pi;
#define fi first
#define se second


signed main()
{
  int N, M;
  Pi data[10005];
  
  while(cin >> N >> M, N || M) {
    int sum = 0;

    Rep(i, N) {
      cin >> data[i].se >> data[i].fi;
    }
  
    sort(data, data + N, greater<Pi>());
  
    Rep(i, N) {
      int val = min(M, data[i].se);

      data[i].se -= val; M -= val;
    
      sum += data[i].se * data[i].fi;
    }
  
    cout << sum << endl;
  }
  return 0;
}
  

Measured memory_bytes: 3252
def edit_dist(S0, S1):
    i = len(S0)
    j = len(S1)
    dp = [i for i in range(len(S1) + 1)]

    for i in range(1, i+1):
        dp_prev = dp[:]
        dp[0] = i
        for j in range(1, j+1):
            dp[j] = min(dp_prev[j-1] + (S0[i-1] is not S1[j-1]), dp_prev[j] + 1, dp[j-1] + 1)
    return dp[-1]

if __name__ == "__main__":
    s0 = input()
    s1 = input()
    print(edit_dist(s0, s1))


Measured memory_bytes: 5596
#include<iostream>
#include<string>
using namespace std;
int main(){
  	string s;
  	cin>>s;
  	int x=0;
  	for(int i=0;i<s.size();++i){
    	if(s[i]=='+')
          ++x;
      	else if(s[i]=='-')
          --x;
    }
  	cout<<x<<"\n";
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin>>n;

	cout << n*(n-1)/2 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
ll expo(ll a,ll b)
{
  if(b==0)return 1;
  ll p=expo(a,b/2);
  p=p;
  p=(p*p);
 
  return b&1? (p*a)%mod :p;
}
ll bC(ll n, ll k)  
{  
  ll res = 1; 
  if ( k > n - k )  
  k = n - k;  
  for (ll i = 0; i < k; ++i)  
  {  
  res *= (n - i);  
  res /= (i + 1);  
  }  
  
  return res;  
}  

int main(int argc, char const *argv[])
{ 
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);


 string s;
 cin>>s;
 int r=0;
int ans=0;
 for(int i=0;i<s.length();i++)
 {
  if(s[i]=='R')r++;
  else{
    ans=max(ans,r);
    r=0;
  }
 }
ans=max(ans,r);
 cout<<ans<<endl;

}
 
 

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

using namespace std;
long long  mod=1000000007;
int main()
{
   int n,c;
   cin>>n>>c;

   char grid[n][c];

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

   long long  dp[n][c];
   memset(dp,0,sizeof(dp));
   for(int i=0;i<n;i++)
   {
      if(grid[i][0]!='#')
      {
        dp[i][0]=1;   
      }
      else
      {
        break;
      }
   }

   for(int i=0;i<c;i++)
   {
      if(grid[0][i]!='#')
      {
         dp[0][i]=1;
     
      }
      else
      {
           break;
      }  
   }

   for(int i=1;i<n;i++)
   {
       for(int j=1;j<c;j++)
       {

           if(grid[i][j]!='#')
            {
                dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
            }
       }
   }



     cout<<dp[n-1][c-1]%mod;



}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
using namespace std;
struct Card
{
    char suit;
    int value;
};

void out_vec(vector<Card> vec, int len_vec)
{
    for (int i = 0; i < len_vec; i++)
    {
        cout << vec[i].suit << vec[i].value;
        if (i == len_vec - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

vector<Card> selectionSort(vector<Card> vec, int len_vec)
{
    // int swap_count = 0;
    for (int i = 0; i < len_vec; i++)
    {
        int min_ind = i;
        for (int j = i; j < len_vec; j++)
        {
            if (vec[min_ind].value > vec[j].value)
            {
                min_ind = j;
            }
        }
        if (i != min_ind)
        {
            swap(vec[i], vec[min_ind]);
            // swap_count++;
        }
    }
    // out_vec(vec, len_vec);
    // cout << swap_count << "\n";
    return vec;
}

vector<Card> bubbleSort(vector<Card> vec, int len_vec)
{
    bool sort_flag = true;
    // int swap_count = 0;
    while (sort_flag == true)
    {
        sort_flag = false;
        for (int i = len_vec - 1; i >= 1; i--)
        {
            if (vec[i].value < vec[i - 1].value)
            {
                swap(vec[i], vec[i - 1]);
                sort_flag = true;
                // swap_count++;
            }
        }
    }
    // out_vec(vec, len_vec);
    // cout << swap_count << "\n";
    return vec;
}

void isStable(vector<Card> input_vec, vector<Card> output_vec, int len_vec)
{
    out_vec(output_vec, len_vec);
    int i = 0;
    while (i < len_vec)
    {
        int j = i + 1;
        int i_value = output_vec[i].value;
        vector<Card> part_out = {output_vec[i]};
        while (output_vec[j].value == i_value && j < len_vec)
        {
            part_out.emplace_back(output_vec[j]);
            j++;
        }
        if (part_out.size() >= 2)
        {
            // vector<Card> part_in = {};
            int k = 0;
            int part_count = 0;
            while (part_count < part_out.size() && k < len_vec)
            {
                if (input_vec[k].value == i_value)
                {
                    if (input_vec[k].suit != part_out[part_count].suit)
                    {
                        cout << "Not stable\n";
                        return;
                    }
                    part_count++;
                }
                k++;
            }
        }
        i += part_out.size();
    }
    cout << "Stable\n";
    return;
}

int main()
{
    int N;
    cin >> N;
    vector<Card> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i].suit >> A[i].value;
    isStable(A, bubbleSort(A, N), N);
    isStable(A, selectionSort(A, N), N);
    return 0;
}


Measured memory_bytes: 3144
a = list(int(i) for i in input().split()) 
ct = 0
for i in range (0,a[0]):
 c = int(0)
 d = int(i+1)
 for j in range(0,5):
  c += d%10
  d  = d//10
 if a[1]<=c and c <=a[2]:
  ct += i+1
print(ct)

Measured memory_bytes: 3060
chk t d =
  let a = foldl (\ a (s:f:_) -> a + (f-s) ) 0 d
  in
    if a >= t
    then "OK"
    else show (t-a)

ans ([0]:_) = []
ans ([t]:[n]:x) =
  let d = take n x
      r = chk t d
      y = drop n x
  in
    r:ans y

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ putStrLn o

Measured memory_bytes: 4140
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
typedef long long LL;

int main()
{
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	if (X < Y) {
		swap(X, Y);
		swap(A, B);
	}

	int allC = X * 2 * C;
	int AorB = A * X + B * Y;
	int CsAB = Y * 2* C + (X - Y) * A;

	int cmin = min({ allC, AorB, CsAB });

	cout << cmin << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll memo[300010][3][2][3];
bool done[300010][3][2][3];
char inp[300010];
int n;
ll dp(int a, int sz, int ind, int found)
{
	if (a == n)
	{
		if (found == 2 || (found == 1 && sz == 0)) return 1;
		return 0;
	}
	if (sz > 2) sz-=2;
	ind%=2;
	if (done[a][sz][ind][found]) return memo[a][sz][ind][found];
	done[a][sz][ind][found] = 1;
	ll ans = 0;
	ll ans2 = 0;
	{
		if (sz == 0 && found == 1 && ind == 1) ans = dp(a+1, 0, ind+1, 2);
		else if (sz == 0 && found == 0 && ind == 0) ans = dp(a+1, 0, ind+1, 1);
		else if (sz == 0) ans = dp(a+1, 0, ind+1, found);
		else if (sz == 1) ans = dp(a+1, 0, ind, found);
		else
		{
			ans = dp(a+1, 0, ind+1, found);
		}
	}
	{
		ans2 = dp(a+1, sz+1, ind, found);
	}
	if (inp[a] == '0') return memo[a][sz][ind][found] = ans2;
	if (inp[a] == '1') return memo[a][sz][ind][found] = ans;
	else return memo[a][sz][ind][found] = (ans + ans2)%mod;
}
int main()
{
	scanf(" %s", inp);
	n = strlen(inp);
	ll ans = dp(0, 0, 0, 0);
	printf("%lld\n", ans);
}

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

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

}

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

int main() {
	int N,D;
	cin >> N>>D;
	int ans;
	if((N %(2 * D + 1))==0)ans = N / (2 * D + 1);
	else ans = (N / (2 * D + 1))+1;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >> a;
    vector<int> A(a);
    int MIN = 10000;
    for(int i = 0;i<a;i++)
        cin >> A.at(i);
    for(int i = 0;i<100;i++){
        int jud = i;
        int up = 0;
        int down = 0;
        for(int j = 0;j<a;j++){
            if(j <= jud){
                down += A.at(j);
            }
            else
            {
                up += A.at(j);
            }
        }
        MIN = min(MIN,abs(up-down));
    }
    cout << MIN << endl;
}

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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

int dfs(int N, string S) {
    int ret = 0;
    if(stol(S) <= N) {
        if(S.find('7') != string::npos &&
           S.find('5') != string::npos &&
           S.find('3') != string::npos) {
            ret++;
        }

        ret += dfs(N, S + "7");
        ret += dfs(N, S + "5");
        ret += dfs(N, S + "3");
    }

    return ret;
}

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

    int N;
    std::cin >> N;
    std::cout << dfs(N, "0") << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
int main() {
  sci(W);scii(a,b)
  int ans;
  if(a<=b&&b<=a+W)ans=0;
  else ans=min(abs(a-(b+W)), abs(b-(a+W)));
  printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;

const int dx[]={1,1,0,-1,-1,-1,0,1},dy[]={0,-1,-1,-1,0,1,1,1};
int field[50][50];
bool visited[50][50];

int main(){
	for(int w,h;scanf("%d%d",&w,&h),w;){
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			scanf("%d",field[i]+j);
			visited[i][j]=false;
		}

		int cnt=0;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			if(field[i][j]==1 && !visited[i][j]){
				visited[i][j]=true;
				queue<pii> qu;	qu.push(mp(i,j));
				while(!qu.empty()){
					pii a=qu.front();	qu.pop();
					for(int k=0;k<8;k++){
						int xx=a.second+dx[k],yy=a.first+dy[k];
						if(0<=xx && xx<w && 0<=yy && yy<h
						&& field[yy][xx]==1 && !visited[yy][xx]){
							qu.push(mp(yy,xx));
							visited[yy][xx]=true;
						}
					}
				}
				cnt++;
			}
		}

		printf("%d\n",cnt);
	}

	return 0;
}


Measured memory_bytes: 2632
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
template<typename T> inline void in(T &e){cin>>e;}
template<typename T> inline void out(T e){cout<<e<<endl;}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

const int MAX_N=500;
int n,m,q;
int ary[MAX_N+1][MAX_N+1];

int l,r;

signed main(){
    io();
    cin>>n>>m>>q;
    rep(i,m) {
        scanf("%lld %lld",&l,&r);
        ary[l][r]++;
    }

    REP(i,1,n+1){
        REP(j,1,n+1){
            ary[i][j]+=ary[i][j-1];
        }
    }
    REP(i,1,n+1){
        REP(j,1,n+1){
            ary[i][j]+=ary[i-1][j];
        }
    }

    while(q--){
        scanf("%lld %lld",&l,&r);
        out(ary[r][r]-ary[r][l-1]-ary[l-1][r]+ary[l-1][l-1]);
    }
    
    return 0;
}


Measured memory_bytes: 2944
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
   long double a,b,c;
   while(cin>>a>>b>>c)
   {
      // cout<<sqrt(a)<<sqrt(b)<<sqrt(c)<<'\n';
       if((a+b+2*sqrt(a*b))<c)
       cout<<"Yes\n";
       else cout<<"No\n";
   }
}


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

signed main(void){
 int A,B,N; cin >> A >> B >> N;
  if( B-1 <= N ){ cout << (A*(B-1))/B << endl;}
  else{ cout << (N*A)/B << endl;}
  
  return 0;
}

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

using namespace std;

string s;

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

	cin >> s;
	set<char> c;
	for (int i=0;i<s.size();i++)
		c.insert(s[i]);
	if (c.size() == 1) cout << "No";
	else cout << "Yes";	
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> vec(4);
    for(int i=0;i<4;i++){
        vec[3-i]=N%10;
        N/=10;
    }
    int i,j,k;
    int ans=0;
    for(i=0;i<2;i++){
        for(j=0;j<2;j++){
            for(k=0;k<2;k++){
                if(i%2==1){
                    ans=vec[0]+vec[1];
                }
                else{
                    ans=vec[0]-vec[1];
                }
                if(j%2==1){
                    ans+=vec[2];
                }
                else{
                    ans-=vec[2];
                }
                if(k%2==1){
                    ans+=vec[3];
                }
                else{
                    ans-=vec[3];
                }
                if(ans==7){
                    cout << vec[0];
                    if(i%2==1){
                        cout << "+";
                    }
                    else{
                        cout << "-";
                    }
                    cout << vec[1];
                    if(j%2==1){
                        cout << "+";
                    }
                    else{
                        cout << "-";
                    }
                    cout << vec[2];
                    if(k%2==1){
                        cout << "+";
                    }
                    else{
                        cout << "-";
                    }
                    cout << vec[3] << "=" << 7 << endl;;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}

	public static long lcm(long m,long n) {
		return m * n / gcd(m ,n);
	}


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A = Long.parseLong(sc.next());
		Long B = Long.parseLong(sc.next());
		Long C = Long.parseLong(sc.next());
		Long D = Long.parseLong(sc.next());
		sc.close();

		long x = A / C;
		long y = B / C;
		long numberC = 0;
		if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		}

		long p = A / D;
		long q = B / D;
		long numberD = 0;
		if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		}

		long E = lcm(C ,D);
		long s = B / E;
		long t = A / E;
		long numberE = 0;
		if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		}

		long result = numberC + numberD - numberE;
		long answer = B - A + 1 -result;
		System.out.println(answer);
	}
}


Measured memory_bytes: 21844
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, N):
        self._data_size = N
        self._roots = [-1] * N

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def unite(self, x, y):
        x = self[x]
        y = self[y]
        if x == y:
            return
        elif self._roots[y] < self._roots[x]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def is_connected(self, x, y):
        return self[x] == self[y]


def main():
    N, Q, *TUV = map(int, open(0).read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 145256
from operator import itemgetter

N = int(input())
a = [0] * N
b = [0] * N
c = [0] *N


for i in range(N):
    a[i],b[i] = map(int,input().split())
    c[i] = [b[i],a[i]]
   
c.sort()
sums = 0
correct = 1
for i in range(N):
    sums+=c[i][1]
    if c[i][0] < sums:
        correct=0
        break
        
if correct:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38844
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 5005;
const int base = 1e9 + 7;

int main() {
    ll n, m;
    cin >> n >> m;
    ll res = min(n, m / 2);
    n -= res;
    m -= res * 2;
    res += m / 4;
    cout << res << endl;
}

Measured memory_bytes: 256
from collections import*
n,p=map(int,input().split())

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b += 1
    if n > 1:
        fct.append(n)
    return Counter(fct)
#print(factorize(p))
x=factorize(p)
#print(x)
ans=1
for k,v in x.items():
    if v>=n:
        for i in range(v//n):
           ans*=k
print(ans)

Measured memory_bytes: 3316
/*
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

void solve(int test_case) {
	ll n;
	cin>>n;
	for(ll i=sqrt(n);i>=1;i--) {
		if(n%i==0) {
			cout<<(i-1)+(n/i-1);
			break;
		}
	}
}

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: 3664
import java.util.*;
class Main
{
  public static void main (String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    System.out.println(Math.min(Math.abs(a-b) + Math.abs(a-c),
                       Math.min(Math.abs(a-b) + Math.abs(b-c),
             			        Math.abs(b-c) + Math.abs(a-c))));
  }
}

Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    queue<ll> q;

    for (int i = 1; i < 10; i++)
    {
        q.push(i);
    }

    for (int i = 1; i < 100010; i++)
    {
        ll ans = q.front();
        q.pop();

        if (i == k)
        {
            cout << ans << endl;
            break;
        }

        if (ans % 10 - 1 >= 0)
        {
            q.push(10 * ans + ans % 10 - 1);
        }

        q.push(10 * ans + ans % 10);

        if (ans % 10 + 1 < 10)
        {
            q.push(10 * ans + ans % 10 + 1);
        }
    }

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n,m;
    cin>>n>>m;
    int a[n];
    priority_queue<pair<int,int> >s;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s.push(mp(a[i],1));
    }
    vector<int>b(m),c(m);
    for(int i=0;i<m;i++)
    {
        cin>>b[i]>>c[i];
        s.push(mp(c[i],b[i]));
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
         priority_queue<pair<int,int> >::value_type it;
        it=s.top();
         s.pop();
         ans+=it.first;
         if(it.second>1)
         {
             it.second--;
             s.push(it);
         }
    }
    cout<<ans<<endl;


}








































Measured memory_bytes: 6296
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      string s;
      cin >> s;
      for(int i=0; i<s.size(); i++){
        if(s.substr(i,2)=="AC") {cout << "Yes" << endl;return 0;}
      }
      cout << "No" << endl;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
LL f[111][111];
int h,w;
int a[111][111],b[111][111];
int x=81*81*2;
int v[88][88][10020];
int main() {
    ios::sync_with_stdio(false);
//    f[1][1]=1;
//    for(int i=1;i<=40;i++){
//        for(int j=1;j<=40;j++){
//            if(i==1&&j==1)continue;
//            f[i][j]=f[i-1][j]+f[i][j-1];
//        }
//    }
//    cout<<f[40][40]<<endl;
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>b[i][j];
            if(a[i][j]<b[i][j])swap(a[i][j],b[i][j]);
        }
    }
    v[1][1][a[1][1]-b[1][1]]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(i<h)
                for(int k=0;k<10020;k++){
                    if(v[i][j][k]){
                        int l=abs(k-a[i+1][j]+b[i+1][j]);
                        if(l<10020)v[i+1][j][l]=1;

                        int r=abs(k+a[i+1][j]-b[i+1][j]);
                        if(r<10020)v[i+1][j][r]=1;
                    }
                }
            if(j<w)
                for(int k=0;k<10020;k++){
                    if(v[i][j][k]){
                        int l=abs(k-a[i][j+1]+b[i][j+1]);
                        if(l<10020)v[i][j+1][l]=1;
                        int r=abs(k+a[i][j+1]-b[i][j+1]);
                        if(r<10020)v[i][j+1][r]=1;
                    }
                }
        }
       // cout<<endl;
    }
    int ans=11111111;
    for(int j=0;j<2000;j++){
        if(v[h][w][j])return cout<<j<<endl,0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 278912
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  int K, S;
  cin >> K >> S;
  int count = 0;

  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (z >= 0 && z <= K) {
        count++;
        // cout << x << " " << y << " " << z << endl;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		HashMap<String, String> map1=new HashMap<String, String>();
		map1.put(" ", "101");
		map1.put("'", "000000");
		map1.put(",", "000011");
		map1.put("-", "10010001");
		map1.put("\\.", "010001");
		map1.put("\\?", "000001");
		map1.put("A", "100101");
		map1.put("B", "10011010");
		map1.put("C", "0101");
		map1.put("D", "0001");
		map1.put("E", "110");
		map1.put("F", "01001");
		map1.put("G", "10011011");
		map1.put("H", "010000");
		map1.put("I", "0111");
		map1.put("J", "10011000");
		map1.put("K", "0110");
		map1.put("L", "00100");
		map1.put("M", "10011001");
		map1.put("N", "10011110");
		map1.put("O", "00101");
		map1.put("P", "111");
		map1.put("Q", "10011111");
		map1.put("R", "1000");
		map1.put("S", "00110");
		map1.put("T", "00111");
		map1.put("U", "10011100");
		map1.put("V", "10011101");
		map1.put("W", "000010");
		map1.put("X", "10010010");
		map1.put("Y", "10010011");
		map1.put("Z", "10010000");

		HashMap<String, String> map2=new HashMap<String, String>();
		map2.put("00000", "A");
		map2.put("00001", "B");
		map2.put("00010", "C");
		map2.put("00011", "D");
		map2.put("00100", "E");
		map2.put("00101", "F");
		map2.put("00110", "G");
		map2.put("00111", "H");
		map2.put("01000", "I");
		map2.put("01001", "J");
		map2.put("01010", "K");
		map2.put("01011", "L");
		map2.put("01100", "M");
		map2.put("01101", "N");
		map2.put("01110", "O");
		map2.put("01111", "P");
		map2.put("10000", "Q");
		map2.put("10001", "R");
		map2.put("10010", "S");
		map2.put("10011", "T");
		map2.put("10100", "U");
		map2.put("10101", "V");
		map2.put("10110", "W");
		map2.put("10111", "X");
		map2.put("11000", "Y");
		map2.put("11001", "Z");
		map2.put("11010", " ");
		map2.put("11011", ".");
		map2.put("11100", ",");
		map2.put("11101", "-");
		map2.put("11110", "'");
		map2.put("11111", "?");

		for(; sc.hasNext();){
			String s=sc.nextLine();
			for(Entry<String, String> entry : map1.entrySet())
				s=s.replaceAll(entry.getKey(), entry.getValue());
			for(; s.length()%5!=0;)
				s+="0";
			// println(s);
			int len=s.length();
			int n=len/5;
			for(int i=0; i<n; i++){
				String ss=s.substring(5*i, 5*i+5);
				for(Entry<String, String> entry : map2.entrySet())
					ss=ss.replaceAll(entry.getKey(), entry.getValue());
				print(ss);
			}
			println("");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 13000