akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
    int t[101]={0};
    int zile, tipuri, maxi=0, sum=0;
    cin>>zile>>tipuri;
    for (int i=0; i<tipuri; i++)
    {
        int nr;
        cin>>nr;
        sum+=nr;
        if (nr>maxi)
            maxi=nr;
    }
    sum-=maxi;
    cout<<max(0, maxi-sum-1);
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var n, w int
var items []item
var dp [][]int64

type item struct {
	w int
	v int64
}

func dfs(i, ww int) int64 {
	if dp[i][ww] != -1 {
		return dp[i][ww]
	}
	if i == n {
		return 0
	}
	if ww+items[i].w <= w {
		dp[i][ww] = maxInt64(dfs(i+1, ww), dfs(i+1, ww+items[i].w)+items[i].v)
	} else {
		dp[i][ww] = dfs(i+1, ww)
	}
	return dp[i][ww]
}

func main() {
	n = readInt()
	w = readInt()
	items = make([]item, n)
	for i := range items {
		items[i] = item{
			w: readInt(),
			v: readInt64(),
		}
	}
	dp = make([][]int64, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int64, w+1)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}

	fmt.Println(dfs(0, 0))
}


Measured memory_bytes: 84308
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>
#include<set>
#include<stack>
#include<map>

using namespace std;

int main(){
    string S;
    cin>>S;
    int N=S.size();
    int num0=0;
    int num1=0;
    for(int i=0;i<N;i++){
        if(S[i]=='0'){
            num0++;
        }else{
            num1++;
        }
    }
    cout<<2*min(num0,num1)<<endl;
    return 0;
}


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

int main(){
  int n, x;
  int card[4][14]={};
  char m;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>m>>x;
    if(m=='S') card[0][x]=1;
    if(m=='H') card[1][x]=1;
    if(m=='C') card[2][x]=1;
    if(m=='D') card[3][x]=1;
  }

  for(int i=0;i<4;i++){
    for(int j=1;j<=13;j++){
      if(i==0&&card[i][j]==0) cout<<"S "<<j<<endl;
      if(i==1&&card[i][j]==0) cout<<"H "<<j<<endl;
      if(i==2&&card[i][j]==0) cout<<"C "<<j<<endl;
      if(i==3&&card[i][j]==0) cout<<"D "<<j<<endl;
    }
  }
  
  return 0;
}

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


int main()
{
    int n;
    cin >> n;
    map<string,int> s;
    rep(i,1,n+1,1)
    {
        string in;
        cin >> in;

        s.insert({in,0});
    }
    cout << s.size() << endl;

    
    

    return 0;
}

Measured memory_bytes: 19176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
void chmin(int a,int b){if(b<a)a=b;}
void chmax(int a,int b){if(a<b)a=b;}

int main(){
  int n;cin>>n;
  vi v(n);
  rep(i,n)cin>>v[i];
  vi dp(n);
  dp[0]=0;
  dp[1]=abs(v[1]-v[0]);
  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-2]+abs(v[i]-v[i-2]),dp[i-1]+abs(v[i]-v[i-1]));
  }
  cout<<dp[n-1]<<endl;
}


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

double eps = 1e-9;
double pi = acos(-1);

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define ff first
#define ss second
#define sp(x) fixed << setprecision(x)
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<>())
#define CASEP(v) cout<<"Case "<<tc<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io

	string s;
	cin >> s;

	if(s[2] == s[3] && s[4] == s[5])
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, k;
    cin >> n >> k;

    vs32 cnt(n + 1, 0);
    int a;
    rep (i, n)
    {
        cin >> a;
        ++cnt[a];
    }

    sort(cnt.begin(), cnt.end(), greater<int>());

    int num = 0;
    rep (i, k)
    {
        num += cnt[i];
    }

    cout << n - num << "\n";

    return 0;
}



Measured memory_bytes: 1024
using System;

namespace dp
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var hList = ReadNumList();
            var cList = new int[hList.Length];
            cList[0] = 0;
            cList[1] = Math.Abs(hList[1] - hList[0]);
            for (var i = 2; i < n; ++i)
            {
                var moveNext = cList[i - 1] + Math.Abs(hList[i] - hList[i - 1]);
                var jumpOne = cList[i - 2] + Math.Abs(hList[i] - hList[i - 2]);
                cList[i] = Math.Min(moveNext, jumpOne);
            }
            Console.WriteLine(cList[cList.Length - 1]);
        }
    }
}


