akhauriyash/Code-Regression huggingface dataset:
//Name: Recutangular Searching
//Level: 3
//Category: 累積和,連続区間
//Note: 類題 POJ1964

/*
 * あるマスについて，そのマスを含めてそれより上にいくつ白マスが連続しているかを記憶しておく．
 * すると，1行内のある区間を底辺に持つ長方形の面積は，区間長 * その区間内の最小値で与えられることが分かる．
 *
 * これはスタックを使い，ある高さの区間がいくつ連続しているかを高さの昇順で管理すると効率良く求められる．
 * 1行を左から右になめながら値をpushしていくが，このとき
 * ・スタックトップより大きい値であればそのままpushする．
 * ・スタックトップより小さい値 h' であれば，このマスを含んで h' より高い長方形は作れないため，スタックトップを h' に揃えてしまう．
 *   つまり， h' より小さい値が出てくるまでスタックを巻き戻しながらその個数を数え，最後に h' を同数追加すればよい．
 *   以前にpushした値を起点とする長方形は，巻き戻しの途中で右方向の最大区間長を得られるためここで計算できる．
 * 
 * また， h' を同数追加するという処理は (値, 長さ) のペアを管理するようにすると効率的に処理できる．
 * この処理をした上でのオーダーは，各マスを1回ずつなめる操作でO(N^2)，スタック操作は高々2N回しかpushされず，したがってpopも2N回であるからO(N)．
 * よって全体のオーダーは O(N^2)．
 */
#include <iostream>
#include <string>
#include <stack>
#include <algorithm>

using namespace std;

