akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	    int n;cin>>n;
	    int a[n],b[n];
	    f(i,n)
	    {
	        cin>>a[i]>>b[i];
	    }
	    sort(a,a+n);
	    sort(b,b+n);
	    if(n%2==1)
	    {
	        int z=b[(n)/2]-a[(n)/2];
	        cout<<z+1<<bn;
	    }
	    else
	    {
	        int z=b[(n+1)/2]+b[(n-1)/2];int z2=a[(n+1)/2]+a[(n-1)/2];
	        cout<<z-z2+1<<bn;
	        
	    }
	   
	   
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 5220
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    REP(i, N) cin >> T[i];
    
    sort(All(T));
    int ans = 0, tmp = 0, wait = 0;
    REP(i, N){
        if(tmp != 0){
            if(tmp == C || T[i] - wait > K){
                tmp = 0;
            }else{
                tmp++;
            }
        }
        if(tmp == 0){
            ans++;
            tmp++;
            wait = T[i];
        }
    }
    cout << ans << "\n";
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  intll n , m ;
  cin >> n >> m ;
  intll all = 0;
  
  rep(i,m){
    int c ;
    cin >> c ;
    all += c ;
  }
  
  if(n-all >=0) cout << n - all;
  else          cout << -1 ;
  


}


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

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  a = a - 1;
  b = b - 1;
  //cout << a << ' ' << b << '\n';
  ans = a * (a + 1) / 2;
  //cout << ans << '\n';
  ans = ans + b * (b + 1) / 2;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    a = {int(input().rstrip('\n')): 0 for _ in range(m)}
    dp = [0] * (n + 1)
    dp[0] = 1 if 0 not in a else 0
    dp[1] = 1 if 1 not in a else 0
    for i in range(2, n + 1):
        if i not in a:
            dp[i] = (dp[i-1] + dp[i-2]) % mod
        else:
            dp[i] = 0
    print(dp[-1])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 50008
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
  ll x , y ; cin>>x>> y;
  if(x%y==0) cout<<-1<<endl ;
  else cout<<x<<endl ;
 return 0 ; 
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
 
// head

int n, m;

int c[100010];
int d[100010];
int kumi[100010];
int amari[100010];
ll ans;

void use_kumi( int i , int tarinai ){
  kumi[i] -= ( tarinai + 1 ) / 2;
}

int main(){

  n = in();
  m = in();

  REP( i , n ){
    int x = in();
    c[x]++;
    d[x%m]++;
  }

  REP( i , 100010 ){
    kumi[i%m] += c[i] / 2;
    amari[i%m] += c[i] % 2;
  }

  /*
  REP( i , 10 ){
    cout << kumi[i] << endl;
  }
  */

  FOR( i , 1 , ( m + 1 ) / 2 ){
    ll a = min( d[i] , d[m-i] );
    ans += a;
    // cout << i << " " << a << endl;
    if( amari[i] < a ){
      use_kumi( i , a - amari[i] );
    }
    if( amari[m-i] < a ){
      use_kumi( m-i , a - amari[m-i] );
    }
  }

  ans += d[0] / 2;
  kumi[0] = 0;

  if( m % 2 == 0 ){
    ans += d[m/2] / 2;
    kumi[m/2] = 0;
  }
  
  /*
  cout << endl;
  
  REP( i , m ){
    cout << kumi[i] << endl;
  }
  */

  REP( i , m ){
    ans += kumi[i];
  }

  printf( "%lld\n" , ans );
  
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const int inf = 1<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int main () {
  int N; cin >> N;
  vi p(N); rep(i,N) cin >> p.at(i);

  int cnt = 0;
  rep(i,N) {
    if (p.at(i)!=i+1) cnt++;
  }

  cout << (cnt<=2?"YES":"NO") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N, L;
    cin >> N >> L;

    int sum = 0;
    for(int i = 1; i <= N; i++){
        sum += L + i - 1;
    }    

    if(L <= 0 && L + N - 1 >= 0){
        cout << sum << endl;
    }
    else if(L > 0){
        cout << sum - L << endl;
    }
    else{
        cout << sum - (L + N - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int A[3][3], ans[3][3], N, flag=0;
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> A[i][j];
      ans[i][j] = 0;
    }
  }
  cin >> N;
  int b[N];
  for(int i=0; i<N; i++) cin >> b[i];
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      for(int k=0; k<N; k++){
        if(A[i][j] == b[k]){
          ans[i][j] = 1;
        }
      }
    }
  }
  for(int i=0; i<3; i++){
    if(ans[i][0] == 1 && ans[i][1] == 1 && ans[i][2] == 1) flag = 1;
  }
  for(int j=0; j<3; j++){
    if(ans[0][j] == 1 && ans[1][j] == 1 && ans[2][j] == 1) flag = 1;
  }
  if(ans[0][0] == 1 && ans[1][1] == 1 && ans[2][2] == 1) flag = 1;
  if(ans[2][0] == 1 && ans[1][1] == 1 && ans[0][2] == 1) flag = 1;
  if(flag == 1) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 1e6+5;

