akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long MOD = 1000000007;


long long fact[210000];
long long inv[210000];
long long finv[210000];
long long init(){
	fact[0]=finv[0]=1;
	inv[1]=1;
	for(int i=2;i<210000;i++){
		inv[i]=(MOD-(MOD/i)*inv[MOD%i]%MOD)%MOD;
	}
	for(int i=1;i<210000;i++){
		fact[i]=fact[i-1]*i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
long long comb(long long n, long long k){
    if( n < k || k < 0 )return 0;
    return fact[n]*finv[n-k]%MOD*finv[k]%MOD;
}

long long routecalc(long long h,long long w){
    h--; w--;
    long long n = h + w;
    return comb(n,h);
}

int main(){
    init();
    long long H, W, A, B; cin >> H >> W >> A >> B;

    vector<long long> sub_ans(W-B);
    long long ans = 0;

    for( int i = 0; i < W-B; i++ ){
        sub_ans[i] = routecalc( H-A, B+1+i );
    }

    for( int i = 0; i < W-B; i++ ){
        ans += sub_ans[i] * routecalc( A, W-B-i );
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6016
n = int(input())
t, a = map(int, input().split())
h = map(int, input().split())
h = [abs(t - _h * 0.006 - a) for _h in h]
m = min(h)
for i, v in enumerate(h):
    if v == m:
        print(i + 1)
        break


Measured memory_bytes: 3060
///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;

//long int ar[10013];
//long int gcd(long int a, long int b)
//{
//    if(b==0)
//        return a;
//    return gcd(b,a%b);
//}
//void sieve()
//{
//    long long int i,j,k = 0;
//    memset(ar,0,sizeof(ar));+
//    ar[1] = 1;
//    for(i=2; i<=713; i++)
//    {
//        if(ar[i]==0)
//        {
//            for(j=i+i; j<=713; j+=i)
//            {
//                ar[j] = 1;
//            }
//        }
//    }
//}

void Ok()
{
    long int a,b,c,d,e,f,g,h,t,i,j,k,l,m,n,Min,Max;
    long int ans_1,ans_2,ans_3,cnt_1,cnt_2,cnt_3,flag_1,flag_2,flag_3,temp,sum;
    double aa,bb,cc,dd,ee,ff,gg;
    char aaa,bbb,ccc,ddd;
    string spc,in,store;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>a>>b>>c;
    aa = c;
    bb = a/aa;
    if(bb<=b)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return;
}

int main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    Ok();

    return 0;
}


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

int main() {
	long long A;
  cin >> A;
  string B;
  cin >> B;
  //cout << B.size() << endl;
  string C;
	for(int i = 0 ; i < B.size() ; i++){
    	if(B.at(i)!='.') {
          C += B.at(i);
        }
    }
  //cout << C <<endl;
  
  
  int num;
  num = stoi(C);
  
  cout << num*A/100 << endl;
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define pii pair<int64_t,int64_t>
#define mp make_pair
#define whole(v) begin(v),end(v)
#define print(c,n) for(int64_t i=0;i<n;i++) cout << c[i] << " ";
#define MOD 1000000007
void solve(){
	int n;
	cin >> n;
	int arr[n];
	for(int i=0;i<n;i++) cin >> arr[i];
	if(n%2==1) {
		cout << 0;
		return ;
	}
	sort(arr,arr+n);
	int mid = n/2;
	int start=arr[mid-1],end = arr[mid];
	cout << end-start ;
}
int main(){
	
	solve();
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
struct Pot{
  int S;
  int H;
  Pot():S(0),H(0){}
  Pot(int S, int H):S(S),H(H){}
};

double height(const int idx, const int water_, const vector< vector< Pot > >& P){
  double res = 0.0;
  double water = (double)water_;
  vector<Pot> p = P[idx];

  for(int i = 0; i < p.size(); i++){
    Pot pot = p[i];
    int pot_size = p[i].S * p[i].H;
    if(water >= pot_size){
      res += p[i].H;
      water -= pot_size;
    }else{
      res += water / p[i].S;
      break;
    }
  }
  return res;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  vector< vector< Pot > > P(N);
  for(int i = 0; i < N; i++){
    int K; cin >> K;
    for(int j = 0; j < K; j++){
      int S, H; cin >> S >> H;
      P[i].push_back( Pot(S, H) );
    }
  }

  double dp[N+1][M+1];
  for(int i = 0; i <= N; i++) for(int j = 0; j <= M; j++) dp[i][j] = -5000;

  for(int j = 0; j <= M; j++){
    dp[0][M-j] = height(0, j, P);
    //cout << dp[0][j] << endl;
  }

  for(int i = 1; i < N; i++){
    for(int j = M; j >= 0; j--){
      for(int k = 0; k <= j; k++){
        dp[i][j-k] = max(dp[i][j-k], dp[i-1][j] + height(i, k, P));
      }
    }
  }

  //cout << dp[1][1] << endl;
  double ans = 0;
  for(int j = 0; j <= M; j++){
    ans = max(ans, dp[N-1][j]);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char inputInt[2000];
	while(true)
	{
		cin.getline(inputInt, 2000);
		int length = strlen(inputInt);
		int sum = 0;
		if(length == 1 && inputInt[0] == '0')
			break;
		for(int i = 0;i < length;i++)
		{
			sum += inputInt[i] - '0';
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
def dfs(n, i, s, maxi):
    global ans
    maxi = max(i, maxi)
    s += chr(i)
    if n == N:
        ans += [s]
        return
    for ii in range(97, maxi+2):
        dfs(n+1, ii, s, maxi)

N = int(input())
i = 97
ans = []
dfs(1, 97, '', 97)
ans = sorted(ans)
for a in ans:
    print(a)

Measured memory_bytes: 64740
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
int INF = 0x3f3f3f3f;

int s[20];
ll res = 0;
vector<int> l(1);
vector<int> r(1);
vector<int> cc(1);
vector<int> dd(1);


void dfs(int prev, int n, int limit, int m) {
    if(n == limit + 1) {
        ll tsum = 0;
        for(int i = 1; i < l.size(); ++i) {
            if(s[r[i]] - s[l[i]] == cc[i]) {
                tsum += dd[i];
            }
        }
        res = max(res, tsum);
        return;
    }

    for(int i = prev; i <= m; ++i) {
        s[n] = i;
        dfs(i, n + 1, limit, m);
    }
}

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < q; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        l.push_back(a); r.push_back(b); cc.push_back(c); dd.push_back(d);
    }
    dfs(1, 1, n, m);
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3572
#include <stdio.h>

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

int main(void) {
	int a,b;
	while(scanf("%d%d",&a,&b)==2) {
		if(a<=0 || b<=0)return 1;
		printf("%d\n",gcd(a,b));
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			long X = scan.nextLong();
			long K = scan.nextLong();
			long D = scan.nextLong();



		long absX = Math.abs(X);
		long ans;
		if(absX/D<K) {//あまりにたどり着くまでの回数よりKが大きいなら
			long k = K-absX/D;
			ans = k%2==0?absX%D:D-absX%D;
			System.out.println(ans);
		}else {
			 ans = absX-D*K;
			System.out.println(ans);
		}


		}
	}


}


Measured memory_bytes: 35784
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef unsigned long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()


int main(){

    ll X, Y, Z, K;    
    cin >> X >> Y >> Z >> K;

    vector<ll> x(X);
    for(int i = 0; i < X; i++){
        cin >> x[i];
    }
    vector<ll> y(Y);
    for(int i = 0; i < Y; i++){
        cin >> y[i];
    }
    vector<ll> z(Z);
    for(int i = 0; i < Z; i++){
        cin >> z[i];
    }

    vector<ll> xy(X * Y);
    for(int i = 0; i < X; i++){
        for(int j = 0; j < Y; j++){
            xy[i*Y+j] = x[i] + y[j];
        }
    }
    sort(rall(xy));
    sort(rall(z));


    ll xy_size = min(K, X*Y);
    vector<ll> ans(xy_size * Z);
    for(int i = 0; i < xy_size; i++){
        for(int j = 0; j < Z; j++){
            ans[i*Z+j] = xy[i] + z[j];
        }
    }
    sort(rall(ans));

    for(int i = 0; i < K; i++){
        cout << ans[i] << endl;
    }


}

Measured memory_bytes: 31616
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int cnt = 0;
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1; i * j < n ;j++)
        {
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

typedef int ll;
typedef double dd;

void Solve(ll) {
  ll n;
  cin >> n;
  vector<ll> cols(n);
  RARA(c, cols) cin >> c;
  ll res = 0, pred = -1, cnt = 0;
  RARA(c, cols) {
    if (c == pred)
      ++cnt;
    else {
      res += cnt / 2;
      pred = c;
      cnt = 1;
    }
  }
  res += cnt / 2;
  cout << res << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 1;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

map <int, int> ss;
int a[nax];
int b[nax];
int ca[nax];
int cb[nax];
pair <int, int> c[nax];
pair <int, int> d[nax];
int n;

int top;

int main () {
    scanf("%d", &n);

    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d %d", a + i, b + i);
        ca[i] = a[i];
        cb[i] = b[i];
        c[i] = make_pair(ca[i], cb[i]);
    }
  //  cb[0] = INT_MAX;

    sort(ca + 1, ca + 1 + n);
    sort(cb + 1, cb + 1 + n);



    sort(c + 1, c + 1 + n);


    int cR = c[1].second;
    int cL = c[1].first;
    for (int i = 2 ; i <= n ; ++ i) {

        if (c[i].first > cR) {
            d[++ top] = make_pair(cL, cR);
            cR = c[i].second;
            cL = c[i].first;
        } else {
            cR = max(cR, c[i].second);
        }
    }

    d[++ top] = make_pair(cL, cR);


    long long ans = 0;
    if (n % 2) {
        for (int i = 1 ; i <= top ; ++ i) {
            int l = d[i].first, r = d[i].second;

            int min_bound = ca[(n + 1) / 2];
            int max_bound = cb[(n + 1) / 2];

            l = max(l, min_bound);
            r = min(r, max_bound);

            if (l > r) continue;

            ans += r - l + 1;
        }

        cout << ans;
    } else {

       /// throw;
        #define int long long

        int l_min = INT_MAX, l_max = INT_MIN;

        for (int i = 1 ; i <= top ; ++ i) {
            int l = d[i].first, r = d[i].second;

            int min_bound = ca[n / 2];
            int max_bound = cb[n / 2];

            l = max(l, min_bound);
            r = min(r, max_bound);

            if (l > r) continue;

            l_min = min(l_min, l);
            l_max = max(l_max, r);

        }


        int r_min = INT_MAX, r_max = INT_MIN;


        for (int i = 1 ; i <= top ; ++ i) {
            int l = d[i].first, r = d[i].second;
            int min_bound = ca[n / 2 + 1];
            int max_bound = cb[n / 2 + 1];

            l = max(l, min_bound);
            r = min(r, max_bound);

            if (l > r) continue;

            r_min = min(r_min, l);
            r_max = max(r_max, r);

        }


        int all = r_max + l_max - r_min - l_min;

        cout << all + 1;
    }


}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 9928
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()

s = sum([int(digit) for digit in str(n)])
if n % s == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3696
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>

using namespace std;

typedef long long ll;

const int MAXN = 100005;
const ll MOD = 1000000007;

int n;

ll ans;
ll a[MAXN];
ll inv[MAXN];
ll sum[MAXN];

ll power(ll a,ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void init()
{
	inv[0] = 1;
	for (int i = 1;i <= n;i++)
		inv[i] = inv[i - 1] * i % MOD;
	inv[n] = power(inv[n],MOD - 2);
	for (int i = n;i >= 1;i--)
	{
		ll tmp = inv[i];
		inv[i] = inv[i] * inv[i - 1] % MOD;
		inv[i - 1] = tmp * i % MOD;
	}
	for (int i = 2;i <= n;i++)
		sum[i] = (sum[i - 1] + inv[i]) % MOD;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	init();
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	for (int i = 1;i <= n;i++)
		(ans += (sum[i] + sum[n - i + 1] + 1) * a[i]) %= MOD;
	for (int i = 1;i <= n;i++)
		(ans *= i) %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define FOR(i,k,n) for(ll i=(k);i<(ll)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)
 
using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin>>s;
  for(auto&&e:s) {
    if(e=='?') e = 'D';
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 3732
<?php
fscanf(STDIN, "%d", $N);
$A = explode(" ", trim(fgets(STDIN)));
$total = array_sum($A);
$l = 0;
$ans = PHP_INT_MAX;
for ($i = 0; $i < $N; $i++) {
    $l += $A[$i];
    $ans = min($ans, abs($l - $total + $l));
}
echo $ans;


Measured memory_bytes: 23200
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = r*r*pi;
        double length = 2*pi*r;
        System.out.printf("%f %f",area,length);
        sc.close();

    }

}


Measured memory_bytes: 28376
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>

using namespace std;

long long MOD = 1000000007;

int main(){
    double a, b, x;
    cin >> a >> b >> x;
    double ans=0.0;
    if(x<a*a*b/2){
        ans=atan(b*b*a/2/x);
    }else{
        ans = atan(2*b/a-2*x/(a*a*a));
    }
    ans*=1/3.1415926535897932*180;
    cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
X,N=map(int,input().split())
p=list(map(int,input().split()))
d=10000
ans=0

for i in range(102):
    if i in p:
        pass
    else:
        if abs(X-i)<d:
            d=abs(X-i)
            ans=i
        else:
            pass


print(ans)

            


Measured memory_bytes: 9176
a = [i*i for i in range(400)]
n,d = map(int,input().split())
x = []
for _ in range(n):
    x.append(list(map(int,input().split())))
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        s = 0
        for k in range(d):
            s += (x[i][k]-x[j][k])**2
        if s in a:
            ans += 1
print(ans)


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

using namespace std;

long long dp[2005][2005];

int main()
{
	int n;
	pair<int, int>a[2005];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a, a + n, [&](pair<int, int> x, pair<int, int> y) {return x.first > y.first; });

	int p;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; (p = i + j) < n; j++)
		{
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + (long long)a[p].first * abs(a[p].second - i));
			dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + (long long)a[p].first * abs(a[p].second - (n - (j + 1))));
		}
	}

	long long ans = 0;
	for (int i = 0; i <= n; i++)
	{
		ans = max(ans, dp[i][n - i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26328
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */
 
#include <iostream>
#include <fstream>
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, int> pii;
 
const int MOD = 1e9 + 7;
const int maxn = 123456;
const double EPS = 1e-8;
const ll inf = 1e18;
 
ll a[maxn], b[maxn];
class DFlippingSigns {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in>>N;
        ll res = -inf, sum = 0;
        for(int i = 0; i < N; ++i)in>>a[i], sum += a[i], b[i] = a[i];
        res = max(res, sum);
        sort(a, a+N);
        for(int i = 1; i < N; i += 2){
            // if(sum - 2*a[i] - a[i-1]*2 >= res){
            //    a[i] = -a[i];
            //    a[i-1] = -a[i-1];
            sum -= (2*a[i] + 2*a[i-1]);
            res = max(res, sum); 
        }
        out<<res<<endl;
    }
};
 
 
int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    DFlippingSigns solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

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

int main(void){
	int N, T;
	cin >> N >> T;
	int rc = 1001;
	for(int i = 0; i < N ; i++){
		int c, t;
		cin >> c >> t;
		if(T >= t && rc > c){
			rc = c;
		}
	}
	if(rc != 1001)	cout << rc << endl;
	else cout << "TLE" << endl;
	return 0;

}


Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n, k;cin>>n>>k;
  vector<int> p(n);
  rep(i, n)cin>>p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k){
    ans += p[i];
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3552
#include <iostream>

using namespace std;

int main() {
	int n, k, x, y, sum;
	cin >> n;
	cin >> k >> x >> y;
	sum = 0;

	if (n <= k) {
		sum = x * n;
	}
	else {
		sum = x * k + y * (n - k);
	}
	cout << sum << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    ll k;
    cin>>n>>m>>k;
    vector<ll> a(n),b(m);
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>b[i];

    vector<ll> sa(n+1,0);
    vector<ll> sb(m+1,0);
    sa[0]=0;
    sb[0]=0;
    rep(i,n) sa[i+1]=sa[i]+a[i];
    rep(i,m) sb[i+1]=sb[i]+b[i];

    /*
    rep(i,n) cout<<sa[i]<<" ";
    cout<<endl;
    rep(i,m) cout<<sb[i]<<" ";
    cout<<endl;*/

    int ans=0;
    int id=m;
    rep(i,n+1){
        while(id>=0 && sa[i]+sb[id]>k){
            id--;
        }

        if(id<0) break;
        ans=max(ans,i+id);
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 9576
#include <iostream>
#include <vector>

using lli = long long int;
const lli mod = 1000000007;
int main(){
        lli N;
        std::cin >> N;
        std::vector<lli> a_arr(N);
        std::vector<lli> n1_arr(61);
        for(lli i = 0; i < N; i++) std::cin >> a_arr[i];

        for(lli i = 0; i < N; i++){
                for(lli j = 0; j < 61; j++){
                        if(((a_arr[i])>>j)&1) n1_arr[j]++;
                }
        }
        lli ans = 0;
        for(lli i = 0; i < 61; i++){
                lli nn1 = (n1_arr[i]*(N-n1_arr[i]))%mod;
                lli nc = (nn1*((1LL<<i)%mod))%mod;
                ans = (ans+nc)%mod;
        }
        std::cout << ans%mod << std::endl;
}


Measured memory_bytes: 2560
N = int(input())
S = input()
alfa = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lis = []
for s in S:
    for i in range(26):
        if s == alfa[i]:
            lis.append((i+N)%26)
            break
for i in range(len(S)):
    print(alfa[lis[i]],end = '')


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

//素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i != 0) continue;
        ll ex = 0;

        while(n % i == 0) {
            ex++;
            n /= i;
        }

        res.push_back({i, ex});
    }

    if(n != 1) res.push_back({n, 1});
    return res;
}
//const auto &res = prime_factorize(n);

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

    const auto &res = prime_factorize(n);
    
    cout << n << ":";
    for(auto p : res) {
        rep(i, p.second) cout << " " << p.first;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3080
from typing import List

def DFS(G: List[int]):
	global time
	time = 0
	n = len(G)
	for u in range(n):
		if color[u] == "WHITE":
			DFS_Visit(u)

def DFS_Visit(u: int):
	global time
	color[u] = "GRAY"
	time += 1
	d[u] = time
	for v in G[u]:
		if color[v] == "WHITE":
			pi[v] = u
			DFS_Visit(v)
	color[u] = "BLACK"
	time += 1
	f[u] = time


if __name__ == "__main__":
	n = int(input())
	G = []
	color = ["WHITE" for _ in range(n)]
	pi = [None for _ in range(n)]
	d = [0 for _ in range(n)]
	f = [0 for _ in range(n)]

	for _ in range(n):
		command = list(map(int, input().split()))
		G.append([x - 1 for x in command[2:]])
	DFS(G)
	for i in range(n):
		print(f"{i + 1} {d[i]} {f[i]}")


Measured memory_bytes: 7280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

typedef long long int ll;

const int N = (int) 500;
const int M = (int) 1e6 + 10;
const int oo = 2e9;

int n, m;
int a[N];
vector<int> divs;

void solve() {
  cin >> n >> m;
  for(int i = 0; i < n; ++i) cin >> a[i];
  int sum = 0;
  for(int i = 0; i < n; ++i) sum += a[i];
  for(int x = 1; x * x <= sum; ++x) {
    if(sum % x) continue;
    divs.push_back(x);
    int y = sum / x;
    if(x != y) divs.push_back(y);
  }
  // sort(a, a + n);
  sort(divs.begin(), divs.end());
  int ans = -1;
  for(int x : divs) {
    multiset<int> pos, neg;
    for(int i = 0; i < n; ++i) {
      int cur = a[i];
      int curk = cur / x;
      int min_diff = oo;
      int y;
      for(int k = curk - 1; k <= curk + 1; ++k) {
        int diff = abs(k * x - cur);
        if(diff < min_diff) {
          min_diff = diff;
          y = k * x;
        }
      }
      int diff = y - cur;
      if(diff < 0) neg.insert(-diff);
      if(diff > 0) pos.insert(diff);
    }
    int p_ptr = 0, n_ptr = 0;
    int cnt = 0;
    while(pos.size() && neg.size()) {
      int p = *pos.begin(), q = *neg.begin();
      pos.erase(pos.begin()); neg.erase(neg.begin());
      int mi = min(p, q);
      p -= mi, q -= mi;
      if(p > 0) pos.insert(p);
      if(q > 0) neg.insert(q);
      cnt += mi;
    }
    while(pos.size()) {
      assert(pos.size() > 1);
      int front = *pos.begin(), back = *pos.rbegin();
      pos.erase(pos.begin()); pos.erase(prev(pos.end()));
      int mi = min(front, x - back%x);
      front -= mi, back = (back + mi) % x;
      if(front > 0) pos.insert(front);
      if(back > 0) pos.insert(back);
      cnt += mi;
    }
    while(neg.size()) {
      assert(neg.size() > 1);
      int front = *neg.begin(), back = *neg.rbegin();
      neg.erase(neg.begin()); neg.erase(prev(neg.end()));
      int mi = min(front, x - back%x);
      front -= mi, back = (back + mi) % x;
      if(front > 0) neg.insert(front);
      if(back > 0) neg.insert(back);
      cnt += mi;
    }
    if(cnt <= m) {
      ans = x;
    }
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_V 102

int
main(int argc, char **argv)
{
	int v[MAX_V + 1];
	int a, b;
	bool b_ok;
	int i;

	while (true)
	{
		for (i = 1; i <= MAX_V; ++i)
			v[i] = 0;

		while (true)
		{
			if (scanf("%d %d", &a, &b) == EOF)
				goto l_end;

			if (a == 0 && b == 0)
				break;

			v[a]++;
			v[b]++;
		}

		b_ok = true;
		for (i = 1; i <= MAX_V; ++i)
		{
			if (i == 1 || i == 2)
			{
				if (v[i] % 2 == 0)
				{
					b_ok = false;
					break;
				}
			}
			else
			{
				if (v[i] % 2 != 0)
				{
					b_ok = false;
					break;
				}
			}
		}

		printf("%s\n", b_ok ? "OK" : "NG");
	}

l_end:
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  int x = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == T.at(i)) { }
    else {x++;}}
  cout << x << endl;
}

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

int pos = 0;
vector<int> pre, in, post;

void reconstruction(int left, int right)
{
    if (left >= right)
        return;
    int root = pre[pos++];
    int mid = distance(in.begin(), find(in.begin(), in.end(), root));
    reconstruction(left, mid);
    reconstruction(mid+1, right);
    post.push_back(root);
}

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

    for (int i = 0; i != n; ++i)
    {
        cin >> v;
        pre.push_back(v);
    }

    for (int i = 0; i != n; ++i)
    {
        cin >> v;
        in.push_back(v);
    }

    reconstruction(0, n);

    for (vector<int>::iterator it = post.begin(); it != post.end(); ++it)
    {
        if (it != post.begin()) cout << " ";
        cout << *it;
    }

    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    deque<int> dq;
    int x = 1;
    FOR(i,1,n-1){
        if (s[i] == s[i-1]) x++;
        if (s[i] != s[i-1]){
            dq.push_back(x);
            x = 1;
        }
    }
    dq.push_back(x);

    int top = (s[0] == 'B');

    while (k--){
        if (!top){
            top = 1;
            int x = dq.front();
            dq.pop_front();
            if (x == 1){
                int y = dq.front();
                dq.pop_front();
                dq.push_front(y + 1);
            }else{
                dq.push_front(x - 1);
                dq.push_front(1);
            }
        }else{
            int x = dq.front();
            dq.pop_front();
            if (x > 1){
                top = 0;
                dq.push_front(x - 1);
            }
            if ((top + dq.size()) % 2 == 0){
                dq.push_back(1);
            }else{
                int y = dq.back();
                dq.pop_back();
                dq.push_back(y + 1);
            }
        }

        if (n % 2 == 0 && dq.size() == n && top){
            k = 0;
        }
        if (n % 2 == 1 && dq.size() == n && !top){
            k %= 2;
        }
    }

    while (!dq.empty()){
        int x = dq.front();
        dq.pop_front();
        cout << string(x, 'A' + top);
        top ^= 1;
    }
    cout << endl;

    return 0;
}






Measured memory_bytes: 1540
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;


const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MAXN = 2e5 + 10;
const ll INF = 1e18;
ll n, dp[MAXN], k;
ll h[MAXN];
int main(){
	IOS;
	memset(dp, 63, sizeof dp);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> h[i];
	dp[1] = 0;
	for (int i = 1; i <= n - 1; i++){
		for (int j = 1; j <= k; j++)dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
	}
	cout << dp[n];
	
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  ll N = s.length();
  ll ans = N*N+1;
  vector<ll> v(26,0);
  rep(i,N) ++v[s[i]-'a'];
  rep(i,26) ans -= v[i]*v[i];
  cout << ans/2+1 << endl;
  return 0;
}


Measured memory_bytes: 720
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            int a = Integer.parseInt(sl[0]);
            int b = Integer.parseInt(sl[1]);

            System.out.println(24 <= a + b ? a + b - 24 : a + b);
        }
    }
}


Measured memory_bytes: 22484
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int t = sc.nextInt();
		int x = sc.nextInt();
    
		// 出力
		System.out.println((double)t / x);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define pi acos(-1)
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


ll power(ll x,ll y){
    ll res = 1;
    while(y){
        if(y&1)
            res = (res*x)%md;
        x = (x*x)%md;
        y = y/2;
    }
    return res;
}

void solve(){
    int n,cnt = 0;
    cin>>n;
    vl dp(100000,0);
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                dp[i*i + j*j + k*k + i*j + j*k + i*k]++;
            }
        }
    }

    for(int i=1;i<=n;i++){
        cout<<dp[i]<<endl;
    }
}
 
int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  //  int n; cin>>n; for (int i = 0; i < n; ++i)
    solve();
    return 0;
}