int acc[1024][1001];

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

    while(true) {
        int H, W;
        cin >> H >> W;
        if(!H && !W) break;
        for(int i = 0; i < W; ++i) {
            acc[0][i] = 0;
        }
        for(int i = 0; i < H; ++i) {
            string line;
            cin >> line;
            for(int c = 0; c < W; ++c) {
                if(i > 0) acc[i][c] = acc[i-1][c];
                if(line[c] == '*') acc[i][c] = 0;
                else acc[i][c]++;
            }
        }
        int ans = 0;
        for(int r = 0; r < H; ++r) {
            // 番兵
            acc[r][W] = 0;
            // スタックの中身は常に昇順になっている．
            stack<pair<int,int> > stk;
            for(int c = 0; c <= W; ++c) {
                int len = 0;
                const int cur = acc[r][c];
                while(!stk.empty() && stk.top().first >= cur) {
                    len += stk.top().second;
                    const int area = len * stk.top().first;
                    ans = max(ans, area);
                    stk.pop();
                }
                ++len;
                stk.push(make_pair(cur, len));
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    int n, t;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    
    t = 0;
    for(int i=0; i<n; i++){
        if(t == h[i]){
            continue;
        }
        if(t < h[i]){
            t = h[i] - 1;
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int A,B,C,D,E,F; cin>>A>>B>>C>>D>>E>>F;
	vector<bool> water(F+1,false), sugar(F+1,false);
	for (int i=0; 100*i*A<=F; i++)
		for (int j=0; 100*(i*A+j*B)<=F; j++)
			water[100*(i*A+j*B)]=true;
	for (int i=0; i*C<=F; i++)
		for (int j=0; i*C+j*D<=F; j++)
			sugar[i*C+j*D]=true;
	int x=-1, y=-1;
	for (int i=1; i<=F; i++) {
		for (int j=0; i+j<=F; j++) {
			if(!water[i]) continue;
			if(!sugar[j]) continue;
			if(j*100>i*E) continue;
			int xx=i+j, yy=j;
			if(x==-1&&y==-1)
				x=xx, y=yy;
			else {
				if(x*yy>=y*xx)
					x=xx, y=yy;
			}
		}
	}
	cout<<x<<" "<<y<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
double max, min, n;
scanf("%lf",&max);
min = max;
while(scanf("%lf",&n) != EOF ) {
if(max < n ) {
max = n;
}
if(min > n ) {
min = n;
}
}
printf("%lf\n",max-min);
return 0;
}

Measured memory_bytes: 644
N = int(input())
a = [int(i) for i in input().split()]
mn = min(a)
mx = max(a)
ans = 10**8
for j in range(mn,mx+1):
    costs = 0
    for i in a:
        cost = (i-j)**2
        costs += cost
    if ans>costs:
        ans = costs
print(ans)

Measured memory_bytes: 38512
#include <iostream>
#include <cstdio>

using namespace std;

long long int DP[10][101][1001]; // DP[i][j][k] : ??????????????\??????????´???§????¨?????????¨????????????????????°

int main(){
	
	int n, s, t;
	
	long long int sum;
	
	cin >> n >> s;
	
	for(int i = 0; i < 10; i++){
		for(int j = 0; j <= 100; j++){
			for(int k = 0; k <= 1000; k++){
				DP[i][j][k] = 0;
			}
		}
	}
	
	DP[1][0][0] = 1;
	
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 100; j++){
			for(int k = 0; k <= 1000; k++){
				if(i == 1 && j == k){
					DP[i][j][k] = 1;
				}else if(k - j < 0){
					DP[i][j][k] = DP[i][j - 1][k];
				}else{
					DP[i][j][k] = DP[i][j - 1][k] + DP[i - 1][j - 1][k - j];
				}
			}
		}
	}
	
	while(n != 0 || s != 0){
		
		cout << DP[n][100][s] << endl;
		
		cin >> n >> s;
	}
	
	return 0;
}

Measured memory_bytes: 9052
#include<cstdio>
#include<queue>
using namespace std;

queue<char>q[3];

void Scan(int n)
{
    char ch;
    while((ch=getchar())!='\n')
    {
        q[n].push(ch);
    }
}

int main()
{
    Scan(0);
    Scan(1);
    Scan(2);
    int k=0;
    while(q[k].size())
    {
        char ch=q[k].front();
        q[k].pop();
        k=ch-'a';
    }
    printf("%c\n",k+'A');
    return 0;
}


Measured memory_bytes: 3184
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i32 n, m;
vec<pair<i32,i64>> g[1001];
i64 t[1001];

i32 main()
{
	cin >> n >> m;
	times(n + 1, i) { t[i] = LLONG_MIN; }
	times(m, i) {
		i64 a, b, c; cin >> a >> b >> c;
		g[a].append(make_pair(b, c));
	}

	set<tuple<i64, i32, i32>> s;
	s.insert(make_tuple(0, 1, 0));
	while (s.size()) {
		i32 i, cc; i64 d;
		tie(d, i, cc) = *s.begin();
		d = -d;
		if (cc > 2010) {
			d = LLONG_MAX/2;
		}
		s.erase(s.begin());
		if (t[i] >= d) {
			continue;
		}
		t[i] = d;
		times(g[i].size(), k) {
			i32 b = g[i][k].first;
			i64 c = g[i][k].second;
			if (t[b] >= c+d) {
				continue;
			}
			s.insert(make_tuple(-(c + d), b, cc+1));
		}
	}
	if (t[n] >= LLONG_MAX/2) {
		cout << "inf" << endl;
	}
	else {
		cout << t[n] << endl;
	}
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
using namespace std;
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 <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    string s;
    set<char> st;
    cin >> s;
    rep(i,s.size()) {
        st.insert(s[i]);
    }
    if (s.size() == st.size()) {
        cout << "yes" <<"\n";
    } else {
        cout << "no" << "\n";
    }
}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    ll x; scanf("%lld" , &x);

    for(ll A = -1000 ; A <= 1000 ; A ++) {
            for(ll B = -1000 ; B <= 1000 ; B ++) {

                    ll B2 = 1;
                    for(int i = 0 ; i < 5 ; i ++) {
                            B2 *= B;
                    }

                    ll A2 = 1;
                    for(int i = 0 ; i < 5 ; i ++) {
                            A2 *= A;
                    }

                    if(A2 - B2 == x) {
                            printf("%lld %lld\n" , A , B);
                            return;
                    }
            }
    }

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 3824
array_out = []
while true
 array_in = gets.split
 if array_in == ["0","0"]
  break
 end
 array_out.push array_in
end

i = 0
while i < array_out.length
 if array_out[i][0].to_i > array_out[i][1].to_i
  puts "#{array_out[i][1]} #{array_out[i][0]}"
 else
  puts "#{array_out[i][0]} #{array_out[i][1]}"
 end

 i = i+1
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0;i<h;i++){
    cin >> a[i];
  }
  int count = 0;
  for (int i = 0; i < h;i++){
    for (int j = 0; j < w;j++){
      if(a[i][j]=='#'){
        count++;
      }
    }
  }
  if(count==h+w-1){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}



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

int h, w;
vector<string> a(8);
vector<vector<int>> arrived(8, vector<int>(8, 0));
int nextY[] = {1, 0, -1, 0};
int nextX[] = {0, 1, 0, -1};

/*In range->true, Out range->false*/
/*
bool range_check(int y, int x) {
  if (y < 0 || x < 0 || y >= h || x >= w) {
    return false;
  }
  return true;
}

bool dfs(int y, int x) {
  if (y == h - 1 && x == w - 1) {
    return true;
  }
  arrived[y][x] = 1;
  int count = 0;
  for (int i = 0; i < 4; i++) {
    int ny = y + nextY[i], nx = x + nextX[i];
    if (range_check(ny, nx) && arrived[ny][nx] == 0) {
      if (a[ny][nx] == '#') {
        count++;
      }
    }
  }
  if (count != 1) {
    return false;
  } else {
    for (int i = 0; i < 2; i++) {
      int ny = y + nextY[i], nx = x + nextX[i];
      if (range_check(ny, nx) && arrived[ny][nx] == 0) {
        if (a[ny][nx] == '#') {
          return dfs(ny, nx);
        }
      }
    }
  }
  return false;
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  if (dfs(0, 0)) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}*/

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
    int a[100010];
  for(int i=1;i<=n;i++)cin>>a[i];
  int ans=0;
  for(int i=1;i<=n;i++){
    if(a[a[i]]==i){
      ans++;
    }
  }
  cout<<ans/2<<endl;
}

Measured memory_bytes: 640
from itertools import groupby, accumulate