pls give {
    AC;
    int n, a;
    cin >> n;
    set<int> s;
    for (int i=0; i<n; i++) {
        cin >> a;
        s.insert(a);
    }
    cout << (s.size() == n ? "YES" : "NO");
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main() {
	int n, k;

	std::string s;

	std::cin >> n >> k >> s;

	k--; // インデックス調整

	s[k] = tolower(s[k]);

	std::cout << s << std::endl;
}

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

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

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define f first
#define s second

const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 1e9;
const int maxn = 1e3+5;
const int mod = 1e9 + 7;

int n, k;
int c[maxn];
int dp[maxn][100005];

int main() {
    fastIO();
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> c[i];
   	dp[n][0] = 1;
    for (int idx = n - 1; idx >= 0; --idx) {
    	int cur = 0;
    	for (int sum = 0; sum <= k; ++sum) {
    		cur = (cur + dp[idx + 1][sum]) % mod;
    		if (sum >= c[idx]) 
    			cur = (cur - dp[idx + 1][sum - c[idx] - 1] + mod) % mod;
    		dp[idx][sum] = cur;
    		/*
			for (int i = 0; i <= c[idx]; ++i) {
				if (sum + i > k) break;
				ans = (ans + solve(idx + 1, sum + i)) % mod;
			}
			*/
    	}
    }
    cout << dp[0][k] << '\n';
    //cout << solve(0, 0) << '\n';
    return 0;
}



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

#define int long long
const int INF = 1e9;

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

  int N;
  cin >> N;

  vector<vector<int> > C(N, vector<int>(N, 0));
  int sum = 0;
  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
      int c;
      cin >> c;
      sum += c;
      C[min(i, j)][max(i, j)] = max(C[min(i, j)][max(i, j)], c);      
    }
  }

  for ( int i = 0; i < N; i++ ) {
    for ( int j = i+1; j < N; j++ ) {
      sum -= C[i][j];
    }
  }

  cout << sum << endl;
  
  return 0;
}



Measured memory_bytes: 3288
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    int d = scan.nextInt();
    String s = "Yes";
    while(a-d>0 || c-b>0){
        c=c-b;
        
        if(a-d <= 0){
            s = "No";
            break;
        }
        a = a-d;
    }
      System.out.println(s);
  }
}