Measured memory_bytes: 35072
S=input()
max=0
flag=0
count=0
for i in range(len(S)):
    if (S[i]=="A")or(S[i]=="T")or(S[i]=="G")or(S[i]=="C"):
        flag=1
    else:
        flag=0

    if flag==1:
        count=count+1
    else:
        count=0

    if max<count:
        max=count
print(max)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 502
#define mod 998244353
ll n,q,i,j,k,t,arr[sz],brr[sz],crr[sz],a,b,c,d,m,x,y,l,r,z,dp[sz][sz][sz];
vector<ll>v;
int main()
{
    scanf("%lld",&n);
    b=100;
    for(i=1;;i++)
    {
        a=b/100;
        b+=a;
        if(b>=n)
        {
            printf("%lld\n",i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  string S, T;
  cin >> S >> T;
  vector<string> vc;
  if (S.length() < T.length())
  {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= S.length() - T.length(); i++)
  {
    if (S[i] == T[0] || S[i] == '?')
    {
      int index = i;
      for (int j = 0; j < T.length(); j++)
      {
        if (S[i + j] != '?' && S[i + j] != T[j])
          index = -1;
      }
      if (index != -1)
      {
        string ans = S;
        for (int j = 0; j < T.length(); j++)
          ans[index + j] = T[j];
        for (int j = 0; j < ans.length(); j++)
        {
          if (ans[j] == '?')
            ans[j] = 'a';
        }
        vc.push_back(ans);
      }
    }
  }
  if (vc.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else
  {
    sort(vc.begin(), vc.end());
    cout << vc[0] << endl;
  }
  return 0;
}

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


using namespace std;

#define int long long
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define ff first 
#define ss second 
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<string> vs;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vpii;
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}

const int mod = 1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h + 1,vector<char>(w + 1));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> a[i][j];
        }
    }
    vvi dp(h + 1,vi(w + 1));
    dp[1][1] = 1;
    for(int i = 1; i <= h; ++i){
        for(int j = 1; j <= w; ++j){
            if(a[i - 1][j - 1] == '.'){
                (dp[i][j] += dp[i-1][j])%=mod;
                (dp[i][j] += dp[i][j-1])%=mod;
            }
        }
    }
    cout << dp[h][w];
}

