akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    cin >> N;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if(i * j == N){
                cout << "Yes" << endl;
                exit(0);
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

int main(){
  string s; cin >> s;
  int left = 0;
  int right = s.size()-1;
  int ans = 0;
  while (left < right){
    if (s[left] == s[right]){
      left++;
      right--;
    }
    else if (s[left] == 'x'){
      ans++;
      left++;
    }
    else if (s[right] == 'x'){
      ans++;
      right--;
    }
    else{
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}


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

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

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

  string s; cin >> s;
  int start = 0, end = 0;
  int N = s.size();
  rep(i, N) {
    if(s[i] == 'A') {
      start = i;
      break;
    }
  }
  for(int i = N-1; i >= 0; i--) {
    if(s[i] == 'Z') {
      end = i;
      break;
    }
  }

  cout << end-start+1 << '\n';
  return 0;
}


Measured memory_bytes: 720
icase=0
if icase==0:
    a,b,k=map(int,input().split())
    if k<=a:
        a1=a-k
        b1=b
    elif k<=a+b:
        a1=0
        b1=b-(k-a)
    else:
        a1=0
        b1=0
    print(a1,b1)
    

Measured memory_bytes: 2940
#include<stdio.h>

int main (void){

  int n,p,d1,d2,i,dt,max, maxp;

  for(;;){

    scanf("%d\n",&n);
  
    if(n==0)
      break;
    
   
    if(n !=0);{    
      scanf("%d %d %d",&p,&d1,&d2);
        dt = d1 + d2;
        max = dt;
        maxp = p;
     for(i=1;i<n;i++){
      scanf("%d %d %d",&p,&d1,&d2);
      dt = d1 + d2;
       if(dt>max){
	max = dt;
	maxp = p;
       }
       else{
	;
       }
     }  
    }
   
  
  
printf("%d %d\n",maxp,max);
  }
  return 0;
  }

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
ll f(ll n) {
    ll res = 0;
    while (n > 0) {
        n >>= 1;
        ++res;
    }
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> v(n); cin >> v;
    ll g = 0;
    REP(i, n) g ^= v[i];
    vector<ll> r;
    while (g > 0) {
        r.pb(g & 1);
        g >>= 1;
    }
    map<ll, ll> m;
    REP(i, n) {
        m[f(v[i] & -v[i])-1]++;
    }
    try {
        ll ans = 0;
        ll b = 0;
        RREP(i, r.size()) {
            if (r[i] ^ b) {
                if (m[i] == 0) throw 1;
                b = !b;
                ++ans;
            }
        }
        cout << ans << endl;
    }
    catch (int err) {
        cout << -1 << endl;
    }
}


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

vector<int>getketa(int n){
  vector<int>ret;
  while(n>0){
    ret.push_back(n%10);
    n/=10;
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  vector<vector<long>>se(10, vector<long>(10, 0)); //se[g[0]][g[g.size()-1]]
  vector<int>g;
  for(int i=1; i<=n; i++){
    g=getketa(i);
    se[g[0]][g[g.size()-1]]++;
  }
  long ret=0;
  for(int i=0; i<10; i++)for(int j=0; j<10; j++){ //i:Aの先頭, j:Bの先頭（どっちでもいいけど
    ret += se[i][j]*se[j][i];
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1       
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];
  double sum = 0;
  rep (i, n) sum += 1.0 / a[i];
  cout << 1 / sum << endl;
  return 0;
}

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

const int MAX_N = 50000;
const int MAX_M = 20;
vector<int> c(MAX_M+1);
vector<vector<int>> dp(MAX_M+1, vector<int>(MAX_N+1, MAX_N+1));
int n, m;

int main(){
    cin >> n >> m;
    
    for(int i = 0; i < m; i++){
        cin >> c[i];
        for(int j = 0; j <= n; j++){
            if(j == 0) dp[i][j] = 0;
            if(j < c[i]){
                dp[i+1][j] = dp[i][j];
            }
            else{
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-c[i]] + 1);
            }
        }
    }
    
    cout << dp[m][n] << endl;
    
    return 0;
}

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

using namespace std;

int main () {
	int n, w;
	cin >> n >> w;
	int peso[n];
	long int valor[n];
	for (int i = 0; i < n; i++)
		cin >> peso[i] >> valor[i];

	long int solucoes[n+1][w+1];
	for (int i = 0; i <= w; i++)
		solucoes[0][i] = 0;
	for (int i = 1; i <= n; i++) {
		int curPeso = peso[i-1];
		long int curValor = valor[i-1];

		for (int j = 0; j <= w; j++) {
			if (j - curPeso >= 0)
				solucoes[i][j] = max(solucoes[i - 1][j],(curValor + solucoes[i - 1][j - curPeso]));
			else
				solucoes[i][j] = solucoes[i - 1][j];
		}
	}

	cout << solucoes[n][w] << endl;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod=1e9+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
#define ent cout<<endl
using P = pair<int, int>;
#define YES "Yes"
#define NO "No"
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse! Oh~MyGod」

int main() {
  int n,m;
  cin>>n>>m;
  vecb s(MAX_N,false);
  vecll dp(n+3,0);
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    s[a]=true;
  }
  dp[0]=1;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=min(n,i+2);j++){
      if(!s[j]){
        dp[j]+=dp[i];
        dp[j]%=mod;
      }
    }
  }
  // rep(i,n+1) cout<<dp[i]<<endl;
  cout<<dp[n]%mod<<endl;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(void)
{
   int a,b,c,d;

   scanf("%d%d%d%d",&a,&b,&c,&d);

   if(a<=b){
      if(c<=d)     printf("%d",a+c);
      else if(c>d) printf("%d",a+d);
   }
   else if(b<a){
      if(c<=d)     printf("%d",b+c);
      else if(c>d) printf("%d",b+d);
   }

   return 0;
}

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

