akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int K,A,B,res=0,S,W,C,D;
long long int N,sum=0;
int main()
{
    cout << fixed << setprecision(18);
    cin>>A>>B>>C>>D;
    IFYes((A-1+D)/D>=(C-1+B)/B)
    
    
}    


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

#define repeat(i, x) for (int64_t i = 0; (i) < (int64_t)(x); (i)++)

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

    int N;
    int64_t x;
    cin >> N >> x;

    vector<int64_t> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

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

    if (accumulate(a.begin(), a.end(), 0LL) == x) {
        cout << N << endl;
        return 0;
    }

    int64_t sum = 0;
    for (int i = 0; i < N; i++) {
        if (sum + a[i] > x or i == N - 1) {
            cout << i << endl;
            return 0;
        }
        sum += a[i];
    }

    return 0;
}


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

const int MAX = 1000000007;

long long int fac(int n)
{
    long long int res = 1;
	while(n != 1)
	{
	    res = (res*n)%MAX;
	    n = n-1;
	}
	return res;
}

int main()
{
	int n;
  	cin>>n;
  	cout<<fac(n)<<"\n";
}

Measured memory_bytes: 256
m, k = gets.chomp.split(' ').map(&:to_i)

if k >= 1 << m
  puts '-1'
elsif m == 1
  puts k == 0 ? '1 0 0 1' : '-1'
elsif m == 0
  puts '0 0'
else
  a = 0.upto((1 << m) - 1).reject { |n| n == k } + [k] + ((1 << m) - 1).downto(0).reject { |n| n == k } + [k]
  puts a.join(' ')
end