Measured memory_bytes: 35792
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
string S;
int main(){
	cin>>S;
	int K[27]={};
	for(int i=0;i<S.size();i++){
		K[S[i]-97]++;
	}
	int M=0;
	for(int i=0;i<26;i++){
		if(K[i]%2!=0){
			M=1;
			break;
		}
	}
	if(M==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){

int a[1000];
int n;
cin>>n;
int i;
   for(i=0;i<=n-1;i++)
            {cin>>a[i];}

int j;
for(j=n-1;j>-1;j=j-1){
    {cout<<a[j];
                if(j>0) {cout<<" ";}
                if(j==0){cout<<endl;}
}
}
}


Measured memory_bytes: 2996
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    def dfs(s):
        if int(s)>n: return 0
        res=int(all(s.count(c)>=1 for c in "753"))
        for c in "753":
            res+=dfs(s+c)
        return res
    print(dfs('0'))
resolve()

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

int main() {
  int A,B;
  cin >> A >> B;
  int counter = 0;

  for(int i = A ; i <= B ; ++i){
    int num_1 = i % 10;
    int num_2 = (i / 10) % 10;
    int num_4 = (i / 1000) % 10;
    int num_5 = i / 10000;
    if(num_1 == num_5 && num_2 == num_4) ++counter;
  }

  cout << counter <<endl;
}


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

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

string S;
int idx;
int N, M;
string alphas;
int curr;

void consume(char c) {
  if(idx >= N) throw exception();
  if(S[idx] != c) throw exception();
  idx ++;
}

bool try_consume(char c) {
  if(idx >= N) return false;
  if(S[idx] != c) return false;
  idx ++;
  return true;
}

int E();

int convert(string const& b) {
  int n = b.size();
  int ret = 0;
  for(int i=0; i<n; i++) {
    ret *= 2;
    assert(isdigit(b[i]));
    ret += b[i] - '0';
  }
  return ret;
}

string B() {
  string ret;
  while(1) {
    if(S[idx] == '0') ret += '0';
    else if(S[idx] == '1') ret += '1';
    else break;
    idx++;
  }
  return ret;
}

int Nu() {
  if(try_consume('0')) return 0;
  consume('1');
  return convert("1" + B());
}

int F() {
  if(try_consume('-')) {
    return -F();
  }
  else if(try_consume('(')) {
    int r = E();
    consume(')');
    return r;
  }
  else {
    return Nu();
  }
}

int T() {
  int num1 = F();
  while(try_consume('*')) {
    int num2 = F();
    num1 *= num2;
  }
  return num1;
}

int E() {
  int term1 = T();
  while(1) {
    bool cont = 0;
    while(try_consume('+')) {
      cont = 1;
      int term2 = T();
      term1 += term2;
    }
    while(try_consume('-')) {
      cont = 1;
      int term2 = T();
      term1 -= term2;
    }
    if(!cont) break;
  }
  return term1;
}

bool Q() {
  int expr1 = E();
  consume('=');
  int expr2 = E();
  return expr1 == expr2 && idx == N;
}

int main() {

  string T = "01+-*()=";
  sort(T.begin(), T.end());
  string RS; cin >> RS;
  N = RS.size();
  for(auto c: RS) if(isalpha(c)) alphas.push_back(c);
  sort(alphas.begin(), alphas.end());
  alphas.erase(unique(alphas.begin(), alphas.end()), alphas.end());
  M = alphas.size();

  if(M > T.size()) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 0;
  set<string> st;
  do {
    S = RS;
    rep(i, N) {
      if(isalpha(S[i])) S[i] = T[alphas.find(S[i])];
    }
    if(!st.count(S)) {
      st.insert(S);
      idx = curr = 0;
      try { ans += Q(); } catch (...) {}
    }
  } while(next_permutation(T.begin(), T.end()));
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7696
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(a,b,c) for(int i=a;i<b;i+=c)  
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}
ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
//send mod-2 for a^-1 if mod is a prime number
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        dsu_arr[i]=i;
        dsu_sz[i]=1;
    }
}
ll find(ll x)
{
     ll root=x;
    while (root!=dsu_arr[root])
    {
        root=dsu_arr[root];
    }
    while(x!=dsu_arr[x])
    {
        dsu_arr[x]=root;
        x=dsu_arr[x];
    }
    return root;
}
ll merge(ll x,ll y)
{
    ll root1=find(x);
    ll root2=find(y);
    
    if(root1==root2)
    return 0ll;
 
    if(dsu_sz[x]>dsu_sz[y]){
    dsu_arr[root2]=root1;
    dsu_sz[x]+=dsu_sz[y];
    }
    else
    {
         dsu_sz[y]+=dsu_sz[x];
        dsu_arr[root1]=root2;
    }
    return 1ll;
}


int main()
{

ll n;
cin>>n;
vector<ll>a;
for(ll i=0;i<n;i++)
{
   ll k;
   cin>>k;
  a.push_back(k);
}
ll ans=0;
for(ll i=1;i<n;i++)
{
   if(a[i]<a[i-1])
   {
       ans+=(a[i-1]-a[i]);
       a[i]=a[i-1];
   }
}
cout<<ans<<endl;
}



   
      
    
        



Measured memory_bytes: 5368
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    let mut list = input.chars().map(|x| x == 'B').collect::<Vec<_>>();
    list.reverse();
    let mut count = 0;
    let mut b = 0;
    for i in 0..list.len() {
        if list[i] {
            count += (i as i64) - b;
            b += 1;
        }
    }
    (count).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "BBW\n" => "2\n",
    test2: "BWBWBW\n" => "6\n",
}


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

int N, K, h[100005], DP[100005];