int main() {
  string S;
  cin >> S;
  if (S == "abc") {
      cout << "Yes" << endl;
  }
  else if (S == "acb") {
      cout << "Yes" << endl;
  }
  else if (S == "bac") {
      cout << "Yes" << endl;
  }
  else if (S == "bca") {
      cout << "Yes" << endl;
  }
  else if (S == "cab") {
      cout << "Yes" << endl;
  }
  else if (S == "cba") {
      cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

int32_t main() {
	FAST_IO;
	
	int n, k;
	cin >> n >> k;
	
	int a[n];
	for (int& x: a) cin >> x;
	
	vb dp(k+1);
	
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (i >= a[j] && !dp[i-a[j]]) {
				dp[i] = true;
			}
		}
	}
	
	cout << (dp[k] ? "First" : "Second") << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    a = list(map(int,input().split()))
    num = 0
    for x in range(m):
        num += a[x] * b[x]
    num += c
    if num > 0:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    if ( n == 2 ) {
        if ( a[0] > a[1] ) cout << a[0] << " " << a[1] << endl;
        else               cout << a[1] << " " << a[0] << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    ll ai = a[n-1];
    int i = 0;
    bool odd = (ai & 1);
    int pre_d = 0;
    int pre_n = 0;
    while(1){
        if ( i == n - 1 ) break;
        if ( odd ) {
            if ( a[n-1-i] <= ai/2 + 1 ) {
                if ( a[n-1-i] == ai/2 + 1 || a[n-1-i] == ai/2 ) {
                    cout << ai << " " << a[n-1-i] << endl;
                    return 0;
                }
                else if ( pre_d < ai/2 - a[n-1-i] ) {
                    cout << ai << " " << pre_n << endl;
                    return 0;
                }
                else {
                    cout << ai << " " << a[n-1-i] << endl;
                    return 0;
                }
            }
        }
        else {
            if ( a[n-1-i] <= ai/2 ) {
                if ( a[n-1-i] == ai/2 ) {
                    cout << ai << " " << a[n-1-i] << endl;
                    return 0;
                }
                else if ( pre_d < ai/2 - a[n-1-i] ) {
                    cout << ai << " " << pre_n << endl;
                    return 0;
                }
                else {
                    cout << ai << " " << a[n-1-i] << endl;
                    return 0;
                }
            }
        }
        if ( odd ) pre_d = a[n-1-i] - ( ai/2 + 1 );
        else       pre_d = a[n-1-i] - ai/2;
        pre_n = a[n-1-i];
        ++i;
    }
    return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  llong disx = tx - sx;
  llong disy = ty - sy;

  cerr << disx << " " << disy << endl;

  cout << string(disx, 'R') <<
      string(disy, 'U') <<
      string(disx, 'L') <<
      string(disy, 'D') <<
      "D" <<
      string(disx + 1, 'R') <<
      string(disy + 1, 'U') <<
      "LU" <<
      string(disx + 1, 'L') <<
      string(disy + 1, 'D') <<
      "R"
  << endl;

  return 0;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(int i= (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl

ll gcd(ll a, ll b) {
	return (b == 0) ? a : gcd(b, a % b);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N; cin >> N;
    int ans; cin >> ans;
    FOR(i, 1, N) {
        int x; cin >> x;
        ans = gcd(ans, x);
    }
    cout << ans << "\n";
}

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



int main(){
  int N;
  cin>>N;
  map<int,int> kaz;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    kaz[x]++;
  }
  int sum=0;
  for(auto & x:kaz){
    if(x.second%2==1) sum++;
  }
  cout<<sum<<endl;
}

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

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

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

  int ans = 0;

  for(int i = 0;i < N;i++){
    int X = a[i];
    auto itr1 = upper_bound(a.begin(),a.end(),X+1);
    auto itr2 = lower_bound(a.begin(),a.end(),X-1);
    ans = max(ans,(int)(itr1 - itr2));
  }

  cout << ans << endl;

}


Measured memory_bytes: 640
n = int(input())
s = input()

w_to_e = [0]*n
e_to_w = [0]*n

for i in range(n-1):
    if s[i] == "W":
        w_to_e[i+1] = w_to_e[i] + 1
    else:
        w_to_e[i+1] = w_to_e[i]

for i in range(1, n):
    if s[-i] == "E":
        e_to_w[-(i+1)] = e_to_w[-i] + 1
    else:
        e_to_w[-(i+1)] = e_to_w[-i]

change = [w_to_e[i] + e_to_w[i] for i in range(n)]

print(min(change))

Measured memory_bytes: 29688
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define flush fflush(stdout)
using namespace std;

#define N 407
#define M 100007

int n, m, res, x, y;

bitset<N> curr[N];

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> m;

	for(int i = 1; i <= m; ++i)
	{
		cin >> x >> y;

		bitset<N> bx = curr[x];
		bitset<N> by = curr[y];

		if((bx&by).any() || bx[y])
			curr[x].set();
		else
		{
			curr[x] = bx|by;
			curr[x][y] = 1;
		}
		
		if((bx&by).any() || by[x])
			curr[y].set();
		else
		{
			curr[y] = bx|by;
			curr[y][x] = 1;
		}
	}

	for(int i = 1; i <= n; ++i)
	{
		for(int j = i+1; j <= n; ++j)
		{
			if(!(curr[i]&curr[j]).any() && !curr[i][j] && !curr[j][i] && !curr[i][i] && !curr[j][j])
				++res;
		}
	}

	cout << res;
}


Measured memory_bytes: 256
MOD = 10**9+7

def fast_pow(x, n, MOD):
    res = 1
    while n:
        if n & 1:
            res = res * x % MOD
        x = x * x % MOD
        n >>= 1
    return res


n = int(input())
a = list(map(int, input().split()))

d = {}
for i in a:
    if n % 2:
        if i > 0 and i % 2:
            print(0)
            exit()
    else:
        if i > 0 and i % 2 == 0:
            print(0)
            exit()

    if not i in d:
        d[i] = 1
    elif d[i] == 1:
        d[i] += 1
    else:
        print(0)
        exit()

if n % 2:
    if d[0] != 1:
        print(0)
        exit()
    print(fast_pow(2, len(d)-1, MOD))
else:
    if 0 in d:
        print(0)
        exit()
    print(fast_pow(2, len(d), MOD))
    

Measured memory_bytes: 20208
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

const int MAX = 100005;
const int INF = 1000000005;

class DisjointSet {
  public:
    vector<int> rank, p;

    DisjointSet(){}
    DisjointSet(int size) {
      rank.resize(size, 0);
      p.resize(size, 0);
      rep(i, size) makeSet(i);
    }

    void makeSet(int x) {
      p[x] = x;
      rank[x] = 0;
    }

    bool same(int x, int y) {
      return findSet(x) == findSet(y);
    }

    void unite(int x, int y) {
      link(findSet(x), findSet(y));
    }

    void link(int x, int y) {
      if (rank[x] > rank[y]) {
        p[y] = x;
      }
      else {
        p[x] = y;
        if (rank[x] == rank[y]) {
          rank[y]++;
        }
      }
    }

    int findSet(int x) {
      if (x != p[x]) {
        p[x] = findSet(p[x]);
      }
      return p[x];
    }
};

class Edge {
  public:
    int source, target, cost;
    Edge(int source = 0, int target = 0, int cost = 0):
    source(source), target(target), cost(cost) {}
    bool operator < (const Edge &e) const {
      return cost < e.cost;
    }
};

int kruskal(int N, vector<Edge> edges) {
  int totalCost = 0;
  sort(edges.begin(), edges.end());

  DisjointSet dset = DisjointSet(N + 1);

  rep(i, N) dset.makeSet(i);

  int source, target;

  rep(i, edges.size()) {
    Edge e = edges[i];
    if (!dset.same(e.source, e.target)) {
      totalCost += e.cost;
      dset.unite(e.source, e.target);
    }
  }
  return totalCost;
}

int main() {
  int N, M ,cost;
  int source, target;

  cin >> N >> M;

  vector<Edge> edges;
  rep(i, M) {
    cin >> source >> target >> cost;
    edges.push_back(Edge(source, target, cost));
  }

  cout << kruskal(N, edges) << endl;

  
  return 0;
}


Measured memory_bytes: 5396
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.List
import Control.Monad

data HeapPolicy = MinHeap | MaxHeap

data HeapT p a = Empty p
               | HeapT p Int a (HeapT p a) (HeapT p a)
    deriving Show

type Heap a = HeapT HeapPolicy a

empty :: HeapPolicy -> Heap a
empty = Empty

rank :: Heap a -> Int
rank (Empty _) = 0
rank (HeapT _ r _ _ _) = r

constract :: HeapPolicy -> a -> Heap a -> Heap a -> Heap a
constract p x a b
  | rank a >= rank b = HeapT p (rank b + 1) x a b
  | otherwise        = HeapT p (rank a + 1) x b a

merge :: Ord a => Heap a -> Heap a -> Heap a
merge h (Empty _) = h
merge (Empty _) h = h
merge h1@(HeapT MinHeap _ x l1 r1) h2@(HeapT MinHeap _ y l2 r2)
  | x < y     = constract MinHeap x l1 (merge r1 h2)
  | otherwise = constract MinHeap y l2 (merge r2 h1)
merge h1@(HeapT MaxHeap _ x l1 r1) h2@(HeapT MaxHeap _ y l2 r2)
  | x > y     = constract MaxHeap x l1 (merge r1 h2)
  | otherwise = constract MaxHeap y l2 (merge r2 h1)

push :: Ord a => a -> Heap a -> Heap a
push x h@(Empty p) = merge (HeapT p 1 x (Empty p) (Empty p)) h
push x h@(HeapT p _ _ _ _) = merge (HeapT p 1 x (Empty p) (Empty p)) h

pop :: Ord a => Heap a -> Heap a
pop (Empty _) = error "empty heap!"
pop (HeapT _ _ _ a b) = merge a b

top :: Heap a -> a
top (Empty _) = error "empty heap!"
top (HeapT _ _ x _ _) = x

fromList :: Ord a => HeapPolicy -> [a] -> Heap a
fromList p = foldl (flip push) (empty p)

toList :: Ord a => Heap a -> [a]
toList (Empty _) = []
toList h         = top h : toList (pop h)

isEmpty :: Heap a -> Bool
isEmpty (Empty _) = True
isEmpty _         = False

main :: IO ()
main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    a <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    print . sum . toList $ f m (fromList MaxHeap a)
  where
    f :: Int -> Heap Int -> Heap Int
    f 0 h = h
    f n h = let x = top h
                h' = push (x `div` 2) (pop h)
             in f (n-1) h'

Measured memory_bytes: 27004
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define for(i,n) for(int i=0;i<n;i++)
#define test(t) int t;cin>>t;while(t--)
#define ll long long
#define mod 1000000007
int main()
{
  ll int x,y,z;
  cin>>x;
  y=(x/500)*1000;
  x=x%500;
  z=(x/5)*5;
  cout<<y+z;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int l = s.size();
	if (s[l - 1] == 's') {
		s += "es";
	} else {
		s += "s";
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <unistd.h>
#define inf 1000000007LL
#define INF 1000000000000000007LL
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector< pair<int,int> >
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define LOG(x) (63-__builtin_clzll(x))
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i, n) for(int i=1; i<=(n); ++i)
#define endr cerr<<'\n'
#ifdef DEBUG
#define pv(...) cerr<<'\n',dbg(#__VA_ARGS__, __VA_ARGS__)
#define ps(x) {cerr<<'\n'<<#x<<":\n:";for(auto _q:(x)){cerr<<_q<<" ";}cerr<<'\n';}
#define pa(x, xs) {cerr<<'\n'<<#x<<":\n:";for(int _q=0; _q<=(xs); ++_q){cerr<<x[_q]<<" ";}cerr<<'\n';}
#define pal(x, xs) {cerr<<'\n'<<#x<<":\n";for(int _q=0; _q<=(xs); ++_q){cerr<<_q<<": "<<setw(_q? 3-(int32_t)log10(_q):3)<<x[_q]<<'\n';}cerr<<'\n';}
#define ppii(x, xs) {cerr<<'\n'<<#x<<":\n";for(int _q=0; _q<=(xs); ++_q){cerr<<_q<<": "<<setw(_q? 6-(int32_t)log10(_q):6)<<x[_q].first<<" "<<setw(5)<<x[_q].second<<'\n';}cerr<<'\n';}
#define pm(x, xn, xm) {cerr<<'\n'<<#x<<":\n";for(int _qa=0; _qa<=(xn); ++_qa){for(int _qb=0; _qb<=(xm); ++_qb){cerr<<setw(6)<<x[_qa][_qb]<<" ";}cerr<<'\n';}cerr<<'\n';}
#else
#define cerr if(0)cout
#define pv(...) if(0)endr
#define ps(x) if(0)endr
#define pa(x, xs) if(0)endr
#define pal(x, xs) if(0)endr
#define ppii(x, xs) if(0)endr
#define pm(x, xn, xm) if(0)endr
#endif
using namespace std;
template<class T> void dbg(const char* xn, T x){cerr<<xn<<": "<<x<<"\n";} template<class T, class... TA> void dbg(const char* xn, T x, TA... t){while(*xn!=',')cerr<<*xn++;cerr<<": "<<x<<",";dbg(xn+1, t...);}
template<class T> inline bool upd_max(T &x, T y){return y>x?x=y,true:false;} template<class T> inline bool upd_min(T &x, T y){return y<x?x=y,true:false;}
const int N = 1000007;
#define int long long

int n, men, q = 0, A[N];
bool mem[N], dp[N];


bool ask(int pos) //0 - male, 1 - fermale
{
  if (mem[pos]) return dp[pos];

  cout<<pos<<endl;
  string ans; cin>>ans;

  if (ans == "Vacant") exit(0);
  dp[pos] = (ans == "Female");
  mem[pos] = 1;
  return dp[pos];
}

bool check(int mid)
{
  bool ans = ask(mid);

  if (mid&1)
  {
    if (men == 1)
    {
      return ans == 1;
    }
    else
    {
      return ans == 0;
    }
  }
  else
  {
    if (men == 0)
    {
      return ans == 1;
    }
    else
    {
      return ans == 0;
    }
  }
}

int BS(int lo, int hi)
{
  int mid;
  while (lo < hi)
  {
    mid = lo + (hi-lo)/2;
    pv(mid, check(mid));
    if (check(mid)) hi = mid;
    else lo = mid+1;
  }

  return lo;
}


void solve()
{
  cin>>n;
  if (ask(0) == 0)  men = 0; //%2 of men
  else men = 1;

  ask(1);

  int border = BS(2, n-1);

  ask(border);
  ask(border-1);
  ask(border+1);
}

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

  solve();

return 0;
}


Measured memory_bytes: 980
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

int n;
map<int, int> me, mo;

int main() {
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        if (i % 2 == 0)
            if (!me.count(a)) me[a] = 1;
            else me[a]++;
        else
            if (!mo.count(a)) mo[a] = 1;
            else mo[a]++;
    }

    pair<int, int> e1, e2, o1, o2;
    e1.first = 0, e1.second = 0;
    e2.first = 0, e2.second = 0;
    o1.first = 0, o1.second = 0;
    o2.first = 0, o2.second = 0;
    for (auto i : me)
        if (e1.second <= i.second) {
            e2.first = e1.first;
            e2.second = e1.second;
            e1.first = i.first;
            e1.second = i.second;
        }
        else if (e2.second <= i.second) {
            e2.first = i.first;
            e2.second = i.second;
        }

    for (auto i : mo)
        if (o1.second <= i.second) {
            o2.first = o1.first;
            o2.second = o1.second;
            o1.first = i.first;
            o1.second = i.second;
        }
        else if (o2.second <= i.second) {
            o2.first = i.first;
            o2.second = i.second;
        }

    if (e1.first != o1.first) cout << n - e1.second - o1.second << endl;
    else cout << min(n - e1.second - o2.second, n - e2.second - o1.second) << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

#include <vector>
#include <set>
#include <functional>
using namespace std;

template<class Node>
struct UnionFind{
  vector<int> par;
  vector<int> rank;
  vector<Node> nodes;
  function<void(Node&,Node&)> f;

  UnionFind(const vector<Node>& init,function<void(Node&,Node&)> func) : par(init.size(),0),rank(init.size(),0),nodes(init) , f(func){
    for(int i = 0;i < init.size();i++){
      par[i] = i;
    }
  }

  int root(int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  int unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y) return 0;

    int r,c;

    int res = 1;

    if(rank[x] < rank[y]){
      par[x] = y;
      r = y;
      c = x;
      res = -1;
    }
    else{
      par[y] = x;
      r = x;
      c = y;
      if(rank[x] == rank[y]) rank[x]++;
      res = 1;
    }

    f(nodes[r],nodes[c]);
    return res;
  }

  bool same(int x,int y){
    return root(x) == root(y);
  }

  Node value(int x){
    return nodes[x];
  }
};

