akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
a = []
b = []

for i in range(n):
    a.append([int(s) for s in input().split()])
for j in range(m):
    b.append([int(input())])

for x in range(n):
    sum = 0
    for y in range(m):
        sum += a[x][y] * b[y][0]
    print(sum)

Measured memory_bytes: 8080
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <cstdio>
#include <cmath>

using namespace std;
using ll = long long;
const int INF = 999999999;

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

    double ans = 0;
    for (int i = 1; i <= N; ++i) {
        double p = 1;
        int x = i;
        while (x < K) {
            x *= 2;
            p *= 0.5;
        }
        ans += p / N;
    }

    printf("%.9f\n", ans);
}

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

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

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

using f32 = float;
using f64 = double;

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

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

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

#define pb push_back
#define mp make_pair

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

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

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


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

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


int main() {
    i64 N; cin >> N;
    vector<i64> A(N);
    i64 cnt = 0;
    REP(i, N) {
        cin >> A[i];
        if (i % 2 == 0 && A[i] % 2 == 1) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N;
    cin >> N;
    vector<int> H(N);
    REP (i, N) cin >> H[i];
    int ans = 0;
    while (true) {
        int p = 0, q = 0;
        REP (i, N) {
            if (H[i] == 0) p = 0;
            else {
                if (p == 0) ans++;
                p = q = 1;
                --H[i];
            }
        }
        if (q == 0) break;
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  vector<int> in(3);
  rep(i, 3) cin >> in.at(i);
  sort(ALL(in));
  int ans = in.back()*10;
  ans += in.front() + in.at(1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{
    int N; cin >> N;
    int ans = 0;
    int min_d = 1e9 + 1;
    REP(i,N) {
        int A,B;
        cin >> A >> B;
        if (min_d > B) {
            min_d = B;
            ans = A + B;
        }
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<string,string> ps;

int main(void) {
    int i,j;
    int n;
    cin >> n;
    string s;
    cin >> s;
    int N = 2*n;
    vector<map<ps,int> > vm1(n+1);
    rep(bit,1<<n){
        string t1="",t2="";
        rep(i,n){
            if(bit&(1<<i))t1+=s[i];
            else t2+=s[i];
        }
        reverse(all(t2));
        vm1[t1.size()][ps(t1,t2)]++;
    }

    vector<map<ps,int> > vm2(n+1);
    rep(bit,1<<n){
        string t1="",t2="";
        rep(i,n){
            if(bit&(1<<i))t1+=s[n+i];
            else t2+=s[n+i];
        }
        reverse(all(t2));
        vm2[t1.size()][ps(t1,t2)]++;
    }

    ll ans = 0;

    rep(i,n+1){
        //cout<<i<<endl;
        for(auto itr1=vm1[i].begin();itr1!=vm1[i].end();itr1++){
            string s1 = itr1->first.first;
            string t1 = itr1->first.second;
            ll c1 = itr1->second;
            string t="";
            for(auto itr2=vm2[n-i].lower_bound(ps(t1,t));itr2!=vm2[n-i].end();itr2++){
                string s2 = itr2->first.first;
                string t2 = itr2->first.second;
                ll c2 = itr2->second;
                //cout << s1 << " " << t1 << " " << s2 <<" " <<t2 << endl;
                if(s1==t2 && s2==t1)ans += c1*c2;
                if(t1!=s2)break;
            }

        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 87040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    public static void Main()
    {
        var val = Console.ReadLine().Split(' ');
        int X, A;
        X = int.Parse(val[0]);
        A = int.Parse(val[1]);
        if (A > X)
        {
            Console.WriteLine("0");
        }
        if (X >= A)
        {
            Console.WriteLine("10");
        }
    }
}


Measured memory_bytes: 13140
import itertools
N, M, Q = map(int, input().split())
abcds = []
for i in range(Q):
  a, b, c, d = map(int, input().split())
  abcds.append((a-1, b-1, c, d))
rs = []
for B in itertools.combinations(range(M+N-1), N):
  #print(B)
  A = [0]
  n = 0
  for b in B:
    a = A[-1]+b-n
    A.append(a)
    n = b+1
  A.pop(0)
  r = 0
  for a, b, c, d in abcds:
    if A[b]-A[a] == c:
      r += d
  #print(B, A, r)
  rs.append(r)
r = max(rs)
print(r)


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

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

  int num = 0;
  if (N % 2 == 0) {
    for (int i = 1; i < N; i += 2) {
      if (cnt[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
      num++;
    }
  } else {
    for (int i = 0; i < N; i += 2) {
      if (i == 0) {
        if (cnt[i] != 1) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (cnt[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
      }
      num++;
    }
    num--;
  }

  long long ans = 1;
  for (int i = 0; i < num; i++) {
    ans *= 2;
    ans %= 1000000007;
  }

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 12){
        cout << b; 
    }else if (a < 6){
        cout << 0;
    }else{
        cout << b/2;
    }
}

Measured memory_bytes: 256
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace Area
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var input = ReadLine();
            var sum = 0;
            var pos = new Stack<int>();
            var puddle = new Stack<Pair<int, int>>();
            var puddleCount = 0;
            for (var i = 0; i < input.Length; i++)
            {
                if (input[i] == '\\')
                {
                    pos.Push(i);
                }else if (input[i] == '/' && pos.Count > 0)
                {
                    var j = pos.Pop();    // 直前の\の場所
                    sum += i - j;
                    var a = i - j;
                    puddleCount++;
                    while (puddle.Count > 0 && puddle.Peek().First > j)
                    {
                        // 水たまりの統合
                        a += puddle.Pop().Second;
                        puddleCount--;
                    }
                    puddle.Push(new Pair<int, int>(j, a));
                }
            }
            WriteLine(sum);
            var result = new List<int>();

            var n = puddle.Count;
            for (var i = 0; i < n; i++)
            {
                result.Add(puddle.Pop().Second);
            }

            Write(puddleCount);
            result.Reverse();
            foreach (var i in result)
            {
               Write(" " + i); 
            }
            WriteLine();
        }
    }

    public class Pair<T, U>
    {
        public Pair()
        {
        }

        public Pair(T first, U second)
        {
            First = first;
            Second = second;
        }

        public T First { get; set; }    // 水たまりの左端の位置
        public U Second { get; set; }    // 面積
    }
}


Measured memory_bytes: 20396
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
char a[30][30]= {0};
int q[]= {1,-1,0,0};
int w[]= {0,0,-1,1};
const int inf = 0x3f3f3f3f;
int l;
int h;
int max1=0;
struct node
{
    int x;
    int y;
};
int main()
{
    cin>>h;
    cin>>l;
    for(int i=0; i<h; i++)
    {
        cin>>a[i];
    }
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<l; j++)
        {
            if(a[i][j]=='#')
                continue;
            int sum1[25][25]= {0};
            memset(sum1,inf,sizeof(sum1));
            sum1[i][j]=0;
            queue<node>p;
            node r;
            r.x=i;
            r.y=j;
            p.push(r);
            while(!p.empty())
            {
                node t=p.front();
                p.pop();
                for(int h1=0; h1<4; h1++)
                {
                    int z=t.x+q[h1];
                    int x=t.y+w[h1];
                    if(z<h&&z>=0&&x<l&&x>=0&&a[z][x]=='.'&&sum1[z][x]==inf)
                    {
                        sum1[z][x]=sum1[t.x][t.y]+1;
                        node u;
                        u.x=z;
                        u.y=x;
                        p.push(u);
                    }
                }
            }
            for(int i2=0;i2<h;i2++)
            {
                for(int j2=0;j2<l;j2++)
                {
                    if(sum1[i2][j2]!=inf)
                    {
                        max1=max(max1,sum1[i2][j2]);
                    }
                }
            }
        }
    }
    cout<<max1<<endl;
    return 0;
}


Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-09-13
**/

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


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	long long prod = max({a * c, a * d, b * c, b * d});
	cout << prod << '\n';
	return 0;	
}


Measured memory_bytes: 3648
/* ex5_3
   moka223711 */

#include <stdio.h>
#define row 101
#define col 101

int main(void){
    int height, width, i, j, black_r[row] = {0}, black_c[col] = {0}, id = 0;
    char sq[row][col];
    scanf("%d %d", &height, &width);
    for(i = 0; i < height; i++){
        for(j = 0; j < width; j++){
            scanf(" %c", &sq[i][j]);
        }
    }
    for(i = 0; i < height; i++){
        for(j = 0; j < width; j++){
            if(sq[i][j]=='#'){
                black_r[i] = 1;
                black_c[j] = 1;
            }
        }
    }
    for(i = 0; i < height; i++){
        for(j = 0; j < width; j++){
            if(black_r[i] == 0){
                id = 0;
                continue;
            }
            if(black_c[j] == 1){
                id = 1;
                printf("%c", sq[i][j]);
            }
        }
        if(id == 1){
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int max(int a, int b){
    return(a>b)?a:b;
}

int nibutan(int* a,int i, int j, int n){
    int low=j;
    int high=n;
    int mid;
    while(low<=high){
        mid=(high+low)/2;
        if((a[mid]>(a[i]-a[j]))&&(a[mid+1]<=(a[i]-a[j])))break;
        else if(a[mid]>(a[i]-a[j]))low=mid+1;
        else high=mid-1;
    }
    return mid;
}

void swap(int *a,int *b){
    int c;
    c=*a;
    *a=*b;
    *b=c;
}
 
void add_num(int*a,int i){
    while(i>1){
        if(a[i]<=a[i/2])break;
        swap(&a[i],&a[i/2]);
        i/=2;
    }
}

void pushdown(int* a,int n){
    int i=1;
    while(1){
        if(a[i]>=max(a[2*i],a[2*i+1]))break;
        if(a[2*i]>a[2*i+1]){
            swap(&a[i],&a[2*i]);
            i*=2;
        }else{
            swap(&a[i],&a[2*i+1]);
            i=2*i+1;
        }
        if(i*2>n)break;
    }
}

int solve(int* a,int n){
    int res=0;
    for(int i=1;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            res+=nibutan(a,i,j,n)-j;
        }
    }
    return res;
}

int main(void){
    int n;
    scanf("%d",&n);
    int a[n+2],b[n+1];
    for(int i=1;i<n+1;i++){
        scanf("%d",&a[i]);
        add_num(a,i);
    }
    a[n+1]=0;
    for(int i=1;i<n+1;i++){
        b[i]=a[1];
        a[1]=a[n-i+1];
        a[n-i+1]=0;
        pushdown(a,n-i);
    }
    printf("%d\n",solve(b,n));
    return 0;
}


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

int main(){
  int X;
  cin >> X;
  switch (X % 7){
    case 0:
      cout << "thu" << endl;
      break;
    case 1:
      cout << "fri" << endl;
     break;
    case 2:
      cout << "sat" << endl;
      break;
    case 3:
      cout << "sun" << endl;
      break;
    case 4:
      cout << "mon" << endl;
      break;
    case 5:
      cout << "tue" << endl;
      break;
    default:
      cout << "wed" << endl;
  }
  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n;
vector<pair<pair<int, int>, int>> v;

int solve();
bool ch(int x, int y);

int main() {
  cin >> n;
  for(int t = 0; t < 2; ++t)
    for(int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      v.push_back({{x, y}, t});
    }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}

int solve() {
  vector<int> now;
  int ans = 0;
  for(int i = 0; i < 2 * n; ++i) {
    if(v[i].se == 0)
      now.push_back(v[i].fi.se);
    else {
      sort(now.begin(), now.end());
      auto it =
          lower_bound(now.begin(), now.end(), v[i].fi.se);
      if(it != now.begin()) {
        ++ans;
        now.erase(--it);
      }
    }
  }
  return ans;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
dp=[[float("inf") for i in range(n+1)] for j in range(m+1)]
dp[0][0]=0
d=[]
for i in range(n):
    d.append(int(input()))
c=[]
for i in range(m):
    c.append(int(input()))
for i in range(1,m+1):
    for j in range(min(i,n)+1):
        dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+d[j-1]*c[i-1])
print(dp[m][n])


Measured memory_bytes: 32176
#include<bits/stdc++.h>
using namespace std;
long long int dp[105][100005];
long long int res(int wt[],int v[],int n,int W)
{
    if(n==0 || W==0)
    {
        return 0;
    }
    if(dp[n][W]!=-1)
    {
        return dp[n][W];
    }
    else
    {
    if(W>=wt[n-1])
    {
        dp[n][W]=max(res(wt,v,n-1,W),(v[n-1]+res(wt,v,n-1,W-wt[n-1])));
        return dp[n][W];
    }
    else
    {
        dp[n][W]=res(wt,v,n-1,W);
        return dp[n][W];
    }
    }
}
int main()
{
    int n,W;
    cin>>n>>W;
    int wt[n],v[n];
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>v[i];
    }
    cout<<res(wt,v,n,W);
}

Measured memory_bytes: 85652
while True:
    num = int(input())
    if num == 0:
        break
    scores = [int(n) for n in input().split()]
    
    mean = sum(scores) / num
    sums = 0
    for index in range(num):
        sums += (scores[index] - mean) ** 2
    print((sums / num) ** 0.5)


Measured memory_bytes: 5676
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
int main(void){
    IOS;
    int n, x, t; cin >> n >> x >> t;
    cout << (n/x+(n%x!=0))*t << endl;
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	const int dx[] = {1, 0, -1, 0};
	const int dy[] = {0, 1, 0, -1};
	int h, w;
	while (cin >> h >> w) {
		int ch, cw, dh, dw;
		cin >> ch >> cw >> dh >> dw;
		ch--; cw--; dh--; dw--;
		vector<string> maze(h);
		for (auto &s : maze) {
			cin >> s;
		}
		vector<vector<int>> color(h, vector<int>(w));
		int cnt = 0;
		auto check = [&](int x, int y) {
			return 0 <= x && x < h && 0 <= y && y < w && maze[x][y] == '.';
		};	
		function<void(int, int)> dfs = [&](int x, int y) {
			color[x][y] = cnt;
			for (int i = 0; i < 4; i++) {
				int nx = x + dx[i], ny = y + dy[i];
				if (!check(nx, ny) || color[nx][ny]) {
					continue;
				}
				dfs(nx, ny);
			}
		};
		for (int x = 0; x < h; x++) {
			for (int y = 0; y < w; y++) {
				if (color[x][y] || maze[x][y] == '#') {
					continue;
				}
				++cnt;
				dfs(x, y);
			}
		}
		vector<vector<int>> graph(cnt);
		for (int x = 0; x < h; x++) {
			for (int y = 0; y < w; y++) {
				if (maze[x][y] == '#') {
					continue;
				}
				int u = color[x][y] - 1;
				for (int nx = max(0, x - 2); nx <= min(h - 1, x + 2); nx++) {
					for (int ny = max(0, y - 2); ny <= min(w - 1, y + 2); ny++) {
						if (maze[nx][ny] == '#') {
							continue;
						}
						int v = color[nx][ny] - 1;
						if (u == v) {
							continue;
						}
						graph[u].push_back(v);
						graph[v].push_back(u);
					}
				}
			}
		}
		for (int i = 0; i < cnt; i++) {
			sort(graph[i].begin(), graph[i].end());
			graph[i].resize(unique(graph[i].begin(), graph[i].end()) - graph[i].begin());
		}
		auto solve = [&]() {
			vector<int> dist(cnt);
			vector<int> qu{color[ch][cw] - 1};
			dist[color[ch][cw] - 1] = 1;
			for (int fr = 0; fr < (int)qu.size(); fr++) {
				int u = qu[fr];
				if (u == color[dh][dw] - 1) {
					cout << dist[u] - 1 << '\n';
					return;
				}
				for (int &v : graph[u]) {
					if (dist[v]) {
						continue;
					}
					qu.push_back(v);
					dist[v] = dist[u] + 1;
				}
			}
			cout << "-1\n";
		};
		solve();
	}
	return 0;
}


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

typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    sort(v.begin(), v.end());
    if(k == 1){
        cout << 0 << endl;
        return 0;
    }
    ModComb mc(n+10);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(i+1 >= k){
            // biggest
            ans += mc.nCk(i, k-1)*v[i]%mod;
            ans %= mod;
        }
        if(n-i >= k){
            // smallest
            ans += (mod-mc.nCk(n-1-i, k-1)*v[i]%mod)%mod;
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int a, b;
	double f;

	cin >> a >> b;
	f = double(a) / b;
	cout << a / b << " ";
	cout << a % b << " ";
	cout << fixed << setprecision(6) << f << endl;

	return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

double g = 0;

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

  vector<ll> a(n);
  cin >> a;

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

  ll maxv = a[n-1];

  double val = a[n - 1];
  val/=2;
  cerr << val <<endl;
  a.pop_back();

  ll minv = 100000000000000;
  ll minp = 0;

  for(auto v:a){
    cerr << v <<"  " <<abs(val - (double)v) <<",";
    if (minv > abs(val - (double)v)){
      minv = abs(val - (double)v);
      minp = v;
    }
  }cerr <<endl;



  cout << maxv << " " << minp <<endl;


}




















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

using namespace std;

int main()
{
	int N;
	long long K;
	cin >> N >> K;
	vector<int> A(N);
	for (auto& x : A) {
		cin >> x;
		--x;
	}

	vector<bool> visited(N, false);
	vector<int> seq;
	int x;
	for (x = 0; !visited[x]; x = A[x]) {
		visited[x] = true;
		seq.push_back(x);
	}

	auto p = find(seq.begin(), seq.end(), x) - seq.begin();

	if (K <= p) {
		cout << seq[(int)K] + 1 << endl;
	}
	else {
		int T = seq.size() - p;
		cout << seq[p + (K - p) % T]  + 1 << endl;
	}
}

Measured memory_bytes: 5120
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin>>s;
    
    cout<<s.substr(0,4)+" "+s.substr(4,8)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
int N;
vector<int> P;






//サブ関数
//入力
void input()
{
	cin >> N;
	P.resize(N);
	REP(i, N) {
		int tmp;
		cin >> tmp;
		P[i] = tmp - 1;
	}
}


//計算
void calc()
{
	int ans = 0;
	vector<int> cont(N, 0);
	REP(i, N) {
		if (P[i] == 0) {
			cont[0] = 1;
		}
		else {
			cont[P[i]] = cont[P[i] - 1] + 1;
		}
	}
	cout << N- *max_element(cont.begin(), cont.end()) << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
s = []
for i in range(n):
    si = input()
    s.append(si)

ac = wa = re = tle = 0
for i in range(n):
    if s[i] == 'AC':
        ac += 1
    elif s[i] == 'WA':
        wa += 1
    elif s[i] == 'RE':
        re += 1
    else:
        tle += 1

print(f'AC x {ac}')
print(f'WA x {wa}')
print(f'TLE x {tle}')
print(f'RE x {re}')

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

using namespace std;

int main(){
    int N, i;
    cin >> N;
    vector<int> L(N);

    for (i=0;i<N;i++){
        cin >> L[i];
    }
    sort( L.begin(), L.end() );

    int sum=0;
    for (i=0;i<N-1;i++){
        sum += L[i];
    }

    if (L[N-1] >= sum) cout << "No\n";
    else cout << "Yes\n";
}
   

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  map<char, int> amap;
  for(int i=0;i<S.size();++i) {
    amap[S[i]]++;
  }
  char ans = 'A';
  for(char a='a';a<='z';++a) {
    if(amap[a]==0) {
      ans = a;
      break;
    }
  }
  if(ans=='A') cout<<"None"<<endl;
  else cout<<ans<<endl;
}



Measured memory_bytes: 3716
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n'&&c!=EOF;)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

struct N {
	int x, x1, y, y1, t;
};

int main() {
	vector<vector<N>> d(101, vector<N>(101));
	d[1][0].y = d[0][1].x = 1;
	int m = 100000;
	for (int i: range(1, 101))
		for (int j: range(1, 101)) {
			auto &t {d[i][j]}, l {d[i][j - 1]}, b {d[i - 1][j]};
			t = {(l.x + l.x1) % m, l.y,
				 (b.y + b.y1) % m, b.x, 0};
			t.t = (t.x + t.x1 + t.y + t.y1) % m;
		}
	for (int w, h; w = in, h = in;)
		outl(d[h][w].t);
}


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

void fnInput(vector<int>& rvnMtrx)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMtrx.resize(nMaxSiz + 1);

  for (int i = 0; i < rvnMtrx.size() - 1; ++i)
    cin >> rvnMtrx[i] >> rvnMtrx[i + 1];
}

int fnMtrxChainMultpl(vector<vector<int>>& rvvnDetDP, const vector<int>& cnrvnMtrx)
{
  for (int i = 1; i < cnrvnMtrx.size(); ++i)  rvvnDetDP[i][i] = 0;

  const int cnMaxSiz = cnrvnMtrx.size() - 1;
  for (int nDif = 1; nDif <= cnMaxSiz - 1; ++nDif)
    for (int nRow = 1; nRow <= cnMaxSiz - nDif; ++nRow)
    {
      int nCol = nRow + nDif;
      for (int nx = nRow; nx <= nCol - 1; ++nx)
        rvvnDetDP[nRow][nCol] =
          min(rvvnDetDP[nRow][nCol],
              rvvnDetDP[nRow][nx] + rvvnDetDP[nx + 1][nCol] 
                                  + cnrvnMtrx[nRow - 1] * cnrvnMtrx[nx] * cnrvnMtrx[nCol]);
    }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnDetDP; 
  vector<int> vnMtrx;

  fnInput(vnMtrx);
  vvnDetDP.resize(vnMtrx.size(), vector<int>(vnMtrx.size(), INT_MAX));

  fnMtrxChainMultpl(vvnDetDP, vnMtrx);
  cout << vvnDetDP[1][vnMtrx.size() - 1] << endl;
  return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;



int main() {
    int n;
    string s;
    cin >> n >> s;
    vvint mem(10, vint(10, 0));
    vint num(n+1, 0);
    set<int> st;
    rrep(i, n) {
        st.insert(s[i]);
        num[i] = st.size();
    }

    rep(i, n) srep(j, i+1, n) {
        if (mem[s[i]-'0'][s[j]-'0'] == 0) mem[s[i]-'0'][s[j]-'0'] = num[j+1];
    }
    
    int ans = 0;
    rep(i, 10) rep(j, 10) ans += mem[i][j];

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

Measured memory_bytes: 384
#include <cstdio>
#include <vector>

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

  std::vector<size_t> a(N+1);
  for (size_t i = 1; i <= N; ++i)
    scanf("%zu", &a[i]);

  int res = 0;
  size_t cur = 1;
  while (true) {
    if (a[cur] == 0) return puts("-1"), 0;
    ++res;
    size_t prev = cur;
    cur = a[cur];
    a[prev] = 0;
    if (cur == 2) break;
  }
  printf("%d\n", res);
}

Measured memory_bytes: 1272
X = int(input()) 

if (400 <=X & X<=599):
    print(8)
elif (600 <=X & X<=799):
    print(7)
elif (800 <=X & X<=999):
    print(6)
elif (1000 <=X & X<=1199):
    print(5)
elif (1200 <=X & X<=1399):
    print(4)
elif (1400 <=X & X<=1599):
    print(3)
elif (1600 <=X & X<=1799):
    print(2)
elif (1800 <=X & X<=1999):
    print(1)

Measured memory_bytes: 9200
#!/usr/bin/env python3
"""
ソートテク関連の基本的な関数の詰め合わせ (命名は C++ STL algorithm による)


stable_partition(seq, func):
    O(n)
    空間計算量も O(n)
    述語が True を返す全ての要素が、述語が False を返す全ての要素よりも前になるようにシーケンスを並び替える (破壊、安定)


nth_element(seq, k, begin, end):
    O(n)
    E = seq[k] とする
    特定の要素 E よりも小さい全ての要素が E よりも前になり、 E 以上の全ての要素がEよりも後になるように seq[begin:end] を並び替える (破壊、不安定)
    heapq の nlargest とは異なるので注意


ith_order_statistic(seq, i, begin, end):
    O(n)
    nth_element を用いて (seq[begin:end] に存在することがわかっている) i 番目の順序統計量を求める (i = 0, 1, ..., n-1)


simple_quick_sort(seq, begin, end):
    O(nlgn)
    nth_element を用いて seq[begin:end] をソートする (破壊、不安定)


modified_merge_sort(seq, begin, end):
    O(nlgn)
    _modified_merge を用いて seq[begin:end] をソートする (非破壊、安定)
    転倒数とソート済み配列を返す


count_inversion(seq):
    O(nlgn)
    modified_merge_sort を用いて seq の転倒数を求める
    (転倒数: seq[i] > seq[j] (i < j) なる (i, j) の組み合わせの数のこと)
"""


import random
from typing import TypeVar, Callable, List, Tuple, Union
T = TypeVar('T')
Num = Union[int, float]




def _modified_merge(left: List[Num], right: List[Num]) -> Tuple[int, List[Num]]:
    """
    ソート済み配列 left, right を受け取り、全体のソート済み配列を生成する (O(n))
    マージの過程で転倒数をメモして返す

    Args:
        left (list): ソート済み
        right (list): ソート済み

    Returns:
        inv (int): 転倒数
        sorted_list (list): ソート済み
    
    Examples:
        >>> _modified_merge([1, 5, 7], [2, 3, 3])
        (6, [1, 2, 3, 3, 5, 7])
    """
    sorted_list = []
    i, j, inv = 0, 0, 0
    buf_1 = left[:] + [float('inf')]
    buf_2 = right[:] + [float('inf')]
    for _ in range(len(left) + len(right)):
        if buf_1[i] < buf_2[j]:
            sorted_list.append(buf_1[i])
            i += 1
            inv += j
        else:
            sorted_list.append(buf_2[j])
            j += 1
    return inv, sorted_list


def modified_merge_sort(L, begin, end):
    """
    L[begin:end] を 非破壊的かつ安定にマージソートする (O(nlgn))
    マージソートの過程で転倒数をメモして返す

    Args:
        L (list)
        begin, end (int)
    
    Returns:
        inv (int): 転倒数
        sorted_list (list): ソート済み
    
    Examples:
        >>> modified_merge_sort([3, 5, 2, 1, 0], 0, 5)
        (9, [0, 1, 2, 3, 5])
    """
    if end - begin == 1:
        return 0, [L[begin]]
    mid = (begin + end) // 2
    left_inv_cnt, left = modified_merge_sort(L, begin, mid)
    right_inv_cnt, right = modified_merge_sort(L, mid, end)
    merge_inv_cnt, sorted_list = _modified_merge(left, right)
    return left_inv_cnt + right_inv_cnt + merge_inv_cnt, sorted_list


def count_inversion(L):
    """
    modified_merge_sort() を用いて L の要素の転倒数を求める (O(nlgn))

    Examples:
        >>> count_inversion([1, 9, 2, 7, 5, 6, 4, 8, 3, 0])
        26
    """
    cnt, _ = modified_merge_sort(L, 0, len(L))
    return cnt


if __name__ == "__main__":
    n = int(input())
    L = list(map(int, input().split()))
    print(count_inversion(L))


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

void trace(vector<int> a, int n)
{
    for(int i=0; i<n; i++){
        if (i == a.size()-1) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
}

int SelectionSort(vector<int> &a, int n)
{
    int swap_cnt = 0;
    for(int i=0; i<n; i++){
        int min_j = i;
        for(int j = min_j; j<n; j++){
            if (a[min_j] > a[j]) min_j = j;
        }
        if (i != min_j){
            swap_cnt++;
            swap(a[i], a[min_j]);
        }
    }
    return swap_cnt;
}

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

    int ans = SelectionSort(a, n);
    trace(a, n);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3144
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    { 
        int n,m;
        cin>>n>>m;
        int sum=0;
        for(int i=0;i<m;i++)
        {
            int x;
            cin>>x;
            sum+=x;
            
        }
        if(sum>n)
        cout<<-1;
        else
        cout<<n-sum;
    }
}
    
// 🍪 🍪 🍪


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n,t,x,y;//不用开数组
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t>>x>>y;//输入每组数据
        if(!(x+y<=t&&(t-x-y)%2==0)){//判断是否符合
            cout<<"No\n";//不符合
            return 0;//避免重复输出
        }
    }
    cout<<"Yes\n";//全部符合
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int n; cin >> n;
    int ans = n - 1;
    for (int i = 2; i * i <= n; ++i)
        if (n % i == 0)
            ans = min(ans, i + n / i - 2);
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

ll N;

int main() {
    cin >> N;
    string ans = "";

    if (N % 2 == 0) {
        ans += '0';
    } else {
        N -= 1;
        ans += '1';
    }

    ll i = 1;
    while (N != 0) {
        ll mod = pow(2, i+1);
        ll rem = N % mod;
        if (rem == pow(-2, i)) {
            ans += '1';
            N -= rem;
        } else if (rem == -pow(-2, i)) {
            ans += '1';
            N += rem;
        } else {
            ans += '0';
        }
        i++;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int t[10];
int m[11][331];

void memo(int i,int s){
	int j;
	if(i>10)return;
	rep(j,10){
		if(!t[j]){
			t[j]=1;
			m[i][s+i*j]++;
			memo(i+1,s+i*j);
			t[j]=0;
		}
	}
}
	
int main(void){
	int n,s;
	memo(1,0);
	while(scanf("%d %d",&n,&s)!=EOF)
		print(s>330?0:m[n][s]);
	return 0;
}


Measured memory_bytes: 1976
N = int(input())

ac, wa, tle, re = 0, 0, 0, 0
for i in range(N):
    judge = input()
    if judge == 'AC':
        ac += 1
    elif judge == 'WA':
        wa += 1
    elif judge == 'TLE':
        tle += 1
    elif judge == 'RE':
        re += 1

print('AC x {}'.format(ac))
print('WA x {}'.format(wa))
print('TLE x {}'.format(tle))
print('RE x {}'.format(re))

Measured memory_bytes: 9208
//
// ABC055B
//
//

#include <iostream>
using namespace std;

int main() {
	int N;
  	cin >> N;
  	long long power =1;
  
  	for (int i=1; i<=N; i++) {
      power = (power * i) % 1000000007 ;
    }  
	cout << power  << endl;;
	return 0;
}


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

int main() {
  ll n,a,b;cin>>n>>a>>b;
  ll score=0;
  ll an[n];rep(i,n)cin>>an[i];
  rep(i,n-1) {
    score += min( (an[i+1]-an[i])*a, b );
  }
  cout << score;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,h[200001],ans;
signed main()
{
	scanf("%lld%lld",&n,&k);
	k=n-k;
	for(int i=1;i<=n;i++)scanf("%lld",&h[i]);
	sort(h+1,h+n+1);
	for(int i=1;i<=k;i++)ans+=h[i];
	printf("%lld",ans);
	return 0;
}

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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t, x;
	cin >> t >> x;
	cout << setprecision(20) << fixed << 1.0 * t / x << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }


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

    string S; cin >> S;
    string T = S;
    reverse(all(T));
    rep(i,S.size()) {
        if(T[i] == 'b') T[i] = 'd';
        else if(T[i] == 'd') T[i] = 'b';
        else if(T[i] == 'p') T[i] = 'q';
        else if(T[i] == 'q') T[i] = 'p';
    }
    if(S == T) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 512
import sys, copy
from itertools import permutations

def wf(d):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        d[i][j] = min(d[i][j],d[i][k]+d[k][j])
  return d

N,M,R = map(int,input().split())
Rs = list(map(int,input().split()))

d = [[float('inf') for i in range(N)] for i in range(N)]
for _ in range(M):
  a,b,c = map(int,sys.stdin.readline().split())
  d[a-1][b-1] = c
  d[b-1][a-1] = c

for i in range(N):
  d[i][i] = 0

wf(d)

ans = float('inf')
for prm in permutations(Rs, R):
  ans = min(ans, sum([d[prm[i-1]-1][prm[i]-1] for i in range(1,R)]))
print(ans)

Measured memory_bytes: 56924
import Control.Monad
import qualified Data.Array.Unboxed as A
import qualified Data.Array.ST as AS
import Data.List (intercalate)

type Info = (Int,Int,Int,Int)

type Room = (Int,Int,Int)

towers = 4
floors = 3
rooms = 10

-- let's play with ST.
manage :: [Info] -> A.UArray Room Int
manage is = AS.runSTUArray $ do
    rec <- AS.newArray ((0,0,0),(towers-1,floors-1,rooms-1)) 0
    forM_ is $
        \(tow,fl,r,n) -> let
            loc = (tow,fl,r)
            in
                AS.readArray rec loc >>= AS.writeArray rec loc . (+n)
    return rec

readline :: String -> Info
readline = (\[x,y,z,w] -> (x,y,z,w+1)) . map (subtract 1 . read) . words

-- let's see how iterative haskell can be!
showRooms :: A.UArray Room Int -> [String]
showRooms ls = let dats = takeEvery (floors*rooms) . map show $ A.elems ls in
    intercalate [replicate 20 '#'] . map (map (concatMap (' ':)) . takeEvery rooms) $ dats

        
takeEvery :: Int -> [a] -> [[a]]
takeEvery _ [] = []
takeEvery n xs = let (pre,post) = splitAt n xs
                     in pre:takeEvery n post

main = do
    _ <- getLine
    getContents >>= mapM_ putStrLn . showRooms . manage . map readline . lines

Measured memory_bytes: 4284