int main()
{
    scanf("%d %d", &N, &K);
    for(int i = 0; i < N; i++) {
        scanf("%d", &h[i]);
    }

    DP[0] = 0;
    DP[1] = abs(h[0]-h[1]);


    if(N > 2) {
        for(int i = 2; i < N; i++) {
            int sol = 1<<30;
            for(int j = max(0,i-K); j < i; j++) {
                sol = min(sol, DP[j] + abs(h[j] - h[i]));
            }
            DP[i] = sol;
        }
        printf("%d\n", DP[N-1]);
    } else {
        printf("%d\n", DP[1]);
    }

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main{ // 

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static long now() {
		return System.currentTimeMillis();
	}

	static void trace(Object... objects) {
		assert null != System.out.format("trace:%s\n", Arrays.deepToString(objects));
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int q = cin.nextInt();
		int h = cin.nextInt();
		int s = cin.nextInt();
		int d = cin.nextInt();
		int n = cin.nextInt();

		long start = now();

		long ans = solve(q, h, s, d, n);
		cout.println(ans);

		trace("elapsed", now() - start);
	}

	private static long solve(long q, long h, long s, long d, long n) {
		long m = 4 * n;
		long[][] bottles = { { 1, q, 8 * q }, { 2, h, 4 * h }, { 4, s, 2 * s }, { 8, d, d } };
		Arrays.sort(bottles, Comparator.comparingLong(b -> b[2]));
		long ans = 0;
		for (int i = 0; i < bottles.length; i++) {
			ans += m / bottles[i][0] * bottles[i][1];
			m %= bottles[i][0];
		}
		return ans;
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 28372
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

void solve() {
	int N, L; cin >> N >> L;
	vector<string>v(N);
	REP(i, N)cin >> v[i];
	VSORT(v);
	REP(i, N)cout << v[i];
	cout << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 1e6 + 5;
const int logn = log2(maxn) + 1;
const int mod = 1e9 + 7;
int f[maxn];
int g[maxn];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".INP", "r")) {
        freopen(taskname".INP", "r", stdin);
        freopen(taskname".OUT", "w", stdout);
    }
    int n;cin >> n;
    int sum = n;
    f[n] = n;
    for(int i = n - 1 ; i >= 1 ; --i){
        f[i] = (sum - f[i + 2] + i + (i != n - 1) + (ll)(n - 1) * (n - 1)) % mod;
        if(f[i] < 0)f[i] += mod;
        sum += f[i];
        if(sum >= mod)sum -= mod;
    }
    cout << f[1];
}

Measured memory_bytes: 6016
s = input()
n = len(s)
ans = n * (n - 1) / 2 + 1
c_list = [0 for _ in range(26)]
for c in s:
	c_list[ord(c) - ord('a')] += 1

delta = 0
for i in c_list:
	if i > 0:
		delta += i * (i - 1) / 2
print(int(ans - delta))


Measured memory_bytes: 3500
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 200010
using namespace std;
int a[N],c[N];
int main()
{
	int n,k,p=0;scanf("%d%d",&n,&k);
	for(int i=1,x;i<=n;i++)
		scanf("%d",&x),c[x]++;
	for(int i=1;i<=n;i++)
		if(c[i]) a[++p]=c[i];
	sort(a+1,a+p+1);int ans=0;
	for(int i=1;i<=p-k;i++) ans+=a[i];
	printf("%d\n",ans);return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int n, m, inf = 1000000000, memo[1005][4100], a[1005], c[1005];

int dp(int pos, int mask) {
	if ((mask + 1) == (1 << n))
		return 0;
	if (pos == m)
		return inf;
	if (memo[pos][mask] == -1)
		memo[pos][mask] = min(dp(pos + 1, mask), dp(pos + 1, mask | c[pos]) + a[pos]);
	return memo[pos][mask];
}

int main() {
	int b, t;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &a[i], &b);
		c[i] = 0;
		for (int j = 0; j < b; j++) {
			scanf("%d", &t);
			c[i] += (1 << (t - 1));
		}
	}
	memset(memo, -1, sizeof memo);
	printf("%d\n", ((dp(0, 0) >= inf) ? -1 : dp(0, 0)));
	return 0;
}

