akhauriyash/Code-Regression huggingface dataset:
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;

int n;
int m;
int a[N];

int main(){
    priority_queue < int > pq;
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &a[i]);
        pq.push(a[i]);
    }
    while(!pq.empty() && m){
        if(pq.size() >= 2){
            int a = pq.top();
            pq.pop();
            int b = pq.top();
            pq.pop();
            if( (a >> 1) + b <= (b >> 1) + a){
                pq.push(a >> 1);
                pq.push(b);
                m--;
            } else {
                pq.push(b >> 1);
                pq.push(a);
                m--;
            }
        } else {
            int cur = pq.top();
            cur >>= 1;
            pq.pop();
            m--;
            if(cur){
                pq.push(cur);
            }
        }
    }
    long long sm = 0;
    while(!pq.empty()){
        sm += pq.top();
        pq.pop();
    }
    printf("%lld\n" , sm);
}


Measured memory_bytes: 1148
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int n,_;
    cin>>n>>_;
    vector<priority_queue<int>> s(n);
    int t,x;
    while(_--){
        int Q;
        cin>>Q;
        switch(Q){
        case 0:
            cin>>t>>x;
            s[t].push(x);
            break;
        case 1:
            cin>>t;
            if(!s[t].empty())cout<<s[t].top()<<endl;
            break;
        case 2:
            cin>>t;
            if(!s[t].empty())s[t].pop();
            break;
        }
    }
}




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

long long int n,c;
long long int x[200000];
long long int v[200000];
long long int pmax[200001];
long long int ans = 0;

int main() {
    cin >> n >> c;
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> v[i];
    }
    x[0] = 0;
    v[0] = 0;
    x[n + 1] = c;
    v[n + 1] = 0;

    long long int E = 0;
    long long int maxi = 0;
    pmax[0] = 0;
    for(int i = 1; i <= n + 1; i++){
        E += v[i];
        E -= x[i] - x[i - 1];
        maxi = max(maxi, E);
        pmax[i] = maxi;
    }
    E = 0;
    ans = max(ans, maxi);
    for(int i = n; i >= 1; i--){
        E += v[i];
        E -= 2 * (x[i + 1] - x[i]);
        ans = max(ans, E + pmax[i - 1]);
    }
    reverse(x, x + n + 2);
    for(int i = 0; i < n + 2; i++){
        x[i] = c - x[i];
    }
    reverse(v, v + n + 2);

    E = 0;
    maxi = 0;
    pmax[0] = 0;
    for(int i = 1; i <= n + 1; i++){
        E += v[i];
        E -= x[i] - x[i - 1];
        maxi = max(maxi, E);
        pmax[i] = maxi;
    }
    E = 0;
    ans = max(ans, maxi);
    for(int i = n; i >= 1; i--){
        E += v[i];
        E -= 2 * (x[i + 1] - x[i]);
        ans = max(ans, E + pmax[i - 1]);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  string S;
  int Q;
  cin >> S >> Q;
  vector<int> T(Q),F(Q);
  vector<char> C(Q),D(Q);
  int a=0,b=0;
  for(int i=0;i<Q;i++){
    cin >> T.at(i);
    if(T.at(i)==1){
      a++;
    }else{
      cin >> F.at(i) >> C.at(i);
      if((a+F.at(i))%2==0){
        S.push_back(C.at(i));
      }else{
        D.at(b)=C.at(i);
        b++;
      }
    }
  }
  reverse(S.begin(),S.end());
  for(int i=0;i<b;i++){
    S.push_back(D.at(i));
  }
  if(a%2==0){
    reverse(S.begin(),S.end());
  }
  cout << S << endl;
}

Measured memory_bytes: 2948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

typedef long long ll;
#define fi first
#define se second


using namespace std;

