akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll rep[100001] , sz[100001];
ll find(ll u)
{
    return rep[u] == u ? u : rep[u] = find(rep[u]);
}
bool join(ll a , ll b)
{
    a = find(rep[a]) , b = find(rep[b]);
    if (a == b)
        return false;
    if (sz[a] < sz[b])
        swap(a , b);
    sz[a] += sz[b];
    rep[b] = a;
    return true;
}
int main()
{
    ll n;
    cin >> n;
    for (int i = 0; i < n; i++)
        rep[i] = i ,sz[i] = 1 ;
    vector <pair <ll , ll>> vx , vy;
    map <ll , vector <pair<ll , ll>>> mop;
    for (int i = 0; i < n; i++)
    {
        ll  a , b;
        cin>> a >> b;
        vx.push_back({a , i});
        vy.push_back({b , i});
    }
    sort(vx.begin() , vx.end());
    sort(vy.begin() , vy.end());
    for (int i = 1; i < n; i++)
        mop[vx[i].first - vx[i-1].first].push_back({vx[i].second , vx[i-1].second});
    for (int i = 1; i < n; i++)
        mop[vy[i].first - vy[i-1].first].push_back({vy[i].second , vy[i-1].second});
    ll ans = 0;
    for (auto i : mop)
    {
        for (auto j : i.second)
            if (join(j.first , j.second))
                ans += i.first;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 12900
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i=0; i<N; i++) {
        cin >> H[i];
    }
    for(int i=N-1; i>=1; i--) {
        if(H[i-1] - H[i] > 1) {
            cout << "No" << endl;
            return 0;
        } else if(H[i-1] == H[i] + 1) {
            H[i-1] --;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, D; cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D, 0));
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) cin >> X[i][j];
    int cnt = 0; double x = 1.0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            double M = 0.0;
            for (int k = 0; k < D; ++k) {
                M += pow(X[i][k] - X[j][k], 2);
            }
            if (modf(sqrt(M), &x) == 0) cnt++;
        }
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 3756
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;

int main(int argc, char* argv[])
{
    int n,V,P; ll M;
    scanf("%d%lld%d%d", &n, &M, &V, &P);
    vector<ll> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a.begin(),a.end());

    int l=-1,r=n;
    while(r-l>1) {
        int m=(l+r)/2;

        ll sum=(ll)M*(m+1);
        sum+=(ll)M*(P-1);

        ll val=a[m]+M;
        int i;
        int bad=0;
        for(i=m+1; i<=n-P; i++) {
            if(val-a[i]<0) bad=1;
            sum+=(val-a[i]);
        }
        //printf("%d,%lld\n", m,sum);

        if( sum>=(ll)M*V && bad==0) {   //ok
            r=m;
        }
        else {   //ng
            l=m;
        }
    }
    printf("%d\n", n-r);

    return 0;
}

Measured memory_bytes: 1024
n = input()
l = [int(x) for x in list(str(n))]
ans = []
if (l[0] < l[1]) or (l[0] < l[2]):
	num = l[0] + 1
else:
	num = l[0]
for i in range(3):
	ans.append(num)
ansn = ans[0] * 100 + ans[1] * 10 + ans[2]
print(ansn)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000000000000LL
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,rx[1005],ry[1005],bx[1005],by[1005],rc[1005],bc[1005];
struct edge
{
	int to,cap,cost,rev;
};
int nn=2100;
vector<edge>G[2100];
int dist[2100];
int prevv[2100],preve[2100];

void add_edge(int from,int to,int cap,int cost)
{
	G[from].pb((edge){to,cap,cost,G[to].size()});
	G[to].pb((edge){from,0,-cost,G[from].size()-1});
}