/*
 * UnionFindTree
 *
 * #Node
 * 頂点に置く値の型
 * uniteしたときに更新をする
 *
 * +function<void(Node&,Node&)> f
 * uniteしたときデータの更新を行う
 * 左が根のnode,右が子のnodeである
 * ex...size,max
 *
 * +UnionFind(const vector<Node>& init,function<void(Node&,Node&)> func)
 * init...各頂点の初期値
 * func...fに設定するもの
 *
 * ex...UnionFind<int> uf(vector<int>(N,1),[](int& rn,int& cn){rn += cn;});
 *
 * +int root(int x)
 * 要素の根の頂点を返す
 *
 * +bool unite(int x,int y)
 * 結合する.
 * 元から同じグループであれば0
 * xが根になったときは1
 * yが根になったときは-1を返す
 *
 * +bool same(int x,int y)
 * 同じグループに属しているかを返す
 *
 * +Node value(int x)
 * 頂点の値を返す
 *
 */

template<class Weight = long long>
struct WeightedUnionFind : public UnionFind<Weight>{

  WeightedUnionFind(int size) : UnionFind<Weight>(vector<Weight>(size,0),[](Weight& rn,Weight& cn){}){
  }

  int root(int x){
    if(x == this->par[x]) return x;
    int parent = root(this->par[x]);
    this->nodes[x] += this->nodes[this->par[x]];
    return this->par[x] = parent;
  }