def solve(t):
    grp = [(c, len(list(itr))) for c, itr in groupby(t)]
    even_ones = 0
    zeros_splitting_odd_ones = [0]
    for c, cnt in grp:
        if c == '1':
            if cnt % 2 == 0:
                even_ones += cnt
            else:
                even_ones += cnt - 1
                zeros_splitting_odd_ones.append(0)
        else:
            zeros_splitting_odd_ones[-1] += cnt

    # 初期状態で加算されるか
    ad = int(zeros_splitting_odd_ones[0] % 2 == 0)
    is_added_init = [ad]
    for cnt in zeros_splitting_odd_ones[1:]:
        ad ^= (cnt % 2) ^ 1
        is_added_init.append(ad)
    is_added_init.pop()
    acc_added_init = list(accumulate(reversed(is_added_init)))  # 自分より右で、初期状態で足される1の数
    acc_added_init.reverse()

    odd_ones = len(is_added_init)
    ans = 0

    if odd_ones > 0:

        # 先頭の0を全て除くまでのスコア
        zso = zeros_splitting_odd_ones[0]
        zso1 = zso // 2
        zso0 = zso - zso1
        ans += acc_added_init[0] * zso0
        ans += (odd_ones - acc_added_init[0]) * zso1

        # 1に挟まれた0を1箇所1つずつ残して全て除くまでのスコア
        ad = int(zeros_splitting_odd_ones[0] % 2 == 0)
        for i in range(1, odd_ones):
            zso = zeros_splitting_odd_ones[i] - 1
            zso1 = zso // 2
            zso0 = zso - zso1
            fixed_ones = i
            right_ones = odd_ones - fixed_ones
            ans += fixed_ones * zso
            if ad:
                # 除外中の0区間の次の"1"が初期状態で足されるなら、区間を操作する直前にも足される
                ans += acc_added_init[i] * zso0
                ans += (right_ones - acc_added_init[i]) * zso1
            else:
                # 除外中の0区間の次の"1"が初期状態で足されないなら、区間を操作する直前には足される
                ans += (right_ones - acc_added_init[i]) * zso0
                ans += acc_added_init[i] * zso1
            ad ^= zso % 2

        # 末尾の0を全て除くまでのスコア
        ans += zeros_splitting_odd_ones[-1] * odd_ones

        # 1に挟まれた0を右から除いていくまでのスコア
        for i in range(1, odd_ones):
            left_ones = odd_ones - i
            right_ones = i
            ans += left_ones + (right_ones + 1) // 2

    # 1だけの列を1つずつ除いていくスコア
    all_ones = odd_ones + even_ones
    ao1 = all_ones // 2
    ao0 = all_ones - ao1
    ans += (ao0 * (ao0 + 1) + ao1 * (ao1 + 1)) // 2

    # 0を除いている間の、偶数個の1によるスコア
    all_zeros = len(t) - all_ones
    ans += all_zeros * (even_ones // 2)

    return ans


t = input()
print(solve(t))


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

#define LL long long

#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) (((l)+(r))>>1)

const int MOD = (int) 1e9 + 7;
const double eps = (double) 1e-8;
const int maxn = (int) 2e5 + 20;

int n;
int cnt[5];

int calc(string s)
{
    int res = 0;
    for(int i = 0; i < s.size() - 1; i++)
    {
        if(s[i] == 'A' && s[i + 1] == 'B')
            res++;
    }
    return res;
}

void work()
{
    memset(cnt, 0, sizeof(cnt));
    int ans = 0;
    cin >>n;
    string s;
    for(int i = 0; i < n; i++)
    {
        cin >>s;
        ans += calc(s);

        int st = 0;
        if(s[0] == 'B') st |= 1;
        if(s[s.size() - 1] == 'A') st |= 2;
        cnt[st]++;
    }

    if(cnt[3])
    {
        ans += cnt[3] - 1;
        if(cnt[1]) ans++, cnt[1]--;
        if(cnt[2]) ans++, cnt[2]--;
    }

    ans += min(cnt[1], cnt[2]);

    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r" ,stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416

    int tc = 1;
//    scanf("%d", &tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, k;
  cin >> n >> k;
  vi h(n);
  rep(i,n) cin >> h[i];
  
  vi dp(n+1,INF);
  dp[0] = 0;
  rep(i,n) {
    rrep(j,k) {
      if (i+j > n) continue;
      chmin(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
    }
  }

  cout << dp[n-1] << endl;
  return 0;
}

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

int main() {
    int n,temp,rev=0;
    cin>>n;
    deque<int> ans;
    rep(i,n) {
        cin>>temp;
        if (rev) ans.push_front(temp);
        else ans.push_back(temp);
        rev=1-rev;
    }
    if (rev) reverse(ans.begin(),ans.end());
    for (auto v : ans) cout<<v<<" ";
    cout<<endl;
}


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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,mn=inf;
int cev,cevap;
string s;
vector<int> v;

main(void){
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
		cevap+=a[i];
	}
	for(int i=1;i<n;i++){
		cev+=a[i];
		mn=min(mn,abs(cev-(cevap-cev)));
	}
	printf("%lld\n",mn);
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll  long long
#define endl '\n'
const ll mod = 10000010;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

	long long  N;
	cin >> N;
	long long  res = N - 1;
	for(ll i=1;i<=mod;i++){
		if (N % i == 0) {
			res = min(res,  (N / i) - 2+i);
		}
	}
	cout << res << endl;

	return 0;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
#define dump(x) cerr << #x " = " << boolalpha << (x) << endl;
using namespace std;
template <typename T>
inline auto input () { T a; return cin >> a ? a : throw runtime_error ("no input"); }

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  auto n = input <size_t> ();
  vector <int64_t> a;
  copy_n (istream_iterator <iterator_traits <decltype (begin (a))>::value_type> (cin), n, back_inserter (a));

  auto minus_cnt = 0;
  auto zero_cnt = 0;
  for (auto && elem : a)
  {
    if (elem == 0) ++ zero_cnt;
    else if (elem < 0) ++ minus_cnt;
  }
  int64_t ans = 0;
  if (minus_cnt % 2 == 0)
  {
    for (auto && elem : a)
    {
      ans += abs (elem);
    }
  }
  else
  {
    sort (ALL (a), [] (auto x, auto y) { return abs (x) < abs (y); });
    FOR (ite, next (begin (a)), end (a))
    {
      ans += abs (* ite);
    }
    ans -= abs (a.front ());
  }
  cout << ans << endl;
}



Measured memory_bytes: 1400
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int i, n, flag = 0;
	scanf("%d", &n);
	if(n%2 != 0) flag = 1;
	char s[n];
	scanf("%s", s);
	rep(i,n/2){
		if(s[i] != s[n/2 + i]) flag = 1;
	}
	if(flag == 1) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;string A,B,C;cin>>N>>A>>B>>C;
    int count=0;
    for(int i=0;i<N;i++){
        if(A.at(i)==B.at(i)&&B.at(i)==C.at(i)){
        }else if(A.at(i)==B.at(i)||B.at(i)==C.at(i)||C.at(i)==A.at(i)){
            count++;
        }else{
            count=count+2;
        }
    }cout<<count<<endl;
}

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