int mincost_maxflow(int s,int t,int f)
{
	int res=0;
	while(f>0)
	{
		//このnはフローを流すグラフの頂点数でありもとのグラフの頂点数ではない!!!!!!
		fill(dist,dist+nn,INF);
		dist[s]=0;
		bool upd=true;
		while(upd)
		{
			upd=false;
			for(int v=0;v<nn;v++)
			{
				if(dist[v]==INF) continue;
				for(int i=0;i<G[v].size();i++)
				{
					edge &e = G[v][i];
					if(e.cap>0 && dist[e.to]>dist[v]+e.cost)
					{
						dist[e.to]=dist[v]+e.cost;
						prevv[e.to]=v;
						preve[e.to]=i;
						upd=true;
					}
				}
			}
		}
		if(dist[t]==INF) return -1;
		int d=f;
		for(int v=t;v!=s;v=prevv[v])
		{
			d = min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*dist[t];
		for(int v=t;v!=s;v=prevv[v])
		{
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

signed main(){
	cin >> n;
	rep(i,n) cin >> rx[i] >> ry[i] >> rc[i];
	rep(i,n) cin >> bx[i] >> by[i] >> bc[i];
	
	int s = 2095, t = 2096, S = 0;
	int x = 3000000000LL;
	rep(i,n){
		add_edge(s,i,rc[i],0);
		add_edge(i,n+0,rc[i],-rx[i]-ry[i]);
		add_edge(i,n+1,rc[i],rx[i]-ry[i]);
		add_edge(i,n+2,rc[i],-rx[i]+ry[i]);
		add_edge(i,n+3,rc[i],rx[i]+ry[i]);
		add_edge(n+0,i+n+5,bc[i],bx[i]+by[i]);
		add_edge(n+1,i+n+5,bc[i],-bx[i]+by[i]);
		add_edge(n+2,i+n+5,bc[i],bx[i]-by[i]);
		add_edge(n+3,i+n+5,bc[i],-bx[i]-by[i]);
		add_edge(i+n+5,t,bc[i],0);
		S += bc[i];
	}
	
	int ans = mincost_maxflow(s,t,S);
	ans = -ans;
	cout<<ans<<endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin, n, k;
    vector<int> p(n);
    REP(i, 0, n) {
        cin, p[i];
    }
    sort(p.begin(), p.end());
    int ans = 0;
    REP(i, 0, k) {
        ans += p[i];
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3620
from collections import defaultdict, deque
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
N = int(input())
A = sorted(inpl())
if A[-1] < 0:
    print(A[-1] - sum(A[:-1]))
    for i in range(N-2, -1, -1):
        print(A[-1], A[i])
        A[-1] -= A[i]
else:
    print(sum(map(abs, A[1:])) - A[0])
    for i in range(N-2, 0, -1):
        a = A[i]
        if a > 0:
            print(A[0], a)
            A[0] -= a
        else:
            print(A[-1], a)
            A[-1] -= a
    print(A[-1], A[0])

Measured memory_bytes: 21300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;


void solve(){

    int x;
    cin >> x;
    cout << 1-x << endl;

}

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


Measured memory_bytes: 3636
from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=1
s=set()
count=0
while a not in s:
	s.add(a)
	a=l[a-1]
	count+=1
	if count==k:
		print(a)
		exit()
if count<k:
	k-=count
	# print(k)
else:
	a=1
	for i in range(k):
		a=l[a-1]
	print(a)
	exit()
s=set()
count=0
while a not in s:
	s.add(a)
	a=l[a-1]
	count+=1
if count<k:
	f=k%count
	for i in range(f):
		a=l[a-1]
	print(a)
else:
	for i in range(k):
		a=l[a-1]
	print(a)

Measured memory_bytes: 120148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

int cnt[110];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int n,k;
	cin>>n>>k;
	for (int i=1; i<=k; i++){
		int d;
		cin>>d;
		for (int j=1; j<=d; j++){
			int a;
			cin>>a;
			cnt[a]++;
		}
	}
	int ans=0;
	for (int i=1; i<=n; i++)
		if (cnt[i]==0) ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3664
/*
    Stay motivated and keep working hard
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N, W;
ll w[107], v[107];
ll dp[107][100007];
ll rec(ll N, ll W){
    if(N == 0 || W == 0){
        return 0;
    }
    if(dp[N][W]){
        return dp[N][W];
    }
    if(W >= w[N-1]){
        return dp[N][W] = max(dp[N][W], max(rec(N-1, W), v[N-1] + rec(N-1, W-w[N-1])));
    }
    else{
        return dp[N][W] = max(dp[N][W], rec(N-1, W));
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin >> N >> W;
    for(ll i=0;i<N;i++){
        cin >> w[i] >> v[i];
    }
    rec(N, W);
    cout << dp[N][W] << "\n";


    return 0;
}

Measured memory_bytes: 79360
//=======================================
// abc143b
//
//  2019/10/19
//=======================================

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

int main(int argc, char* argv[])
{
	cin.tie(0);
  ios::sync_with_stdio(false);

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

  int sum=0;
  for(int i=0; i<n-1; ++i)
  {
    for(int j=i+1; j<n; ++j)
    {
      sum+=v[i]*v[j];
    }
  }

  cout << sum << endl;

  return 0;
}

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

using namespace std;

bool check(int k, int W) {
    for (int i = 0; i + 1 < (W - 1); i++) {
        if ((k >> i & 1) && ((k >> (i + 1)) & 1)) return false;
    }
    return true;
}

int main() {
    int H, W, K;
    const int mod = 1e9 + 7;
    cin >> H >> W >> K;

    vector<vector<int>> dp(H + 1, vector<int>(W));
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            for (int k = 0; k < 1 << (W - 1); k++) {
                if (!check(k, W)) continue;
                int pos = j;

                if (k >> j & 1) pos++;
                else if (j >= 1 && k >> (j - 1) & 1) pos--;
                
                dp[i + 1][pos] += dp[i][j];
                dp[i + 1][pos] %= mod;
            }
        }
    }
    cout << dp[H][K - 1] << endl;
    return 0;
}

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

int main(){
  int w;
 
  while(1){
    cin >> w;
    if(w == -1) break;
    
    int ans = 3130;
    w -= 10;

    if(10 <= w){
      ans -= 10*125;
      w -= 10;
    }
    else if(0 < w){
      ans -= w*125;
      w = 0;
    }
    else{
      cout << ans << endl;
      continue;
    }

    if(10 <= w){
      ans -= 10*140;
      w -= 10;
    }
    else if(0 < w){
      ans -= w*140;
      w = 0;
    }
    else{
      cout << ans << endl;
      continue;
    }
    
    if(0 < w){
      ans -= w*160;
    }
    else{
      cout << ans << endl;
      continue;
    } 
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <cassert>

const int maxn = 9e5+1;
typedef long long ll;
using namespace std;
const ll MOD =1e9+7;
ll fac[maxn];
ll rev[maxn];
ll inv[maxn];
ll C(int n,int k){
    if (n<k || k<0)
        return 0;
    return fac[n]*inv[n-k]%MOD*inv[k]%MOD;
}
ll precalc(){
    fac[0]=1;
    inv[0]=1;
    rev[1]=1;
    inv[1]=1;
    fac[1]=1;
    for(int i=2; i<maxn; ++i){
        fac[i]=fac[i-1]*i%MOD;
        rev[i]=(MOD-MOD/i)*rev[MOD%i]%MOD;
        inv[i]=inv[i-1]*rev[i]%MOD;
    }
}
ll pw(ll a,ll b){
    ll res=1;
    while(b){
        if (b&1)
            res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 //   freopen("input.txt","r",stdin);
    int n,m,k;
    cin>>n>>m>>k;
    precalc();
    ll ans=0;
    int l=-1;
    int r=-1;
    ll val=0;
    for(int i=n; i<=n+m+k; ++i){
        int cur_l=max(i-n-m,0);
        int cur_r=min(i-n,k);
      //  cout<<i<<" "<<cur_l<<" "<<cur_r<<endl;
        if (l==-1){
            for(int j=cur_l; j<=cur_r; ++j) {
                val += C(i-n,j);
                if (val>=MOD)
                    val-=MOD;
            }
            l=cur_l;
            r=cur_r;
        }
        else{
         //   cout<<"BEF "<<val<<endl;
             val=2*val-C(i-n-1,r);
             val+=C(i-n-1,l-1);
         //    cout<<i-n<<" "<<l<<" "<<r<<" "<<val<<"NOW\n";
             val%=MOD;
             if (val<0)
                 val+=MOD;
             while(l>cur_l){
                 assert(false);
                 --l;
                 val+=C(i-n,l);
                 if (val>=MOD)
                     val-=MOD;
             }
             while(r<cur_r){
                 ++r;
                 val+=C(i-n,r);
                 if (val>=MOD)
                     val-=MOD;
             }
             while(l<cur_l){
                 val-=C(i-n,l);
                 ++l;
                 if (val<0)
                     val+=MOD;
             }

        }
       // cout<<val<<endl;
        ans+=val*C(i-1,n-1)%MOD*pw(3,n+m+k-i)%MOD;
        if (ans>=MOD)
            ans-=MOD;
    }
    cout<<ans;
}

Measured memory_bytes: 21376
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    s = []
    while True:
        n = N % K
        N //= K
        if N == 0 and n == 0:
            break
        s.append(n)
    print(len(s))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(void){

    ll X; cin>>X;

    for (int i = 0; i <= 120; ++i) {
        for (int j = -120; j <= 120; ++j) {
            if(pow(i,5)-pow(j,5) == X){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }


}


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

using namespace std;

int count(int n) {
	int ans = 1;
	int cur = 7;
	while (cur % n != 0) {
		cur = (cur * 10 + 7) % n;
		ans++;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	if (n % 2 == 0 || n % 5 == 0) {
		cout << -1 << endl;
	} else {
		cout << count(n) << endl;
	}
}


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



int main(){
    long long int n,k,ans=0;
    cin>>n>>k;
    vector<pair<long long int,long long int>>a(200000);
    for(int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
    }
    sort(a.begin(),a.end(),greater<>());
    for(int i=0;i<n;i++){
        k-=a[n-1-i].second;
        if(k<=0){
            ans=a[n-1-i].first;
            break;
        }
    }

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

Measured memory_bytes: 3328
A, B, C ,X, Y = map(int, input().split())

ans = 0
if A <= C and B <= C: #A, Bの値段がCよりも安い-->素直にA, Bのみを買う
    ans = A * X + B * Y
elif A > C and B > C: #Cの値段がA, Bのどちらよりも安い
    if X > Y: #Aの必要枚数のほうが多い
        zan = (X-Y) * A
    else: #Bの必要枚数のほうが多い
        zan = (Y-X) * B
    ans = min(X, Y) * 2 * C + min(zan, C * (max(X, Y)- min(X, Y)) * 2) #残り枚数をA or Bで買うか、余るのを覚悟してABを買うか
else:
    if X > Y: #Xのほうが枚数多い
        ans = A * X + B * Y #素直に買う
        kari = Y * 2 * C + A * (X-Y) #余らないようにできるだけCを買う
        ans = min(ans, kari)
        kari = X * 2 * C #余ってもいいからCを買う
        ans = min(ans, kari)
    else: #X <= Y
        ans = A * X + B * Y
        kari = X * 2 * C + B * (Y-X)
        ans = min(ans, kari)
        kari = Y * 2 * C
        ans = min(ans, kari)
print (ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
	char a[9];
	while(cin>>a[0]){
		for(int i=1;i<9;i++) cin>>a[i];
		int b = 2;
		if(a[0]=='o' and a[1]=='o' and a[2]=='o') b = 0;
		if(a[3]=='o' and a[4]=='o' and a[5]=='o') b = 0;
		if(a[6]=='o' and a[7]=='o' and a[8]=='o') b = 0;
		if(a[0]=='o' and a[3]=='o' and a[6]=='o') b = 0;
		if(a[1]=='o' and a[4]=='o' and a[7]=='o') b = 0;
		if(a[2]=='o' and a[5]=='o' and a[8]=='o') b = 0;
		if(a[0]=='o' and a[4]=='o' and a[8]=='o') b = 0;
		if(a[2]=='o' and a[4]=='o' and a[6]=='o') b = 0;
		if(a[0]=='x' and a[1]=='x' and a[2]=='x') b = 1;
		if(a[3]=='x' and a[4]=='x' and a[5]=='x') b = 1;
		if(a[6]=='x' and a[7]=='x' and a[8]=='x') b = 1;
		if(a[0]=='x' and a[3]=='x' and a[6]=='x') b = 1;
		if(a[1]=='x' and a[4]=='x' and a[7]=='x') b = 1;
		if(a[2]=='x' and a[5]=='x' and a[8]=='x') b = 1;
		if(a[0]=='x' and a[4]=='x' and a[8]=='x') b = 1;
		if(a[2]=='x' and a[4]=='x' and a[6]=='x') b = 1;
		if(b==0) cout << "o" << endl;
		if(b==1) cout << "x" << endl;
		if(b==2) cout << "d" << endl;
	}
}

Measured memory_bytes: 1132
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] inputs = br.readLine().split(" ");

		int a = Integer.parseInt(inputs[0]);
		int b = Integer.parseInt(inputs[1]);
		int c = Integer.parseInt(inputs[2]);

		if (a + b - c == 0 || a + c - b == 0 || b + c - a == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 8148
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n, k = Is()
H = LI()
H.sort(reverse=True)
if n > k:
    print(sum(H[k:]))
else:
    print("0")

Measured memory_bytes: 113736
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
    int N;
	VI P;
	cin >> N;
	P.resize(N);
	int max_p = -1e7;
	REP(i, N) {
		cin >> P[i];
		if (P[i] > max_p) {
			max_p = P[i];
		}
	}

	int sum = 0;
	REP(i, N) {
		sum += P[i];
	}
	sum -= (int)(max_p / 2);

	cout << sum << endl;

	return 0;
}


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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

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

  cout << n - a - b + c << endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

#define INF 10000000000009
#define MAX_V 100000

struct edge {
    int to;
    double cost;
    edge(int to,double cost):to(to),cost(cost){}
};



int V;
vector<edge> G[MAX_V];
double d[MAX_V];

void dijkstra(int s) {
    priority_queue<pair<double,int>, vector<pair<double,int>>, greater<pair<double,int>> > que;
    fill(d, d+V, (double)INF);
    d[s] = (double)0;
    que.push(make_pair((double)0, s));

    while (!que.empty()) {
        pair<double,int> p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

int main(){
  int xs,ys,xt,yt;cin>>xs>>ys>>xt>>yt;
  int n;cin>>n;
  V=n+2;
  double x[n+2],y[n+2],r[n+2];
  rep(i,n)cin>>x[i]>>y[i]>>r[i];
  x[n]=xs;y[n]=ys;
  x[n+1]=xt;y[n+1]=yt;
  rep(i,n+2){
    rep(j,n+2){
      if(i==j)continue;
      double res=max(sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j],(double)0);
      G[i].push_back(edge(j,res));
    }
  }
  dijkstra(n);
  cout<<setprecision(15)<<d[n+1]<<endl;
}


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

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

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-12

#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())

// bitmask operations
#define SETBIT(S, j) S |= (1 << j)
#define CLEARBIT(S, j) S &= ~(1 << j)
#define ISSET(S, j) S & (1 << j)
#define FLIPBIT(S, j) S ^= (1 << j)
#define LSBIT(S) (S & (-S))

// debug
#define DEBUGSTR(S) cout << "(" << S << ")\n";

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  string s;

  cin >> s;

  bool is_YYMM = false, is_MMYY = false;

  int first = stoi(s.substr(0, 2));
  int second = stoi(s.substr(2));

  if(first > 0 && first < 13)
    is_MMYY = true;
  
  if(second > 0 && second < 13)
    is_YYMM = true;

  if(is_YYMM && is_MMYY)
    cout << "AMBIGUOUS\n";
  else if(is_YYMM)
    cout << "YYMM\n";
  else if(is_MMYY)
    cout << "MMYY\n";
  else
    cout << "NA\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string S;
    cin >> S;
    if (S[1] == 'R')
        cout << "ABC";
    else
        cout << "ARC";
    return 0;
}

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

//right+1,front+0,left+3,back+2
enum{NORTH,EAST,SOUTH,WEST};
const int dir[4]={1,0,3,2};
const int dx[]={0,1,0,-1};
const int dy[]={-1,0,1,0};

const int gdir[]={WEST,SOUTH,EAST,NORTH};
const int gx[]  ={1,0,-1,0};
const int gy[]  ={0,-1,0,1};


const int N = 100;
char inp[N][N];
//-1 daremo inai
int m[N][N];//-1,  dir 0,1,2,3 
int mnext[N][N];

void output(int r,int c){
  rep(i,r){
    rep(j,c){
      cout << m[i][j]<<" " ;
    }
    cout << endl;
  }
  cout << endl;
}

void solve(int r,int c){
  rep(loop,181){
    rep(i,r)rep(j,c)if (m[i][j] != -1)goto end;
    cout << loop << endl;
    return;
  end:;

    //change dir
    rep(i,r){
      rep(j,c){
	if (m[i][j] == -1)continue;
	rep(k,4){
	  int next = (m[i][j] + dir[k])%4;
	  int nex = j+dx[next],ney=i+dy[next];
	  if (nex == -1 || ney == -1 || nex == c || ney == r)continue;
	  if (inp[ney][nex] != '#' && m[ney][nex] == -1){
	    m[i][j] = next;
	    break;
	  }
	}
      }
    }

    rep(i,r)rep(j,c)mnext[i][j] = m[i][j];
    //move
    rep(i,r){
      rep(j,c){
	if (inp[i][j] == '#' || m[i][j] != -1)continue;
	rep(k,4){
	  int ney = i+gy[k],nex=j+gx[k];
	  if (nex == -1 || ney == -1 || nex == c || ney == r)continue;
	  //cout << i <<" " << j <<" " << ney <<" " << nex <<" " << m[ney][nex] << " " << k << " " << gdir[k] << endl;
	  if (m[ney][nex] == gdir[k]){
	    swap(mnext[i][j],mnext[ney][nex]);
	    break;
	  }
	}
      }
    }

    rep(i,r)rep(j,c)m[i][j] = mnext[i][j];
    //output(r,c);
    rep(i,r)rep(j,c)if (inp[i][j] == 'X' && m[i][j] != -1)m[i][j] = -1;
  }
  cout << "NA" << endl;
}

main(){
  int c,r;
  while(cin>>c>>r && c){
    rep(i,r)cin>>inp[i];
    rep(i,r){
      rep(j,c){
	if (inp[i][j] == '.' || inp[i][j] == '#' || inp[i][j] == 'X'){
	  m[i][j] = -1;
	}else if (inp[i][j] == 'E'){
	  inp[i][j] = '.';
	  m[i][j] = 1;
	}else if (inp[i][j] == 'S'){
	  inp[i][j] = '.';
	  m[i][j] = 2;
	}else if (inp[i][j] == 'W'){
	  inp[i][j] = '.';
	  m[i][j] = 3;
	}else if (inp[i][j] == 'N'){
	  inp[i][j] = '.';
	  m[i][j] = 0;
	}
      }
    }
    solve(r,c);
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int q;
int cnta[100010][2];
int cntb[100010][2];
signed main() {
    memset(cnta, 0, sizeof(cnta));
    memset(cntb, 0, sizeof(cntb));
    string s1, s2;
    cin >> s1 >> s2;
    cin >> q;

    rep(i,0,s1.length()) {
        cnta[i+1][0] = cnta[i][0] + (s1[i] == 'A');
        cntb[i+1][0] = cntb[i][0] + (s1[i] == 'B');
    }
    rep(i,0,s2.length()) {
        cnta[i+1][1] = cnta[i][1] + (s2[i] == 'A');
        cntb[i+1][1] = cntb[i][1] + (s2[i] == 'B');
    }

    rep(i,0,q) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        int a1 = cnta[b][0] - cnta[a-1][0];
        int b1 = cntb[b][0] - cntb[a-1][0];
        int a2 = cnta[d][1] - cnta[c-1][1];
        int b2 = cntb[d][1] - cntb[c-1][1];

        a1 %= 3;
        b1 %= 3;
        a2 %= 3;
        b2 %= 3;

        while(a1 && b1) {a1--; b1--;}
        while(a2 && b2) {a2--; b2--;}
        if(a1 == 2) {a1 = 0, b1++;}
        else if(b1 == 2) {b1 = 0, a1++;}
        if(a2 == 2) {a2 = 0, b2++;}
        else if(b2 == 2) {b2 = 0, a2++;}

        // printf("a1 = %lld, b1 = %lld, a2 = %lld, b2 = %lld\n", a1, b1, a2, b2);
        if(a1-b1 == a2-b2) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
from collections import deque

def solve(h, w, ch, cw, dh, dw, s):
    W, H = w+5, h+5
    def pos(r, c):
        return (r+2)*W + c+2
    G = [0] * (W*H)
    label = 0
    for r in range(h):
        for c in range(w):
            if (s[r][c] == '.') and (G[pos(r,c)] == 0):
                label += 1
                que = deque([(r, c)])
                G[pos(r,c)] = label
                while que:
                    cr, cc = que.popleft()
                    for dr, dc in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                        nr, nc = cr+dr, cc+dc
                        if (0 <= nr < h) and (0 <= nc < w) and (s[nr][nc] == ".") and (G[pos(nr,nc)] == 0):
                            G[pos(nr,nc)] = label
                            que.append((nr, nc))

    start = pos(ch-1, cw-1)
    goal = pos(dh-1, dw-1)

    neighbors = [(dr*W+dc) for dc in range(-2, 3) for dr in range(-2, 3) if abs(dr) + abs(dc) > 0]
    used = [True] * (W*H)
    for r in range(h):
        for c in range(w):
            used[pos(r,c)] = (s[r][c] == "#")
    que = deque([(start, 0)])
    label_dist_mapping = [-1] * (label + 1)
    used[start] = True
    label_dist_mapping[G[start]] = 0
    while que:
        cpos, n = que.popleft()
        if cpos == goal:
            return n
        for d in neighbors:
            npos = cpos + d
            if not used[npos]:
                used[npos] = True
                m = label_dist_mapping[G[npos]]
                if (G[npos] == G[cpos]) or (n == m): # 同一グループ
                    que.appendleft((npos, n))
                else:
                    label_dist_mapping[G[npos]] = n + 1
                    que.append((npos, n+1))
    return -1

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
s = [input() for i in range(h)]
print(solve(h, w, ch, cw, dh, dw, s))


Measured memory_bytes: 37756
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int calc(string s, string target)
{
    int res = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == target[i]) continue;
        bool ok = false;
        for(int j = i + 1; j < s.size(); j++)
        {
            if(target[i] == s[j])
            {
                swap(s[i], s[j]);
                res += j - i;
                ok = true;
                break;
            }
        }
        if(not ok) return INF;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    string b = "", target1 = "", target2 = "";
    for(int i = 0; i < n; i++)
    {
        char ch; cin >> ch;
        b += ch;
    }
    bool flag;
    for(int i = 0; i < m; i++)
    {
        int x; cin >> x;
        if(i == 0) flag = true;
        else if(target1.back() == '1') flag = false;
        else flag = true;
        for(int j = 0; j < x; j++)
        {
            target1 += (flag ? '1' : '0');
            target2 += (flag ? '0' : '1');
        }
    }
    int ans = min(calc(b, target1), calc(b, target2));
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3216
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    int N;
    cin >> N;
    if (N % 2 == 0) {
        cout << N / 2 - 1 << endl;
    } else {
        cout << (N - 1) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 998244353
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, m;

	ll ans=0;

	cin>>n>>m;

	vvb a(n, vb(n, false));
	vb visited(n, false);

	vi v(n-1);

	rep(i, m){
		int from, to;
		cin>>from>>to;
		a[from-1][to-1]=true;
		a[to-1][from-1]=true;
	}

	iota(v.begin(), v.end(), 1);
	do{
		repr(i, 1, n) visited[i]=false;

		int node=0;
		rep(i, n-1){
			if(a[node][v[i]]){
				node=v[i]; visited[v[i]]=true;
			}
		}
		bool flag=true;
		repr(i, 1, n){
			if(!visited[i]) flag=false;
		}
		if(flag) ans++;
	}while(next_permutation(v.begin(), v.end()));     // 次の順列を生成
	
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<string> S;
	for (int i = 0; i < N; i++) {
		string A;
		cin >> A;
		S.push_back(A);
	}

	bool flag = true;

	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (S[i] == S[j]) flag = false;
		}
	}

	for (int i = 1; i < N; i++) {
		if (S[i].front() != S[i - 1].back()) flag = false;
	}

	if (flag == true) cout << "Yes";
	else cout << "No";


	return 0;
}


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

class Main {




  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int N = in.nextInt();
    int W = in.nextInt();
    int[] w = new int[N];
    int[] v = new int[N];
    for (int i = 0; i < N; i++) {
      w[i] = in.nextInt();
      v[i] = in.nextInt();
    }

    long[] dp = new long[W + 1];
    for (int i = 0; i < N; i++) {
      for (int j = W; j >= w[i]; j--) {
        dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i]);
      }
    }

    


    System.out.println(dp[W]);
  }

  

  
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int s_1;
  s_1=N/1000;
  int s_2;
  s_2=(N-1000*s_1)/100;
  int s_3;
  s_3=(N-1000*s_1-100*s_2)/10;
  int s_4;
  s_4=N-1000*s_1-100*s_2-10*s_3;
  if (s_1 ==s_2 && s_2== s_3) {
    cout << "Yes" << endl;
  }
  else if (s_2== s_3 && s_3 == s_4) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define inf 1e18
#define all(v) (v).begin(),(v).end()
using namespace std;

vector <int> dx = {-1,1,0,0};
vector <int> dy = {0,0,-1,1};
const int maxn = 1e5 + 10;
ll fact[maxn];
ll modexp(ll a,ll b){
	a %= MOD;
	ll res = 1;
	while(b > 0){
		if(b&1){
			res = (res*a)%MOD;
		}
		b >>= 1;
		a = (a*a)%MOD;
	}
	return res;
}
ll modinv(ll n){
	return modexp(n,MOD-2);
}
ll c(ll n, ll r){
	return (fact[n]*((modinv(fact[r])*modinv(fact[n-r]))%MOD))%MOD;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll s; cin >> s;
	ll l = s/3;
	if(l == 0){
		cout << 0 <<"\n";
		return 0;
	}
	ll ans = 0;
	int i;
	fact[0] = 1;
	for(i = 1 ;i <= 100000; ++i){
		fact[i] = (fact[i-1] * i)%MOD;
	}
	ll n,r;
	for(i = 1;i <=l; ++i){
		n = s - 2*i - 1;
		r = i - 1; 
		
		ans +=  (c(n,r))%MOD;
		
		//cout << ans<<"\n";
	}
	cout << ans%MOD <<"\n";

	return 0;
}

Measured memory_bytes: 4424
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();

    sc.close();

    int count = 0;

    for (int i = A; i <= B; i++) {
      
      String i_ = String.valueOf(i);
      String[] I = i_.split("");

      if (I[0].equals(I[4]) && I[1].equals(I[3])) {
        count++;
      }

    }

    System.out.println(count);

  }

}

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

void solve(){
	int n,k;
	cin >> n >> k;
	vector<int> x(n);

	vector<int> ds;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		if(i != 0){
			int d = x[i] - x[i-1];
			ds.push_back(d);
		}
	}
	int sum = 0;
	sort(ds.begin(),ds.end());
	for(int i=0;i<(int)ds.size()-k+1;i++){
		sum += ds[i];
	}
	cout << sum << endl;
}

int main(void){
	int T;
	cin >> T;
	for (int t = 0; t < T; t++) {
		solve();
	}


	return 0;
}

Measured memory_bytes: 4200
#include<iostream>
#include<stdio.h>
#include<cmath> 
using namespace std;
 
int main(){
 
  int N,f,a,t,x,y; 
  int tmp_f,tmp_a,tmp_t,tmp_x,tmp_y; 
  int i,j;
  int flg_a=0,flg_b=0;
  double tmp_distance_a,tmp_distance_b,tmp_time_a,tmp_time_b,distance_a,time_a,distance_b,time_b;
  
  cin >> N;
 
  for(i = 0 ; i < N ; i++){
   
    cin >> f >> a >> t >> x >> y;
     
    if(i > 0){
      if(tmp_a!=a&&tmp_t==t&&t==0){
    flg_a=1;
    distance_a = sqrt((x-tmp_x)*(x-tmp_x)+(y-tmp_y)*(y-tmp_y));
    time_a = (double)(f - tmp_f)/60;
    if( tmp_distance_a < distance_a || (tmp_distance_a == distance_a && tmp_time_a > time_a)){
    tmp_distance_a = distance_a;
    tmp_time_a = time_a;
    }
      }
    }
    if(tmp_a!=a&&tmp_t==t&&t==1){
      flg_b=1;
      distance_b = sqrt((x-tmp_x)*(x-tmp_x)+(y-tmp_y)*(y-tmp_y));
      time_b = (double)(f - tmp_f )/60;
      if( tmp_distance_b < distance_b || (tmp_distance_b == distance_b && tmp_time_b > time_b)){
    tmp_distance_b = distance_b;
    tmp_time_b = time_b;
    }
    }
 
    tmp_f = f; tmp_a = a; tmp_t = t; tmp_x = x; tmp_y = y; 
  }
 
  if(flg_a==0&&flg_b==1){
    cout << -1 << " " << -1 << endl;
    printf("%.8lf %.8lf\n",tmp_distance_b,tmp_time_b);
  }
  if(flg_a==1&&flg_b==0){
    printf("%.8lf %.8lf\n",tmp_distance_a,tmp_time_a); 
    cout <<  -1 << " " << -1 << endl;
  }
  if(flg_a==0&&flg_b==0){
    cout <<  -1 << " " << -1 << endl;
    cout <<  -1 << " " << -1 << endl;
  }
  if(flg_a==1&&flg_b==1){
    printf("%.8lf %.8lf\n",tmp_distance_a,tmp_time_a);
    printf("%.8lf %.8lf\n",tmp_distance_b,tmp_time_b);
  }
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;


lli INF=1e18;

lli memo[101][100001];
lli N,W;
lli w[101];
lli v[101];
lli P;

//0(10^(2+3))
lli min_weight(lli index,lli tot_price){
	if(tot_price<0)
		return  INF;
	if(tot_price==0)
		return 0;

	if(index==N){
		return INF;
	}
	if(memo[index][tot_price]!=-1)return memo[index][tot_price];
	return memo[index][tot_price] = min({ min_weight(index+1,tot_price) , min_weight(index+1,tot_price-v[index])+w[index] });
}

void solve()
{
	lli i,ans=0;

	for(i=100001;i>=0;i--)
	{
		P=i;
 		if(min_weight(0,0)<=W && min_weight(0,0)!=0)
 		{
			ans=i;
			break;
		}
	}
	cout<<ans;
}


//0(10^5(loop in main) * 10^5(formin_weight part))
//0(10^10)
int main()
{
	lli i,j;
	for(i=0;i<100;i++)
	{
		for(j=0;j<100001;j++)
			memo[i][j]=-1;
	}



	cin>>N>>W;

	for(i=0;i<N;i++)
	{
		cin>>w[i]>>v[i];
	}

	lli a;

	for(i=0;i<100001;i++)
		a=min_weight(0,i);


	for(i=100000;i>=0;i--)
	{
		if(memo[0][i]<=W)
		{
			cout<<i;
			break;
		}
	}


	return 0;

}



Measured memory_bytes: 78336
#include<stdio.h>
#include<iostream>
#include <algorithm>
	using namespace std;

	int main(){
		int data ;
			cin>>data;
			for(int n=0;n<data;n++)
			{	int i[3];
			cin>>i[0]>>i[1]>>i[2] ;
			sort(i,i+3);
				if (i[0]*i[0] + i[1]*i[1] == i[2]*i[2]){
					cout<< "YES\n";
				}else {
					cout<< "NO\n";
			}
			if ( data ==0) {
				break;
	}

	}
	 return 0;
	}
	
	

Measured memory_bytes: 1136
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

#h[i] 足場0~n-1の高さ
#dp[i] 足場iに行くのにかかるコスト
def main():
	n = int(input())
	h = list(map(int,input().split()))
	dp = [0,abs(h[1]-h[0])]
	for i in range(2,n):
		dp.append(min(dp[i-2] + abs(h[i-2]-h[i]), dp[i-1] + abs(h[i-1]-h[i])))
	print(dp[-1])


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

Measured memory_bytes: 60676
#include <stdio.h>
#include <stdlib.h>


int n, l, j, u, k,tmp;

int list[100][100];

int llist[100];

void search(int y, int length){
  int i;
  length++;
  llist[y] = length;


  for( i = 0 ; i < n ; i++){
    if( list[y][i] == 1 ){
      if( llist[i] <= length && llist[i] >= 0 ){
        continue;
      }
      search(i, length);
    }
  }
}

int main(){


  scanf("%d", &n);

  for(l = 0 ; l < n ; l++){
    scanf("%d", &u);
    scanf("%d", &k);
    for( j = 0 ; j < k ; j++){
      scanf("%d", &tmp);
      list[u-1][tmp-1] = 1;
    }
  }



  for( l = 0 ; l < n ; l++){
    llist[l] = -1;
  }
  search(0, -1);

  for(j = 0 ; j < n ; j++){
    printf("%d %d\n", j+1, llist[j]);
  }

  return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
const int total = 5000;
long long dp[60][60][total];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int>v(n);
  for(auto &x: v)cin >> x;
  dp[0][0][0] = 1;
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j <= n; ++j) {
      for(int k = 0; k <= 50*50; ++k) {
        if(dp[i][j][k] == 0)continue;
        assert(k+v[i] < total);
        dp[i+1][j][k] += dp[i][j][k];
        dp[i+1][j+1][k+v[i]] += dp[i][j][k];
      }
    }
  }
  long long ans = 0;
  for(int i = 1; i <= n; ++i) {
    ans+= dp[n][i][k*i];
  }
  cout << ans << endl;
  return 0;
}

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

N = int(input())
ax = list(map(int, input().split()))

ls = []
A = sum(ax[:1])
B = sum(ax[1:])

for i in range(1, N):
    sub = abs(A-B)
    ls.append(sub)
    if(sub is 0):
        break
    A += ax[i]
    B -= ax[i]

print(sorted(ls)[0])


Measured memory_bytes: 23800
#include<stdio.h>
#define N 100

int main(void) {
  
  int tmp,n,i,mini,j,A[N],cnt=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++) 
    scanf("%d",&A[i]);
  
  for(i=0;i<n;i++) {
    mini = i;
    
    for(j=i;j < n;j++) {
      
      if(A[j] < A[mini])
	mini = j;
      
    }
    if(mini != i){
      tmp = A[i];
      A[i] = A[mini];
      A[mini] = tmp;
  }
    if(i != mini)
      cnt++;
  }  
  
  for(i=0;i<n;i++) {
    if(i > 0)
      printf(" ");
    printf("%d",A[i]);
    
  }   
  printf("\n");
  printf("%d\n",cnt);
  
  return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <string.h>
int main(){
	char num[1001];
	int len,x,m,sum,n,i;
	for(;;){
		sum=0;
		scanf("%s",num);
		len=strlen(num);
		if(strcmp(num,"0")==0)break;
		for(i=0;i<len;i++){
			sum+=(int)num[i]-48;
		}
		printf("%d\n",sum);
	}
	return 0;
}


Measured memory_bytes: 1836