  int unite(int x,int y,Weight w){
    w  = w + weight(x) - weight(y);
    x = root(x);
    y = root(y);
    int res = UnionFind<Weight>::unite(x,y);
    if(res == 0) return 0;
    if(res == -1){
      w = -w;
      swap(x,y);
    }
    this->nodes[y] = w;
    return res;
  }

  Weight weight(int x){
    root(x);
    return this->nodes[x];
  }

  bool same(int x,int y){
    return root(x) == root(y);
  }

  pair<bool,Weight> diff(int x,int y){
    if(!same(x,y)) return {false,0};
    return {true,weight(x) - weight(y)};
  }
};

/*
 * WeightedUnionFind
 *
 * +Weight weight(int x)
 * 頂点の重みを返す
 *
 * +pair<bool,Weight> diff(int x,int y)
 * first...同じグループに属しているかを返す
 * second...yからxの重みの差を返す
 * 
 */
int main(){

  int N,M;
  cin >> N >> M;

  WeightedUnionFind<i64> uf(N + 1);

  rep(i,0,M - 1){
    int l,r,d;
    cin >> l >> r >> d;
    auto p = uf.diff(r , l);
    if(!p.first){
      uf.unite(l,r,d);
    }
    else if(p.second != d){
      cout << "No" <<endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n;
	cin >> n;
	vector<int> fib(n+1);
	fib[0] = fib[1] = 1;
	rep(i,n-1){
		fib[i+2] = fib[i] + fib[i+1];
	}
	cout << fib[n] << endl;
}



Measured memory_bytes: 3080
a, b = map(int, input().split())
c = []
d = []
g = []
for i in range(a):
    e, f = map(int, input().split())
    c.append([e, f])
for i in range(b):
    e, f = map(int, input().split())
    d.append([e, f])
for i in range(a):
    f = 10 ** 9
    h = 0
    for j in range(b):
        if f > abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1]):
            f = abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1])
            h = j + 1
    g.append(h)