Measured memory_bytes: 3868
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = (1ll << 31) - 1;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
struct RangeMinimumQuery {
	// 1-indexed??§??¨????§????
	// ???????????????????´???? 0-indexed
	int n;
	vector<T>d;
	RangeMinimumQuery(int m) {
		// m is the number of data
		// ?°??????????????????????????´???°?????????????????????
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, INF);
	}
	void update(int i, T x) {
		// update ith (0-indexed) number
		// index i ???????????????leaf node ???
		// The index of leaf node which corresponds to ith num is (n+i).
		d[n + i] = x;
		for (int j = (n + i) / 2; j > 0; j >>= 1) {
			d[j] = min(d[j * 2], d[j * 2 + 1]);// children: (2*n),(2*n+1)
			// ?°?????????????????????¢???????????§??????
			// This is because SegmentTree is a complete binary tree.
		}
	}
	T query(int l, int r) {
		// query [l,r)
		return query(l, r, 1, 0, n);// n??§????????¨?????¨????????¨???????????????
	}
	T query(int a, int b, int k, int l, int r) {
		// query for min of [a,b)
		// ????????????????????°???????¨????????°????????????????????????°
		// k?????????????????????l,r ??????????????????[l,r)?????????????????????????????¨?????¨???
		// ???????????£??????????????????query(a,b,0,0,n)??¨???????????¶

		// [a,b) ??¨ [l,r)???????????????????????°INF
		if (r <= a || b <= l)return INF;

		// [a,b)???[l,r)????????¨???????????§????????°?????????????????????
		if (a <= l&&r <= b)return d[k];
		else {
			//????????§???????????°???2????????????????°????
			T vl = query(a, b, k * 2, l, (l + r) / 2);
			T vr = query(a, b, k * 2 + 1, (l + r) / 2, r);
			return min(vl, vr);
		}
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	RangeMinimumQuery<int> rmq(n);
	rep(i, 0, q) {
		int com; cin >> com;
		int x, y; cin >> x >> y;
		if (com)cout << rmq.query(x, y + 1) << endl;
		else rmq.update(x, y);
	}
	//dump(rmq.d);
	return 0;
}

