akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int s, h;
	cin >> s >> h;
	cout << (s <= h? "unsafe": "safe") << '\n';
}



Measured memory_bytes: 3644
a, b, c = [int(i) for i in input().split(" ")]
mn, me, mx = sorted([a, b, c])

c = 0

if (me - mn) % 2 == 0:
    c += (me - mn) // 2
    mn = me
else:
    c += (me - 1 - mn) // 2 + 1
    mn = me
    mx += 1
    
c += mx - me

print(c)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//FUNCTION
void solve(void)
{
  int N,K; cin>>N; cin>>K;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  int ANS = INF;
  for (int i = 0; i < N-K+1; i++)
  {
    int MIN = vec[i];
    int MAX = vec[i+K-1];
    MIN = min(0LL,MIN);
    MAX = max(0LL,MAX);
    MIN = abs(MIN);
    // DEBUG(MIN,MAX);
    chmin(ANS,min(MAX + 2*MIN,MIN + 2*MAX));

  }
  
  cout<<ANS<<endl;
  
  
  
  return;
}

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

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  	int a , b , c;
    cin >> a >> b >> c;
  	if ( c >= a && c <= b ) cout << "Yes";
    else cout << "No";
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int N; cin >> N;
    vector<int> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];
    vector<i_i> p(N);
    rep(i, N) p[i] = i_i(a[i] + b[i], i);
    sort(all(p));
    reverse(all(p));
    ll ans = 0;
    rep(t, N) {
        int i = get<1>(p[t]);
        if (t % 2 == 0) ans += a[i];
        else ans -= b[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

# define max_n 40

int main(void) {
  int i,j;
  int n;
  while(cin >> n, n){
     vector<vi> v(max_n);//v[i]:= i日目に集まる人
     rep(i,n){
         int m;
         cin >> m;
         rep(j,m){
             int a;
             cin >> a;
             v[a].push_back(i);
         }
     }

     if(n == 1){
         cout << 0 << endl;
         continue;
     }

     vector< set<int> > s(n);//s[i] := iさんが持ってる地図
     rep(i,n)s[i].insert(i);

     rep(i,max_n) if(v[i].size()){
         set<int> st; //i日目に集まる地図

         //地図を回収する
         rep(j,v[i].size()){ //v[i][j]さんが来る
             for(auto x: s[v[i][j]])
                st.insert(x);
         }

         if(st.size() == n){
             cout << i << endl;
             goto END;
         }

        //地図を配布する
        rep(j,v[i].size()){
            s[v[i][j]] = st;
        }
     }

     cout << -1 << endl;
     END:;
    }

}



Measured memory_bytes: 3256
#include "bits/stdc++.h"
using namespace std;

void intersection(int dd[],int n){
	int v,j;
	for (int k = 0; k < n; ++k) {
		if(k){cout<<" "<<dd[k];}
		else{cout<<dd[k];}
	}cout<<endl;
	for (int i = 1; i < n; ++i) {
		v=dd[i];
		j=i-1;
		while(j>=0&&dd[j]>v){
			dd[j+1]=dd[j];
			j--;
		}
		dd[j+1]=v;
		for (int k = 0; k < n; ++k) {
			if(k){cout<<" "<<dd[k];}
			else{cout<<dd[k];}
		}cout<<endl;
	}
}

int main() {
int n;
cin>>n;
int d[n];
for (int i = 0; i < n; ++i) {
	cin>>d[i];
}
	intersection(d,n);

}

Measured memory_bytes: 3088
import sys
M, K = map(int,input().split())
if M == 0:
    if K == 0:
        print(*[0, 0])
    else:
        print(-1)
    sys.exit()

if M == 1:
    if K == 0:
        print(*[0, 1, 1, 0])
    else:
        print(-1)
    sys.exit()

N = 2 ** M

if K >= N:
    print(-1)
    sys.exit()

ans = []

for i in range(N):
    if i != K:
        ans.append(i)

ans.append(K)

for i in range(N-1,-1,-1):
    if i != K:
        ans.append(i)

ans.append(K)

print(*ans)

Measured memory_bytes: 19316
#!/usr/bin/env python3
import sys

PARTS = ["eraser", "erase", "dreamer", "dream"]
# PARTS2 = []


def main():
    global PARTS2
    sys.setrecursionlimit(100000)
    S = input()

    # for i in range(0, 4):
    #     for j in range(0, 4):
    #         PARTS2.append(PARTS[i] + PARTS[j])

    # PARTS2 = PARTS2 + PARTS

    if judgeStr2(S):
        print("YES")
    else:
        print("NO")


def judgeStr2(target: str) -> bool:
    currentStr = target
    while currentStr != "":
        isNextOK = False
        for item in PARTS:
            if not currentStr.startswith(item):
                continue

            tempStr = currentStr.replace(item, "", 1)
            if tempStr == "":
                return True

            for item2 in PARTS:
                if tempStr.startswith(item2):
                    isNextOK = True
                    break

            if isNextOK:
                currentStr = tempStr
                break
        if isNextOK:
            continue
        else:
            break
    return currentStr == ""


def judgeStr(target: str) -> bool:
    for item in PARTS:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False


if __name__ == "__main__":
    main()


Measured memory_bytes: 9316
#include <cstdio>
#include <stack>
#include <algorithm>
#define N 200005
#define pi pair<int,int>
#define fi first
#define se second

using namespace std;

int n;
int a[N];

bool check(int);

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	int l = 1, r = 1e9, res;
	while(l <= r){
		int mid = (l + r) >> 1;
		if(check(mid)) res = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", res);
	return 0;
}

bool check(int x){
	stack<pi> st;
	for(int i = 2; i <= n; ++i)
		if(a[i - 1] >= a[i]){
			if(x == 1) return false;
			while(!st.empty() && st.top().fi > a[i]) st.pop();
			if(!st.empty() && st.top().fi == a[i]) ++st.top().se;
			else st.push(make_pair(a[i], 1));
			if(st.top().se == x){
				int las = st.top().fi; st.pop(); bool flag = false;
				while(!st.empty() && st.top().fi == las - 1){
					++st.top().se;
					if(st.top().se == x) 
						las = st.top().fi, st.pop();
					else{
						flag = true; break;
					}
				}
				if(las == 1 && !flag) return false;
				if(!flag) st.push(make_pair(las - 1, 1));
			}
		}
	return true;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;
    cout << ((a*b % 2 == 0) ? "Even" : "Odd") << endl;
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

ll f(ll n) {
    if (n == 1) {
        return 1;
    }
    return 1 + 2 * f(n / 2);
}
int run(istream& in, ostream& out) {
    ll H;
    in >> H;
    ll ans = f(H);
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

int main(void){
  	cin.tie(0);
  	ios::sync_with_stdio(false);
  	
    int n,timing,total=0;
    cin>>n;
    vector<string> title(n);
    vector<int> dist(n);
    string fintitle;
    for(int i=0;i<n;i++){
        cin>>title[i]>>dist[i];
    }
    cin>>fintitle;
    for(int i=0;i<n;i++){
        if(title[i]==fintitle){
            timing=i;
        }
    }
    
    for(int i=timing+1;i<n;i++){
        total+=dist[i];
    }
    
    cout<<total<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long LL;
const int N=5022;
LL dp[N][N];
int n,a,b,x[N],pos[N];
int main(){
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;i++) scanf("%d",&x[i]), pos[x[i]]=i;
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)dp[i][j]=1e18;
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        LL mn=dp[i-1][0];
        for(int j=0;j<=n+1;j++){
            mn=min(mn,dp[i-1][j]);

            if(j==pos[i]) dp[i][j]=mn;
            else if(j<pos[i]) dp[i][j]=mn+min(1LL*b,1LL*a*(pos[i]-j));
            else dp[i][j]=mn+min(1LL*a,1LL*b*(j-pos[i]));
    
            //printf("dp[%d][%d]=%lld\n", i,j,dp[i][j]);
        }
    }
    LL ans=1e18;
    for(int i=0;i<=n+1;i++)ans=min(ans,dp[n][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 197376
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  vector<int> y=x;

  ll ans=0;
  rep(i,n){
    for(int j=i+1; j<n; j++){
      ans+=x[i]*y[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// Credits : Palindroam



// Problem : C - Sum of product of pairs
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

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

/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void print(T t, V... v) {_print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */ 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  lcm(x, y)   ((x) * (y) / __gcd(x, y))
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

void solve(){
    int n; cin >> n;
    vi v(n);
    ll sum1 = 0;
    rep(i,0,n){
        cin >> v[i];
        sum1 += v[i];
        sum1 %= MOD;
    }
    
    ll sum = 0,pref = 0;
    rep(i,0,n){
        pref += v[i];
        pref %= MOD;
        v[i] %= MOD;
        sum %= MOD;
        ll temp = (sum1 - pref + MOD)%MOD;
        sum += (v[i]*temp);
    }
        
    cout << sum;
}

int main(){
    IOS;
    solve();
}

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

int main() {
  
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import bisect
n,m = map(int, input().split())

L = [[] for i in range(n)]
D = []

for i in range(m):
    p, y= map(int, input().split())
    L[p-1].append(y)
    D.append([p,y])

for i in range(n):
    L[i].sort()

for i in range(m):
    s1 = str(D[i][0]).zfill(6)
    s2 = str(bisect.bisect_left(L[D[i][0]-1], D[i][1])+1).zfill(6)
    print(s1+s2)

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

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b,x;
    cin >> a >> b >> x;
    ll cnt;
    if(a == 0) cnt = b/x + 1;
    else cnt = b/x - (a-1)/x;
    if(cnt<0){
        cout << 0 << endl;
        return 0;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B,C,X;
	cin>>A;
	cin>>B;
	cin>>C;
	cin>>X;
	int aw=0;
	int i,j,k;
	for (i=0;i<=A;i++){
		for (j=0;j<=B;j++){
			for (k=0;k<=C;k++){
				if (i*500+j*100+k*50==X){
					aw++;
				}
			}
		}
	}
	cout<<aw<<endl;
	return 0;
}

Measured memory_bytes: 256
import random
import numpy as np
d = int(input())
c = list(map(int, input().split()))
s = []
for i in range(d):
    temp = list(map(int, input().split()))
    s.append(temp)
s = np.array(s)
#print(s)
with open('output.txt', 'w') as f:
    dice = list(range(26))
    w = c
    samples = random.choices(dice, k=d, weights=w)
    for one in samples:
        print(one+1)

Measured memory_bytes: 27432
import java.util.*;

class Main {
    static int n;
    static int k;
    static int[] a;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        Arrays.sort(a);
        if(check(0)){
            System.out.println(0);
            System.exit(0);
        }
        if(!check(n-1)){
            System.out.println(n);
            System.exit(0);
        }
        int hi = n-1;
        int lo = 0;
        while(hi-lo>1){
            int mid = (lo+hi)/2;
            if(check(mid)) hi = mid;
            else lo = mid;
        }
        System.out.println(hi);
    }
    static boolean check(int idx){
        int cur = a[idx];
        boolean[] range = new boolean[k+1];
        range[0]=true;
        for(int i=0;i<n;i++){
            if(i==idx) continue;
            int now = a[i];
            for(int j=k;j>=now;j--){
                if(range[j-now]) {
                    range[j] = true;
                    if(k-cur<=j&&j<k) return true;
                }
            }
        }
        for(int j=Math.max(0,k-cur);j<k;j++){
            if(range[j]) return true;
        }
        return false;
    }
}


Measured memory_bytes: 30044
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
from heapq import heapify,heappush,heappop
n,m=n1()
AB=t3(n)

d=defaultdict(list)
for a,b in AB:
    d[a].append(b)

ans=0
h=[]
for i in range(1,m+1):
    while len(d[i])>0:
        heappush(h,-1*d[i].pop())
    if len(h)>0:
        ans+=-1*heappop(h)
print(ans)

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

int main(){
  int a,b,C;
  double c,S,L,h;
  scanf("%d %d %d",&a,&b,&C);
  S=(0.5*a*b*sin(M_PI*C/180.0));
  c=pow(a*a+b*b-2*a*b*cos(M_PI*C/180.0),0.5);
  L=a+b+c;
  h=2*S/a;
  printf("%lf\n%lf\n%lf\n",S,L,h);
  return 0;
}

Measured memory_bytes: 672
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var list = new List<string> { Line() };
            for (int i = 1; i < N; i++) {
                var tmp = Line();
                if (list.Last().Last() != tmp.First()) {
                    Console.WriteLine("No");
                    return;
                }
                list.Add(tmp);
            }

            if (list.Distinct().Count() == N) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13396
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, q;
	cin >> n >> q;
	vector<int> c(n);
	for(auto &x : c) {
		cin >> x;
		x--;
	}

	vector<tuple<int, int, int>> qq;
	for(int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		qq.emplace_back(l, r, i);
	}

	int b = ceil(sqrt(n));
	sort(qq.begin(), qq.end(), [&] (auto u, auto v) {
		if(get<0>(u) / b != get<0>(v) / b) {
			return u < v;
		}

		return (get<0>(u) / b & 1) ? (get<1>(u) < get<1>(v)) : (get<1>(u) > get<1>(v));
	});

	vector<int> cnt(n, 0);
	vector<int> res(q);
	int u = 0, ml = 0, mr = -1;
	for(int i = 0; i < q; i++) {
		while(mr < get<1>(qq[i])) {
			++cnt[c[++mr]];
			if(cnt[c[mr]] == 1) u++;
		}

		while(ml < get<0>(qq[i])) {
			--cnt[c[ml++]];
			if(cnt[c[ml - 1]] == 0) u--;
		}

		while(ml > get<0>(qq[i])) {
			++cnt[c[--ml]];
			if(cnt[c[ml]] == 1) u++;
		}

		while(mr > get<1>(qq[i])) {
			--cnt[c[mr--]];
			if(cnt[c[mr + 1]] == 0) u--;
		}
		res[get<2>(qq[i])] = u;
	}

	for(auto &x : res) cout << x << '\n';
}

Measured memory_bytes: 15456
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var ret int
	for i := 0; i <= n; i++ {
		s := strings.Split(strconv.Itoa(i), "")
		var r int
		for j := 0; j < len(s); j++ {
			r++
		}
		if r%2 == 1 {
			ret++
		}
	}
	fmt.Println(ret - 1)
}


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

struct Node{
  int key;
  struct Node *r,*l,*p;
};

 struct Node *B,*NIL;

void insert(int k){
   struct Node *y = NIL;
   struct Node *x = B;
   struct Node *z;

   z = (struct Node *)malloc(sizeof(struct Node));
   z->key = k;
   z->l = NIL;
   z->r = NIL;

   while(x!=NIL){
     y = x;
     
     if(z->key < x->key){
       x = x->l;
     }
     else x = x->r;
   }
   
   z->p = y;
   if(y == NIL ){
     B=z;
   }
   else if(z->key < y->key){
       y->l = z;
     }
   else y->r = z;
}




void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(struct Node *u){
  if(u == NIL )return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}

int main(){
  
  int i,x,y;
  char G[8];
  scanf("%d",&x);
  
  for(i=0;i<x;i++){
    scanf("%s",&G);
    
    if(G[0] == 'i'){
      scanf("%d",&y);
      insert(y);
    }
    
    else if(G[0] == 'p'){
      inorder(B);
      printf("\n");
      preorder(B);
      printf("\n");
    }
  }
  return 0;
}

  

Measured memory_bytes: 24040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

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

  long n;
  cin >> n;

  vector<long> a(n);
  fillLong(a, n);

  sortv(a);
  while(1) {
    if(a[0] == a[n-1]) break;
    long m = a[0];
    rep(i, n) {
      a[i] = a[i] % m ? a[i] % m : m;
    }
    sortv(a);
  }

  cout << a[0] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
  ll n;
  cin >> n;
  ll r;
  for (r = 0; r * r <= n; r++);
  int maxd = 1;
  for (int i = 2; i < r; i++) {
    if (n % i == 0) {
      maxd = i;
    }
  }
  int ans = 0;
  for (int i = n / maxd; i > 0; i /= 10) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# 座標圧縮した場合

import sys
from itertools import accumulate
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


class BIT:
    def __init__(self,init_value):
        self.n = len(init_value)
        self.tree = [0]*(self.n+1)
        for i in range(1,self.n+1):
            x = init_value[i-1]
            while i <= self.n:
                self.tree[i] += x
                i += i & (-i)

    def update(self,i,x):  # i(1-index)番目の値を+x
        while i <= self.n:
            self.tree[i] += x
            i += i & (-i)
        return

    def query(self,i):  # 1番目からi(1-index)番目までの和を返す
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & (-i)
        return res


N = I()
A = LI()
C = sorted(list(set(A)))
dict_A = {}  # dict_A[a] = (a は A の中で何番目に小さい値か)
dict_C = {}  # dict_C[i] = (A の中で i 番目に小さい値)
for i in range(1,len(C)+1):
    dict_C[i] = C[i-1]
    dict_A[C[i-1]] = i
A = [dict_A[a] for a in A]


def f(x):  # A[l:r+1] の中央値が x 以上になる (l,r) の個数が、全体の半分以上あるか
    B = [0] + [1 if A[i] >= x else -1 for i in range(N)]
    B = list(accumulate(B))
    B = [b+N+1 for b in B]  # 全て正になるように補正
    # Bi <= Bj たる (i,j) の個数を数える
    bit = BIT([0]*(2*N+2))
    count = 0
    for i in range(N+1):
        b = B[i]
        count += bit.query(b)
        bit.update(b,1)
    if count >= (N*(N+1)+3)//4:
        return True
    return False


ok = 1
ng = 10**5+1
while ok+1 < ng:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid

print(dict_C[ok])


Measured memory_bytes: 158756
# coding: utf-8
# Your code here!

A,B = input().split()

A=int(A)

B=int(B)

if A == 1:
    A = 14

if B == 1:
    B = 14

if A>B:
    print("Alice")
elif A<B:
    print("Bob")
else:
    print("Draw")

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a > 9 || a < 0 || b>9 || b < 0) {
		cout << "-1";
	}
	else {
		cout << a * b;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...







int Main(){


int n ;
cin>>n;
ll arr[n];
for (int i=0 ; i < n;i++)
cin>>arr[i];

int flag =0 ;



for(int i =0 ; i < n;i++){
	
	if( arr[i]%2==0){
		
		if(arr[i]%5!=0 && arr[i]%3!=0)
		flag =1;
		
		
	}


}

if(flag == 0)
cout<<"APPROVED ";
else
cout<<"DENIED";



return 0;

}






int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;


}


Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int n;
int a[510][510];

int main() {
	scanf("%d", &n);
	int fl = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			char c;
			scanf(" %c", &c);
			if (c == '#')
				a[i][j] = 1, fl = 1;
			else
				a[i][j] = 0;
		}
	}
	if (!fl) { 
		cout << -1 << "\n";
		return 0;
	}
	int dd = 0;
	for (int j = 0; j < n; ++j) {
		int fl = 0;
		for (int i = 0; i < n; ++i)
			if (!a[i][j])
				fl = 1;
		if (fl)
			++dd;
	}
	int ans = 2 * n + 100;
	for (int i = 0; i < n; ++i) {
		int cnt = 0;
		for (int j = 0; j < n; ++j)
			if (!a[i][j])
				++cnt;
		int fl = 1;
		for (int j = 0; j < n; ++j)
			if (a[j][i])
				fl = 0;
		ans = min(ans, cnt + fl);
	}
	cout << ans + dd << "\n";
	return 0;
}




Measured memory_bytes: 1280
#include <iostream>
#include<string>

using namespace std;
int main()
{
	int A, B;
	int ans = 0;
	cin >> A >> B;
	string str;
	for (int i = A; i <= B; i++)
	{
		str = to_string(i);
		if (str[0]==str[4]&&str[1]==str[3])
		{
			ans++;
		}
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = null;
        try {
            sc = new Scanner(System.in);
			String ball = "A";
            while (sc.hasNext()) {
                String[] cup = sc.next().split(",");

                if(ball.equals(cup[0])){
                    ball = cup[1];
                }else if(ball.equals(cup[1])){
                    ball = cup[0];
                }
            }
            System.out.println(ball);

        } finally {
            sc.close();
        }
    }
}

Measured memory_bytes: 26256
#include <bits/stdc++.h>
using namespace std;
struct strongly_connected_components{
  vector<vector<int>> scc;
  vector<int> c;
  void dfs1(vector<vector<int>> &E, vector<bool> &used, vector<int> &t, int v){
    for (int w : E[v]){
      if (!used[w]){
        used[w] = true;
        dfs1(E, used, t, w);
      }
    }
    t.push_back(v);
  }
  void dfs2(vector<vector<int>> &E, vector<bool> &used, int v){
    scc.back().push_back(v);
    for (int w : E[v]){
      if (!used[w]){
        used[w] = true;
        dfs2(E, used, w);
      }
    }
  }
  strongly_connected_components(vector<vector<int>> G){
    int V = G.size();
    vector<vector<int>> E1(V), E2(V);
    for (int i = 0; i < V; i++){
      for (int j : G[i]){
        E1[i].push_back(j);
        E2[j].push_back(i);
      }
    }
    vector<bool> used(V, false);
    vector<int> t;
    for (int i = 0; i < V; i++){
      if (!used[i]){
        used[i] = true;
        dfs1(E1, used, t, i);
      }
    }
    reverse(t.begin(), t.end());
    vector<bool> used2(V, false);
    for (int i = 0; i < V; i++){
      if (!used2[t[i]]){
        used2[t[i]] = true;
        scc.push_back(vector<int>());
        dfs2(E2, used2, t[i]);
      }
    }
    c = vector<int>(V);
    int sz = scc.size();
    for (int i = 0; i < sz; i++){
      for (int j : scc[i]){
        c[j] = i;
      }
    }
  }
  int size(){
    return scc.size();
  }
  int operator [](int k){
    return c[k];
  }
};
int main(){
  cout << fixed << setprecision(9);
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<double> p(N);
    vector<vector<int>> E(N);
    for (int i = 0; i < N; i++){
      cin >> p[i];
      int m;
      cin >> m;
      for (int j = 0; j < m; j++){
        int a;
        cin >> a;
        a--;
        E[i].push_back(a);
      }
    }
    strongly_connected_components S(E);
    int sz = S.size();
    vector<bool> ok(sz, false);
    vector<double> q(sz, 1);
    for (int i = 0; i < N; i++){
      for (int j : E[i]){
        if (S[i] != S[j]){
          ok[S[j]] = true;
        }
      }
      q[S[i]] *= p[i];
    }
    double ans = 1;
    for (int i = 0; i < sz; i++){
      if (!ok[i]){
        ans *= 1 - q[i];
      }
    }
    cout << ans << endl;
  }
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

struct edge {
    int to;
    ll cost;
};

// <最短距離, 頂点の番号>
using P = pair<ll, int>;
const int MAX_V = 100100;

vector<edge> G[MAX_V];
vector<ll> d(MAX_V, LINF);

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    d[s] = 0;
    que.push(P(0, s));

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

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

void solve() {
    int n, m;
    cin >> n >> m;
    int l, r;
    ll c;
    REP(i, m) {
        cin >> l >> r >> c;
        l--; r--;
        edge e = {r, c};
        G[l].push_back(e);
    }
    REP(i, n - 1) {
        edge e = {i, 0};
        G[i + 1].push_back(e);
    }
    dijkstra(0);
    cout << (d[n - 1] == LINF ? -1 : d[n - 1]) << EOL;
}


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

int main() {
  int A,B,c=0;
  cin >> A >> B;
  for(A;A<B+1;A++){
    if(A/10000==(A-A/10*10)){
      if((A-A/10000*10000)/1000==(A-A/100*100)/10){
        c++;
      }
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t N,A,B; cin>>N>>A>>B;

    int64_t ans;
    if(N>=2){
        if(B>=A) ans=(N-2)*(B-A)+1;
        else ans=0;
    }else{
        if(A==B) ans=1;
        else ans=0;
    }

    cout<<ans<<endl;
}

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

#define LENGTH 2000000000

int main(void)
{
    int L, R, i, j, ij_2019;
    scanf("%d %d", &L, &R);
    if (0 > L || 0 > R || L >= R || L > LENGTH || R > LENGTH)
    {
        exit(0);
    }
    else
    {
        if ((R - L) >= 2019)
        {
            printf("0");
        }
        else
        {
            i = L;
            j = R;
            L %= 2019;
            R %= 2019;
            if (L >= R)
            {
                R += 2019;
            }
            int ij_2019_min = 50000;
            for (int i = L; i <= (j - 1); i++)
            {
                for (int j = i + 1; j <= R; j++)
                {
                    ij_2019 = (i * j) % 2019;
                    if (ij_2019 < ij_2019_min)
                    {
                        ij_2019_min = ij_2019;
                    }
                    if(ij_2019_min == 0){
                        printf("0");
                        return 0;
                    }
                }
            }
            printf("%d", ij_2019_min);
        }
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    string s , t;
    cin>>s>>t;
    int counter = 0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])
            counter++;
    }
    cout<<counter;
}


Measured memory_bytes: 3764
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        System.out.println(n % 1000 % 111 == 0 || n / 10 % 111 == 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 23252
N = map(int, raw_input().split())
a = map(int, raw_input().split())
xsum = 0
for i in range(len(a)-1):
    xsum += a[i]
dif = xsum - a[-1]
m = abs(dif)
for i in range(1,len(a)-1)[::-1]:
    dif -= 2*a[i]
    if m > abs(dif):
        m = abs(dif)
print(abs(m))

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	vector<int> v, P, Q;
	cin >> N;
	rep(i, 1, N + 1)v.push_back(i);
	int A;
	rep(i, 0, N)
	{
		cin >> A;
		P.push_back(A);
	}
	rep(i, 0, N)
	{
		cin >> A;
		Q.push_back(A);
	}

	int l, r;
	int cnt = 0;
	do {
		bool ok[2] = { false };
		rep(i, 0, SZ(v))
		{
			if (v[i] != P[i])ok[0] = true;
			if (v[i] != Q[i])ok[1] = true;
		}
		if (!ok[0])l = cnt;
		if (!ok[1])r = cnt;
		cnt++;
	} while (next_permutation(all(v)));

	cout << abs(l - r) << endl;

	return 0;
}

Measured memory_bytes: 256
S=input()
x=len(S)
c=0
for i in range(0,x,2):
  if S[i]=="L":
    c=c+1
for j in range(1,x,2):
  if S[j]=="R":
    c=c+1
if c==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
//     . .. ... ..... be naame khodaa ..... .... ... .. .     \\

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

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define pb push_back

inline int in(){int x, y; y = scanf("%d", &x); return x;}

const int N = 200002;

map <ll, int> mp;

int main()
{
	ll sum = 0, ans = 0;
	int n = in();
	mp[0]++;
	for(int i = 0; i < n; i++)
	{
		sum += in();
		ans += mp[sum];
		mp[sum]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 12800
import copy
from itertools import product as prod

n, m = [int(x) for x in input().split()]

wait = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(n):
    wait[i][i] = 0
for _ in range(m):
    a, b, c = map(int, input().split())
    wait[a-1][b-1] = c
    wait[b-1][a-1] = c

dist = copy.deepcopy(wait)
for k, i, j in prod(range(n), range(n), range(n)):
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    dist[j][i] = min(dist[j][i], dist[j][k] + dist[k][i])

ans = 0
for i, j in prod(range(n), range(n)):
    if not wait[i][j] == float("inf") and dist[i][j] < wait[i][j]:
        ans += 1

print(ans // 2)


Measured memory_bytes: 4212
n, a, b, c, d = gets.chomp.split.map(&:to_i)
s = gets.chomp
if s[b..d-2].include?("##") || s[a..c-2].include?("##")
  puts "No"
else
  if c < d
    puts "Yes"
  else
    if s[b-2..d].include?("...")
      puts "Yes"
      exit
  	end
    puts "No"
  end
end

Measured memory_bytes: 2428
#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)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  ll dp[h + 1][w + 2];
  memset(dp, 0, sizeof(dp));
  dp[0][1] = 1;

  vector<int> fib(8, 1);
  FOR(i, 2, 8) fib[i] = fib[i - 1] + fib[i - 2];

  FOR(i, 1, h + 1) {
    FOR(j, 1, w + 1) {
      dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * fib[max(j - 2, 0)] * fib[w - j]) % mod;
      dp[i][j] = (dp[i][j] + dp[i - 1][j] * fib[j - 1] * fib[w - j]) % mod;
      dp[i][j] = (dp[i][j] + dp[i - 1][j + 1] * fib[j - 1] * fib[max(w - j - 1, 0)]) % mod;
    }
  }

  cout << dp[h][k] << endl;


  
  return 0;
}

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

int main() {

    int N;
    cin>>N;
    int temp = N/1000;
    int n = temp + 1;

    int ans = n * 1000 - N;
    if(ans == 1000) ans = 0;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3632