int  a[200005];
int  ans[200005];
vector<int> vec[200005];

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        int x;
        cin >> x;
        a[i] = x;
    }
    int sum=0;
    for(int i=n;i>=1;i--){
      sum = 0;
        for(int j = i+i;j<=n;j+=i){
                sum ^= ans[j];
        }
        ans[i] = sum ^a[i];
    }
  	vector <int> b;
  	int m=0;
    rep(i,n){
      if(ans[i+1]){
        b.push_back(i+1);
      }
    }
    cout << b.size()<< endl;
    rep(i,b.size()){
     	cout << b[i] << " ";
    }
    
    
    
    return 0;
}




















Measured memory_bytes: 7928
N = gets.chomp.to_i
A = gets.chomp.split(' ').map(&:to_i)
TOTAL = A.reduce(:+)

M = [0]
0.step((N*2)-1, 2).each do |i|
  i = i % N
  diff = (A[(i+1)%N] - A[i]) * 2
  M[(i+2)%N] = M[i] + diff
end

base = (TOTAL - M.reduce(:+)) / N
puts M.map { |n| n + base }.join(' ')


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

int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d;
  e=max(a,c);
  f=min(b,d);
  if(f>e){
    cout<<f-e<<endl;
  }else{
    cout<<0<<endl;
  }
  
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;int main() {
  int N, K, a, b, Sum;
  cin >> N >> K;
  Sum = 1;
  for(int i = 0; i < N; i++){
  a = Sum * 2;
  b = Sum + K;
    if(a < b){
     Sum = a;
    }
    else{
     Sum = b;
    }
  }
  cout << Sum << endl;
}

Measured memory_bytes: 384
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		long[] V = { sc.nextLong(), sc.nextLong() };
		Arrays.sort(V);
		if (V[1] - V[0] > 1) {
			System.out.println("Alice");
		} else {
			System.out.println("Brown");
		}