Measured memory_bytes: 3764
package main

import "fmt"

func CoinsPattern(A int,B int,C int,X int) int {
	var pattern int

	for i:=A; i >= 0 ; i-- {
		if X - 500*i < 0 {
			continue
		} else {
			var amari int
			amari = X - 500*i
			if amari == 0 {
				pattern += 1
				continue
			}
			for y:=B; y >= 0; y -- {
				if amari - 100*y < 0 {
					continue
				} else {
					var amari2 int
					amari2 = amari - 100*y
					if amari2 == 0 {
						pattern +=1
					} else if amari2 / 50 <= C {
						pattern += 1
					}
				}

			}

		}
			

	}
	return pattern
}


func main() {
	var A int
        var B int
        var C int
	var X int
        fmt.Scan(&A)
        fmt.Scan(&B)
        fmt.Scan(&C)
        fmt.Scan(&X)
        defer fmt.Println(CoinsPattern(A,B,C,X))

}

Measured memory_bytes: 512
from bisect import bisect_left, bisect_right

N = int(input())
As = [int(input()) for _ in range(N)]


dp = [float('inf')] * (N+1)
for A in reversed(As):
    i = bisect_right(dp, A)
    dp[i] = A

print(dp.index(float('inf')))


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

int main(){
    int N;
    cin >> N;
    vector<int> VC(N);
    for(int i=0; i<N; i++)
        cin >> VC[i];
    for(int i=0; i<N; i++){
        int C;
        cin >> C;
        VC[i] -= C;
    }
    int ans = 0;
    for(int i=0; i<N; i++)
        if(VC[i] > 0)
            ans += VC[i];
    cout << ans << 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 c[n] = {}, s[n] = {}, f[n] = {};
	for(ll i = 1; i < n; ++i) cin >> c[i] >> s[i] >> f[i];
	for(ll j = 0; j < n; ++j){
		ll now = 0;
		for(ll i = j + 1; i < n; ++i){
			if(now > s[i]){
				now = now / f[i] * f[i] + (now % f[i] > 0) * f[i] + c[i];
			}else{
				now = s[i] + c[i];
			}
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	ll n;
	cin>>n;
	ll i=1,j=1;
	for(int x=sqrt(n);x>=1;x--){
		if(n/x*x==n){
			i=x,j=n/x;
			break;
		}
	}
	cout<<i-1+j-1<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		String t=sc.next();
		int[][] dp=new int[s.length()+1][t.length()+1];
		for(int i=1; i<=s.length(); i++){
			for(int j=1; j<=t.length(); j++){
				if(s.charAt(i-1)==t.charAt(j-1)){
					dp[i][j]=dp[i-1][j-1]+1;
				}else{
					dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
				}
			}
		}
		int n=s.length();
		int m=t.length();
		String ans="";
		while(n>0 && m>0){
			if(s.charAt(n-1)==t.charAt(m-1)){
				n--;
				m--;
				ans=s.charAt(n)+ans;
			}else if(dp[n][m]==dp[n-1][m]){
				n--;
			}else{
				m--;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 89292
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n, k, ans = 0, l;
    set<int> typ;
    vector<int> a(200000, 0);
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> l;
        a[l] += 1;
        typ.insert(l);
    }
    sort(a.begin(), a.end());
    auto itr = lower_bound(a.begin(), a.end(), 1);
    for(int i = 0; i < int(typ.size()) - k; i++){
        ans += *itr;
        itr++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
 ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,x,t,l=0;
  cin>>n>>x>>t;
  while(n!=0&&n>0)
  {
   l+=t;
    n-=x;
  }
  cout<<l<<"\n";
  return 0;
} 

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   int n; cin>>n;
   int res=0,cur=0;
   rep(i,0,n){
      int x,y; cin>>x>>y;
      if(x==y)cur++;
      else{
         chmax(res,cur);
         cur=0;
      }
   }
   chmax(res,cur);
   if(res>=3)cout<<"Yes"<<endl;
   else puts("No");
   return 0;
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll A,B; cin >> A >> B;
    res = lcm(A,B);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys

def solve():
    readline = sys.stdin.readline
    write = sys.stdout.write
    H, W, N = map(int, readline().split())
    A = [0]*W
    B = [0]*W
    C = [0]*W
    for i in range(W//2):
        A[i] = i * 2 + 1
        A[-i-1] = i * 2
        B[i*2] = C[i*2 - 1] = i
        B[-1-i*2] = C[-1-i*2 + 1] = i + W//2
    *X, = range(W)
    P = [list(map(int, readline().split())) for i in range(N)]
    P.sort()
    for a, b in P:
        if a % 2 == 1:
            k = a // 2
            m = b//2*2
            p = A[(B[m] + k) % W]
            q = A[(B[m+1] + k) % W]
        else:
            k = a // 2 - 1
            m = (b-1)//2*2
            p = A[(C[m+1] + k) % W]
            q = A[(C[m+2] + k) % W]
        X[p], X[q] = X[q], X[p]

    *E0, = range(W)
    for i in range(W//2):
        E0[2*i], E0[2*i+1] = E0[2*i+1], E0[2*i]
    E1 = E0[:]
    for i in range(W//2-1):
        E1[2*i+1], E1[2*i+2] = E1[2*i+2], E1[2*i+1]
    k = H//2
    *Y, = range(W)
    while k:
        if k & 1:
            Y = [Y[e] for e in E1]
        E1 = [E1[e] for e in E1]
        k >>= 1
    if H % 2:
        Y = [Y[e] for e in E0]
    ans = [0]*W
    for i, e in enumerate(Y):
        ans[X[e]] = i+1
    for e in ans:
        write("%d\n" % e)
solve()


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.length();
    stack<ll> s;
    stack<pll> a;
    REP(i, N) {
        if (S[i] == '\\') {
            s.push(i);
            continue;
        }
        if (S[i] == '/' && !s.empty()) {
            ll idx = s.top();
            s.pop();
            ll sum = i - idx;
            while (!a.empty() && a.top().second > idx) {
                pll t = a.top();
                a.pop();
                sum += t.first;
            }
            a.push(pll(sum, idx));
        }
    }

    vector<ll> v;
    while (!a.empty()) {
        pll t = a.top();
        a.pop();
        v.push_back(t.first);
    }

    reverse(v.begin(), v.end());

    ll ans = 0;
    REP(i, v.size()) {
        ans += v[i];
    }
    cout << ans << endl;
    cout << v.size();
    REP(i, v.size()) {
        cout << " " << v[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3332
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

#include <iostream>

int main()
{
	int A, P;
	cin >> A >> P;

	cout << (3*A+P)/2 << endl;
}

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

int main() {
	int N; cin >> N;
	vector<int> V;
	int a;
	for (int i = 0; i < N; i++) {
		cin >> a;
		V.push_back(a);
	}
	sort(V.begin(), V.end());

	cout << abs(V[0] - V[N-1]) << endl;
}

Measured memory_bytes: 256