int main(){
  
  int H, W;
  cin>>H>>W;
  
  int cnt = 0;
  
  char S[H][W+1];
  
  int i;
  int j;
  
  for( i = 0; i < H; i++){
    scanf("%s", S[i]);
  }
  
  for( i = 0; i < H; i++ ){
    for( j = 0; j < W; j++ ){
      if( S[i][j] == '#' ) cnt++;
    }
  }
  
  if( cnt == H+W-1 ) puts("Possible");
  else{              puts("Impossible");}
  
  return 0;
}


Measured memory_bytes: 256
from math import sqrt
N = int(input())
kMaxBound = sqrt(N+1/4) - 1/2
kMax = int(kMaxBound)
if kMax == kMaxBound:
    kMax -= 1
ans = 0
for k in range(1,kMax+1):
    if N % k == 0:
        ans += N//k - 1
print(ans)

Measured memory_bytes: 40172
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{	
	int maxv,minv;
	int n;
	cin>>n;
	int R[200000];
	int i,j;
	for (int i = 0; i < n; ++i)
	{
		cin>>R[i];
	}
	maxv=R[1]-R[0];
	minv=R[0];
	for ( j = 1; j < n; ++j)
	{
		maxv=max(maxv,R[j]-minv);
		minv=min(minv,R[j]);
	}
	cout<<maxv<<endl;
	return 0;
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<pair<short,short>,int> cnt;
	for (int i = 0; i < n; i++) {
		double x;
		cin >> x;
		long long y = llround(x * 1e9);
		short two = 0, five = 0;
		while (!(y % 2)) {
			two++;
			y /= 2;
		}
		while (!(y % 5)) {
			five++;
			y /= 5;
		}
		cnt[pair<short, short>(two, five)]++;
	}
	long long ans = 0;
	for (map<pair<short, short>, int>::iterator i = cnt.begin(); i != cnt.end(); i++)
		for (map<pair<short, short>, int>::iterator j = cnt.begin(); j != cnt.end(); j++)
			if (i->first.first + j->first.first >= 18 && i->first.second + j->first.second >= 18)
				if (i->first < j->first) ans += 1ll * i->second * j->second;
				else if (i->first == j->first) ans += 1ll * i->second * (i->second - 1) / 2;
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

const int N = 1010;
const int M = 1e4 + 10;
const int mod = 1e9 + 7ll;

long long dp[N][M];
int w[N], s[N], v[N], idx[N];
int n;

int main(void) {

    cin.sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    int mx = 0;
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> s[i] >> v[i];
        idx[i] = i;

        mx = max(mx, s[i]);
    }

    sort(idx, idx+n, [] (int a, int b) {
        return w[a] + s[a] < w[b] + s[b];
    });

    long long ans = 0;
    for (int j = 0; j <= mx; ++j) {
        for (int i = 0; i < n; ++i) {
            if (i) dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if (j) dp[i][j] = max(dp[i][j], dp[i][j-1]); 
            const int ii = idx[i];
            if (w[ii] <= j) dp[i][j] = max(dp[i][j], (i ? dp[i-1][min(s[ii], j - w[ii])] : 0LL) + v[ii]);

            ans = max(ans, (i ? dp[i-1][s[ii]] : 0LL) + v[ii]);
            ans = max(ans, dp[i][j]);

        }
    }

    cout << ans << endl;

    return 0;
}


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