//		for (int i = 0; i < 100; ++i) {
//			for (int j = i; j < 100; ++j) {
//				System.out.println(i + " " + j + " " + dfs(i, j));
//			}
//		}
	}

	int[][] memo = new int[1000][1000];

	boolean dfs(int a, int b) {
		if (memo[a][b] != 0) {
			return memo[a][b] == 1;
		}
		boolean f = false;
		for (int i = 1; 2 * i <= a; ++i) {
			f |= !dfs(a - i * 2, b + i);
		}
		for (int i = 1; 2 * i <= b; ++i) {
			f |= !dfs(a + i, b - 2 * i);
		}
		if (f) {
			memo[a][b] = 1;
		} else {
			memo[a][b] = -1;
		}
		return f;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

#define mp make_pair
#define pb push_back 
#define pf push_front 
#define pbp pop_back
#define pfp pop_front 
#define sz(x) x.size()
#define all(x) x.begin(),x.end() 
#define ios_base ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define open(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define F first
#define S second

using namespace std;

typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;

const int mod = 1e9+7;
const int N = 1e5+123;
const int inf = 1e9+123;
const long long INF = 1e18;
const double eps = 1e-5;

int n, m, x, y;
int ok[N], cnt[N];
int main (){
 ios_base
 cin >> n >> m;
 ok[1] = 1;
 for(int i = 1; i <= n; i ++){
  cnt[i] = 1;
 }
 for(int i = 1; i <= m; i ++){
  cin >> x >> y;
  if(ok[x] == 1 && cnt[x] == 1){
   ok[x] = 0;
   ok[y] = 1;
  }else if(ok[x] == 1){
   ok[y] = 1;
  }
  cnt[x] --;
  cnt[y] ++;
 }
 int cnt = 0;
 for(int i = 1; i <= n; i ++){
  if(ok[i] == 1) cnt ++;
 }
 cout << cnt;
 return  0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define pint pair<int,int>
#define pdouble pair<double,double>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    if(s == "SUN")puts("7");
    if(s == "MON")puts("6");
    if(s == "TUE")puts("5");
    if(s == "WED")puts("4");
    if(s == "THU")puts("3");
    if(s == "FRI")puts("2");
    if(s == "SAT")puts("1");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int dp[1010][1010];

int main(){
	while(1){
		int n,m; cin >> n >> m;
		if(n==0&&m==0)break;
		vector<int> a(n),b(n),c(n+1);
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n;i++){
			cin >> b[i];
		}
		c[0]=0;
		for(int i=0;i<n;i++){
			if(a[i]==b[i])c[i+1]=0;
			else if(a[i]<b[i])c[i+1]=b[i]-a[i];
			else c[i+1]=b[i]+m-a[i];
		}
		for(int i=0;i<1010;i++){
			for(int j=0;j<1010;j++){
				dp[i][j]=1e9;
			}
		}
		dp[0][0]=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(dp[i][j]==1e9)continue;
				if(j>0){
					dp[i+1][j-1]=min(dp[i+1][j-1],dp[i][j]+(c[i]+j*m<c[i+1]+(j-1)*m?c[i+1]+(j-1)*m-c[i]-j*m:0));
				}
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(c[i]+j*m<c[i+1]+j*m?c[i+1]+j*m-c[i]-j*m:0));
				dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(c[i]+j*m<c[i+1]+(j+1)*m?c[i+1]+(j+1)*m-c[i]-j*m:0));
			}
		}
		int ans=1e9;
		for(int i=0;i<10;i++){
			ans=min(ans,dp[n][i]);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 7064
// 失敗するからこそ そこから立ち向かって行く強さがあって そんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int main(){
	FIO
	
	string s, t, u;cin >> s >> t >> u;
	int i = 0, j = -1, k = -1;
	char curr = s[0];
	while(true){
		if(i == s.size()){
			cout << 'A';
			return 0;
		}
		if(j == t.size()){
			cout << 'B';
			return 0;
		}
		if(k == u.size()){
			cout << 'C';
			return 0;
		}
		if(curr == 'a')i++, curr = s[i];
		if(curr == 'b')j++, curr = t[j];
		if(curr == 'c')k++, curr = u[k];
		
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;

int main() {
  int n, T, c, t, ans= 1<<30;
  cin >> n >> T;
  rep(i, n){
    cin >> c >> t;
    if(t <= T){
      ans = min(ans, c);
    }
  }
  if(ans < 10000){
    cout << ans << endl;
  }else{
    cout << "TLE" << endl;
  }
}



Measured memory_bytes: 256
import math

data = input().split()
data = [int(i) for i in data]

short_x = data[0] * math.cos(math.radians(360 * (60 * data[2] + data[3]) /720))
short_y = data[0] * math.sin(math.radians(360 * (60 * data[2] + data[3]) /720))

long_x = data[1] * math.cos(math.radians(360 * (data[3]) / 60))
long_y = data[1] * math.sin(math.radians(360 * (data[3]) / 60))

print( math.sqrt((short_x - long_x) * (short_x - long_x) + (short_y - long_y) * (short_y - long_y)))

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

int main (void) {
  int N;
  scanf("%d", &N);
  char S[4];
  int c0 = 0;
  int c1 = 0;
  int c2 = 0;
  int c3 = 0;

  for (int i = 0; i < N; i++) {
    scanf("%s", S);
    if (strcmp(S, "AC") == 0) {
      c0 += 1;
    } else if (strcmp(S, "WA") == 0) {
      c1 += 1;
    } else if (strcmp(S, "TLE") == 0) {
      c2 += 1;
    } else if (strcmp(S, "RE") == 0) {
      c3 += 1;
    }
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", c0, c1, c2, c3);
}

Measured memory_bytes: 1700
#include <stdio.h>
#define N 10000

int arrayA[2000001],arrayC[N+1],arrayB[2000001];
int main()
{

  int k,i,j,max=0;
  //int arrayA[2000001],arrayC[N+1],arrayB[2000001];

  scanf("%d",&k);
  for(i = 0 ; i < k ; i++)
    {
      scanf("%d",&arrayA[i]);
      if(max<arrayA[i])max = arrayA[i];
    }




  for(i = 0 ; i <= max ; i++) arrayC[i] = 0;


  for(j = 0 ; j < k ; j++) arrayC[arrayA[j]]++;



  for(i = 1 ; i <= max ; i++)arrayC[i] = arrayC[i] + arrayC[i-1];



  for(j = k-1 ; j >= 0 ; j--)
    {
      arrayB[arrayC[arrayA[j]]]= arrayA[j];
      arrayC[arrayA[j]]--;

    }






  for(i = 1 ; i < k ; i++)
    {
      printf("%d ",arrayB[i]);
    }
  printf("%d",arrayB[k]);
  printf("\n");

  return 0;
}


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

#define int long long
const int INF = 1e9;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

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

  for ( int a0 = -200; a0 <= 200; a0++ ) {    
    int b[3];
    for ( int i = 0; i < 3; i++ ) {
      b[i] = c[0][i]-a0;      
    }
    
    int a[3];
    a[1] = a[2] = INF;
    a[0] = a0;

    bool flag = true;    
    for ( int i = 0; i < 3; i++ ) {
      for ( int j = 0; j < 3; j++ ) {
	if ( a[i] == INF ) {
	  a[i] = c[i][j]-b[j];	  
	} else {
	  if ( a[i] != c[i][j]-b[j] ) {
	    flag = false;
	    break;	    
	  }
	}
      }      
    }

    if ( flag ) {
      cout << "Yes" << endl;
      return 0;
    } 
  }

  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    string s, t;
    cin >> s;
    l = s.length();
    if(l % 2 == 1){
        cout << "No";
        return 0;
    }
    for(i = 0; i < l-1; i = i+2){
        if(s[i] != 'h' || s[i+1] != 'i'){
           cout << "No";
           return 0;
        }
    }
    cout << "Yes";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
 
using namespace std;
using ll = long long;
 
ll gcd (ll a, ll b) {
    return (b==0)? a : gcd(b, a%b);
}
 
int main() {
    ll a, b;
    cin >> a >> b;
    ll c = gcd(a, b);
    //cout << c << endl;
    ll count=1;
    ll n = c;
    for (ll i=2; i*i <= n; ++i) {
        if (n%i == 0) {
            ++count;
            //cout << i << endl;
        }
        while (n%i == 0) {
            n = n/i;
        }
    }
    if (n != 1) ++count;
    cout << count << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<P> v(n);
  rep(i, n) cin >> v[i].first >> v[i].second;
  int count = 0;
  rep(i, n){
    if (v[i].first == v[i].second){
      count++;
    } else {
      count = 0;
    }
    if (count == 3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int main(){
  int n;cin>>n;
  int a[110];
  rep(i,n) cin>>a[i];
  sort(a,a+n);
  prin(a[n-1]-a[0]);

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int[] Antennas= new int[5];
    boolean abc=false;
    for (int i = 0; i < 5; i++) {
      int Antenna=sc.nextInt();
      Antennas[i]=Antenna;
    }
    int Distanse=sc.nextInt();
   
    for(int i=0;i<4;i++){
      for(int j=1;j<5;j++){
        if(Math.abs(Antennas[i]-Antennas[j])>Distanse){
          abc=true;
        }
     }
  }
    if(abc==true){
      System.out.println(":(");
    }else{
      System.out.println("Yay!");
    }
}
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

typedef struct Node{
    int key;
    Node *prev, *next;
}Node;

Node* nil = (Node*)malloc(sizeof(Node));

void initialize(void){
    nil -> key = -1;
    nil -> prev = nil;
    nil -> next = nil;
}

void insert(int value){
    Node* n = (Node*)malloc(sizeof(Node));
    nil->next->prev = n;
    n->key = value;
    n->prev = nil;
    n->next = nil->next;
    nil->next = n;
}

void delete_(int value){
    Node* n = nil->next;
    while(1){
        if(n == nil){
            break;
        }
        if(n->key == value){
            Node* n_prev = n->prev;
            Node* n_next = n->next;
            n->prev->next = n_next;
            n->next->prev = n_prev;
            free(n);
            break;
        }
        n = n->next;
    }
}

void deleteFirst(){
    Node* n = nil->next;
    n->next->prev = nil;
    nil->next = n->next;
    free(n);
}

void deleteLast(){
    Node* n = nil->prev;
    n->prev->next = nil;
    nil->prev = n->prev;
    free(n);
}

void print_elements(){
    bool is_first = true;
    Node* n = nil->next;
    while(n != nil){
        if(is_first){
            is_first = false;
        }else{
            printf(" ");
        }
        printf("%d", n->key);
        n = n->next;
    }
    printf("\n");
}

int main(void){
    int n;
    scanf("%d", &n);
    initialize();
    
    for(int i = 0; i < n; i++){
        char s[20];
        int value;
        scanf("%s", s);
        string s_ = s;

        if(s_ == "insert"){
            scanf("%d", &value);
            insert(value);
        }else if(s_ == "delete"){
            scanf("%d", &value);
            delete_(value);
        }else if(s_ == "deleteFirst"){
            deleteFirst();
        }else if(s_ == "deleteLast"){
            deleteLast();
        }
    }
    print_elements();
}



Measured memory_bytes: 34444
#include<iostream>

using namespace std;

int data[300][3];
int sum[300][3]={0};
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>data[i][0]>>data[i][1]>>data[i][2];
	}
	
	for(int k=0;k<3;k++)for(int i=0;i<n;i++){
		sum[i][k]=data[i][k];
		for(int j=0;j<n;j++){
			if(data[i][k]==data[j][k] && i!=j)sum[i][k]=0;
		}
	}
	for(int i=0;i<n;i++){
		cout<<sum[i][0]+sum[i][1]+sum[i][2]<<endl;
	}
}

Measured memory_bytes: 1168
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(void) {
    int n;
    cin >> n;
    rep(i, 26) {
        if ((n-4*i) < 0) break;
        if ((n-4*i) % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

namespace AtCoder_ABC089_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            foreach(var s_ in s)
            {
                if (s_ == "Y")
                {
                    Console.WriteLine("Four");
                    return;
                }
            }
            Console.WriteLine("Three");
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define N 20
#define M 65540
#define Mod 1000000007
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, m, ans, maxl, a[N], dp[N][M], f[M], inv[M];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
bool cmp(int a, int b){ return a > b;}
int Inc(int a, int b){ return (a += b) >= Mod ? a - Mod : a;}
int Dec(int a, int b){ return (a -= b) < 0 ? a + Mod : a;}
int Mul(int a, int b){ return 1ll * a * b % Mod;}
int C(int n, int m){
    if(m > n) return 0;
    return Mul(f[n], Mul(inv[m], inv[n - m]));
}
int Qpow(int a, int b){ 
    int ans = 1;
    while(b){
        if(b & 1) ans = Mul(ans, a);
        a = Mul(a, a), b >>= 1;
    }
    return ans;
}
int main(){
    m = read(), n = read();
    rep(i, 1, n) a[i] = read();
    sort(a + 1, a + n + 1, cmp);
    f[0] = inv[0] = 1;
    rep(i, 1, M - 4) f[i] = Mul(f[i - 1], i), inv[i] = Qpow(f[i], Mod - 2);
    dp[0][0] = 1, maxl = (1 << m) - 1;
    rep(i, 0, n - 1) rep(j, 0, maxl){
        int res = maxl + 1 - a[i + 1] - j;
        dp[i + 1][j] = Inc(dp[i + 1][j], dp[i][j]);
        rep(k, 0, m - 1) if(!(j & (1 << k))){
            dp[i + 1][j | (1 << k)] = Inc(dp[i + 1][j | (1 << k)], Mul(dp[i][j], Mul(C(res, (1 << k) - 1), f[(1 << k)])));
        } 
    }
    rep(i, 0, maxl){
        int s = i, cnt = 0;
        while(s){
            if(s & 1) cnt++;
            s >>= 1;
        }
        if(cnt & 1) ans = Dec(ans, Mul(dp[n][i], f[maxl - i]));
        else ans = Inc(ans, Mul(dp[n][i], f[maxl - i]));
    }
    printf("%d", Mul(ans, maxl + 1));
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  if (S.at(5) == '0' && S.at(6) == '1'){
    cout << "Heisei" << endl;
  }
  else if (S.at(5) == '0' && S.at(6) == '2'){
    cout << "Heisei" << endl;
  }
  else if (S.at(5) == '0' && S.at(6) == '3'){
    cout << "Heisei" << endl;
  }
  else if (S.at(5) == '0' && S.at(6) == '4'){
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 3576
package main

import "fmt"

func main(){
  var A,B,C,X int
  fmt.Scan(&A)
  fmt.Scan(&B)
  fmt.Scan(&C)
  fmt.Scan(&X)
  // fmt.Println(A,B,C,X)
  result := 0
  i := X
  for a:=0; a<= A; a++{
    for b:=0; b<= B; b++{
      for c:=0; c<= C; c++{
        // fmt.Println(a,b,c)
        if a*500+b*100+c*50 == i{
          result +=1
        }
      }
    }
  }

  // fmt.Println(A,B,C,X)
  fmt.Println(result)
}


Measured memory_bytes: 512
from collections import Counter
n=int(input())
v = list(map(int,input().split()))
even = [v[i] for i in range(n) if i % 2 == 0]
odd = [v[i] for i in range(n) if i%2==1]
ct_even = Counter(even).most_common(2)
ct_odd = Counter(odd).most_common(2)
if ct_even[0][0]!=ct_odd[0][0]:
  print(n-ct_even[0][1]-ct_odd[0][1])
else:
  if len(ct_even)==1 and len(ct_odd)==1:
    print(n//2)
  elif len(ct_even)!=1 and len(ct_odd)==1:
    print(n//2 - ct_even[1][1])
  elif len(ct_even)==1 and len(ct_odd)!=1:
    print(n//2-ct_odd[1][1])
  else:
    k=max(ct_even[0][1]+ct_odd[1][1], ct_even[1][1]+ct_odd[0][1])
    print(n-k)

Measured memory_bytes: 15972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int ans = 0;
        for (int i = 0; i < n; i+=2) {
            if (a[i] % 2 == 1)
                ans++;
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 32664
import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

class Main {
        static BufferedReader jvin = new BufferedReader(new InputStreamReader(System.in));
        static PrintWriter jvout = new PrintWriter(System.out);

        public static void main(String[] args) throws IOException {
                Main instance = new Main();
                Main.passStaticVar();
        }

        public static void passStaticVar() throws IOException {
                int X, A, B;
                String l = jvin.readLine();
                String[] t = l.split(" ");
                X = Integer.parseInt(t[0]);
                A = Integer.parseInt(t[1]);
                B = Integer.parseInt(t[2]);

                if (A >= B)
                        jvout.write("delicious");
                else if (A+X >= B)
                        jvout.write("safe");
                else
                        jvout.write("dangerous");
                jvout.flush();
        }
}


Measured memory_bytes: 22356
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////

int w,h;
int si,sj;

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

int room[25][25];
int ans=0;
int dfs(int x,int y){
    room[x][y]=2;ans++;
    for(int i=0;i<=3;i++){
        int xx=x+dx[i],yy=y+dy[i];
        if(0<=xx&&xx<=h-1&&0<=yy&&yy<=w-1&&room[xx][yy]==0)dfs(xx,yy);
    }
    return ans;
}


int main(){
    while(1){
        cin>>w>>h;
        if(w==0)break;
        ans=0;
        for(int i=0;i<=h-1;i++){
            char s[w+1];cin>>s;
            for(int j=0;j<=w-1;j++){
                if(s[j]=='.')room[i][j]=0;
                else if(s[j]=='#')room[i][j]=1;
                else if(s[j]=='@')room[i][j]=2,si=i,sj=j;
            }
        }
        cout<<dfs(si,sj)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3072
import sys
readline = sys.stdin.readline
from fractions import gcd

def main():
    N = int(readline())
    ans = 1
    for _ in range(N):
        t = int(readline())
        ans = (ans * t) // gcd(ans, t)
    
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 5048
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct{
	char g;
	int num;
}card;

card B[100000];

card L[(100000 / 2) +1], R[(100000 / 2)+1];

int A[100000];
char C[100000][2];

int Partition(int A[], int p, int r) {
	int x, i, j, tmp;
	char mark[2];
	x = A[r];
	i = p - 1;
	for (j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
			strcpy(mark, C[i]);
			strcpy(C[i],C[j]);
			strcpy(C[j],mark);
		}
	}
	tmp = A[i + 1];
	A[i + 1] = A[r];
	A[r] = tmp;
	strcpy(mark,C[i+1]);
	strcpy(C[i+1],C[r]);
	strcpy(C[r], mark);
	return i + 1;
}

void Quick(int A[],int p,int r) {
	int q;
	if (p < r) {
		q = Partition(A, p, r);
		Quick(A, p, q - 1);
		Quick(A, q + 1, r);
	}
}

void merge(int n, int left, int mid, int right) {
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	for (i = 0; i < n1; i++) L[i] = B[left + i];
	for (i = 0; i < n2; i++) R[i] = B[mid + i];
	L[n1].num = R[n2].num = 200000;
	i = j = 0;
	for (k = left; k < right; k++) {
		if (L[i].num <= R[j].num) 	B[k] = L[i++];
		else	B[k] = R[j++];
	}
}

void merge_sort(int n, int left, int right) {

	int mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		merge_sort( n, left, mid);
		merge_sort( n, mid, right);
		merge(n, left, mid, right);
	}

}

int main() {

	int i, n, q,flag = 1;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s %d", C[i], &A[i]);
		B[i].g = *C[i];
		B[i].num = A[i];
	}

	Quick(A, 0, n - 1);
	merge_sort(n,0, n );
	for (i = 0; i < n; i++) {
		if (*C[i] != B[i].g || A[i] != B[i].num) {
			flag = 0;
			break;
		}
	}
	if (flag == 0) printf("Not stable\n");
	else printf("Stable\n");

	for (i = 0; i < n; i++) {
		printf("%s %d", C[i], A[i]);
		if (i != n) printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3884
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

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

	boolean used[];
	ArrayList<String> list = new ArrayList<String>();
	ArrayList<String> ans = new ArrayList<String>();
	int pi = 0;
	int qi = 0;
	String p="";
	String q="";
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();

		for(int i=0; i<n; i++) {
			p = p + sc.next();
		}
		for(int i=0; i<n; i++) {
			q = q + sc.next();
		}
		used = new boolean[n+1];
		calc(n, "");
		System.out.println(Math.abs(pi-qi));
		sc.close();
	}


	private void calc(int n, String s) {
		if(s.length()==n) {
			list.add(s);
			if(s.equals(p)) {
				pi=list.size();
			}
			if(s.equals(q)) {
				qi=list.size();
			}
			return;
		}
		for(int i=1; i<=n; i++) {
			if(!used[i]) {
				used[i]=true;
				calc(n, s + String.valueOf(i));
				used[i]=false;
			}
		}

	}
}


Measured memory_bytes: 43840
// DP

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) {  a = b;  return true;  } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {  a = b;  return true;  } return false; }

ll dp[100010][3];

int main() {
  int n; cin >> n;
  ll A[100010][3];
  rep(i,n){ rep(j,3) cin >> A[i][j]; }
  
  rep(i,n) {
    rep(j,3) {
      rep(k,3) {
        if(j == k) continue;
        chmax( dp[i+1][k], dp[i][j] + A[i][k] );
      }
    }
  }
  ll ans = 0;
  rep(j,3) chmax(ans, dp[n][j]);
  cout << ans << endl;
}

Measured memory_bytes: 8300