Measured memory_bytes: 21772
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;
int main()
{
  int A,B,C,D;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  scanf("%d",&D);
  printf("%d\n",min(A,B)+min(C,D));
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
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);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int H, W;
    char a[100][100];
    cin >> H >> W;
    REP(i, H) {
        REP(j, W) {
            cin >> a[i][j];
        }
    }
    REP(i, H + 2) {
        REP(j, W + 2) {
            if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
                cout << '#';
            } else {
                cout << a[i - 1][j - 1];
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

A, B, N = map(int, input().split())

# for x in range(1, N + 1):
#     tmp1 = (A * x) // B
#     tmp2 = A * (x // B)
#     print("{}: {} - {} = {}".format(x, tmp1, tmp2, tmp1 - tmp2))

# x == B - 1??
x = min(B - 1, N)
tmp1 = (A * x) // B
tmp2 = A * (x // B)
print(tmp1 - tmp2)



Measured memory_bytes: 10808
#include<bits/stdc++.h>
#define re    return
#define pii   pair<int,int>
#define hell  1000000007
#define rep(i,a,b)  for (__typeof(b) i=(a)-((a)>(b));i!=(b)-((a)>(b));i+=1-2*((a)>(b)))
#define boost ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb  push_back
#define ff          first
#define ss          second
#define sz(x)       (int)x.size()
#define all(a)      (a).begin(),(a).end()

//v.resize(distance(v.begin(),unique(v.begin(),v.end())));

typedef long long  ll;
using namespace std;

const ll INF=(1LL<<60)-1;
const int N=1e5+20;

int main(){
   
    boost;
    
    int n; cin >> n;
    string s; cin >> s;
    
    int dp1[n], dp2[n];
    
    if(s[0] == 'W') dp1[0] = 1;
    else dp1[0] = 0;
    
    for(int i = 1; i < n; i++){
    	if(s[i] == 'E'){
    		dp1[i] = dp1[i-1];
		} 
    	if(s[i] == 'W'){
    		dp1[i] = dp1[i-1]+1;
		}
	}
	
    if(s[n-1] == 'E') dp2[n-1] = 1;
    else dp2[n-1] = 0;
    
    for(int i = n-2; i >= 0; i--){
    	if(s[i] == 'E'){
    		dp2[i] = dp2[i+1]+1;
		} 
    	if(s[i] == 'W'){
    		dp2[i] = dp2[i+1];
		}
	}
	
    
    int ans = 1e9;
    
    ans = dp2[0];
    
	rep(i,1,n-1){
			ans = min(ans, dp1[i-1]+dp2[i+1]);
	}
    
	ans = min(ans, dp1[n-1]);
	
	cout << ans;
	
   	return 0;
}

Measured memory_bytes: 2964
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<a[0]<<" "<<a[2]<<endl;

  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll diff(ll a,ll b)
{
	if(a>b) return a-b;
	else return b-a ;
}

int main()
{
	std::ios::sync_with_stdio(false);
		ll n,k;
		std::cin >> n >> k;
		std::vector<ll> a(n);
		ll ans[n];
		for(ll i=0;i<n;i++) cin>>a[i],ans[i]=LLONG_MAX;
		ans[0]=0;
		for(ll i=1;i<n;i++)
		{
			for(ll j=1;j<=k;j++)
			{
				if(i-j>=0)
				{
					ans[i]=min(ans[i],ans[i-j]+diff(a[i],a[i-j]));
				}
			}
		}
		cout<<ans[n-1]<<"\n";
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int a, b;
  cin >> a >> b;

  if (a <= 0 && 0 <= b) {
    cout << "Zero";
  } else if (a > 0) {
    cout << "Positive";
  } else {
    if ((-a+b+1) % 2 == 0) {
      cout << "Positive";
    } else {
      cout << "Negative";
    }
  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt) if (!vis[y=E[i].to])
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
 
int rd() {
	char c=getchar_unlocked(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar_unlocked();
	while (isdigit(c)) t=t*10+c-48,c=getchar_unlocked(); return t*f;
}
void wt(int x) {
	if (x<0) putchar_unlocked('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar_unlocked(x%10+48); }
}
 
const int N=300035;
 
int n,m,head[N],cnt;
struct Edge { int to,nxt; }E[N<<1];
void Link(int u,int v) {
	E[++cnt]=(Edge){v,head[u]}; head[u]=cnt;
	E[++cnt]=(Edge){u,head[v]}; head[v]=cnt;
}
 
int stk[N],top,vis[N];
 
bool dfs1(int x) {
	vis[x]=1,stk[++top]=x;
	Rep (i,x) if (dfs1(y)) return 1;
	return 1;
}
 
bool dfs2(int x) {
	vis[x]=1,stk[++top]=x;
	Rep (i,x) if (dfs2(y)) return 1;
	return 1;
}
 
int main() {
	n=rd(),m=rd();
	For (i,1,m) Link(rd(),rd());
	dfs1(1);
	reverse(stk+1,stk+top+1); top--;
	dfs2(1);
	
	printf("%d\n",top);
	while (top) printf("%d ",stk[top--]);
	
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll sum = 0;
    int a[n];
    rep(i, n){
        cin >> a[i];
        sum += a[i] - 1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
   long long n,k;cin>>n>>k;
   priority_queue<long long> que;
   for(int i=0;i<n;i++){
       long long h;cin>>h;
       que.push(h);
   }
   long long cou=0;
   for(int i=0;i<k;i++){
       if(que.size()==0){
           cout<<cou<<endl;
           return 0;
       }
       que.pop();
       //cou++;
   }
   while(que.size()>0){
       long long x=que.top();que.pop();
       cou+=x;
   }
   cout<<cou<<endl;
}


Measured memory_bytes: 3444
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<short,short> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define MAX_N 10000000
int N;
P A[MAX_N];
bool comp(P a,P b){return a.sec<b.sec;}
ll closest_pair(P* a,int n)
{
    if(n<=1)return INF;
    int m=n/2;
    ll x=(ll)a[m].fi;
    ll d=min(closest_pair(a,m),closest_pair(a,n-m));
    inplace_merge(a,a+m,a+n,comp);
    vector<P> b;
    for(int i=0;i<n;i++)
    {
        if(abs((ll)a[i].fi-(ll)x)>=d)continue;
        for(int j=0;j<b.size();j++)
        {
            ll dx=(ll)a[i].fi-(ll)b[b.size()-1-j].fi;
            ll dy=(ll)a[i].sec-(ll)b[b.size()-1-j].sec;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b.pb(a[i]);
    }
    return d;
}
int main()
{
    cin >> N;
    for(int i=0;i<N;i++)cin >> A[i].fi >> A[i].sec;
    sort(A,A+N);
    cout << closest_pair(A,N) << endl;
    return 0;
}

Measured memory_bytes: 43064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<pair<ll,ll> > A(N);
    rep(i,N){
        cin >> A[i].first;
        cin >> A[i].second;
    }
    sort(all(A));
    ll money = 0;
    ll number = 0;
    rep(i,N){
        if (number + A[i].second >= M){
            money += A[i].first * (M - number);
            break;
        }
        else{
            number += A[i].second;
            money += A[i].first * A[i].second;
        }
    }
    cout << money << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
// do operations c and d at the end
const ll mxN = 55;
multiset<ll> dp[mxN][mxN];

void solve(){
	ll n,cnt; cin >> n >> cnt;
	ll a[n],b[n];
	FOR(n){
		cin >> a[i];
		b[i] = a[i];
	}
	reverse(b,b+n);
	
	// i signifies number of operations a's and j signifies number of operations of type b
	FOR(i,0,n+1){
		FOR(j,0,n+1){
			if(i + j < n){
				FOR(k,i){
					dp[i][j].insert(a[k]);
				}
				FOR(k,j){
					dp[i][j].insert(b[k]);
				}
			} else{
				FOR(k,n) dp[i][j].insert(a[k]);
			}
		}
	}
	
	ll ans = 0;
	FOR(i,0,n+1){
		FOR(j,0,n+1){
			if(i+j > min(cnt,n)) continue;
			int operations_left = cnt - (i+j);
			while(operations_left){
				auto itr = dp[i][j].begin();
				if(*itr < 0) dp[i][j].erase(itr);
				else break;
				--operations_left;
			}
			ll new_ans = 0;
			for(ll xx : dp[i][j]) new_ans += xx;
			ans = max(new_ans,ans);
		}
	}
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 8848
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	for (int i=0;i<s.size();i++){
		string key;
		for (int j=0;j<s.size();j++)
			key+=s[(i+j)%s.size()];
		if (key==t){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
	2000:Misterious Gems
*/
#include	<iostream>

using namespace std;

int main(void) {
	while(1) {
		int Map[21][21] = { 0 };
		int cGems = 0;
		int point[2] = { 10, 10 };
		int cCount;
		
		cin >> cGems;
		if(cGems == 0) { break; }
		
		for(int i = 0; i < cGems; i++) {
			int a, b;
			cin >> a >> b;
			
			Map[a][20 - b] = 1;
		}
		
		cin >> cCount;
		for(int i = 0; i < cCount; i++) {
			char dir;
			int num;
			
			cin >> dir >> num;
			
			if(dir == 'N') {
				for(int j = 0; j < num; j++) {
					point[1]--;
					if(Map[ point[0] ][ point[1] ] == 1) {
						cGems--;
						Map[ point[0] ][ point[1] ] = 0;
					}
				}
			} else if(dir == 'S') {
				for(int j = 0; j < num; j++) {
					point[1]++;
					if(Map[ point[0] ][ point[1] ] == 1) {
						cGems--;
						Map[ point[0] ][ point[1] ] = 0;
					}
				}
			} else if(dir == 'E') {
				for(int j = 0; j < num; j++) {
					point[0]++;
					if(Map[ point[0] ][ point[1] ] == 1) {
						cGems--;
						Map[ point[0] ][ point[1] ] = 0;
					}
				}
			} else if(dir == 'W') {
				for(int j = 0; j < num; j++) {
					point[0]--;
					if(Map[ point[0] ][ point[1] ] == 1) {
						cGems--;
						Map[ point[0] ][ point[1] ] = 0;
					}
				}
			}
		}
		if(cGems == 0) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#define MAX 100000
typedef struct { int pa, le, ri; } Node;
Node T[MAX];
int n,D[MAX];

void print(int u) {
	int i, c;
	printf("node %d: parent = %d, depth = %d, ", u, T[u].pa, D[u]);
	if (T[u].pa == EOF) printf("root, ");
	else if (T[u].le == EOF) printf("leaf, ");
	else printf("internal node, ");

	printf("[");
	for (i = 0, c = T[u].le; c != EOF; i++, c = T[c].ri) {
		if (i) printf(", ");
		printf("%d", c);
	}
	printf("]\n");
}

void rec(int u, int p) {
	D[u] = p;
	if (T[u].ri != EOF) rec(T[u].ri, p);
	if (T[u].le != EOF) rec(T[u].le, p + 1);
}

int main() {
	int i,j,k,v,c,l,r;
	scanf("%d", &n);
	for (i=0; i<n; i++)  T[i].pa = T[i].le = T[i].ri = EOF;

	for (i = 0; i < n; i++) {
		scanf("%d %d", &v, &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &c);
			if (j == 0) T[v].le = c;
			else T[l].ri = c;
			l = c;
			T[c].pa = v;
		}
	}
	for (i = 0; i < n; i++) {
		if (T[i].pa == EOF) r = i;
	}
	rec(r, 0);
	for (i = 0; i < n; i++) print(i);
}




Measured memory_bytes: 6412
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] iArr = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int n = iArr[0];
            int m = iArr[1];
            int l = iArr[2];
            int[,] arrA = new int[n, m];
            for(int i=0; i<n;i++)
            {
                int[] rArr = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                for(int j=0; j<m;j++)
                {
                    arrA[i, j] = rArr[j];
                }
            }

            int[,] arrB = new int[m, l];
            for(int i=0;i<m;i++)
            {
                int[] rArr = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                for(int j=0;j<l;j++)
                {
                    arrB[i, j] = rArr[j];
                }
            }

            long[,] arrC = new long[n, l];
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<l;j++)
                {
                    for(int k=0;k<m;k++)
                    {
                        arrC[i, j] += arrA[i, k] * arrB[k, j];
                    }
                }
            }

            for(int i=0;i<n;i++)
            {
                for(int j=0;j<l-1;j++)
                {
                    Console.Write("{0} ", arrC[i, j]);
                }
                Console.WriteLine(arrC[i, l - 1]);
            }


            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 10052
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	if(n%1000 == 0)
		cout << 0 << "\n";
	else
		cout << (1000-n%1000) << "\n";
}

Measured memory_bytes: 3660
l,r=map(int,input().split())
if r-l>2019:
    print(0)
    exit()
lst=[]
for i in range(l,l+min(4038,r-l+1)):
    lst.append(i%2019)
ans=2018
for i in range(len(lst)-1):
    for j in range(i+1,len(lst)):
        tmp=lst[i]*lst[j]%2019
        if tmp<ans:ans=tmp
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<ll, int> MAP;
  int N; cin >> N;
  FOR(i,0,N) {
    int in; cin >> in;
    MAP[in]++;
  }
  int M; cin >> M;
  FOR(i,0,M) {
    int in; cin >> in;
    if(MAP.count(in) == 0 || MAP[in] == 0) {
      cout << "NO" << endl;
      return 0;
    }
    MAP[in]--;
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]) {
  int a[3];
  for (size_t i = 0; i < 3; i++) cin >> a[i];
  sort(a,a+3);
  cout << a[2]-a[0] << endl;
  return 0;
}


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

using namespace std;

int n, m, p, r, c;
string s, t;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m >> p >> r >> c >> s >> t;

    int cur = r;
    for (int i = 0; i < p; i++) {
        if (s[i] == 'U') cur--;
        if (cur < 1) return cout << "NO", 0;
        if (t[i] == 'D' && cur < n) cur++;
    }

    cur = r;
    for (int i = 0; i < p; i++) {
        if (s[i] == 'D') cur++;
        if (cur > n) return cout << "NO", 0;
        if (t[i] == 'U' && cur > 1) cur--;
    }

    cur = c;
    for (int i = 0; i < p; i++) {
        if (s[i] == 'L') cur--;
        if (cur < 1) return cout << "NO", 0;
        if (t[i] == 'R' && cur < m) cur++;
    }

    cur = c;
    for (int i = 0; i < p; i++) {
        if (s[i] == 'R') cur++;
        if (cur > m) return cout << "NO", 0;
        if (t[i] == 'L' && cur > 1) cur--;
    }

    cout << "YES";
    return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}

int main(){

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

    int ans = 0;
    int v = 0;
    for(int i = 0; i < n; i++){
        if(v >= h[i]) v = h[i];
        else{
            ans += h[i] - v;
            v = h[i];
        }
    }

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

Measured memory_bytes: 256
n=int(input())
A=[]
B=[]
C=[]
for i in range(n):
    a,b,c=map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
def vac(n):
    if n==1:
        return max(A[0],B[0],C[0])
    else:
        dp=[[0]*3 for i in range(n)]
        dp[0][0]=A[0]
        dp[0][1]=B[0]
        dp[0][2]=C[0]
        for i in range(n-1):
            dp[i+1][0]=max(dp[i][1],dp[i][2])+A[i+1]
            dp[i+1][1]=max(dp[i][0],dp[i][2])+B[i+1]
            dp[i+1][2]=max(dp[i][0],dp[i][1])+C[i+1]
        return max(dp[n-1])
print(vac(n))

Measured memory_bytes: 34564
// -> limitless <- //
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PB push_back
#define MP make_pair
using namespace std;
typedef  long long ll;
    ll gcd(ll a, ll b){
    if(b == 0)return a;
    gcd(b,a%b);
    }
int main()
{
  ll n;
  cin >> n;
  cout << ((n*2)/gcd(n,2)*1ll)<<endl;
	return 0;
}





Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp

ans = t.size

for i in 0...(s.size+1-t.size)
  cnt = 0
  for j in 0...t.size
    if s[i+j] != t[j]
      cnt += 1
    end
  end
  ans = [ans, cnt].min
end

puts ans

Measured memory_bytes: 14376
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int K,N,ans;
	cin>>K>>N;
	int a[N];
	for(int i=0;i<N;i++)
	cin>>a[i];
	ans=a[N-1]-a[0];
	for(int i=1;i<N;i++)
	ans=min(ans,a[i-1]+K-a[i]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
   int n,k,sum=0;
   cin>>n>>k;
   vector<int>arr(n);
   for(int i=0 ; i<n ; i++)
    cin>>arr[i];
    sort(arr.begin(),arr.end());
    for(int i=0 ; i<k ; i++)
        sum+=i<n?arr[i]:0;
    cout << sum;
    return 0;
 }


Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

struct Node {
	int key;
	Node *left, *right, *parent;
};

Node *root, *NIL;

Node* treeMin(Node *x) {
	while (x->left != NIL) x = x->left;
	return x;
}


Node* find(Node* u, int k) {
	while (u != NIL && u->key != k) {
		if (k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

Node* treeSuccessor(Node* x) {
	if (x->right != NIL) return treeMin(x->right);
	Node *y = x->parent;
	while (y != NIL && x == y->right) {
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(Node *z) {
	Node *y;
	Node *x;
	if (z->left == NIL || z->right == NIL) y = z;
	else y = treeSuccessor(z);
	if (y->left != NIL) {
		x = y->left;
	}
	else {
		x = y->right;
	}
	if (x != NIL) {
		x->parent = y->parent;
	}
	if (y->parent == NIL) {
		root = x;
	}
	else {
		if (y == y->parent->left) {
			y->parent->left = x;
		}
		else {
			y->parent->right = x;
		}
	}
	if (y != z)
		z->key = y->key;
	free(y);
}

void preParse(Node *u) {
	if (u == NIL)
		return;
	cout << ' ' << u->key;
	preParse(u->left);
	preParse(u->right);
}

void inParse(Node* u) {
	if (u == NIL)
		return;
	inParse(u->left);
	cout << ' ' << u->key;
	inParse(u->right);
}

void postParse(Node* u) {
	if (u == NIL)
		return;
	postParse(u->left);
	postParse(u->right);
	cout << ' ' << u->key;
}

void insert(int key) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	z = (Node*)malloc(sizeof(Node));
	//Node* z = new Node;
	z->key = key;
	z->left = NIL;
	z->right = NIL;
	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

signed main() {
	int n, i, x;
	string com;
	cin >> n;
	rep(i, n) {
		cin >> com;
		if (com == "find") {
			int k;
			cin >> k;
			auto t = find(root, k);
			if (t == NIL)
				cout << "no" << endl;
			else
				cout << "yes" << endl;
		}
		if (com == "insert") {
			cin >> x;
			insert(x);
		}
		if (com == "print") {
			inParse(root);
			cout << endl;
			preParse(root);
			cout << endl;
		}
		if (com == "delete") {
			cin >> x;
			if (find(root, x) != NIL) {
				treeDelete(find(root,x));
			}
		}
	}
	return 0;
}


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

#define slld(longvalue) scanf("%lld", &longvalue)
#define plld(longvalue) printf("%lld\n", longvalue)

#define slf(longvalue) scanf("%lf", &longvalue)
#define plf(longvalue) printf("%lf\n", longvalue)
#define sc(letter) scanf("%c", &letter)
#define pc(letter) printf("%c", letter)

#define ss(name) scanf("%s", name)
#define ps(name) printf("%s", name)

#define pnew printf("\n")

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >
#define pii pair < int, int >

#define printcase(indexing,ans) printf("Case %lld: %lld\n", indexing, ans)

#define pb(x) push_back(x)

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 1000000009


using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

ll arr[200005];
deque < ll > dq;

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

    // freopen("in.txt", "r", stdin);

    while(cin >> n)
    {
        for(i = 1; i <= n; i++) slld(arr[i]);

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

        dq.clear();

        dq.push_back(arr[n]);

        ll lft = 1;
        ll rgt = n - 1;

        ll sz = 0;

        while(lft <= rgt)
        {
            ll x = dq[0], y = dq[sz];

            ll e = abs(arr[lft] - x);
            ll f = abs(arr[lft] - y);

            ll g = abs(arr[rgt] - x);
            ll h = abs(arr[rgt] - y);

            ll mx = max(e,max(g,max(f,h)));

            if(mx == e)
            {
                dq.push_front(arr[lft]);
                lft++;
            }
            else if(mx == f)
            {
                dq.push_back(arr[lft]);
                lft++;
            }
            else if(mx == g)
            {
                dq.push_front(arr[rgt]);
                rgt--;
            }
            else
            {
                dq.push_back(arr[rgt]);
                rgt--;
            }

            sz++;
        }

//        for(i = 0; i < n; i++)
//        {
//            cout << dq[i] << " ";
//        }
//
//        cout << endl;

        ll sum = 0;

        for(i = 1; i < n; i++)
        {
            sum += abs(dq[i] - dq[i - 1]);
        }

        cout << sum << endl;
    }


}





Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)
#define debug(x) cerr << #x << ": " << x << "\n";

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

ll MOD = 1e+9 + 7;

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

  ll ans = 0;
  for(ll i=K; i<=(N+1); i++){
    ans += i * N - i * (i-1) + 1;
    ans %= MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3648
n = int(input())
a = list(map(int,input().split()))
b = list(a)
b.sort()
if b[n-1]-b[0] >=2:
    print("No")
else:
    b = sum(a)%n
    c = int((sum(a)-b)/n)
    if b == 0:
        if 2*c > n and n != c+1:
            print("No")
        else:
            print("Yes")
    else:
        if b == 1:
            print("No")
        else:
            if n - b/2 >= c+1 and n <= c+b:
                print("Yes")
            else:
                print("No")

Measured memory_bytes: 14092
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

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

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

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

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

signed solve()
{
	i64 a, b, c;
	cin >> a >> b >> c;
	if (a == 1)
	{
		print("YES");
		return 0;
	}

	for (i64 i = 1, end = a * b; i <= end; ++i)
	{
		if ((a * i) % b == c)
		{
			print("YES");
			return 0;
		}
	}
	print("NO");
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

using namespace std;
#define mod 1000000007
#define int long long int
#define pb push_back
#define mk make_pair
#define flp(i, k, n) for(int i=k; i<n; i++)
#define F first
#define S second
#define SIZE 4000

vector<char> v;
int dp[SIZE][SIZE];
string a, b;

int32_t main(void)
{
  cin>>a>>b;
//  memset(dp, -1, sizeof(dp));
  int n=a.length();
  int m=b.length();
 // myfunc(n, m);
  int key=1;
  string s="";
  
  flp(i, 0, n+1)
  {
  	flp(j, 0, m+1)
  	{
  		if(i==0 || j==0)
  		 dp[i][j]=0;

  		else if(a[i-1]==b[j-1])
  		 dp[i][j]=1+dp[i-1][j-1];	
  		
  		else
  		 dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
  		
  	//	cout<<dp[i][j]<<" ";
  	}
  //	cout<<"\n";
  }
 
  int i=n, j=m;
  while(i>0 && j>0)
  {
  	if(a[i-1]==b[j-1])
  	{
  		s+=a[i-1];
  		i--; j--;
  	}

  	else
  	{
  		if(dp[i][j]==dp[i-1][j])
  			i--;

  		else
  			j--;
  	}
  }
  reverse(s.begin(), s.end());
  cout<<s<<"\n";

  return 0;
}

Measured memory_bytes: 94208
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int n, k;
	cin >> n >> k;
	set<int> s;
	for(int i = 1; i <= 1e5; i++)
	{
		n = n % k;
		s.insert(n);
		n = abs(n - k);
	}
	cout << *s.begin();
	return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int h,w;cin>>h>>w&&h|w;){
		if(h>w) swap(h,w);
		if(h==1){
			if(w==1)
				cout<<1<<endl;
			else
				cout<<w-2<<endl;
		}
		else{
			cout<<ll(h-2)*(w-2)<<endl;
		}
	}
}


Measured memory_bytes: 256
#include <cstdio>
int main() {
  int n; scanf("%d", &n);
  int res = 0;
  for (int i = 1; i <= n; i+=2) {
    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) cnt++;
    }
    if (cnt == 8) res++;
  }
  printf("%d\n", res);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n-1);
  for (int i = 0; i < n-1; i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  
  vector<int> ans(n, 0);
  int m = 1;
  
  for (int i = 0; i < n-1; i++){
    if (a.at(i) == m){
      ans.at(m-1)++;
      continue;
    }
    else{
      m = a.at(i);
      ans.at(m-1)++;
    }
  }
  
  for (int i = 0; i < n; i++){
    cout << ans.at(i) << endl;
  }
}

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




int main(){
    string s;cin>>s;
    ll N=s.size();
    char c[600000];
    rep(i,250000,N+250000){
        c[i]=s.at(i-250000);
    }
    ll l=249999,r=250000+N;
    ll Q;cin>>Q;
    ll cn=0;
    int plus;
    char ci;
    rep(i,0,Q){
        int sousa;
        cin>>sousa;
        if(sousa==1)cn++;
        else{
            cin>>plus>>ci;
            if((cn+plus)%2==1){
                c[l]=ci;
                l--;
            }
            else{
                c[r]=ci;
                r++;
            }
        }
    }
    if(cn%2==1){
        for(int i=r-1;i>l;i--)cout<<c[i];
    }
    else{
        rep(i,l+1,r)cout<<c[i];
    }
    cout<<endl;
}







Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<utility>
#include<cmath>
using namespace std;
int main(){
	long long int x,ans;
	cin>>x;
	ans=ceil( sqrt(2.0*x) );
	while(ans*(ans+1)>=2*x){
		ans--;
	}
	cout<<ans+1<<endl;
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int r;

int main(void) {
  // Here your code !
  scanf("%d", &r);

  printf("%d\n", r * r);

  return 0;
}


Measured memory_bytes: 256
N=int(input())
note=[]
for i in range(N):
	s,p=list(input().split())
	p=int(p)
	note.append([i+1,s,p])


note.sort(key=lambda x:(x[1],-x[2]))
#print(note)

for i in range(N): print(note[i][0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <climits>
#define int long long int
using namespace std;
signed main() 
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
        int x,t;
        set<int> s;
        cin>>x>>n;
        vector<int> a(101);
        for(int i=0;i<n;i++)
        {
            cin>>t;
            s.insert(t);
        }
        for(int i=0;i<=101;i++)
        {
            if(s.find(i)==s.end())
            a.push_back(i);
        }
        int ub=INT_MIN;
        int lb = INT_MAX;
        int ans;
        for(int i=0;i<a.size();i++)
        {
            if(a[i]<=x)
            ub = max(ub,a[i]);
            if(a[i]>=x)
            lb = min(lb,a[i]);
        }
        if(abs(x-ub)!=abs(x-lb))
        ans = (abs(x-ub)>abs(x-lb))?lb:ub;
        else
        ans = min(ub,lb);
        cout<<ans;
        return 0;
    }


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,tmp,s=0;
	cin>>n;
	tmp=n;
	
	while(tmp!=0)
	{
		s+=tmp%10;
		tmp=tmp/10;
	}
	
	if(n%s==0)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N, K; cin >> N >> K;
    map<int, int> C;
    REP(i, N) {
        int a; cin >> a;
        C[a]++;
    }
    vector<int> V;
    for (const auto& p : C) V.push_back(p.second);
    sort(V.begin(), V.end());
    int sum = 0;
    REP(i, (int)V.size() - K) sum += V[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 10748
#include<iostream>
#include<string>
using namespace std;
string S;
long long p; long long q[26];
long long ncr(long long a, long long b) {
	long long cnt = 1;
	for (int i = a; i > a - b; i--) cnt *= i;
	for (int i = b; i >= 1; i--) cnt /= i;
	return cnt;
}
int main() {
	cin >> S; long long cnt = 0, cnt2 = S.size() / 2, sum = 1;
	for (int i = 0; i < S.size(); i++) q[S[i] - 'a']++;
	for (int i = 0; i < 26; i++) {
		if (q[i] % 2 == 1) { cnt++; q[i] = 0; }
		else { q[i] /= 2; }
	}
	for (int i = 0; i < 26; i++) {
		sum *= ncr(cnt2, q[i]);
		cnt2 -= q[i];
	}
	if (cnt >= 2) sum = 0;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    string T = S.substr(0, (N-1)/2);
    string U = S.substr((N+3)/2-1);
    bool ok = true;
    for(int i=0;i<N/2;i++){
        if(S[i] != S[N-i-1]) ok = false;
    }
    for(int i=0;i<(N-1)/2;i++){
        if(T[i] != T[(N-1)/2 - i - 1]) ok = false;
        if(U[i] != U[(N-1)/2 - i - 1]) ok = false;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

const int mx = 305;

int ase[4], n, m=0;
int vis[mx][mx][mx];
double dp[mx][mx][mx];

double fun(int i, int j, int k){
    if((i+j+k) == 0) return 0;

    if(vis[i][j][k])
        return dp[i][j][k];
    vis[i][j][k] = 1;

    double &ans = dp[i][j][k]; ans=0;
    double res = double(n) / (i+j+k);

    if(i) ans += (fun(i-1, j, k)+res) * i / (i+j+k);
    if(j) ans += (fun(i+1, j-1, k)+res) * j / (i+j+k);
    if(k) ans += (fun(i, j+1, k-1)+res) * k / (i+j+k);
    return ans;
}

void solve(){
    cin >> n;
    for(int i=0, x; i<n; i++){
        cin >> x;
        ase[x]++;
    }

    cout << setprecision(8) << fixed;
    cout << fun(ase[1], ase[2], ase[3]) << "\n";
}

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

    int tc = 1;
    while(tc--) solve();
    return 0;
}



Measured memory_bytes: 167644
n,k=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l,key=lambda x:x[0])
#print(l)
a=0
for i in l:
    a+=i[1]
    if k<=a:
        print(i[0])
        break


Measured memory_bytes: 29912
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;

class Program {
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine()), count = 0;;
        var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); a.Insert(0, 0); a.Add(0);
        var b = new int[n + 1];
        for (int i = 1; i < n + 2; i++) {
            b[i - 1] = Abs(a[i] - a[i - 1]);
            count += b[i - 1];
        }
        for (int i = 1; i < n + 1; i++) {
            Console.WriteLine(count - b[i - 1] - b[i] + Abs(a[i + 1] - a[i - 1]));
	    }
    }
}

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

int main(){
	
	int n,j=0;
	int A[10000], B[10000];
	
	
	while(j<5){
	
	int scoreA=0,scoreB=0;
		cin>>n;
		if(n==0){break;}
	for(int i=0;i<n;i++)
	{
		
		cin >>A[i];
		cin>>B[i];
		if(A[i]>B[i])
		{scoreA+=(A[i]+B[i]);}
			
		else if(A[i]<B[i])
			{scoreB+=(A[i]+B[i]);}
		else if(A[i]==B[i])
				{scoreA+=A[i];
				scoreB+=B[i];}
	}
		cout<<scoreA<<" "<<scoreB<<endl;
		j++;
	}
	return 0;
}


Measured memory_bytes: 3140