ll solve() {
    ll N;
    cin >> N;
    string S;
    cin >> S;

    vector<vector<int>> n(3,vector<int>(N+1));
    for ( int i = 0; i < N; i++ ) {
        vector<int> a(3); 
        if ( S[i] == 'R' ) a[0] = 1;
        if ( S[i] == 'G' ) a[1] = 1;
        if ( S[i] == 'B' ) a[2] = 1;
        n[0][i+1] = n[0][i] + a[0];
        n[1][i+1] = n[1][i] + a[1];
        n[2][i+1] = n[2][i] + a[2];
    }

    auto getnum = [&](int i1, int i2, int i3) {
        ll r = 0;
        for ( int i = 1; i < N; i++ ) {
            if ( n[i2][i] - n[i2][i-1] == 0 ) continue;
            r += n[i1][i-1] * (n[i3][N] - n[i3][i]);
        }
        return r;
    };

    
    ll ans = 0;
    ans += getnum(0,1,2);
    ans += getnum(0,2,1);
    ans += getnum(1,0,2);
    ans += getnum(1,2,0);
    ans += getnum(2,0,1);
    ans += getnum(2,1,0);

    ll ng = 0;
    for ( int k = 1; k < 2001; k++ ) {
        for ( int i = 0; i < N; i++ ) {
            int i1 = i, i2 = i+k, i3 = i+2*k;
            if ( i3 >= N ) continue;
            if ( S[i1] != S[i2] && S[i1] != S[i3] && S[i2] != S[i3] ) ng++;
        }
    }
    ans -= ng;

    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
bool used[100]={false};
//int d[100][100]={{0}};
vector<int> d[100];
vector<int> ord;
bool in[100]={false};
void dfs(int v){
	used[v]=true;
	for(int i =0;i <d[v].size();i++){
		if(!used[d[v][i]])dfs(d[v][i]);
	}
	ord.push_back(v);
}

int main(){
	int m;
	int n;
	cin>>m>>n;
	for(int i =0;i <n;i++){
		int x,y;
		cin>>x>>y;
		d[--x].push_back(--y);
		in[y]=true;
	}
	for(int i =0;i <m;i++){
		if(!in[i])dfs(i);
	}
	for(int i =m-1;i >=0;i--){
		cout <<ord[i]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll A,B;
    cin >> A >> B;
    print(devc(B - 1, A - 1));

    return 0;
}

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

int n;
long long a[405];
long long sum[405];
long long dp[405][405];

long long f(int x, int y) {
    if(dp[x][y] != -1) return dp[x][y];
    if(x == y) return dp[x][y] = 0;
    
    long long res = LLONG_MAX;
    for(int i = x+1; i <= y; i++) {
        res = min(res, f(x, i-1) + f(i, y) + 
        (sum[y] - sum[i] + a[i] + sum[i-1] - sum[x] + a[x]));
    }
    // cout << x << " " << y << " " << res << "\n";
    return dp[x][y] = res;
}

int main() {
	// your code goes here
	cin >> n;
	a[0] = 0;
	sum[0] = 0;
	for(int i = 1; i <= n; i++) {
	    cin >> a[i];
	    sum[i] = a[i] + sum[i-1];
	}
	memset(dp, -1, sizeof dp);
	cout << f(1, n);
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
struct edge { int to, cost; };
typedef pair<int, int> P; //firstは最短距離、secondは頂点番号
int V; int d[213456];
vector<edge> G[213456];
void dijkstra(int s) {
	//greater<P>を指定→firstが小さい順
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + 213456, 1000000000);
	d[s] = 0; que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) { continue; }
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
signed main() {
	for (int y = 0; y < 5; y++) {
		for (int i = 0; i < 213456; i++) {
			d[i] = 0;
			G[i].clear();
		}
		int n, m, a, iti, ni, san, si, go; cin >> n >> m;
		if (n == 0 && m == 0) { return 0; }
		for (int h = 0; h < m; h++) {
			cin >> a;
			if (a == 1) {
				cin >> iti >> ni >> san;
				G[iti].push_back({ ni, san });
				G[ni].push_back({ iti, san });
			}
			if (a == 0) {
				cin >> si >> go;
				dijkstra(si);
				if (d[go] == 1000000000) { cout << -1 << endl; }
				else { cout << d[go] << endl; }
			}
		}
	}
	return 0;
}


Measured memory_bytes: 9888
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, P = i2nn()
    n = int((3*A + P) / 2)
    print(n)

main()


Measured memory_bytes: 38384
a, b, k = gets.chomp.split.map(&:to_i)

k.times do |i|
  if i.even?
    if a.odd?
      a -= 1
    end
    h = a/2
    a -= h
    b += h
  else
    if b.odd?
      b -= 1
    end
    h = b/2
    b -= h
    a += h
  end
end
puts "#{a} #{b}"


Measured memory_bytes: 1788
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [str(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))
n = i()
l = []
for i in range(n):
    k = input()
    l.append(k)
print(len(list(set(l))))

Measured memory_bytes: 35596
h, w = gets.split.map(&:to_i)


def mindiff(h,w)
  min = 10 ** 12

  1.upto(h-1) do |i|
    sa = i * w
    # split vertically
    sb = (h-i) * (w/2)
    sc = (h-i) * (w/2 + w%2)
    a = [sa, sb, sc]
    diff = a.max - a.min
    min = diff if diff < min

    # split horizontally
    sb = (h-i)/2 * w
    sc = ((h-i)/2 + (h-i)%2) * w
    a = [sa, sb, sc]
    diff = a.max - a.min
    min = diff if diff < min
  end
  min
end

# pattern 1
p1_set = [
  (h/3) * w,
  (h/3) * w,
  (h/3 + h%3) * w,
]
a1 = p1_set.max - p1_set.min

# pattern 2
p2_set = [
  (w/3) * h,
  (w/3) * h,
  (w/3 + w%3) * h,
]
a2 = p2_set.max - p2_set.min

# pattern 3
a3 = mindiff(h,w)

# pattern 4
a4 = mindiff(w,h)

puts [a1,a2,a3,a4].min

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
    int n,tle,jud=0,m=9999;;
    cin>>n>>tle;
    while(n--){
        int cost,t;
        cin>>cost>>t;
        if(t<=tle){
            jud=1;
            if(cost<m)m=cost;
        }
    }
    if(jud)cout<<m;
    else cout<<"TLE";
}


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

int main()
{
	long long n,a;
	scanf("%lld",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",&a);
		if(a%2==0){
			if(a%3!=0 && a%5!=0){
				printf("DENIED");
				return 0;
			}
		}
	} 
	printf("APPROVED");
	return 0;
}

Measured memory_bytes: 256
import math

N, D = map(int, input().split())

point = []
for i in range(N):
    point.append(tuple(map(int, input().split())))

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        v = 0
        for d in range(D):
            v += abs(point[i][d] - point[j][d]) ** 2
        v = math.sqrt(v)
        if v.is_integer():
            ans += 1

print(ans)

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    sieve(300000);
    while(!IsPrime[x]) x++;
    cout << x << endl;
}