Measured memory_bytes: 16256
//#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
//#include<algorithm>
//#include<cmath>
//#include<string>
//#include<cctype>
//#include <vector>
using namespace std;
int main() {
	int y, m, d;
	while (cin >> y >> m >> d) {
		int s = y * 416 + m * 32 + d;
		if (s < 777384) cout << "pre-meiji" << endl;
		else if (s < 795646) cout << "meiji " << y - 1867 << " " << m << " " << d << endl;
		else if (s < 801625) cout << "taisho " << y - 1911 << " " << m << " " << d << endl;
		else if (s < 827464) cout << "showa " << y - 1925 << " " << m << " " << d << endl;
		else cout << "heisei " << y - 1988 << " " << m << " " << d << endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int h,w,a[1410][1410];
int s[1410][1410];

int main(){
	cin >> h >> w;
	REP(i,0,h) REP(j,0,w) cin >> a[i][j],s[i+1][j+1]=a[i][j];
	REP(i,1,h+1) REP(j,1,w+1) s[i][j]+=s[i-1][j];
	REP(j,1,w+1) REP(i,1,h+1) s[i][j]+=s[i][j-1];
	
	int c=0;
	REP(i,0,h){
		REP(j,0,w){
			if(a[i][j]) continue;
			if(i+c<=h and j+c<=w){
				if(!(s[i+c][j+c]-s[i+c][j]-s[i][j+c]+s[i][j])){
					for(int k=c+1;i+k<=h and j+k<=w;k++){
						if(s[i+c+1][j+c+1]-s[i+c+1][j]-s[i][j+c+1]+s[i][j]) continue;
						c++;
					}
				}
			}
		}
	}
	
	cout << c*c << endl;
	return 0;
}



Measured memory_bytes: 18536
#include <stdio.h>
int main (void)
{
	double men,syu,r;
	scanf("%lf",&r);
	if(r>0||r<10000)
	{
		men=r*r*3.141592653589;
		syu=r*2*3.141592653589;
		printf("%lf %lf\n",men,syu);
	}
	return 0;
}

Measured memory_bytes: 648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if(H == 0 && W ==0)	break;
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					if(i % 2 == 0) {
						if(j % 2 == 0)	System.out.printf("#");
						else	System.out.printf(".");
					}
					else {
						if(j % 2 == 0)	System.out.printf(".");
						else	System.out.printf("#");
					}
				}
				System.out.printf("\n");
			}
			System.out.printf("\n");
		}
	}
}



Measured memory_bytes: 62896
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  char s[5];
  scanf("%s", s);
  int n[4];
  char ans[3];
  for (int i=0; i<4; i++)
    n[i] = s[i] - '0';
  for (int i=0; i<(1<<3); i++) {
    int res = n[0];
    for (int j=0; j<3; j++) {
      if (i & (1<<j)) {
        res -= n[j+1];
        ans[j] = '-';
      } else {
        res += n[j+1];
        ans[j] = '+';
      }
    }
    if (res == 7)
      break;
  }
  printf("%d%c%d%c%d%c%d=7\n", n[0], ans[0], n[1], ans[1], n[2], ans[2], n[3]);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int uruudays[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int countday(int y, int m, int d) {
	int i, count;
	count = y * 365 + (y - 1) / 4 - (y - 1) / 100 + (y - 1) / 400;
	if(y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)) {
		for(i = 0; i < m - 1; ++ i) count += uruudays[i];
	} else {
		for(i = 0; i < m - 1; ++ i) count += days[i];
	}
	count += d;
	return count;
}
int main() {
	int y1, y2, m1, m2, d1, d2;
	while(1) {
		scanf("%d %d %d %d %d %d", &y1, &m1, &d1, &y2, &m2, &d2);
		if(y1 == -1) break;
		printf("%d\n", countday(y2, m2, d2) - countday(y1, m1, d1));
	}
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
import java.util.ArrayList;
 
public class Main {
  final static int max = 100;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
      ArrayList<String> list = new ArrayList<String>();
      int K;
      String S;
       while (scan.hasNextLine()) {
      String an = scan.nextLine();
      list.add(an);
      }
      K = Integer.parseInt(list.get(0));
      S = list.get(1);
//      System.out.println(K+S);
      check(K,S);
        scan.close();
    }
  
  public static void check(int k, String s){
    String cutS;
   if(k > max){
      System.err.println("文字が長すぎます。");
   } else if(k >= s.length()){
     System.out.println(s);
     return;
   } else{
     cutS = s.substring(0,k);
     System.out.println(cutS+"...");
     return;
   }
    
  }
}

