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

int main() {
  long int N, count;
  count = 0;
  cin >> N;
  vector<long int> Capa(5);
  for (int i = 0; i < 5; i++) {
    cin >> Capa.at(i);
  }
  sort(Capa.begin(), Capa.end());
  if (N % Capa.at(0) != 0) {
    cout << N / Capa.at(0) + 5 << endl;
  }
  else {
    cout << N / Capa.at(0) + 4 << endl;
  }
}

Measured memory_bytes: 256
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MAX_N = 100010;

int N;
vector<int> h;

int dp[MAX_N];

void _main()
{
    cin >> N;
    h.resize(N);
    rep(i, 0, N) cin >> h[i];
    rep(i, 0, N + 1) dp[i] = inf;
    dp[0] = 0;
    rep(i, 0, N)
    {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include<cmath>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

char s[105];

int main(){
	scanf("%s",s+1);
	int len=strlen(s+1),j=0;
	for(int i=1;i<=len;++i){
		if(s[i]=='C'){
			j=i;break;
		}
	}
	if(j==0){printf("No");return 0;}
	bool flag=false;
	for(int i=j;i<=len;++i)if(s[i]=='F'){flag=true;break;}
	if(flag==true)printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

using namespace std;

int main () {
    int n;
    cin >> n;
    vector <int> a(n);

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

    for (int i = 0; i < n; i++) {
        if (i == n-1) printf("%d\n", a[i]);
        else printf("%d ", a[i]);
    }

    return 0;
}


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

int main(){
	int n, x, y, tot = 0;
	cin >> n;

	for( int i = 0; i < n; ++i ){
		cin >> x >> y;
		tot += y-x+1;
	}
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 256
open Batteries
open Printf
let () =
  let n,k = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let a_arr = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  Printf.printf "%d\n" @@ 
  (
  if (n-1) mod (k-1) = 0 then
    (n-1) / (k-1)
  else
    (n-1) / (k-1) +1
)


Measured memory_bytes: 5504
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
// using ll = long long;
// using P = pair<int,int>;
// using vi = vector<int>;
// using vvi = vector<vi>;

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

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

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


int main() {
  int N;
  int ans = 0;
  cin >> N;
  for(int i=1; i <= N; i++){
    if(i%2 == 0) continue;
    int div = 0;
    for(int j=1; j <= N; j++) {
      if(i % j == 0) div++;
    }
    if(div == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}







Measured memory_bytes: 3164
while(1):
    n=float(raw_input())
    if n<0:
        break
    else:
        nn=int(n*32)
        f=""
        if nn>=2**(13):
            print "NA"
        elif nn!=n*32:
            print "NA"
        else:
            for i in range(12):
                d=nn/2**(12-i)
                f=f+str(d)
                if i==7:
                    f=f+"."
                nn=nn%2**(12-i)
            if nn==0:
                print f
            else:
                print "NA"

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

using namespace std;

int cal(string s, int num)
{
	int ans = 0;
	int table[30] = {};

	int c = (int)('a');

	int size = s.size();

	for (int i = 0; i < num; i++)
	{
		char a = s[i];

		for (int j = num; j < size; j++)
		{
			if (a == s[j])
			{
				if (table[a - c] == 0)
				{
					ans++;
				}
				table[a - c]++;
			}
			
		}
	}

	return ans;
}

int main(void)
{
	int a;
	cin >> a;

	string s;
	cin >> s;

	int size = s.size();

	int best_ans = 0;

	for (int i = 1; i < size; i++)
	{
		int ans = cal(s, i);

		if (best_ans < ans)
		{
			best_ans = ans;
		}
	}

	cout << best_ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

vector<bool> eratosthenes;

void create_eratosthenes(int n) {
    eratosthenes.resize(n + 1, true);
    eratosthenes[0] = eratosthenes[1] = false;
    for(int i = 2; (i * i) <= n; i++) {
        if (!eratosthenes[i]) continue;
        for (int ii = 2; (i * ii) <= n; ii++) {
            eratosthenes[i * ii] = false;
        }
    }
}

bool is_prime(int n) {
    return eratosthenes[n];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    vector<ll> dp(101000);
    create_eratosthenes(sz(dp));
    dp[0] = 0;
    reps(i, 1, sz(dp)) {
        bool f = is_prime(i) & is_prime((i + 1) / 2);
        dp[i] = dp[i - 1] + (f ? 1 : 0);
    }
    ll q;
    cin >> q;
    rep(i, q) {
        ll l, r;
        cin >> l >> r;
        cout << (dp[r] - dp[l - 1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long n;
long long step(long long a,long long b) {
    if(b==0) return 1;
    if(b&1ll) return (a*step(a,b-1ll))%mod;
    else return step((a*a)%mod,b>>1ll);
}
char x[600000];
char a[600000];
long long ct[600000];
long long deg[600000];
long long num = 0;
long long disc = 0;
long long ans = 0;
long long gcd(long long a,long long b) {
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
void solve(long long k) {
    long long rem=gcd(n,k);
    long long cnt=0;
    for(int i=0;i<rem;i++) {
        if(x[i]=='1') {
            cnt=(cnt+deg[rem-i-1])%mod;
            a[i]='1';
            long long tp=n/rem;
            int u=i;
            for(int j=0;j<tp;j++) {
                if(u+k<n) {
                    a[u+k]=a[u];
                    u=u+k;
                }
                else {
                    if(a[u]=='0') a[u+k-n]='1';
                    else a[u+k-n]='0';
                    u=u+k-n;
                }
            }
        }
        else {
            a[i]='0';
            long long tp=n/rem;
            int u=i;
            for(int j=0;j<tp;j++) {
                if(u+k<n) {
                    a[u+k]=a[u];
                    u=u+k;
                }
                else {
                    if(a[u]=='0') a[u+k-n]='1';
                    else a[u+k-n]='0';
                    u=u+k-n;
                }
            }
        }
    }
    bool ls=true;
    for(int i=0;i<n;i++) {
        if(a[i]>x[i]) {
            ls=false;
            break;
        }
        if(a[i]<x[i]) {
            ls=true;
            break;
        }
    }
    if(ls) cnt++;
    cnt%=mod;
    ct[k]=cnt;
}
int main() {
    scanf("%d",&n);
    scanf("%s",x);
    deg[0]=1;
    for(int i=1;i<=2*n;i++) deg[i]=(2*deg[i-1])%mod;
    for(long long k=2;k<=n;k++) {
        if((2*n)%k==0 && n%k!=0) {
            for(int i=0;i<n;i++) a[i]='0';
            solve(k);
        }
    }
    num=0;
    for(int i=0;i<n;i++) {
        if(x[i]=='1') {
            num=num*2+1;
        }
        else num=num*2;
        num%=mod;
    }
    ct[2*n]=(num+1)%mod;
    for(long long i=2;i<=n;i++) {
        if((2*n)%i==0 && n%i!=0) {
            for(long long j=2*i;j<=n;j+=i) {
                ct[j]=(ct[j]-ct[i]+mod);
                if(ct[j]>=mod) ct[j]-=mod;
            }
            ans = (ans+ct[i]*i)%mod;
            disc = (disc+ct[i])%mod;
        }
    }

    printf("%lld",((ct[2*n]-disc+mod)*(2*n)+ans)%mod);
    return 0;
}


Measured memory_bytes: 10496
#include<bits/stdc++.h>
#define For(i,k,n) for(ll i=k;i<n;i++)
#define endl "\n"
#define ll long long int
using namespace std;
#define test int t; cin>>t; while(t--)
#define vi vector<int>
#define vl vector<ll>
#define umapii unordered_map<int,int>
#define umapll unordered_map<ll,ll>
#define p_b push_back
#define m_p make_pair 
#define fst first
#define snd second

void dummy(){
    for(int i=0;i<23;i++);
}void scanArr(ll a[],ll n){
    For(i,0,n)cin>>a[i];
}void scanArr(int a[],int n){
    For(i,0,n)cin>>a[i];
}void printl(){
  cout<<endl;
}void dummy2(){
  For(i,0,10)cout<<"";
}void dummy3(int n){
  int p = 0,q=0;
  p=n;n = q;q = p;n++;q--;
}

ll mexp(ll a,ll b){
  if(a==0) return 0;
  if (b==0) return 1;
  ll ans=1;
  while(b>0){
    if(b&1){
      ans*=a;b--;
    }
    else{
      a*=a;b=b>>1;
    }
  }
  return ans;
}

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

  //        ------Code Here------

    ll d, t, s;
    cin>>d>>t>>s;
    if(d<=s*t)cout<<"Yes";
    else cout<<"No";
    cout<<endl;
	return 0;
}

Measured memory_bytes: 3644
a,b,c = map(int,input().split())

m = a%b

can_make = []

for i in range(a,a*b+1):
    if i%a == 0 and i%b not in can_make:
        can_make.append(i%b)

if c in can_make:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
n,m,f[2000];main(p){for(;~scanf("%d%d",&n,&m);n&&printf("%d\n",1+*f)){for(p=n;p--;)f[p]=p;for(p=0;n>1;memmove(f+p,f+p+1,4000))p=(p+m-1)%n--;}}

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

using lint = long long;
const int MAXN = 6005;
const int INF = 1e5;

int N;
int A[MAXN];

int ans = 0;
int base = 0;
int nxt[MAXN];
int dp[MAXN][MAXN];

int Cost(int a, int b, int c) {
  return A[a] == A[b] && A[b] == A[c];
}

void Transition(int i, int j, int cur) {
  if (cur > 3 * N) return;
  if (cur == 3 * N) {
    ans = max(ans, dp[i][j] + Cost(i, j, cur));
    return;
  }
  dp[cur + 0][cur + 1] = max(dp[cur + 0][cur + 1], dp[i][j] + Cost(i, j, cur + 2));
  dp[cur + 0][cur + 2] = max(dp[cur + 0][cur + 2], dp[i][j] + Cost(i, j, cur + 1));
  dp[cur + 1][cur + 2] = max(dp[cur + 1][cur + 2], dp[i][j] + Cost(i, j, cur + 0));

  dp[i][cur + 0] = max(dp[i][cur + 0], dp[i][j] + Cost(j, cur + 1, cur + 2));
  dp[i][cur + 1] = max(dp[i][cur + 1], dp[i][j] + Cost(j, cur + 0, cur + 2));
  dp[i][cur + 2] = max(dp[i][cur + 2], dp[i][j] + Cost(j, cur + 0, cur + 1));

  dp[j][cur + 0] = max(dp[j][cur + 0], dp[i][j] + Cost(i, cur + 1, cur + 2));
  dp[j][cur + 1] = max(dp[j][cur + 1], dp[i][j] + Cost(i, cur + 0, cur + 2));
  dp[j][cur + 2] = max(dp[j][cur + 2], dp[i][j] + Cost(i, cur + 0, cur + 1));
  dp[i][j] = max( dp[i][j], dp[i][j] + Cost(cur+0, cur + 1, cur + 2));

}

int main() {

  cin >> N;
  for (int i = 1; i <= 3 * N; i++)
    cin >> A[i];


  while (true) {
    bool change = false;
    for (int i = 3; i + 2 <= 3 * N; i += 3) {
      if (A[i] == A[i + 1] && A[i + 1] == A[i + 2]) {
        base += 1;
        for (int j = i + 3; j <= 3 * N; j++) {
          A[j - 3] = A[j];
        }
        N -= 1;
        change = true;
        break;
      }
    }
    if (!change) {
      break;
    }
  }

  vector<int> last(3 * N + 1, 3 * N + 1);
  for (int i = 3 * N; i > 0; i--) {
    nxt[i] = last[A[i]];
    last[A[i]] = i;
  }
  for (int i = 0; i < MAXN; i++) {
    for (int j = 0; j < MAXN; j++) {
      dp[i][j] = -INF;
    }
  }
  dp[1][2] = 0;
  for (int i = 1; i <= 3 * N; i++) {
    for (int j = i + 1; j <= 3 * N; j++) {
      Transition(i, j, (j + 3) / 3 * 3);
      // Find next occurrence of A[i]
      if ( (j / 3 * 3) < (nxt[i] / 3 * 3) )
        Transition(i, j, nxt[i] / 3 * 3);

      // Find next occurrence of A[j]
      if (j / 3 * 3 < nxt[j] / 3 * 3)
        Transition(i, j, nxt[j] / 3 * 3);

    }
  }

  cout << ans + base << "\n";
  return 0;
}

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

int main() {
  char s[10];
  scanf("%s", s);

  int res = 0;
  int t = 0;
  bool pr = false;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R') {
      if (pr) t++;
      else t = 1;
      pr = true;
    } else {
      res = max(res, t);
      pr = false;
    }
  }

  res = max(res, t);

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 3680
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;cin>>n;
	vector<int> a(n);
	REP(i,n)cin>> a[i];
	int ct = 1;
	int mode = 0;
	FOR(i,1,n){
		if(a[i] < a[i-1]){
			if(mode==0){
				mode = 1;
			}else if(mode == 2){
				mode = 0;
				ct++;
			}
		}else if(a[i] > a[i-1]){
			if(mode==0){
				mode = 2;
			}else if(mode == 1){
				mode = 0;
				ct++;
			}
		}
	}
	cout << ct << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int c=1,ans;
    string s;
    cin>>s;
    int n=s.size();
    ans=n;
    for(int i=1;i<n;i++){
        if(s.at(i)==s.at(i-1)){ans--;i+=2;}
    }
    cout<<ans;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	string base("abcdefghijklmnopqrstuvwxyz");
	string ans("");
	for (LL k = 1; k <= 12;k++) {
		LL sub = 0;
		LL t = 1;
		for (LL kk = 0; kk < k; kk++) {
			sub += t;
			t *= 26;
		}
		LL k26 = 1;
		for (LL kk = 0; kk < k; kk++)k26 *= 26;
		if (N-sub < 0)continue;
		if (N - sub >= k26)continue;
		N -= sub;
		for (LL kk = 0; kk < k; kk++) {
			ans = base.substr(N % 26, 1) + ans;
			N /= 26;
		}
		break;
	}
	cout << ans << "\n";
	return 0;
}

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


int main(){
    int x; cin >> x;

    int r = 1, y = 360;
    int res = 0;
    while(r){
        r = y%x;
        res+=(y/x);
        y = 360 + r;
    }
    cout << res << endl;
}

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main
{
	
	public static ArrayList<String> AL = new ArrayList<String>();
	
	
	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		String k = fs.next();
		
		int count=0;
		
		for(int i= 0 ;i<k.length();i++) {
			count+=Integer.parseInt(k.substring(i, i+1));
		}
		
		if(count%9==0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
	}
	
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 45764
#include <iostream>
using namespace std;
int main(){
    int n, t;
    cin >> n >> t;
    int ans = 10001;
    for(int i = 0; i < n; i++) {
        int c, d;
        cin >> c >> d;
        if(d <= t) ans = min(ans, c);
    }
    if(ans == 10001) puts("TLE");
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <vector>
#include<valarray>
#include<map>
#include <bits/stdc++.h>
#include <utility>
#include<bits/stdc++.h>
using namespace std;

int main()
{
string s,t;
cin>>s>>t;
long long counter=0;
for(int i=0;i<s.length();i++)
{
    if(s[i]!=t[i])
    {
        counter++;
    }
}
cout<<counter;
    return 0;
}

Measured memory_bytes: 3820
#! /usr/bin/python3
# Haiku

"""
    s の長さは 19 である。
    s の 6 文字目と 14 文字目は , である。
    それら以外の s の文字は英小文字である。
"""

# s = input()
# s = s.replace(',', ' ')
print(input().replace(',', ' '))


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 109, M = 509, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n, cap, w[N], v[N], first;

ll dp[N][N][M];

ll solve(int i, int cnt, int total){
    if(i == n)  return ((ll)cnt * first + total  <= cap ? 0 : -llOO);

    ll &ret = dp[i][cnt][total];
    if(~ret)    return ret;

    return ret = max(v[i] + solve(i + 1, cnt + 1, total + w[i]), solve(i+ 1, cnt, total));
}
int main(){
    init();

    cin >> n >> cap;
    for(int i = 0;i < n;i++){
        cin >> w[i] >> v[i];
        if(!i)  first = w[i];
        w[i] -= first;
    }

    memset(dp, -1, sizeof dp);
    cout << solve(0, 0, 0);
}

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

int main() {
  char a;
  for (int i = 0; i < 9; i++) {
    cin >> a;
    if (i == 0 || i == 4 || i == 8) {
      cout << a;
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int sum =0;
  vector<int>a(m);
  for(int i=0;i<m;i++){
  cin >> a[i];
  sum =sum+a[i];
  }
  if(sum>n){
    cout << "-1";
  }
  else cout << n-sum;
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  int a[n],b[n];
  bool bo[n+1]={false};
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    if(a[i]==1) bo[b[i]]=true;
  }
  int che=0;
  for(int i=0;i<m;i++){
    if(b[i]==n){
      if(bo[a[i]]==true){
        che=1;
        break;
      }
    }
  }
  if(che==1) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

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

  ll m = INF;
  ll ans = 0;
  for (ll i = 0; i < N; i++)
  {
    ll P;
    cin >> P;

    if (m >= P)
      ans++;

    chmin(m, P);
  }
  cout << ans << endl;
}

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

signed main(){
  int N;
  cin >> N;
  
  vector<tuple<int, int, int>> A(N);
  for( int i = 0; i < N; i++ ){
    int a, b;
    cin >> a >> b;
    A.at(i) = make_tuple(a+b, a, b);
  }
  sort(A.rbegin(), A.rend());
  
  int taka = 0;
  int aoki = 0;
  for( int i = 0; i < N; i++ ){
    if( i%2 == 0 ){
      taka += get<1>(A.at(i));
    }else{
      aoki += get<2>(A.at(i));
    }
  }
  cout << taka-aoki << endl;
  
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int dp[30005][5][1000] = {0};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    dp[0][0][0] = 1;
    
    rep(i, n) {
        rep(j, 4) rep(k, 1000) {
            if (dp[i][j][k]) {
                dp[i + 1][j][k] = 1; // j == 3もloopに入れる
                if (k * 10 + (s[i] - '0') < 1000)
                    dp[i + 1][j + 1][k * 10 + (s[i] - '0')] = 1;
            }
        }
    }
    
    int ans = 0;
    rep(k, 1000) {
        ans += dp[n][3][k];
    }
    cout << ans << endl;
}


Measured memory_bytes: 586240
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int cnt = 0;
		boolean flg = false;
		for(int i = 0; i < n; i++){
		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    if(a == b){
		        cnt++;
		    }else{
		        cnt = 0;
		    }
		    if(cnt >= 3) flg = true;
		}
		
		// 計算
		String result = "No";
		if(flg) result = "Yes";
		
		// 出力
		System.out.println(result);
		
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}

}


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

typedef long long ll;
typedef pair<int,int> pii;


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

  string s;
  cin >> s;
  bool ret = true;
  for(int i = 0;i < s.length();i++){
    if(i%2 == 0 && s[i] == 'L')ret = false; 
    if(i%2 == 1 && s[i] == 'R')ret = false;
  }
  if(ret)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()





int main() {
    int k, x;
    cin >> k >> x;
    for (int i = max(-1000000, x - (k - 1)); i <= min(1000000, x + (k - 1)); ++i) {
        cout << i << ' ';
    }
    return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
vector<int>g[101010];
vector<pair<int,int> >e;
int n,m;
bool vis[101010],d[101010];
void dfs(int x,int y)
{
	if(vis[y])
	{
		return;
	}
	vis[y]=true;
	int z=1;
	if(x>0)
	{
		z=x^e[y].first^e[y].second;
	}
	for(int i=0;i<g[z].size();i++)
	{
		if(g[z][i]!=y)
		{
			dfs(z,g[z][i]);
		}
	}
	if(!x)
	{
		return;
	}
	if(d[z])
	{
		cout<<z<<' '<<x<<endl;
		d[z]=false;
	}
	else
	{
		cout<<x<<' '<<z<<endl;
		d[x]^=true;
	}
}
int main()
{
	cin>>n>>m;
	if(m%2==1)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		e.push_back(make_pair(a,b));
		g[a].push_back(i);
		g[b].push_back(i);
	}
	dfs(0,m);
	return 0;
}

Measured memory_bytes: 17268
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt = 0;
  reverse(S.begin(),S.end());
  for(int i=0; i<N; i++){
    cnt += (S[i]=='1');
  }
  ll two;
  ll sum_mn = 0;
  vector<ll> two_mn(N);
  two = 1;
  if(cnt > 1){
    for(int i=0; i<N; i++){
      if(S[i] == '1'){
        sum_mn += two;
        sum_mn %= (cnt-1);
      }
      two_mn[i] = two;
      two *= 2;
      two %= (cnt-1);
    }
  }
  vector<ll> two_mx(N);
  ll sum_mx = 0;
  two = 1;
  if(cnt != N){
    for(int i=0; i<N; i++){
      if(S[i] == '1'){
        sum_mx += two;
        sum_mx %= (cnt+1);
      }
      two_mx[i] = two;
      two *= 2;
      two %= (cnt+1);
    }
  }
  vector<int> ans(N,0);
  for(int i=0; i<N; i++){
    if(S[i] == '0'){
      ll now = sum_mx;
      now += two_mx[i];
      now %= (cnt+1);
      ll temp = now;
      ans[i] = 1;
      while(temp){
        ll nxt = 0;
        ll temp2 = temp;
        while(temp2){
          nxt += temp2%2;
          temp2 /= 2;
        }
        temp %= nxt;
        ans[i]++;
      }      
    }else{
      if(cnt == 1){
        ans[i] = 0;
        continue;
      }
      ll now = sum_mn;
      now -= two_mn[i];
      now += (cnt-1);
      now %= (cnt-1);
      ans[i] = 1;
      ll temp = now;
      while(temp){
        ll nxt = 0;
        ll temp2 = temp;
        while(temp2){
          nxt += temp2%2;
          temp2 /= 2;
        }
        temp %= nxt;
        ans[i]++;
      }
    }
  }
  reverse(ans.begin(),ans.end());
  for(int i=0; i<N; i++){
    cout << ans[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 7544
#include <iostream>
#include <stack>
#include <algorithm>
#include <sstream>
using namespace std;

int main()
{
  stack<int> data;
  string s;
  int num1, num2;
  while (cin >> s)
  {

    if (s == "+")
    {
      num1 = data.top();
      data.pop(); //末尾のデータ削除
      num2 = data.top();
      data.pop();
      data.push(num2 + num1);
    }
    else if (s == "-")
    {
      num1 = data.top();
      data.pop(); //末尾のデータ削除
      num2 = data.top();
      data.pop();
      data.push(num2 - num1);
    }
    else if (s == "*")
    {
      num1 = data.top();
      data.pop(); //末尾のデータ削除
      num2 = data.top();
      data.pop();
      data.push(num2 * num1);
    }
    else
    {
      stringstream ss(s);
      int x;
      ss >> x;
      data.push(x);
    }
  }
  cout << data.top() << endl;
  return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>

using namespace std;

typedef pair<int, int> P;
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define _1 first
#define _2 second
#define pb push_back
#define mod 1000000007
#define INF 105000000000

const int maxn = 1e5 + 10;



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

	int a, b, c;

	vi v;
	cin >> a >> b >> c;
	v.pb(a+b);
	v.pb(b+c);
	v.pb(c+a);
	
	vsort(v);

	cout << v[0] << endl;




	return 0;
}

Measured memory_bytes: 256
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll       =    long long;
using   ld       =    long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const int MOD =(int)1e9+7;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int n;
    cin>>n;
    if(n%1000==0)cout<<0<<nl;
    else{
        int cnt=(n/1000)+1;
        cout<<(cnt*1000)-n<<nl;
    }
    return 0;
}


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

ll n,m;
bool flag;
string a[51],b[51];
int main(){
  cin>>n>>m;
  rep(i,n)cin>>a[i];
  rep(i,m)cin>>b[i];

  for(int k=0;k<=n-m;k++){
      for(int i=0;i<=n-m;i++){
          if(a[k][i]==b[0][0]){
            flag=true;
            for(int j=0;j<m;j++){
              for(int l=0;l<m;l++){
                if(a[k+j][i+l]!=b[j][l])flag=false;
              }
            }
            if(flag){
              cout<<"Yes"<<endl;
              return 0;
            }
          }
    }
  }
  if(flag==false){
    cout<<"No"<<endl;
  }


}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	long A, B, C, re;
	cin >> A >> B >> C;
	if (A + B >= C) {
		re = B + C;
	}
	else{
		re = 2 * B + A + 1;
	}
	cout << re;
	return 0;
}


Measured memory_bytes: 256
n, *A = map(int, open(0).read().split())
def sgn(n):
    return 0 if n==0 else 1 if n>0 else -1

a = A[0]
C = [0 if a>0 else -a+1, 0 if a<0 else a+1]
S = [max(1, a), min(-1, a)]

for a in A[1:]:
    for i, s in enumerate(S):
        sgn_sum = sgn(s)
        if sgn(s+a) == -sgn_sum:
            S[i] += a
        else:
            C[i] += abs(s+a+sgn_sum)
            S[i] = -sgn_sum

print(min(C))

Measured memory_bytes: 14084
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

using namespace std;
typedef long long ll;

#define f first
#define s second

const ll mod = 1e9 + 7;


ll logpow (ll a, ll b) {
  ll p = 1;
  while (b) {
    if (b & 1)
      p = 1ll * p * a % mod;
    a = 1ll * a * a % mod;
    (b >>= 1);
  }
  return p;
}

ll f[200002];
ll comb (ll n, ll k) {
  return 1LL * f[n] * logpow(f[k], mod - 2) % mod * logpow(f[n - k], mod - 2) % mod;
}

ll n, c[200002], sum[200002];

int main()
{
  ios_base::sync_with_stdio(false);
  cin >> n;
  f[0] = 1;
  for (ll i = 1; i <= n; i++)
    f[i] = 1LL * f[i - 1] * i % mod;
  for (ll i = 1; i <= n; i++)
    cin >> c[i];
  sort(c + 1, c + n + 1);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll k = logpow(2, n - i);
    if ((n - i) % 2 == 0)
      k = (k - comb(n - i, (n - i) / 2) + mod) % mod;
    k *= logpow(2, mod - 2);
    k %= mod;
    k = k * (n - i + 2) % mod;
    if ((n - i) % 2 == 0)
      k = (k + (((n - i) / 2 + 1) * comb(n - i, (n - i) / 2)) % mod) % mod;
    ans = (ans + logpow(2, n + i - 1) * c[i] % mod * k % mod) % mod;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3584
'use strict';

function Main(input) {
  if (input === "A") {
    console.log("T")
  }
  if (input === "T") {
    console.log("A")
  }
  if (input === "G") {
    console.log("C")
  }
  if (input === "C") {
    console.log("G")
  }
};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 7372
def list2d(a, b, c): return [[c] * b for i in range(a)]
mod =10**9+7

n = int(input())
p = list(map(float, input().split()))
dp = list2d(n + 1,n + 1 ,0)

dp[0][0] = 1.
for i in range(1, n + 1):
  for j in range(n + 1):
    if(j==0):
      dp[i][j] = (1 - p[i-1])*dp[i-1][0]
    else:
      dp[i][j] = (1 - p[i-1])*dp[i-1][j] + p[i-1]*dp[i-1][j-1]
ans = 0
for k in range(n//2 + 1, n + 1):
  ans+=dp[n][k]
print(ans)
  


Measured memory_bytes: 259720
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, M;
    cin >> N >> M;
    int sum = 0;
    for(int i = 0; i < M; i++){
        int a;
        cin >> a;
        sum += a;
    }
    if(N - sum >= 0){
        cout << N - sum << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3636
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process(int test_number)throws IOException
    {
        String s = nln();
        int n = s.length();

        if(s.charAt(n - 1) == 's')
            pn(s+"es");
        else
            pn(s+"s");
    }
 
    static final long mod = (long)1e9+7l;
    
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc = new FastReader();
 
        long s = System.currentTimeMillis();
        int t = 1;
       // t = ni();
        for(int i = 1; i <= t; i++)
            process(i);
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }

    static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
    static void pn(Object o){ out.println(o); }
    static void p(Object o){ out.print(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
    static long nl()throws IOException{ return Long.parseLong(sc.next()); }
    static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
    static String nln()throws IOException{ return sc.nextLine(); }
    static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
    static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 37068
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors
                
n = int(input())

a = make_divisors(n)
b = make_divisors(n - 1)

d = list(set(a + b))

ans = 0

for i in list(d):
    if i == 1:
        continue
    x = n
    while x % i == 0:
        x /= i
    
    if x % i == 1:
        ans += 1

print(ans)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll p[55];
    rep(i,0,N) cin >> p[i];
    ll cnt = 0;
    rep(i,0,N){
        if(p[i] != i+1) cnt++;
    }
    if(cnt == 2 || cnt == 0){
        print("YES");
    }else{
        print("NO");
    }

    
}

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

int calc_distance(int K, std::vector<int> heights) {
  // Sort the vector and find the set of K trees with the smallest gap in height
  std::sort(heights.begin(), heights.end());
  int minDistance = INT_MAX; 
  for(int i = 0; i <= heights.size() - K; i++) {
    int dist = heights[i + K - 1] - heights[i];
    if(dist < minDistance) minDistance = dist;
  }
  return minDistance;
}


int main() {
  int K, N;
  std::cin >> N >> K;
  std::vector<int> heights;

  for(int i = 0; i < N; i++) {
    int h;
    std::cin >> h;
    heights.push_back(h);
  }

  int ret = calc_distance(K, heights);
  std::cout << ret << std::endl;
}


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

int puz[3][3];
int cp[3][3];

void input() {
	int i, j;
	for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++)
			scanf("%d", &puz[i][j]);
}


void copy(int m[3][3], int t[3][3]) {
	int i, j;
	for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++) m[i][j] = t[i][j];
}

int calc() {
	int i, sum = 0;
	for (i = 0; i < 9; i++) {
		int v = puz[i / 3][i % 3];
		if (v) {
			v--;
			sum += abs(i / 3 - v / 3) + abs(i % 3 - v % 3);
		}
	}
	return sum;
}

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

void swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int is_in(int x, int y) {
	return 0 <= x && x<3 && 0 <= y && y<3;
}

int depth(int x, int y, int p, int dep, const int lim) {
	int i, h = calc();
	if (h == 0) return dep;
	if (dep + h > lim) return -1;
	for (i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i], res;
		if (~p && i == (p + 2) % 4) continue;
		if (!is_in(nx, ny)) continue;
		swap(&puz[y][x], &puz[ny][nx]);
		res = depth(nx, ny, i, dep + 1, lim);
		if (~res) return res;
		swap(&puz[y][x], &puz[ny][nx]);
	}
	return -1;
}

void get_empty(int *x, int *y) {
	int i, j;
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			if (!puz[i][j]) {
				*x = j;
				*y = i;
				return;
			}
		}
	}
}

int solve() {
	int x, y, lim, ans;
	get_empty(&x, &y);
	for (lim = 0; lim < 50; lim++) {
		copy(cp, puz);
		if ((ans = depth(x, y, -1, 0, lim)) != -1) return ans;
		copy(puz, cp);
	}
	return -1;
}

int main() {
	input();
	printf("%d\n", solve());
	return 0;
}


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

int main() {
  int n;cin>>n;
  vector<int> a(n),vec(n);
  rep(i,n){
    cin>>a[i];
    vec[i]=i+1;
  }
  bool ok=false;
  int x=0;
  rep(i,n){
    if(a[i]==vec[x]){
      ok=true;
      x++;
    }
  }
  if(ok)cout<<n-x<<endl;
  else cout<<-1<<endl;
}

Measured memory_bytes: 4784
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;

    if (n == 0) {
      break;
    }

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

    vector<string> c(n);
    for (int i = 0; i < n; i++) {
      c[i] += s[i][0];
      char last = s[i][0];
      for (int j = 1; j < s[i].size(); j++) {
	if (last == 'a' || last == 'e' || last == 'i' ||
	    last == 'o' || last == 'u') {
	  c[i] += s[i][j];
	}
	last = s[i][j];
      }
    }

    int l = 0;
    for (int i = 0; i < n; i++) {
      if (c[i].size() > l) {
	l = c[i].size();
      }
    }

    bool f = false;
    for (int k = 1; k <= l && !f; k++) {
      map<string, bool> m;
      for (int i = 0; i < n; i++) {
	string sc = c[i].substr(0, k < c[i].size() ? k : c[i].size());
	if (m.count(sc) != 0) {
	  break;
	}
	if (i == n - 1) {
	  cout << k << endl;
	  f = true;
	  break;
	}
	m[sc] = true;
      }
    }

    if (!f) {
      cout << -1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<vector>
#include<limits>
#include<math.h>
#include<bits/stdc++.h>

using namespace std;

#define make_graph(m,G) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b;G[a-1].push_back(b-1); G[b-1].push_back(a-1);}
#define make_dir_graph(m,G) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b;G[a-1].push_back(b-1);}
#define make_weighted_graph(m,G,w) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b; cin>>w[a-1][b-1];w[b-1][a-1]=w[a-1][b-1];G[a-1].push_back(b-1); G[b-1].push_back(a-1);}
#define make_weighted_dir_graph(m,G,w) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b; cin>>w[a-1][b-1]; G[a-1].push_back(b-1);}

int main()
{
	int t=1;
	// cin>>t;
	while (t--)
	{
		// code
		int n; cin>>n;
		int a[n], b[n], c[n];
		for (int i = 0; i<n; i++)
		{
			cin>>a[i]>>b[i]>>c[i];
		}
		int dp[n][3] = {};
		dp[0][0] = a[0];
		dp[0][1] = b[0];
		dp[0][2] = c[0];

		for (int i = 1; i<n; i++)
		{
			dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
			dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i];
			dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
		}

		cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
		cout<<endl;	
	}
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    n=n%10;
    if (n==2||n==4||n==5||n==7||n==9){
        cout << "hon";
    }
    if (n==0||n==1||n==6||n==8){
        cout << "pon";
    }
    if (n==3){
        cout << "bon";
    }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n; cin >> n;
	cout << n * (n + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

const int N=3010;

int n, a[N], f[N];
int head[N], cnt;

struct EDGE {
	int y, nex;
}edge[N<<1];

void add(int x, int y) {
	edge[++cnt].y=y;
	edge[cnt].nex=head[x];
	head[x]=cnt;
}

void dfs(int x, int fa) {
	f[x]=0;
	for(int i=head[x]; i; i=edge[i].nex) {
		int y=edge[i].y;
			if(y!=fa&&a[x]>a[y]) {
				dfs(y, x);
				if(!f[y]) {
					f[x]=1;
					return;
				}
			}
	}
}

int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	for(int i=1; i<n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y), add(y, x);
	}
	for(int i=1; i<=n; i++) {
		dfs(i, 0);
		if(f[i]) printf("%d ", i);
	}
}

Measured memory_bytes: 1816
H, W = gets.split.map(&:to_i)
A = readlines.map{|l| l.chomp.split(//)}

hs = (0 ... H).select{|h| A[h].all?{|x| x == '.'}}
ws = (0 ... W).select{|w| A.transpose[w].all?{|x| x == '.'}}
(0 ... H).each do |h|
  next if hs.include?(h)
  (0 ... W).each do |w|
    next if ws.include?(w)
    print A[h][w]
  end
  puts
end

Measured memory_bytes: 9724
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    t = S()
    s = ''.join(sorted([c for c in s]))
    t = ''.join(sorted([c for c in t], reverse=True))
    if s < t:
        return 'Yes'

    return 'No'



print(main())




Measured memory_bytes: 5460
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      String s = sc.next();
      String t = sc.next();
      int sleng = s.length();
      String tcut = t.substring(0, sleng);
      if (s.equals(tcut)) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }

	}
}

Measured memory_bytes: 26888
# def bit():
#     S = input()
#     n = len(S) - 1
#     ieS = S[0]
#     for i in range(n):
#         ieS += '*'
#         ieS += S[i+1]
#     ans = 0
#     for i in range(2 ** n):
#         eS = ieS
#         for j in range(n):
#             if (i >> j) & 1:
#                 eS = eS[:(j+1)*2-1] + '+' + eS[(j+1)*2:]
#         ans += eval(eS.replace('*', ''))
#     print(ans)


def solve():
    S = input()
    eS = S[0]
    print(dfs(0, S, eS))


def dfs(i, S, eS):
    if i == len(S)-1:
        return eval(eS)
    return dfs(i+1, S, eS+(S[i+1])) + dfs(i+1, S, eS+'+'+(S[i+1]))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060