Measured memory_bytes: 256
s=input()
a=1
b=1
if int(s[:2])==0 or int(s[:2])>12:a=0
if int(s[2:])==0 or int(s[2:])>12:b=0
if a==1 and b==1:print('AMBIGUOUS')
elif a==0 and b==0:print('NA')
elif a==1:print('MMYY')
else:print('YYMM')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;

const int N = 2e3 + 5;
int n, k;
int f[N], cnt = 0;
int nnext[N << 1], v[N << 1];

inline void add(int a, int b) {
	nnext[++cnt] = f[a];
	f[a] = cnt;
	v[cnt] = b;
}

int dfs(int a, int b, int c, int d) {
	int ans = 1;
	if (c > d) return 0;
	for (int i = f[a]; i; i = nnext[i]) {
		int to = v[i];
		if (to != b) {
			ans += dfs(to, a, c + 1, d);
		}
	}
	return ans;
}

int main() {
	read(n), read(k);
	for (int i = 1; i < n; ++i) {
		int a, b;
		read(a), read(b);
		add(a, b);
		add(b, a);
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int tot = 0, pre = 0;
		for (int j = f[i]; j; j = nnext[j]) {
			int to = v[j];
			int a = dfs(to, i, 1, k / 2);
		    int b = dfs(to, i, 1, k - k / 2);
		    tot += a;
		    pre = max(pre, b - a);
		}
		ans = max(ans, 1 + tot + pre);
	}
	printf("%d\n", n - ans);
    return 0;
}