Measured memory_bytes: 38564
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {

      
 public static void main(String[] args) {
    
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int N = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
    int[] arr = new int[N];
    int[] dp = new int[N];
    for (int m = 1; m <= N; ++m) {
       int n = in.nextInt();
       arr[m-1] = n;
    }
     
    dp[0] = arr[0];
    for(int i = 1; i < N; i++) {
      if(i == 1) {
        dp[i] = Math.abs(arr[i]-dp[i-1]);
      }
      else if(i == 2)
      {
        dp[i] = Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]), Math.abs(arr[i]-dp[i-2]));
      }
      else
      {
        dp[i] = Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]), dp[i-2]+Math.abs(arr[i]-arr[i-2]));
      }
    }

    System.out.println(dp[N-1]);
  }
  
}

Measured memory_bytes: 59820
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


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

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


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

long long int N,M,K,A,C,B,res=0,L[2005]={},Lsum[4005]={};


int main()
{
    cout << fixed << setprecision(18);
    cin>>A>>B>>C;
    for(long long int i = 1; i < 1200; i++){
        if((A*i)%B==C){cout<<"YES"<<endl;return 0;}
    }
    cout<<"NO"<<endl;
}    


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
  int n;cin>>n;
  int a[3*n];
  for(int i=0;i<3*n;i++) cin>>a[i];
  sort(a,a+3*n,greater<int>());
  ll ans=0;
  for(int i=0;i<n;i++){
    ans+=a[2*i+1];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1408
def dist(A, B):
	res = 0
	for i in range(D):
		res += (A[i] - B[i]) ** 2
	res = res ** 0.5
	return res


N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		if dist(X[i], X[j]).is_integer():
			ans += 1
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h> 
    #include<ext/pb_ds/assoc_container.hpp> 
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long  
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define all(s) s.begin(),s.end()
    #define ashow(a)  for(auto i:a)cout<<i<<" ";
    #define take(a,n) f(i,0,n)cin>>a[i];
    #define print(a,n) f(i,0,n){cout<<a[i]<<" ";}
    #define len(a) a.length()
    #define ps(x,y)         fixed<<setprecision(y)<<x
    #define INF 4e18
    const double pi=3.14159265358979323;
    const int mod=998244353;
    const int MAX=1e7+5;
    int gcd(int a, int b) 
    { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
    } 
    void swap(int a,int b)
    {
      int temp=a;
      a=b;
      b=temp;
    } 
    int  binpow(int  a,int  b) 
    {
    int res = 1;
    while (b > 0) {
        if (b%2 == 1)
            res = (res * a)%mod;
        a = (a* a)% mod;
        b >>= 1;
    }
    return res;
}
    int modinv(int y)
    {
        return binpow(y,mod-2);
    }
 
    int fact[500000+5];
    void precal()
    {
    fact[0]=1;
    for(int i=1;i<500000+5;i++)
    {
        fact[i]=(i*fact[i-1])%mod;
    }
}   
    bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
   
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
    vector<vector<int >> adj;
    int vis[200000+5]={0};
    void dfs(int j)
    {
        vis[j]=1;
        for(auto i:adj[j])
        {
            if(vis[i]==0)
                dfs(i);
        }
    }
    void bfs(int j)
    {
        vis[j]=1;
        queue<int > q;
        q.push(j);
        while(!q.empty())
        {
            int x=q.front();
            q.pop();
            for(auto i:adj[x])
            {
                if(vis[i]==0)
                {
                vis[i]=1;
                q.push(i);
                }
             }    
        }
    }
    signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    #ifndef ONLINE_JUDGE
     if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout); 
      }
    #endif  
    // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1; 
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int x=n%1000;
        if(x==0)
        cout<<0<<endl;
        else
        cout<<1000-x<<endl;      
    }
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int x=0;
    int n=a.length();
    int z=0;
    for (int i = 0; i < n; ++i) {
        if(a[i]=='o')
            x++;
        else
            z++;
    }
    if(x>=z||(15-x-z)+x>=8)
        cout<<"YES";
    else
        cout<<"NO";
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int INF=0x3f3f3f3f;
long long MAX=(long long)INF*(long long)INF;

vector<pair<int,int> >v;