for i in g:
    print(i)


Measured memory_bytes: 3064
n=int(input())
a=[int(i) for i in input().split()]
count=0
flag=0
b=[]
maxi=0
for i in range(len(a)-1):
  if(a[i]>=a[i+1] and flag==0):
      count=1
      flag=1
      
  elif(a[i]>=a[i+1] and flag==1):
    count+=1
    if(maxi<count):
        maxi=count
        
  else:
    count=0
    flag=0
      
print(maxi)

Measured memory_bytes: 14224
use List::Util qw(min);

my $s = <>;
chomp $s;
my $a0 = 0;
my $a1 = 0;

for(my $i = 0; $i < length $s; $i++){
    if(substr($s, $i, 1) == $i % 2){
        $a0++;
    } else {
        $a1++;
    }
}

print min($a0, $a1);


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template<class Abel> struct UnionFind {
    const Abel UNITY_SUM = 0;      // to be set
    vector<int> par;
    vector<Abel> diff_weight;
    
    UnionFind(int n) : par(n, -1), diff_weight(n, UNITY_SUM) {}
    void init(int n) { par.assign(n, -1), diff_weight.assign(n, UNITY_SUM); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
    
    Abel calc_weight(int x) {
        root(x);
        return diff_weight[x];
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y, Abel w = 0) {
        w += calc_weight(x); w -= calc_weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y), w = -w; // merge technique
        par[x] += par[y];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
    
    Abel diff(int x, int y) {
        return calc_weight(y) - calc_weight(x);
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


int main() {
    int n, m;
    cin >> n >> m;
    UnionFind<int> uf(n);
    rep(i, 0, m) {
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        if (uf.issame(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int,int>P;
vector<P>node[100005];
int color[100005];

int dfs(int pos,int stat);
int main(){
  int n;
  cin>>n;
  for(int i=0;i<=n;i++){
    color[i]=-1;
  }

  for(int i=0;i<n-1;i++){
    int a,b,cost;
    cin>>a>>b>>cost;
    node[a].push_back(P(b,cost));
    node[b].push_back(P(a,cost));
  }
  
  dfs(1,0);
  
  for(int i=1;i<=n;i++){
    cout<<color[i]<<endl;
  }
  return(0);
}

int dfs(int pos,int stat){
  color[pos]=stat;
  for(int i=0;i<(int)node[pos].size();i++){
    int next=node[pos][i].first;
    int cost=node[pos][i].second;
    if(color[next]==-1){
      if(cost%2==0){
	dfs(next,stat);
      }else{
	dfs(next,(stat+1)%2);
      }
    }
  }
  return(0);
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
    string a, b, c;
    cin >> a >> b >> c;
    char now = a[0];
    a.erase(0, 1);
    while (1) {
        if (now == 'a') {
            if (a.empty()) {
                cout << "A" << endl;
                return 0;
            } else {
                now = a[0];
                a.erase(0, 1);
            }
        } else if (now == 'b') {
            if (b.empty()) {
                cout << "B" << endl;
                return 0;
            } else {
                now = b[0];
                b.erase(0, 1);
            }
        } else {
            if (c.empty()) {
                cout << "C" << endl;
                return 0;
            } else {
                now = c[0];
                c.erase(0, 1);
            }
        }
    }

    return 0;
}


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

int main(){
     char a,b;
     cin >> a>>b;
     if(a=='H'&&b=='H')  cout << 'H' <<endl;
     else if(a=='H'&&b=='D') cout << 'D' <<endl;
     else if(a=='D'&&b=='H') cout << 'D' <<endl;
     else cout << 'H' << endl;
      }

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.insert(0, 1e10)
    ans = []
    B = [0] * len(A)
    for i in range(len(A)-1, 0, -1):
        idx = i
        s = 0
        while idx <= len(A) - 1:
            s += B[idx]
            idx += i

        if s % 2 != A[i]:
            ans.append(i)
            B[i] = 1

    
    if len(ans) > 0:
        print(len(ans))
        print(*ans)
    else:
        print(0)


if __name__ == '__main__':
    main()


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

string db(int a){
	string ret;
	for(int i=0;i<5;i++){
		ret += '0'+a%2;
		a/=2;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}

bool cmp(string a,string b){
	return a.length() > b.length();
}

int main(){
	map<char,string> table;
	
	for(int i=0;i<26;i++)table['A'+i] = db(i);
	string tmp = " .,-'?";
	for(int i=0;i<tmp.size();i++)table[tmp[i]] = db(26+i);
	
	string n;
	
	map<string,char> r;
	
	r["101"] = ' '; r["0101"] = 'C'; r["0110"] = 'K'; r["00110"] = 'S';
	r["000000"] = '\''; r["0001"] = 'D'; r["00100"] = 'L'; r["00111"] = 'T';
	r["000011"] = ','; r["110"] = 'E'; r["10011001"] = 'M'; r["10011100"] = 'U';
	r["10010001"] = '-'; r["01001"] = 'F'; r["10011110"] = 'N'; r["10011101"] = 'V';
	r["010001"] = '.'; r["10011011"] = 'G'; r["00101"] = 'O'; r["000010"] = 'W';
	r["000001"] = '?'; r["010000"] = 'H'; r["111"] = 'P'; r["10010010"] = 'X';
	r["100101"] = 'A'; r["0111"] = 'I'; r["10011111"] = 'Q'; r["10010011"] = 'Y';
	r["10011010"] = 'B'; r["10011000"] = 'J'; r["1000"] = 'R'; r["10010000"] = 'Z';
	
	while( getline(cin,n) ){
		string use,ret;
		for(int i=0;i<n.length();i++)
			use += table[n[i]];
		string choice;
		int pos = 0;
		
		vector<string>reset;
		
		for( map<string,char>::iterator it=r.begin(); it != r.end(); ++it){
			reset.push_back((*it).first);
		}
		sort(reset.begin(),reset.end(),cmp);
		
		for(;;){
			choice = "";
			for(int i=0;i<reset.size();i++){
				if(use.find(reset[i]) == 0){
					choice = reset[i];
					break;
				}
			}
			if(choice != "")ret += r[choice];
			else break;
			
			use = use.substr(choice.length(),use.length()-choice.length());
		}
		cout << ret << endl;
		
	}

}

Measured memory_bytes: 928
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int N,T,Niz[200001],poc;
LL tret,rez,pam;
int main()
{
    scanf("%d %d",&N,&T);
    for(int i=1;i<=N;i++){
        scanf("%d",&Niz[i]);
    }
    tret=(LL)T;
    for(int i=2;i<=N;i++){
        if(Niz[i]<=tret){
            tret=(LL)Niz[i]+T;
        }

        else{
            rez+=(LL)(tret-poc);
            poc=Niz[i];
            tret=(LL)Niz[i]+T;
        }
    }
    rez+=(LL)(tret-poc);
    printf("%I64d",rez);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
    int ans,tmp,X;
    cin >> X;
    int i;
    ans=1;
    for(i=2;i<=31;i++){
      tmp=i*i;
      while(tmp<=X){
        if (tmp>ans) {
          ans=tmp;
        }
        tmp=tmp*i;
      }
    }
    cout << ans;
}

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

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

    if (K == 1) cout << 0 << endl;
    else {
        int mi = 1;
        int ma = N-(K-1);
        cout << ma-mi << endl;
    }
}


Measured memory_bytes: 256
l0 = input().split(' ')
N = int(l0[0])
H = int(l0[1])
L = []
i=0
while i < N:
    l1 = input().split(' ')
    l2 = [int(l1[0]), int(l1[1])]
    L.append(l2)
    i += 1
L.sort(key = lambda x:x[1])
#b_iの順に並び変え
L2 = L.copy()
L2.sort()
Amax = L2[N-1][0]
p=N-1
while p >= 0:
    if L[p][1] > Amax:
        p -= 1
    else:
        break
k=N-1
Btot = 0
c=0
counter = 0
while k > p:
    H -= L[k][1]
    k -= 1
    counter += 1
    if H <= 0:
        c = counter
        break

st =  H // Amax
counter += st
if st * Amax != H:
    counter += 1
if c ==0:
    print(counter)
else:
    print(c)

Measured memory_bytes: 21128
H, W = map(int, input().split())
MAP = [list(input()) for _ in range(H)]
L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if MAP[i][j] == "#":
            L[i][j] = 0
        elif j == 0:
            L[i][j] = 1
        else:
            L[i][j] = L[i] [j - 1] + 1

        if MAP[i][W - j - 1] == "#":
            R[i][W - j - 1] = 0
        elif j == 0:
            R[i][W - j - 1] = 1
        else:
            R[i][W - j - 1] = R[i][W - j] + 1

for j in range(W):
    for i in range(H):
        if MAP[i][j] == "#":
            U[i][j] = 0
        elif i == 0:
            U[i][j] = 1
        else:
            U[i][j] = U[i - 1][j] + 1

        if MAP[H - i - 1][j] == "#":
            D[H - i - 1][j] = 0
        elif i == 0:
            D[H - i - 1][j] = 1
        else:
            D[H - i - 1][j] = D[H - i][j] + 1
result = 0
for i in range(H):
    for j in range(W):
        result = max(result, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)

print(result)


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

const int INF = 1001001001;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> to[n];
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dist[0] = 0;
  queue<int> q;
  q.push(0);
  auto bfs = [&](int u, int v) {
    dist[u] = dist[v]+1;
    pre[u] = v;
    q.push(u);
  };
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      bfs(u,v);
    }
  }
  cout << "Yes" << endl;
  for(int i=1; i<n; ++i) {
    int ans = pre[i];
    ++ans;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 10736
#include <stdio.h>

int main(void)
{
int x,y;
int syo = 0;

scanf("%d %d", &x, &y);

syo = x / 2;
if ((x % 2) == 1){syo++;}
if(syo >= y){
	printf("YES");
}
else{
	printf("NO");
}
return (0);
}

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

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
int main()
{
    string N;
    cin >> N;

    string M = "ABC" + N;

    cout << M << endl;

}

Measured memory_bytes: 256
N=int(input())
S=input()
mod=10**9+7

#DP[i]#最後においた数の右にある残っている個数
rest=N-1
DP=[1]*(N)

for s in S:
    NDP=[0]*(N)
    if s=="<":
        for i in range(rest+1):
            if i>=1:
                NDP[i-1]=(DP[i]+NDP[i-1])%mod

        DP=NDP
        for i in range(N-2,-1,-1):
            DP[i]=(DP[i+1]+DP[i])%mod

    else:
        DP=[DP[rest-i] for i in range(N)]#左右逆にして考える

        #print(DP)
        for i in range(rest+1):
            if i>=1:
                NDP[i-1]=(DP[i]+NDP[i-1])%mod

        DP=NDP
        for i in range(N-2,-1,-1):
            DP[i]=(DP[i+1]+DP[i])%mod


        DP=[DP[rest-1-i] for i in range(N)]

    rest-=1
    #print(DP,rest)

print(DP[0])

Measured memory_bytes: 51420
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bits/stdc++.h>
#include <array>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int main(int argc, const char * argv[]) {
    // source code
    int a;
    cin >> a;
    cout << a * a; 
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b, d;
	ll c;
	//char c;
	ll h, w;
	ll k;
	string s, t;
	ll l_ans = 0;
	string s_ans = "NG";

	cin >> x >> k >> d;

	ll cnt = abs(x) / d;
	if (cnt >= k) {
		l_ans = abs(x) - k * d;
	}
	else {
		if ((k - cnt) % 2 == 0) {
			l_ans = abs(x) - d * cnt;
		}
		else {
			l_ans = abs(x) - d * (cnt + 1);
		}
	}

	cout << abs(l_ans) << "\n";

	return;
}


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

	solve_abc_a();

	return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
const double inf=1e8;
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a||b){
    int d1[101][101];
    int d2[101][101];
    rep(i,101)rep(j,101){
      d1[i][j]=inf;
      d2[i][j]=inf;
    }
    rep(i,a){
      int c,d,e,f;
      cin>>c>>d>>e>>f;
      c--;d--;
      d1[c][d]=e;d1[d][c]=e;
      d2[c][d]=f;d2[d][c]=f;
    }
    rep(k,b)rep(i,b)rep(j,b){
      d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]);
      d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]);
    }
    int n;cin>>n;
    rep(i,n){
      int g,h,l;cin>>g>>h>>l;
      g--;h--;
      if(l)cout<<d2[g][h]<<endl;
      else cout<<d1[g][h]<<endl;
    }
  }
}

Measured memory_bytes: 1236
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int x=in.nextInt();
		System.out.println(x*x*x);
	}
}


Measured memory_bytes: 22356