Measured memory_bytes: 3764
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int cnt = 0;
		int p, q;
		for(int i=0;i<n;i++){
			p = sc.nextInt();
			
			if((p-1)%3==0 || (p-2)%5==0 || (p-3)%7==0){
				cnt++;
			}else{
				for(int j=5;j<Integer.MAX_VALUE/2;j++){
					if(p-j<2*j+1) break;
					else if((p-j)%(2*j+1)==0){
						cnt++;
						break;
					}
					j++;
					if(p-j<2*j+1) break;
					else if((p-j)%(2*j+1)==0){
						cnt++;
						break;
					}
					j++;
				}
			}
		}
		System.out.println(n-cnt);
	}	
}

Measured memory_bytes: 60660
// AtCoderAlloy.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;

int n, h, w, a, b;
int c = 0;

int main()
{
	cin >> n >> h >> w;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (a >= h && b >= w) {
			c++;
		}
	}

	cout << c << endl;
	return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >> n;
    vector<ll> s(n);
    rep(i,0,n) cin >> s[i];
    ll q;
    cin >> q;
    vector<ll> t(q);
    rep(i,0,q) cin >> t[i];

    ll cnt(0);
    for (auto i: t) 
        if (binary_search(s.begin(), s.end(), i))
            cnt++;

    cout << cnt << endl;
 
    return 0;
}



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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  p((x - z) / (y + z));
}

Measured memory_bytes: 256
n=int(input())
l=[str(input()) for i in range(n)]
ans = 'Yes'
for i in range(1,n):
    if l[i][0] != l[i-1][-1]:
        ans = 'No'
        break
if len(set(l)) != n:
  ans = 'No'
print(ans)


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

int n,l[2006],ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",l+i);
	sort(l+1,l+n+1);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			for(int k=j+1;k<=n;++k) {
				if(l[i]+l[j]>l[k]) ans++;
			}
	printf("%d",ans);
}

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

public class Main{



  public static OutputStream out=new BufferedOutputStream(System.out);
  static Scanner sc=new Scanner(System.in);
  static long mod=1000000007l;
  static int INF=10000000;