Measured memory_bytes: 9088
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  Int N = in();
  for (Int h = 1; h <= 3500; ++h) {
    for (Int n = 1; n <= 3500; ++n) {
      // w = Nhn / (4hn - Nn - Nh)
      Int Z = N * h * n;
      Int W = 4 * h * n - N * n - N * h;
      if (W != 0 && Z % W == 0 && Z / W >= 1) {
        printf("%lld %lld %lld\n", h, n, Z / W);
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,min,val;
    cin>>n>>m;
    int min2[n],c[m];
    for(int i=0;i<m;i++){
        cin>>c[i];
    }
    min2[0]=0;
    min2[1]=1;
    for(int i=2;i<=n;i++){
        min=n+1;
        for(int j=0;j<m;j++){
            if(c[j]<=i){
                val=min2[i-c[j]]+1;
                min=((min<=val)?min:val);
            }
        }
        min2[i]=min;
    }
    cout<<min2[n]<<endl;
    return 0;
}


Measured memory_bytes: 3268
#include<stdio.h>
int main(void)
{
  int column;
  int row;
  int i,j;

  scanf("%d %d",&column,&row);

  int a[column][row];
  int b[row];
  int c[column];

  //c????????????
  for(i=0;i<column;i++){
    c[i] = 0;
  }


  //a
  for(i=0;i<column;i++){
    for(j=0;j<row;j++){
      scanf("%d",&a[i][j]);
    }
  }

  //b
  for(i=0;i<row;i++){
    scanf("%d",&b[i]);
  }

  //c
  for(i=0;i<column;i++){
    for(j=0;j<row;j++){
      c[i] += a[i][j]*b[j];
    }
    printf("%d\n",c[i]);
  }
  return 0;
}

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

typedef unsigned long long int lli;

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

    lli n;
    cin >> n;

    vector<lli> v(n+1);
    vector<lli> frequency(1000001);

    lli sum = 0;

    for(int i = 1; i <= n; i++)
    {
        cin >> v[i];
        frequency[v[i]]++;
        sum += v[i];
    }

    lli q;
    cin >> q;

    while(q--)
    {
        lli b, c;
        cin >> b >> c;

        sum += -frequency[b]*b + frequency[b]*c;

        cout << sum << endl;

        frequency[c] += frequency[b];
        frequency[b] = 0;
    }

}


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

int main() {

  int N;
  cin >> N;

  int cnt = 0;
  for (int i=1; i<=N; ++i) {
	int l = to_string(i).length();
	if (l%2 == 1) cnt++;
  }

  cout << cnt << endl;

  return 0;
}

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

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

    string s, r;
    int count = 0;
    for (auto i = a; i <= b; i++) {
        s = to_string(i);
        r = s;
        reverse(r.begin(), r.end());
        if(s == r) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(each) for each in input().split()]

money = 1000
stock = 0

for i in range(len(a)-1):
    if a[i] > a[i+1]:
        money += stock*a[i]
        stock = 0
    if a[i] < a[i+1]:
        stock += money//a[i]
        money -= (money//a[i])*a[i]

money += stock*a[-1]
print(money)

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

using namespace std;
using ll = long long;

int main() {
    ll n; cin >> n;
    string str = "";

    while (n != 0) {
        int r = n % 2;
        if (r < 0) r += 2;

        n = (n - r) / (-2);
        str += (char)(r + '0');
    }
    reverse(str.begin(), str.end());
    if (str == "") str = "0";
    cout << str << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
    const char *A = "A";
    const char *B = "B";

    int x, a, b;
    if (scanf("%d%d%d", &x, &a, &b) < 3) return 0;

    printf("%s\n", abs(x - a) <= abs(x - b) ? A : B);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
string d[N];
int n;
char ans[N];
void dfs(int i,int a,int b,int c){
  if(i>n && a>=0 &&b>=0&&c>=0){
    cout<<"Yes\n";
    for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
    exit(0);
  }
  if(d[i]=="AB"){
    if(b>=1){
      ans[i]='A';
      dfs(i+1,a+1,b-1,c);
    }
    if(a>=1){
      ans[i]='B';
      dfs(i+1,a-1,b+1,c);
    }
  }else if(d[i]=="AC"){
    if(c>=1){
      ans[i]='A';
      dfs(i+1,a+1,b,c-1);
    }
    if(a>=1){
      ans[i]='C';
      dfs(i+1,a-1,b,c+1);
    }
  }else{
    if(c>=1){
      ans[i]='B';
      dfs(i+1,a,b+1,c-1);
    }
    if(b>=1){
      ans[i]='C';
      dfs(i+1,a,b-1,c+1);
    }
  }
}
int a,b,c;

int main() {
  ios::sync_with_stdio(false);
  cin>>n>>a>>b>>c;
  for(int i=1;i<=n;i++){
    cin>>d[i];
  }
  dfs(1,a,b,c);
  cout<<"No\n";
  return 0;
}

Measured memory_bytes: 17824
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll N =1e5+5;
const ll mod = 1e9+7;
vector<ll> G[N];
ll w[N],b[N],n;

void dfs(ll v, ll p)
{
	w[v]=b[v]=1;
	for(ll i:G[v])if(i!=p){dfs(i,v);w[v]*=(w[i]+b[i]);b[v]*=w[i];w[v]%=mod;b[v]%=mod;}
}

int main()
{
    ios_base::sync_with_stdio(false);

	cin>>n;forn(i,n-1){ll u,v;cin>>u>>v;u--,v--;G[u].pb(v);G[v].pb(u);}
	dfs(0LL,0LL);
	cout<<(w[0]+b[0])%mod<<endl;
}


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

using namespace std;
using ll = long long;

#define endl "\n"
#define pb push_back

const int MAX = 10e5;

ll counter[MAX] = {0};

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

	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b));
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int>V;
	vector<int>x;
	int sum = 0;
	for (int i = 0; i < M; ++i) {
		int a;
		cin >> a;
		x.push_back(a);
	}
	sort(x.begin(), x.end());
	if (N >= M || M==1) {
		cout << 0 << endl;
	}
	else {
		for (int i = 0; i < M - 1; ++i) {
			V.push_back(x[i + 1] - x[i]);
		}
		sort(V.begin(), V.end());
		for (int i = 0; i < M-N; ++i) {
			sum += V[i];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1400
def check(x, y, data, num):
    high = 0
    check_data = []
    for i in range(num):
       if data[i][2] == 0:
           check_data.append(data[i])
           continue
       if high == 0:
           high = abs(x - data[i][0]) + abs(y - data[i][1]) + data[i][2]
       else:
           if high != abs(x - data[i][0]) + abs(y - data[i][1]) + data[i][2]:
               return 0
    for i in range(len(check_data)):
        high_now = high - abs(x - check_data[i][0]) - abs(y - check_data[i][1])
        if high_now > 0:
            return 0

    return high



if __name__ == '__main__':
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]

    if len(data) == 1:
        print(data[0][0], data[0][1], data[0][2])
    else:

        for i in range(101):
            for j in range(101):
                flg = check(i, j, data, num)
                if flg:
                    print(i, j, flg)
                    break
            if flg:
                break



Measured memory_bytes: 3064
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        ans += ((P[i][0]-P[j][0])**2 + (P[i][1]-P[j][1])**2)**(1/2)
print(ans*2/N)

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

int main() {
	stack<int>s;
	int n;
	while(cin>>n)
	{
		if(n)s.push(n);
		else
		{
			cout<<s.top()<<endl;s.pop();
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	string s;
	cin>>h>>w;
	int ans1, ans2;
	REP(i, h){
		REP(j, w){
			cin>>s;
			if(s=="snuke"){
				ans1=i;
				ans2=j;
			}
		}
	}
	cout<<(char)('A'+ans2)<<ans1+1<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans=0;
  for(int i=1;i<N;i++){
    string a=S.substr(0,i);
    string b=S.substr(i,N-i);
    sort(a.begin(),a.end());
    int cnt=0;
    for(int j=0;j<a.size();j++){
      if(j>0 && a[j]==a[j-1]){continue;}
      for(int k=0;k<b.size();k++){
        if(a[j]==b[k]){cnt++; break;}
      }
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int s, w;
  cin >> s >> w;
  if(w>=s)cout << "unsafe" << "\n";
  else cout << "safe" << "\n";
  return 0;
}


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

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
	return 0;
}

Measured memory_bytes: 256
<?php

$N = fgets(STDIN);
$A = split(" ", fgets(STDIN));
$cnt = 0;

for (;;) {
  $all_gu = true;

  for ($i=0; $i < $N; $i++) {
    if ($A[$i] %2 !== 0) {
      $all_gu = false;
      break;
    } else {
      $A[$i] = $A[$i] / 2;
    }
  }

  if (!$all_gu) {
    break;
  } else {
    $cnt++;
  }
}

echo $cnt . "\n";

?>


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int w;
    cin >> w;
    string a;
    if((int)s.size()%w !=0){
    for(int i=0;i<=((int)s.size())/w;i++){
        a+=s[i*w];
    }
    }else{
        for(int i=0;i<(int)s.size()/w;i++){
            a+=s[i*w];
        }
    }
    cout << a << endl;

}

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

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;
const int INFi = 2e9 + 1;
const lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto &(i) : (vec))


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


// 素数の真偽値表を返す : res.at(i) := 自然数 i が素数であるか
vector<bool> enumeration_primes(int n){
  vector<bool> res(n + 1, true); res.at(0) = false; res.at(1) = false;
  int edge = sqrt(n);
  for(int i = 2; i <= edge; i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i) res.at(j) = false;
    }
  }
  return res;
}

int count_prime(int n, int &p){
  if(n < p) return 0;
  return (n / p) + count_prime(n / p, p);
}

int main(void){
  int n; cin >> n;
  lli res = 1;
  vector<bool> is_prime = enumeration_primes(n);
  REP(i, n + 1) if(is_prime.at(i)) res = (res * (count_prime(n, i) + 1)) % MOD;
  cout << res << "\n";
  return 0;
}

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

typedef long long ll;

ll sum( vector<ll> X, ll b, ll N){
    ll sum = 0;
    for ( ll i = 0; i < N; ++i){
        sum += llabs(X[i]-b);
    }
    return sum;
}

int main() {
    int64_t N;
    cin >> N;
    vector<ll> A(N),B(N);
    for ( ll i = 0; i < N; ++i){
        cin >> A[i];
        B[i] = A[i] - (i+1);
    }
    
    sort(B.begin(),B.end());
    
    ll b1=0,b2=0;
    b1 = B[N/2];
    if ( N != 1 ) b2 = B[N/2+1];
    
    ll sum1 = sum(B,b1,N), sum2 = sum(B,b2,N);
    
    if ( sum1 > sum2 ) sum1 = sum2;

    cout << sum1 << endl;
    
    return 0;
}


Measured memory_bytes: 7980
#include<iostream>
#include<vector>
#include<math.h>
#include<map>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define INF int(1e9)
#define N 200000
#define MP make_pair
typedef pair<int, int> P;
typedef pair<pair<P, P>, P>PP;
long long int k;
long long int ans[50];
int main()
{
	cin >> k;
	for (int i = 0; i < 50; i++)
	{
		ans[i] -= k / 50;
	}
	for (int i = 0; i < k % 50; i++)
	{
		ans[i] -= 50 - k % 50 + 1;
	}
	for (int i = k%50; i < 50; i++)
	{
		ans[i] += k % 50;
	}
	for (int i = 0; i < 50; i++)
	{
		ans[i] = 49 - ans[i];
	}
	cout << 50 << endl;
	for (int i = 0; i < 50; i++)
	{
		if (i)
			cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#define ll long long
#define maxn 1000010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
struct edge{
	int to,nxt;
}e[maxn];
int fir[maxn],col[maxn],a[maxn],mark[maxn];
int n,tot;
void add_edge(int x,int y){e[tot].to=y; e[tot].nxt=fir[x]; fir[x]=tot++;}
void dfs(int now,int fa)
{
	for(int i=fir[now];~i;i=e[i].nxt)
		if(e[i].to!=fa){
			col[e[i].to]=!col[now];
			dfs(e[i].to,now);
		}
}
int main()
{
	n=read();
	memset(fir,255,sizeof(fir)); tot=0;
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add_edge(x,y); add_edge(y,x);
	}
	col[1]=0;
	dfs(1,-1);
	int cnt0=0,cnt1=0;
	for(int i=1;i<=n;i++)
		if(col[i])++cnt1;
		else ++cnt0;
	if(cnt0>cnt1){
		for(int i=1;i<=n;i++)
			col[i]=!col[i];
		std::swap(cnt0,cnt1);
	}
	// writesp(cnt0); writeln(cnt1);
	if(cnt0<=n/3){
		int cur0=3;
		for(int i=1;i<=n;i++)
			if(!col[i]){
				a[i]=cur0;
				mark[cur0]=1;
				cur0+=3;
			}
		int cur=1;
		for(int i=1;i<=n;i++)
			if(!a[i]){
				while(mark[cur])++cur;
				a[i]=cur++;
			}
	}
	else{
		int cur1=1,cur2=2;
		for(int i=1;i<=n;i++)
			if(!col[i]&&cur1<=n){
				a[i]=cur1;
				mark[cur1]=1;
				cur1+=3;
			}
			else if(col[i]&&cur2<=n){
				a[i]=cur2;
				mark[cur2]=1;
				cur2+=3;
			}
		int cur=1;
		for(int i=1;i<=n;i++)
			if(!a[i]){
				while(mark[cur])++cur;
				a[i]=cur++;
			}
	}
	for(int i=1;i<=n;i++)
		writesp(a[i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 25216
import math

## only rebel input techniques allowed.
input = str(input()).split(" ")
for index in range(len(input)):
    input[index] = int(input[index])
h, w, a, b = input[0], input[1], input[2], input[3]

## make an array of zeros
array = []
for index1 in range(h):
    row = []
    for index2 in range(w):
        row.append(0)
    array.append(row)

## okay so now we have an array of zeros
## and all we have to do is look at each row and column
def populate( h, w, a, b, array):
    rowCounter = []
    columnCounter = []
    for index in range(h):
        rowCounter.append(0)
    for index in range(w):
        columnCounter.append(0)

    for rowIndex in range(h):
        for colIndex in range(w):
            ## if after we add a one nothing is violated
            if ((rowCounter[rowIndex] < a or w  - rowCounter[rowIndex] > a) and (columnCounter[colIndex] < b or h - columnCounter[colIndex] > b)):
                array[rowIndex][colIndex] = 1
                rowCounter[rowIndex] += 1
                columnCounter[colIndex] += 1

    for element in rowCounter:
        if (min(element, w - element) != a):
            return -1
    for element in columnCounter:
        if (min(element, h - element) != b):
        ##if (element != b and h - elemet != b):
            return -1
    return array

def display(array):
    if (array == -1):
        print("-1")
        pass
    else:
        strings = []
        for row in array:
            string = ""
            for index in range(len(row)):
                if (index != len(row) - 1):
                    string += str(row[index])
                else:
                    string += str(row[index])
            strings.append(string)
        for element in strings:
            print(element)
##print("here")
"""
for h in range(1, 30):
    for w in range(1,30):
        for a in range(0, math.floor(w/2) + 1):
            for b in range(0, math.floor(h/2)+1):
                array = []
                for index1 in range(h):
                    row = []
                    for index2 in range(w):
                        row.append(0)
                    array.append(row)
                if (populate(h, w, a, b, array) == -1):
                    print(h,w,a,b)
"""
##print("done")
display(populate(h, w, a, b, array))
## we could also do this problem by splitting the array into two or four chuncks of ones and zeros
## but I cannot be bothered.


Measured memory_bytes: 13940
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
static const double pi = 3.141592653589793;

int main()
{
  int n, m;
  cin >> n >> m;
  
  vector<int> node[n];
  
  REP(i, m)
  {
    int a, b;
    cin >> a >> b;
    --a; --b;
    node[a].push_back(b);
    node[b].push_back(a);
  }
  
  queue<int> que;
  vector<int> count(n, -1);
  vector<int> dir(n, 0);
  count[0] = 0;

  que.push(0);
  while(!que.empty())
  {
    int x = que.front();
    que.pop();

    for(int index : node[x])
    {
      if(count[index] != -1)
      {
        continue;
      }
      count[index] = count[x] + 1;
      dir[index] = x + 1;
      que.push(index);
    }
  }
  
  REP(i, n)
  {
    if(count[i] == -1)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  REP(i, n - 1)
  {
    cout << dir[i + 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 10656
#include <cmath>
#include <cstring>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

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

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

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


double dp[N][N];

int main () {
    int n;cin>>n;
    double p;cin>>p;
    memset(dp,0,sizeof(dp));
    dp[1][1] = p;dp[1][0] = 1 - p;
    for (int i=2;i<=n;i++) {
    	cin>>p;
    	dp[i][0] = dp[i-1][0] * (1-p);
    	for (int j=i;j>0;j--) {
    		dp[i][j] = dp[i-1][j] * (1-p) + dp[i-1][j-1] * p;
    	}
    }
    double ans = 0;
    int m = (n+1)/2;
    for (int i=m;i<=n;i++) {
    	ans += dp[n][i];
    }
    printf("%.9lf\n",ans);
    return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

const int maxn=2e5+5;

int n;
bool l[maxn];
int br[maxn];
vector < int > sol;

void dodaj(int x){
	for(int i=1; i<=sqrt(x); i++){
		if(x%i==0){
			br[i]++;
			if(i!=x/i){
				br[x/i]++;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> l[i+1];
	}
	for(int i=n; i>0; i--){
		if(br[i]%2!=l[i]){
			sol.push_back(i);
			dodaj(i);
		}
	}
	sort(sol.begin(), sol.end());
	cout << sol.size() << '\n';
	for(int i=0; i<sol.size(); i++){
		cout << sol[i] << " ";
	}
	if(sol.size()){
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 2680
#include <cstdio>
#include <vector>
#define maxn 100010
using namespace std;

vector<int> V[maxn];
int n, u, v, dep[maxn], maxb;
void dfs(int u, int pre, int d) {
	dep[u] = d;
	int size = V[u].size();
	for (int i = 0; i < size; i++) {
		int v = V[u][i];
		if (v == pre) continue;
		dfs(v, u, d + 1);
	}
}
int updaten(int u, int x) {
	if (x == 0)
		return u;
	int size = V[u].size();
	for (int i = 0; i < size; i++) {
		int v = V[u][i];
		if (dep[v] == dep[u] - 1)
			return updaten(v, x - 1);
	}
}
void querymaxb(int u) {
	maxb++;
	int size = V[u].size();
	for (int i = 0; i < size; i++) {
		int v = V[u][i];
		if (dep[v] > dep[u])
			querymaxb(v);
	}
}
int main(void) {
	scanf("%d", &n);
	for (int i = 1; i <= n - 1; i++) {
		scanf("%d%d", &u, &v);
		V[u].push_back(v);
		V[v].push_back(u);
	}
	dfs(n, -1, 1);
	int x;
	if (dep[1] % 2)
		x = (dep[1] - 1) / 2;
	else
		x = (dep[1] - 2) / 2;
	maxb = 0;
	querymaxb(updaten(1, x));
	if (maxb > n - maxb)
		printf("Fennec");
	else
		printf("Snuke");
}

Measured memory_bytes: 12288
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<algorithm>
#include <cstring>
#include<set>
#include<cmath>
# define ll long long 
using namespace std;

int main()
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll cnt=0;
	for(int i=0;i<=(n-3);++i)
	{
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
			cnt++;
	}
	cout<<cnt<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef pair < int , int > Pi;
bool data[5001][5001];
bool isOK(int x,int y){
  return x >= 0 && x < 5001 && y >= 0 && y < 5001 && data[x][y];
}
int main(){
  int n;
  Pi p[3000];
  while(cin >> n , n){
    fill_n( *data, 5001 * 5001 , false);
    for(int i = 0 ; i < n ; i++ ){
      cin >> p[i].first >> p[i].second;
      data[p[i].first][p[i].second] = true;
    }
    int ret = 0;
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < i ; j++ ){
        int x = p[j].first - p[i].first;
        int y = p[j].second - p[i].second;
        if((isOK(p[i].first + y,p[i].second - x) & isOK(p[j].first + y,p[j].second - x))
          |(isOK(p[i].first - y,p[i].second + x) & isOK(p[j].first - y,p[j].second + x)))
          ret = max( ret, x * x + y * y);
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 25608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int N; cin >> N;
  bool ok = true;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {ok = false;}
  }
  if (ok) {cout << "APPROVED" << endl;}
  else {cout << "DENIED" << endl;}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	ll H[200001];
	scan(N>>K);
	rep(i,N){
		scan(H[i]);
	}
	sort(H,H+N);
	ll ans=0;
	rep(i,N-K){
		ans+=H[i];
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

k = int(input())

if k < 10:
    print(k)
    sys.exit()

k -= 9

a = [['00', '01'], ['10', '11', '12'], ['21', '22', '23'], ['32', '33', '34'], ['43', '44', '45'], ['54', '55', '56'], ['65', '66', '67'], ['76', '77', '78'], ['87', '88', '89'], ['98', '99']]

for i in range(1, 10):
    if k <= len(a[i]):
        print(a[i][k - 1])
        sys.exit()
    else:
        k -= len(a[i])

while True:
    a_ = [[] for _ in range(10)]
    for i in range(10):
        n = str(i)
        for j in range(i - 1, i + 2):
            if j < 0:
                continue
            if j > 9:
                continue
            for k_ in a[j]:
                a_[i].append(n + k_)
    a = a_
    #print(a)
    for i in range(1, 10):
        if k <= len(a[i]):
            print(a[i][k - 1])
            sys.exit()
        else:
            k -= len(a[i])

    




Measured memory_bytes: 49756
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
  int r,d,x,i;
  cin>>r>>d>>x;
  vector<int> v(11,0);
  v[0]=x;
  for(i=1;i<=10;i++)
  {
    v[i]=v[i-1]*r -d;
    cout<<v[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  int N,M;
  int sum_AC=0,sum_WA = 0;
  int temWs[100000];
  bool ACed[100000];
  int p;
  string str;
  cin >> N >> M;
  for(int i = 0;i<N;i++){
    temWs[i] = 0;
    ACed[i] = false;
  }
  for(int i=0;i<M;i++){
    cin >> p >> str;
    if(str.compare("AC") == 0){
      if(ACed[p-1] == false){
        sum_AC += 1;
        sum_WA += temWs[p-1];
        ACed[p-1] = true;
      }
    }else{
      temWs[p-1] += 1;
    }
  }
  printf("%d %d",sum_AC,sum_WA);
  return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());
    int T = Integer.parseInt(sc.next());
    int[] t = new int[N];

    for (int i = 0; i < N; i++) {
      t[i] = Integer.parseInt(sc.next());
    }

    int cnt = 0;
    int tmp = 0;
    for (int i = 0; i < N; i++) {
      if (t[i] < tmp) {
        cnt += t[i] - t[i - 1];
        tmp = t[i] + T;
      } else {
        cnt += T;
        tmp = t[i] + T;
      }
    }

    System.out.println(cnt);
    sc.close();
  }
}

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

int n, ss[303030][2];
string s;

int main()
{
    cin >> n >> s;
    rep(i, n)
    {
        if(s[i] == 'W')
        {
            ss[i][0]++;
        }
        ss[i + 1][0] = ss[i][0];
    }
    for (int i = n - 1; i > 0; i--)
    {
        if(s[i] == 'E')
        {
            ss[i][1]++;
        }
        ss[i - 1][1] = ss[i][1];
    }
    
    int res = min(ss[1][1], ss[n - 1][0]);
    for(int i = 1; i < n - 1; i++)
    {
        res = min(res, ss[i - 1][0] + ss[i + 1][1]);
    }
    cout << res << endl;
    
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    bool ans = true;
    if(s.size()%2==1)ans=false;
    else
    rep(i,s.size()/2){
        if(!(s[2*i]=='h'&&s[2*i+1]=='i'))
        ans=false;
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanRunes()
	t := scanRunes()

	ans := []string{}
	for i := 0; i < len(s)-len(t)+1; i++ {
		f := true
		ss := make([]rune, len(s))
		copy(ss, s)

		for j := 0; j < len(t); j++ {
			if s[i+j] != t[j] && s[i+j] != '?' {
				f = false
				break
			} else {
				ss[i+j] = t[j]
			}
		}
		if f {
			ans = append(ans, strings.Replace(string(ss), "?", "a", -1))
		}
	}
	sort.Strings(ans)
	if len(ans) == 0 {
		fmt.Fprintln(wr, "UNRESTORABLE")
	} else {
		fmt.Fprintln(wr, ans[0])
	}
}


Measured memory_bytes: 1816
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	
	string s;
	cin >> s;

	int n = s.size();

	cout << string(n, 'x') << endl;

	return 0;
}

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

int main(void){

    int N;
    cin>>N;

    int i=1;
    int count=0;
    while(i<=N){

        if(int(log10((double)i)+1) % 2 == 0){
            i++;
            continue;
        }
        count++;
        i++;
    }
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

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

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

	ll n, x;
	cin>>x>>n;
	ll a[n];
	set<int> s;
	s.insert(0);
	for(int i=0;i<=100;i++){
		s.insert(i+1);
	}
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		s.erase(s.find(a[i]));
	}
//	sort(a, a+n);
	ll mi = INT_MAX;
	ll op=0;
	for(ll ai : s){
		if(abs(ai-x)<mi){
			op = ai;
			mi = abs(ai-x);
		}
		else if(abs(ai-x)==mi){
			op = min(op, ai);
		}
	}
	cout<<op;

	return 0;
}

Measured memory_bytes: 3672
#include <cstdio>
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <string>

using namespace std;
using ll = long long;

ll L;
vector<ll> A;

void input() {
    cin >> L;
    A.resize(L);
    for (auto& a : A)
        cin >> a;
}

void solve() {
    array<array<ll, 4>, 2> dp;
    {
        auto f = A[0];
        bool odd = f % 2;
        bool nonzero = f > 0;
        dp[0] = {
            odd ? 1 : (nonzero ? 0 : 2),
            odd ? 0 : 1,
            odd ? 1 : (nonzero ? 0 : 2),
            f
        };
    }
    ll sum = A[0];
    for (ll i = 1; i < L; i++) {
        bool odd = A[i] % 2 == 1;
        bool nonzero = A[i] > 0;
        auto& cdp = dp[i%2];
        auto& pdp = dp[(i-1)%2];
        ll tmp;
        cdp[0] = (tmp = min(sum, pdp[0])) + (odd ? 1 : (nonzero ? 0 : 2));
        cdp[1] = (tmp = min(tmp, pdp[1])) + (odd ? 0 : 1);
        cdp[2] = (tmp = min(tmp, pdp[2])) + (odd ? 1 : (nonzero ? 0 : 2));
        cdp[3] = (tmp = min(tmp, pdp[3])) + A[i];
        sum += A[i];
    }
    auto& bdp = dp[(L-1)%2];
    ll ans = *min_element(bdp.begin(), bdp.end());
    cout << ans << endl;
}

int main() {
    input();
    solve();
    
    return 0;
}



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

using namespace std;

int main(void){
    string S;
    cin >> S;

    string test[] = {
        "KIHBR",
        "KIHBRA",
        "KIHBAR",
        "KIHBARA",
        "KIHABR",
        "KIHABRA",
        "KIHABAR",
        "KIHABARA",
        "AKIHBR",
        "AKIHBRA",
        "AKIHBAR",
        "AKIHBARA",
        "AKIHABR",
        "AKIHABRA",
        "AKIHABAR",
        "AKIHABARA",
    };

    for(int i=0;i<16;i++){
        if(test[i] == S){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256