long long dp[105][100005];

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

    for(int i=0;i<n;i++){
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }

    for(int i=0;i<100001;i++)dp[0][i]=-MAX;

    long long sol=0;
    dp[0][0]=0;
    dp[0][v[0].first]=v[0].second;
    for(int i=1;i<n;i++){
        //printf("i == %d, first: %d, second: %d\n", i, v[i].first, v[i].second);
        for(int j=0;j<=t;j++){
            if(j-v[i].first<0) dp[i][j]=dp[i-1][j];
            else {
                //printf("tuuuuuuuuuu\n");
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-v[i].first]+(long long)v[i].second);
                //if (dp[i-1][j-v[i].first]>0) printf("i == %d, j == %d\n", i, j);
            }
            sol=max(sol,dp[i][j]);
        }
//        printf("i == %d: ", i);
//        for (int j=0; j<=t; ++j) printf("%lld ", dp[i][j]<0 ? -1 : dp[i][j]);
//        printf("\n");
    }
    for (int i=0; i<=t; ++i) sol=max(sol, dp[0][i]);
    cout<<sol;





    return 0;
}


Measured memory_bytes: 80128
#include<stdio.h>

int main()
{
    int p[51];
    int i,j,n;

    while(scanf("%d",&n),n){

        for(i=0;i<51;i++) p[i]=0;

        for(i=0;i<n;i++){
            scanf("%d",&p[i]);
        }   

        for(i=0;i<n;i++){
            if(p[i]+1==p[i+1]){
                for(j=i;p[j]+1==p[j+1];j++);
                printf("%d-%d",p[i],p[j]);
                i=j;
            } else {
                printf("%d",p[i]);
            }   
            if(i!=n-1) printf(" ");
        }   
        puts("");
    }   
    return 0;
}

Measured memory_bytes: 616
n = int(input())
h = list(map(int, input().split()))

flag = False
ans = 0
while not flag:
  for i in range(n):
    if flag:
      if h[i] != 0: h[i] -= 1
      else: break
    elif not flag and h[i] != 0: 
      flag = True
      h[i] -= 1
      ans += 1
  if not flag: break
  flag = False
print(ans)  

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

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

class Solver {
  public:
    bool solve() {
        int H, W; cin >> H >> W;
        vector<string> G(H); cin >> G;

        queue<tuple<int, int, int>> que;
        rep(y, H) rep(x, W) if(G[y][x] == '#') que.emplace(y, x, 0);
        vector<vector<int>> g(H, vector<int>(W, -1));
        int cnt = 0;
        int max_cnt = -1;
        while(que.size()) {
            int y, x, c;
            tie(y, x, c) = que.front(); que.pop();
            if(g[y][x] >= 0) continue;
            g[y][x] = c;
            cnt++;
            max_cnt = max(max_cnt, c);
            rep(i, 4) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if(0 <= ny and ny < H and 0 <= nx and nx < W and g[ny][nx] < 0) {
                    que.emplace(ny, nx, c + 1);
                }
            }
        }

        assert(cnt == H * W);
        cout << max_cnt << endl;
        return 0;
    }
};

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


Measured memory_bytes: 29492
from collections import defaultdict
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def S(): return input()
# ----------------------------------------------------------- #

n = I()
s = S()
sa = s[:n]
sb = s[n:][::-1]

A = defaultdict(int)
B = defaultdict(int)

for bit in range(1<<n):
    red_A = []
    red_B = []
    blue_A = []
    blue_B = []
    for i in range(n):
        if bit & 1<<i:
            red_A.append(sa[i])
            blue_B.append(sb[i])
        else:
            blue_A.append(sa[i])
            red_B.append(sb[i])
    a_key = (''.join(red_A), ''.join(blue_A))
    b_key = (''.join(blue_B), ''.join(red_B))
    A[a_key] += 1
    B[b_key] += 1

ans = 0
for key in A.keys():
    if key in B:
        ans += A[key]*B[key]

print(ans)


Measured memory_bytes: 176636
#include<stdio.h>
#include<iostream>
using namespace std;
typedef long long int ll;
ll a[5],n;
int main()
{
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	cin>>n;
	for(int i=1;i<=4;i++)
		a[i]=min(a[i],2*a[i-1]);
	printf("%lld\n",n/2*a[3]+(n&1)*a[2]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int a[N];
    rep(i, N) {
        cin >> a[i];
    }

    int ans = 0;
    rep(i, N) {
        if(a[i] == a[i+1]) {
            ans++;
            a[i+1] = 200 + i;
        }
    }

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

Measured memory_bytes: 256