  //nl-->neew line; //l-->line;  //arp-->array print;  //arpnl-->array print new line
  public static void nl(Object o) throws IOException{out.write((o+"\n").getBytes()); }
  public static void l(Object o) throws IOException{out.write((o+"").getBytes());}
  public static void arp(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+" ").getBytes()); out.write(("\n").getBytes());}
  public static void arpnl(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+"\n").getBytes());}
  public static void scanl(long[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextLong();}
  public static void scani(int[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextInt();}
  public static void scan2D(int[][] a,int n,int m) {for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=sc.nextInt();}
  //
  static long cnt;
  static TreeSet<Integer> ans;
  static int n,m;
  static int[][] dp;
  static HashMap<Pair,Boolean> arrl;
  static Stack<Integer> stk;
  static Queue<Integer> queue;
  static HashSet<Integer> mtrnode;
  static ArrayList<Pair> arrlans;
  static int[] ff;


  public static void main(String[] args) throws IOException{
    long sttm=System.currentTimeMillis();
    long mod=1000000007l;

    int n=sc.nextInt(), x=sc.nextInt(), t=sc.nextInt();
    int ans=n/x;
    if(n%x!=0){
        ans++;
    }
    nl(ans*t);

    out.flush();
  }

}

class Pair{
  int x; int y;
  Pair(int x,int y){
    this.x=x;
    this.y=y;
  }
}


Measured memory_bytes: 38524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll mod(ll a) {
	return ((a%=MOD) > 0 ? a : a+MOD);
}

ll fact(ll n) {
	ll res = 1;
	for(ll i=1;i<=n;i++) {
		res *= i;
		res %= MOD;
		if(res==0) res = MOD;
	}
	return res;
}

//aのb乗
ll calc(ll a, ll b) {
	ll res = 1;
	while(b > 0) {
		if(b & 1) res = res * a % MOD;
		if(res==0) res = MOD;
		a = a * a % MOD;
		if(a==0) a = MOD;
		b >>= 1;
	}
	return res;
}

ll comb(ll a, ll b){
	if(a==b || b==0) return 1;
	return (((fact(a)*calc(fact(b),MOD-2))%MOD)*calc(fact(a-b),MOD-2))%MOD;
}

int main(){
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans;
	ll sum = calc(2, n) - 1;
	ll left = 1, right = 1;
	for(int k=1;k<=a;k++) {
		left *= (n-k+1);
		left %= MOD;
		left *= calc(k,MOD-2);
		left %= MOD;
	}
	for(int k=1;k<=b;k++) {
		right *= (n-k+1);
		right %= MOD;
		right *= calc(k,MOD-2);
		right %= MOD;
	}
	ans = sum - left - right;
	while(ans < 0) ans += MOD;
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;
int main(){

  char c;cin>>c;
  out(char(c+1));

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		boolean[][] C = new boolean[W][H];
		for(int y = 0;y < H;++y) {
			String str = sc.next();
			for(int x = 0;x < W;++x) {
				C[x][y] = str.charAt(x) == '.';
			}
		}
		sc.close();
		
		StringBuilder sb = new StringBuilder();
		for(int y = 0;y < 2*H;++y) {
			int y2 = y/2;
			for(int x = 0;x < W;++x) {
				if(C[x][y2])
					sb.append(".");
				else
					sb.append("*");
			}
			sb.append("\n");
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 22228
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
u = UnionFind(n)

for i in range(m):
    a,b = map(int,input().split())
    u.union(a-1,b-1)

a = u.roots()
print(len(a)-1)

Measured memory_bytes: 12932
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, K;
        public string S;
        public long MOD = 1000000007;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                K = line[1];
            }

            S = Console.ReadLine();

            List<int> lst = new List<int>();

            {
                int last = '1';
                int i = 0;
                int c = 0;
                while (true)
                {
                    if (last != S[i])
                    {
                        lst.Add(c);
                        last = S[i];
                        c = 1;
                    }
                    else
                    {
                        c++;
                    }

                    i++;

                    if (i == N)
                    {
                        lst.Add(c);
                        if (last == '0')
                        {
                            // 1で終わるようにする
                            lst.Add(0);
                        }

                        break;
                    }
                }
            }

            // 累積和
            int[] A = new int[lst.Count];
            for (int i = 0; i < lst.Count; i++)
            {
                A[i] = i == 0 ? lst[i] : (lst[i] + A[i - 1]);
            }

            int ret = 0;
            for (int i = 0; i < lst.Count; i+=2)
            {
                int l = i;
                int r = Math.Min(lst.Count - 1, i + 2 * K);
                int sl = i == 0 ? 0 : A[i - 1];
                int sr = A[r];
                ret = Math.Max(ret, sr - sl);
            }
            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

i64 n;

int main()
{
    cin >> n;
    int result = 100000;

    for(i64 i = 1;i * i <= n;i++)
    {
        if(n % i == 0)
        {
            i64 other = n / i;
            result = min(result,(int)max(to_string(i).size(),to_string(other).size()));
            
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

vec<vec<lint>> memo(4001, vec<lint>(4001, 0));
lint combination(int n, int k, const lint MOD) {
    if (memo.at(n).at(k) != 0) {
        return memo.at(n).at(k);
    }
    lint result;
    if (k == 0 || k == n) {
        result = 1;
    }
    else {
        result = combination(n - 1, k - 1, MOD) + combination(n - 1, k, MOD);
        result %= MOD;
    }
    memo.at(n).at(k) = result;
    return result;
}

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

    const lint MOD = 1e9 + 7;
    int N, K;
    cin >> N >> K;
    range(i, 1, K + 1) {
        if (N - K - i + 1 >= 0) {
            lint num_such_alignments = combination(K - 1, K - i, MOD)
                * combination(N - K + 1, N - K - i + 1, MOD) % MOD;
            cout << num_such_alignments << "\n";
        } else {
            cout << 0 << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 125568
#include<iostream>
#include<bits/stdc++.h>
#define MAX_N 100000
int L[MAX_N],R[MAX_N];
int partition(int * A,int len);
void merge(int *A,int l,int mid,int r);
int main(void){
	int A[MAX_N],n,i,f;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",A+i);
	}
	f=partition(A,n);
	for(i=0;i<n;i++){
		if(i==f) printf("%s[%d]",i==0?"":" ",A[i]);
		else printf("%s%d",i==0?"":" ",A[i]);
	}
	puts("");
	return 0;
	
} 
int partition(int * A,int len){
	int i=-1,j,temp; 			//双指针
	 
	for(j=0;j<len-1;j++){
		if(A[j]<=A[len-1]) {
			i++;
			temp=A[i];
			A[i]=A[j];
			A[j]=temp;
		}
	}
	temp=A[i+1];
	A[i+1]=A[len-1];
	A[len-1]=temp; 
	return i+1;
}


Measured memory_bytes: 3516
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}
const int ININF = 1000000;
long long longPow(int n) {
    long long res = 1;
    rep(i, 0, n) { res *= 2; }
    return res;
}

int main() {
    long long N, K;
    cin >> N >> K;
    vector<double> p(N);
    rep(i, 0, N) { cin >> p[i]; }
    double tmp = 0.0;
    rep(i, 0, K) { tmp += (p[i] + 1.0) / 2.0; }
    double m = tmp;
    rep(i, 1, N - K + 1) {
        tmp -= (p[i - 1] + 1.0) / 2.0;
        tmp += (p[i + K - 1] + 1.0) / 2.0;
        if(m < tmp) {
            m = tmp;
        }
    }

    cout << setprecision(10) << m << endl;
}


Measured memory_bytes: 1792
import math,sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
MOD = 1000000007
d = defaultdict(int)
l,r = 0,0
count = 0
for i in range(n):
  a,b = map(int,input().split())
  if a == b == 0:
    count += 1
    continue
  elif a == 0 or b == 0:
    if a == 0:
      l += 1
    else:
      r += 1
  else:
    g = math.gcd(a,b)
    a,b = a//g,b//g
    if a<0:
      a,b = -a,-b
    d[str(a)+':'+str(b)] += 1
c = 1
for i in d.keys():
  if d[i] != 0:
    cur = pow(2,d[i],MOD)
    if '-' in i:
      ind = i.index(':')
      ci = i[ind+2:] + ':' + i[:ind]
    else:
      ind = i.index(':')
      ci = i[ind+1:] + ':-' + i[:ind]
    if ci in d.keys():
      cur += pow(2,d[ci],MOD)-1
      d[ci] = 0
    c = (c*cur)%MOD
c = (c*(pow(2,l,MOD)+pow(2,r,MOD)-1)-1+count)%MOD
print(c)

Measured memory_bytes: 128052
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n,sum=0;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i);
	}
	sort(v.begin(),v.end(),greater<int>());
	for(int i=1;i<v.size();i++){
		sum+=v.at(i);
	}
	if(v.at(0)<sum){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 set<string> s ; 
 int  n ; cin >> n ; 
 while(n--)
 {
 	string temp ; 
 	cin >> temp ; 
 s.insert(temp) ; 
  }
  cout << s.size() ; 
}

Measured memory_bytes: 19212
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200, mod = 1e9 + 7;

string s;
int k;
int d[10003][10][2][101];

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s >> k;
	for (int i = 0; i < s.size(); i++){
		int x = s[i] - '0';
		if (!i){
			for (int j = 0; j < x; j++){
				d[i][j][0][j % k] = 1;
			}
			d[i][x][1][x % k] = 1;
		}
		else{
			for (int o = 0; o < k; o++){
				int y = s[i - 1] - '0';
				for (int j = 0; j < x; j++){
					(d[i][j][0][(o + j) % k] += d[i - 1][y][1][o]) %= mod;
				}
				(d[i][x][1][(o + x) % k] += d[i - 1][y][1][o]) %= mod;
			}
			for (int o = 0; o < k; o++){
				for (int y = 0; y < 10; y++){
					for (int j = 0; j < 10; j++){
						(d[i][j][0][(o + j) % k] += d[i - 1][y][0][o]) %= mod;
					}
				}
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < 10; i++){
		(ans += (d[s.size() - 1][i][0][0] + d[s.size() - 1][i][1][0]) % mod) %= mod;
	}
	cout << (ans - 1 + mod) % mod;
	return 0;
}












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

int main() {
  int n;
  int64_t a;
  vector<int64_t> vec = {2, 1};
  
  cin >> n;

  for (int i = 2; i < 87; i++) {
    a = vec.at(i-1) + vec.at(i-2);
    vec.push_back(a);
  }
  cout << vec.at(n) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd
#define int ll

ll n,m;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    if(n==1 && m==1) cout << 1;
    else if(n==1) cout << m-2;
    else if(m==1) cout << n-2;
    else cout << (n-2)*(m-2);
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long quo;
    long rem;
    long ans;

    quo = n / (a + b);
    rem = n % (a + b);
    if(rem > a){
      ans = (quo + 1) * a;
    } else {
      ans = quo * a + rem;
    }
    System.out.println(ans);
  }
}


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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e10
typedef long long ll;
typedef long double ld;
int main(){
    string str;
    cin>>str;
    ll a=0,z=0;
    bool done=false;
    REP(i,SIZE(str)){
        if(str[i]=='A' && !done){a=i;done=true;}
        if(str[i]=='Z')z=i;
    }
    cout<<z-a+1<<endl;
    return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n;
    cin >> n;

    bool ans = true;
    bool down = false;
    int prev = 0;
    REP(i,n) {
        int x;
        cin >> x;
        if (x  == prev-1) {
            if (down) {
                ans = false;
            } else {
                down = true;
            }
        } else if (x < prev) {
            ans = false;

        } else if (x > prev) {
            down = false;
        }
        
        prev = x;
        
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cerr << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi  pair    <int,int>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define OO  (ll)1e18
#define EPS 1e-9
using namespace std;
using namespace __gnu_pbds;
void ONLINE__JUDGE();

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
pii swapii( pii pr ){ return { pr.S , pr.F }; }
ll binEXP( ll x , ll pw , ll MOD = LLONG_MAX );
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 1e2 + 9;

ll x;

int main()
{
    FASTIO //ONLINE__JUDGE();

    cin >> x;
    cout << 3*(x*x);
    return 0;
}


void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}

ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
    char grid[1005][1005];
int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 0 ; i<n;i++)
        cin >> grid[i];
    for(int i =0;i<n;i++){
        cout<<grid[i]<<endl;
        cout<<grid[i]<<endl;
}

}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
bool f[100100];
int a[100100];

int main() {
	cin >> n;
	int now = 0;
	int cnt = 0;
	rep(i, n)cin >> a[i];
	while(!f[now]){
		f[now] = 1;
		cnt++;
		now = a[now] - 1;
		if (now == 1) {
			cout << cnt << endl;
			break;
		}
		if (f[now]) {
			cout << -1 << endl;
			break;
		}
	}
}

Measured memory_bytes: 768