akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;(i)<(n);++(i))
using namespace std;

// Description: ????????????
// Verifyed: various problem 
using namespace placeholders;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P c;R r;};

auto& operator >> (istream& is,P& p){ R x,y; is >> x >> y,p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline P vec(L l){return l.t-l.s;}
auto sdot = bind(sgn,bind(dot,_1,_2,_3));
auto sdet = bind(sgn,bind(det,_1,_2,_3));

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/vec(l)); return (1-u)*l.s+u*l.t;}
// Polygon
#define at(a,i) (a[(i + a.size()) % a.size()])


// farthest point pair Verify AOJ CGL_4_B
R fpp(VP pol){
	int n=pol.size(),i=0,j=0;
	if(n<=2) return abs(pol[0]-pol[1]);
	R res=0.0;

	auto cmp_x=[](P a,P b)->bool{
		int sr = sgn(real(a-b)), si = sgn(imag(a-b));
		return sr ? sr < 0 :si < 0;
	};
	
	rep(k,n){
		if(!cmp_x(pol[i],pol[k]))i=k;
		if(cmp_x(pol[j],pol[k]))j=k;
	}

	int si=i,sj=j;
	while(i!=sj||j!=si){
		res = max(res,abs(pol[i]-pol[j]));
		if(sdet(0,vec(L{at(pol,i),at(pol,i+1)}),vec(L{at(pol,j),at(pol,j+1)}))<0)
			i=(i+1)%n;
		else 
			j=(j+1)%n;
	}
	return res;
}

int main(void){
	int n;
	cin >> n;
	VP pol;
	rep(i,n){
		P p;
		cin >> p;
		pol.push_back(p);
	}
	cout.precision(10);
	cout << fixed << fpp(pol) << endl;
	return 0;
}

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



using namespace std;

#define int long long int
#define loop(i,s,e) for(int i=s; i<e; i++)
#define endl '\n'
#define vii vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX
#define M (int)(1e9+7)

void INP();

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
int arr[22][22];
int n;
int dp[22][(1<<22)];

int util(int i, int mask){

	if(i<0 and mask==0) return 1;
	if(i<0) return 0;
	//if(i + 1 < __builtin_popcount(mask)) return dp[i][mask] = 0;

	if(dp[i][mask]!=-1) return dp[i][mask];

	int ans=0;
	loop(j,0,n){
		if(arr[i][j]==1 and (mask & (1<<j))){
			int nmask = (mask ^ (1<<j));
			ans += util(i-1, nmask);
			ans%=M;
		}
	}

	return dp[i][mask] = ans;
	
}

void alpha()
{	
	cin>>n;

	memset(dp, -1, sizeof(dp));

	loop(i,0,n){
		loop(j,0,n){
			cin>>arr[i][j];
		}
	}

	cout<<util(n - 1, (1 << n) - 1)<<endl;

	return;
}

int32_t main(){

	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//INP();
    int t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}






















inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}
 
 

Measured memory_bytes: 721152
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean[] a = new boolean[3];
        for (int i = 0; i < 2; i++) {
            a[sc.nextInt() - 1] = true;
        }
        for(int i = 0; i < 3; i++) {
            if (!a[i])
                System.out.println(i + 1);
        }
    }
}

Measured memory_bytes: 24020
#include<bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979323846
#define mod 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll int h=pow(10,6)+1;
int main(){
	fast;
	
	bool bl[h];
	for(int i=0;i<h;i++)
	bl[i]=true;
	
	bl[0]=bl[1]=false;
	
	for(int i=4;i<h;i+=2)
	bl[i]=false;
	
	for(ll int i=3;i*i<=h;i+=2){
		if(bl[i]==true){
			for(ll int j=i*i;j<h;j+=2*i){
				bl[j]=false;
			}
		}
	}
	
	ll int x;
	cin>>x;
	
	for(int i=x;i<h;i++){
		if(bl[i]==true){
			cout<<i;
			break;
		}
	}
	
	return 0;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  
  // 文字列の切り替わり(1or0)のindexを取得
  vector<int> IDX;
  IDX.push_back(0);
  for(int i = 0; i < N - 1; i++){
    if( S[i+1] != S[i] ){ IDX.push_back(i+1); }
  }
  IDX.push_back(N); // 終端文字のindexを追加
  
  vector<int> Cnts;
  int k, idx;
  
  for(auto i = IDX.begin(); i < IDX.end(); i++){
    //cout << *i << " ";
    
    if( S.compare(*i, 1, "1") == 0 ){ k = 2 * K + 1; }
    else if( S.compare(*i, 1, "0") == 0 ){ k = 2 * K; }
    
    // 範囲外アクセス防止
    idx = distance( IDX.begin(), i );
    if( idx + 1 + k > IDX.size() ){ k = IDX.size() - (idx + 1); } 
    //cout << k << " ";
    
    Cnts.push_back( *(i + k) - *i );
  }
 
  int max = *max_element( Cnts.begin(), Cnts.end() );
  cout << max;
  
  return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>N;
    vec p(N), pinv(N);
    rep(i,N){
        cin>>A;
        --A;
        p[i] = A;
        pinv[A] = i;
    }
    set<ll> big;
    mat memo(N,vec(2,0));
    ll  a, b, c, d, ans = 0;
    for(int i = N-1; i >= 0; --i){
        ll now = pinv[i];
        big.insert(now);
        auto ite = big.find(now);
        b = (ite == big.begin()) ? -1 : *(--ite);
        a = (ite == big.begin()) ? -1 : *(--ite);
        ite = big.find(now);
        c = ((++ite) == big.end()) ? N : *ite;
        if(ite == big.end()) --ite;
        d = ((++ite) == big.end()) ? N : *ite;
        ans += (i + 1) * ((b - a) * (c - now) + (now - b) * (d - c));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12032
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(i,p,q) for(ll i = p;i < q;++i)
#define ll long long

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll npk(ll n, ll k) {
	ll ret = 1;
	if (n < k || n < 0)return 0;
	rep(i, 0, k) {
		ret *= (n - i);
		ret %= MOD;
	}
	if (ret < 0) ret = 0;
	return ret;
}

//E	
int main(void) {
	ll n, k;
	cin >> n >> k;
	vector<vector<ll>> graph = vector<vector<ll>>(n, vector<ll>());
	rep(i, 0, n - 1) {
		ll a, b;
		cin >> a >> b;
		--a;
		--b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	ll count = k;
	count *= npk(k - 1, graph[0].size());
	count %= MOD;
	vector<ll> watched = vector<ll>(n, 0);
	watched[0] = 1;
	stack<ll> st = stack<ll>();
	rep(i, 0, graph[0].size()) {
		st.push(graph[0][i]);
		watched[graph[0][i]] = 1;
	}
	while (st.size() > 0) {
		ll v = st.top();
		st.pop();
		ll nVis = 0;
		rep(i, 0, graph[v].size()) {
			ll nbr = graph[v][i];
			if (watched[nbr] == 0) {
				nVis++;
				st.push(nbr);
				watched[nbr] = 1;
			}
		}
		count *= npk(k - 2, nVis);
		count %= MOD;
	}
	cout << count << endl;
}


Measured memory_bytes: 8052
import java.util.Scanner;

class Main{
  public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);
    //入力の受け取り
    int x = scanner.nextInt();
    //xが 3 OR 5 OR 7なら
    if(x == 3 || x == 5 || x == 7){
      System.out.println("YES");
    //そうでなければ
    }else{
      System.out.println("NO");
    }
  }
}

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

int main(){
    int n;
    cin >> n;
    long long int sum = 0, mini = LLONG_MAX;
    for(int i=0;i<n;++i){
        long long int a, b;
        cin >> a >> b;
        sum += a;
        if(a > b)mini = min(mini, b);
    }

    cout << (mini != LLONG_MAX ? sum - mini : 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,s,a;
	s = 0;
	for(i = 1;i < 10;i++){
		for(s = 1;s<10;s++){
			a = i*s;
			printf("%dx%d=%d\n",i,s,a);
		}
	}
	return 0;
}
	

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

int main() {
    int n, x;
    cin >> n;
    while (n--) {
        int a = 0, b = 0;
        bool ok = true;
        for (int j=0; j<10; ++j) {
            cin >> x;
            if (a < x && b < x) {
                if (a < b) {
                    b = x;
                } else {
                    a = x;
                }
            } else if (a < x) {
                a = x;
            } else if (b < x) {
                b = x;
            } else {
                ok = false;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
int main(){
	int d,t,s;
	cin>>d>>t>>s;
	if(t*s>=d)
	cout<<"Yes";
	else
	cout<<"No";
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(){
    long long n ;
    cin >> n;
    long long c=0;
    long long m;
    for (long long i = 1 ;  i <=n ;i++){
        cin >> m;
        if (i%2==1 && m%2==1){
            c++;
        }
    }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int a,b,c,i,d,f,g;
	string A,B,C;
	cin>>a>>b>>c;

	if(a+b>=c){
		cout<<"Yes"<<endl;
	}else{

	cout<<"No"<<endl;
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    bool a = false;
    rep(i, 0, n) {
        char s;
        cin >> s;
        if (s == 'Y') {
            a = true;
            break;
        }
    }
    cout << (a ? "Four" : "Three") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int A[1000000];

int insertionSort(int n, int g) {
	int cnt = 0;
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
	return cnt;
}

void shellSort( int n) {
	int cnt = 0;
	vector<int> G;
	for (int i = 1;;) {
		if (i > n) break;
		G.push_back(i);
		i = i * 3 + 1;
	}
	for (int i = G.size() - 1; i >= 0;i--) {
		cnt += insertionSort( n, G[i]);
	}

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		cout << G[i];
		if (i) cout << " ";
	}
	cout << endl << cnt << endl;
	for (int i = 0; i < n; i++) {
		cout << A[i] << endl;
	}
}
int main(void) {
	int n;
	cin >> n;

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

	shellSort( n);
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, k, h[N], mem[N];

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

	cin >> n >> k;

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

	for (int i = n - 2; i >= 0; i--) {
		mem[i] = INT_MAX;
		for (int j = 1; j <= k; j++) {
			if (i + j >= n) break;
			int a = mem[i + j] + abs(h[i] - h[i + j]);
			mem[i] = min(mem[i], a);
		}
	}

	cout << mem[0] << '\n';
	
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include<string.h>

int main()
{
  char s[27]={};
  int i,j;
  
 scanf("%s",s);
  
  for(i=0;i<strlen(s);i++)
  {
    for(j=i+1;j<strlen(s);j++)
    {
      if(s[i]==s[j])
      {
        printf("no\n");
        return 0;
      }
    }
  }
  printf("yes\n");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    int n, i, s = 100000;

    scanf("%d", &n);
    for (i = 0; i < n; ++i)
        s = (int)((s * 1.05 + 999) / 1000) * 1000;
    printf("%d\n", s);

    return 0;
}

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, m, x;
map<int, int> M;

void gg(){
	printf("NO\n");
	exit(0);
}

int main(){
	scanf("%d", &n);
	FI(i, 1, n){
		scanf("%d", &x);
		if(!M.count(x)) M[x] = 1;
		else M[x]++;
	}
	scanf("%d", &m);
	FI(i, 1, m){
		scanf("%d", &x);
		if(!M.count(x)) gg();
		else if(M[x] == 0) gg();
		else M[x]--;
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
#import <Foundation/Foundation.h>

int main() {
  
  int X, K;
  
  scanf("%d %d", &K, &X);
  
  int left = MAX(-1000000, X - K + 1);
  int right = left + 2 * K - 2;
  NSInteger i;
  for (i=left; i<=right; i++) {
    printf("%d ", i);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <cassert>
#include <time.h>
#include <numeric>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define ll long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i, a, b) for(int i = a; i < b; i++)


#define trarr(a,n) forn(i,0,n) cerr<<a[i]<<" \n"[i==n-1];
#define trmat(g,n,m) forn(i,0,n)forn(j,0,m) cerr<<g[i][j]<<" \n"[i==m-1];
#define tr(...) cerr<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = acos(-1);
const ld EPS = 1e-9;
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int P = 1e9+7;
const int N = 3e3+10;

void solve(int _t){
	int n;
	cin >> n;
	ll a[n];
	rep(i, 0, n) cin >> a[i];
	ll dp[N][N][2] = {0ll};
	rep(i, 0, n) rep(j, 0, n){
		dp[i][j][0] = 0;
		dp[i][j][1] = INF;
	}
	rep(i, 0, n){
		dp[i][i][0] = a[i];
		dp[i][i][1] = -a[i];
	}
	rep(l, 2, n+1){
		rep(i, 0, n-l+1){
			int j = i+l-1;
			dp[i][j][0] = max({a[i]+dp[i+1][j][1], a[j]+dp[i][j-1][1]});
			dp[i][j][1] = min({dp[i+1][j][0]-a[i], dp[i][j-1][0]-a[j]});
		}
	}
	cout<<dp[0][n-1][0]<<endl;
}	
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	// cin >> t;
	rep(test, 1, t+1){
		solve(test);
	}
	return 0;
}

Measured memory_bytes: 145200
n,s = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
MOD =998244353
dp = Array.new(n+1).map{Array.new(s+1,0)}
dp[0][0] = 1
for i in 1..n
  for j in 0..s
    if j - a[i-1] >= 0
      dp[i][j] = (dp[i-1][j]*2+dp[i-1][j-a[i-1]])%MOD
    else
      dp[i][j] = (dp[i-1][j]*2)%MOD
    end
  end
end
puts dp[n][s]%MOD

Measured memory_bytes: 84660
N,K = map(int, input().split())
p = list(map(int, input().split()))
p = list(map(lambda x:(x+1)/2, p))
temp = []
p_sum=0
for i in range(N):
    p_sum+=p[i]
    temp.append(p_sum)
ans = []
for j in range(K,N):
    ans.append(temp[j]-temp[j-K])
if len(ans) != 0:
    print(max(ans))
else:
    print(p_sum)

Measured memory_bytes: 25060
s = input()
now = []

for i in s:
    if i == '0':
        now.append(0)
    elif i == '1':
        now.append(1)
    else:
        if len(now) == 0:
            continue
        else:
            now.pop(-1)
for i in now:
    print(i, end="")

Measured memory_bytes: 38384
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int M = Integer.parseInt(S[1]);
    
    String[] T = sc.nextLine().split(" ");
    int now = 0;
    int ans = 0;
    for(int i = 0; i < N; i++){
      int sec = Integer.parseInt(T[i]);
      if(now + M > sec && i != 0){
        ans += sec - now;
        now = sec;
      }else{
        ans += M;
        now = sec;
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[3][3];
    for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) {
        cin >> a[i][j];
    }
    int n;
    cin >> n;
    while (n--) {
        int x;
        cin >> x;
        for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) if (a[i][j] == x) a[i][j] = 0;
    }
    
    bool an = false;
    for (int i = 0; i < 3; ++i) {
        bool ok = true;
        for (int j = 0; j < 3; ++j) {
            if (a[i][j] != 0) ok = false;
        }
        if (ok) an = true;
    }
    for (int j = 0; j < 3; ++j) {
        bool ok = true;
        for (int i = 0; i < 3; ++i) {
            if (a[i][j] != 0) ok = false;
        }
        if (ok) an = true;
    }
    if (!a[0][0] && !a[1][1] && !a[2][2]) an = true;
    if (!a[2][0] && !a[1][1] && !a[0][2]) an = true;
    cout << (an ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main(){
	string t, w;
	int count = 0;
	cin >> w;
	for(int i= 0; i < (int)w.size(); i++){
		w[i] = toupper(w[i]);
	}
	
	while(1){
		cin >> t;
		if(t.find("END_OF_TEXT") != string::npos) break;
		
		for(int i = 0; i < (int)t.size(); i++){
			t[i] = toupper(t[i]);
		}
		if(t == w) count++;
		
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 3176
#include <stdio.h>

int main(void){
        int i, j, k, h[10000], w[10000], sum=0;
        for(k=0;k<10000;k++){
                scanf("%d %d", &h[k], &w[k]);
                if(h[k]==0 && w[k]==0)
                        break;
                sum++;
        }
        for(k=0;k<sum;k++){
                for(i=0;i<h[k];i++){
                        for(j=0;j<w[k];j++)
                                putchar('#');
                        putchar('\n');
                }
                putchar('\n');
        }
        return 0;
}


Measured memory_bytes: 2032
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

const int maxn = 1e6 + 7;

int main() {
    LL a,b,k;
    while(cin >> a >> b >> k) {
        if(a >= k) {
            cout << a-k << " " << b << endl;
        } else {
            cout << 0 << " " << max(b - (k-a) , 0LL) << endl;
        }
    }
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

lli extgcd(lli a, lli b, lli& x, lli& y)
{
  lli g = a;
  x = 1;
  y = 0;
  if (b != 0) {
    g = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  return g;
}

lli mod_inverse(lli a, lli m)
{
  lli x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

constexpr lli mod = 1e9 + 7;
constexpr int N = min<lli>(mod, 100000 + 5);
lli fact[N]; // P.263

template<typename T, typename U>
T mod_fact(T n, U p, U &e)
{
  e = 0;
  if (n == 0) return 1;

  T res = mod_fact(n / p, p, e);
  e += n / p;
  if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
  return res * fact[n % p] % p;
}

// nCk mod P O(n log p )
lli mod_comb(lli n, lli k, lli p = mod)
{
  if (n < 0 || k < 0 || n < k) {
    return 0;
  }
  lli e1, e2, e3;
  lli a1 = mod_fact(n, p, e1);
  lli a2 = mod_fact(k, p, e2);
  lli a3 = mod_fact(n - k, p, e3);
  if (e1 > e2 + e3) {
    return 0;
  }
  return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

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

  fact[0] = 1;
  for (int i = 1; i < N; ++i) {
    fact[i] = (fact[i - 1] * i) % mod;
  }

  lli n;
  while (cin >> n) {
    ++n;
    vector<int> a(n);
    each (i, a) cin >> i;
    int mn = 0;
    int mx = 0;
    {
      map<int, int> idx;
      for (int i = 0; i < a.size(); ++i) {
        if (idx.count(a[i])) {
          mn = idx[a[i]];
          mx = i;
          break;
        }
        idx[a[i]] = i;
      }
    }

    const int x = mn;
    const int y = mx - mn - 1;
    const int z = n - 2 - x - y;

    cout << n - 1 << endl;
    for (int i = 2; i <= n; ++i) {
      lli m = mod_comb(n, i);
      if (0 < x + z && i - 1 <= x + z) {
        m = (m - mod_comb(x + z, i - 1) + mod) % mod;
      }
      cout << m << endl;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 7040
use proconio::input;
#[allow(unused_mut)]
fn main() {
    input! {
        s: String,
    }
    let res = match s.as_str() {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => unreachable!(),
    };
    println!("{}", res);
}


Measured memory_bytes: 2156
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

int main(){
  // startupcpp();
  ll i,ok,ng=-1,mid,ch,f;
  string s;
  cin>>s;
  ok=s.size()-1;
  while(ok-ng>1){
    mid=(ok+ng)>>1;++mid;
    f=0;
    vec cnt(26,0);
    rep(i,mid){
      ++cnt[s[i]-'a'];
      f|=1<<(s[i]-'a');
    }
    ch=f;
    while(i<(int)s.size()){
      ++cnt[s[i]-'a'];
      f|=1<<(s[i]-'a');
      if(--cnt[s[i-mid]-'a']==0){
        f^=1<<(s[i-mid]-'a');
      }
      ch&=f;
      ++i;
    }
    --mid;
    if(ch){
      ok=mid;
    }else{
      ng=mid;
    }
  }
  print(ok);
}

Measured memory_bytes: 256
// AOJ 1100
#include<cstdio>
#include<cmath>
#include<utility>
#define rep(i,a) for(int i=0;i<(a);++i)

typedef std::pair<int, int> P;

int n;
P pts[50];

int cross( const P &a, const P &b )
{ return a.first*b.second-a.second*b.first; }

int main()
{
	int t = 0;
	while( scanf( "%d", &n ), n )
	{
		rep( i, n )
		{
			int x, y;
			scanf( "%d%d", &x, &y );
			pts[i] = P( x, y );
		}

		double area = 0;
		rep( i, n )
			area += cross( pts[i], pts[(i+1)%n] )/2.0;
		++t;
		printf( "%d %.1f\n", t, fabs(area) );
	}

	return 0;
}

Measured memory_bytes: 1064
#include<stdio.h>
#include<math.h>
long long int w[110],v[110],f[110][100010];
long long int knapsack(int W,int n)
{
    if(f[n][W]==-1)
    {
        if(W==0 || n==0)
        return f[n][W]=0;
        if(w[n]>W)
        return f[n][W]=knapsack(W,n-1);
        else
        return f[n][W]=fmax((v[n]+knapsack(W-w[n],n-1)),knapsack(W,n-1));
    }
    else
    return f[n][W];
}
int main()
{
    long long int i,W,n,ans,j;
    scanf("%lld%lld",&n,&W);
    for(i=1;i<=n;i++)
    scanf("%lld%lld",&w[i],&v[i]);
    for(i=0;i<=n;i++)
    for(j=0;j<=W;j++)
    f[i][j]=-1;
    ans=knapsack(W,n);
    /*for(i=0;i<=n;i++)
    {for(j=0;j<=W;j++)
    {printf("%lld\t",f[i][j]);}printf("\n");}
    printf("\n\n");*/
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 80000
import java.util.Scanner;
import java.math.BigInteger;
class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       BigInteger a = sc.nextBigInteger();
       BigInteger b = sc.nextBigInteger();
       int result = a.compareTo(b); //compareTo
       if(result==1) {
       System.out.println("GREATER");
       }
       else if (result== -1) {
       System.out.println("LESS");
       }
       else {
       System.out.println("EQUAL");
       }
       
 }
 }          

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int x;
	vector<string> v;
	
	cin >> x;

	for(int i = 0; i < x; i++) {
		int data[3];
		for(int j = 0; j < 3; j++)
			cin >> data[j];
		sort(data, data + 3);

		if(data[2]*data[2] == data[0]*data[0] + data[1]*data[1]) {
			v.push_back("YES");
		} else {
			v.push_back("NO");
		}
	}

	for(int i = 0; i < v.size(); i++) {
		cout << v[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll h,w,n;cin>>h>>w>>n;
    map<pll,ll> mp;
    rep(i,0,n){
        ll a,b;cin>>a>>b;
        rep(j,a-2,a+1){
            rep(k,b-2,b+1){
                if(j<=0||k<=0)continue;
                if(j+2>h||k+2>w)continue;
                mp[{j,k}]++;
            }
        }
    }
    ll ans[10];
    fill(ans,ans+10,0);
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        //cout<<itr->first.first<<" "<<itr->first.second<<endl;
        ans[itr->second]++;
    }
    ll sum=(h-2)*(w-2);
    rep(i,1,10)sum-=ans[i];
    ans[0]=sum;
    rep(i,0,10)cout<<ans[i]<<endl;
}


Measured memory_bytes: 56576
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

string three[3] = {
    "aa.",
    "..b",
    "..b"
};
string four[4] = {
    "aacd",
    "bbcd",
    "efgg",
    "efhh"
};
string five[5] = {
    "aagjj",
    "bbg.i",
    "cchhi",
    "..def",
    "..def"
};
string seven[7] = {
    "aa.bb.c",
    ".kki..c",
    "hlli...",
    "h...jjd",
    "....nmd",
    "g...nm.",
    "g.ff.ee"
};

void embedthree(int a, vector<string> &A) {
    rep(i, a, a + 3) {
        rep(j, a, a + 3) {
            A[i][j] = three[i - a][j - a];
        }
    }
}

void embedfour(int a, vector<string> &A) {
    rep(i, a, a + 4) {
        rep(j, a, a + 4) {
            A[i][j] = four[i - a][j - a];
        }
    }
}

void embedfive(int a, vector<string> &A) {
    rep(i, a, a + 5) {
        rep(j, a, a + 5) {
            A[i][j] = five[i - a][j - a];
        }
    }
}

void embedseven(int a, vector<string> &A) {
    rep(i, a, a + 7) {
        rep(j, a, a + 7) {
            A[i][j] = seven[i - a][j - a];
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    if(N == 2) {
        output(-1);
        return 0;
    }
//    if(N == 3) {
//        output("aa.");
//        output("..b");
//        output("..b");
//        return 0;
//    }
    
    vector<string> ans(N);
    string s = "";
    rep(i, N) s += '.';
    rep(i, N) ans[i] = s;
    
    if (N % 3 == 0) {
        int cur = 0;
        rep(i, N / 3) {
            embedthree(cur, ans);
            cur += 3;
        }
        rep(i, N) {
            output(ans[i]);
        }
        return 0;
    }
    
    rep(fours, 1000) rep(fives, 1000) {
        int rem = N - 4 * fours - 5 * fives;
        if(rem >= 0 && rem % 7 == 0) {
            int sevens = rem / 7;
//            cout << fours << "," << fives << "," << sevens << endl;
            int cur = 0;
            rep(i, fours) {
                embedfour(cur, ans);
                cur += 4;
            }
            rep(i, fives) {
                embedfive(cur, ans);
                cur += 5;
            }
            rep(i, sevens) {
                embedseven(cur, ans);
                cur += 7;
            }
            rep(i, N) {
                output(ans[i]);
            }
            return 0;
        }
    }
    
    
    
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

int main() {
	rep(i, 3) {
		rep(j, 3) {
			cin >> bingo[i][j];
		}
	}
	int n;
	cin >> n;
	vector<int>b(n);
	rep(i, n) {
		cin >> b[i];
	}
	bool ans = false;
	rep(i, 3) {
		rep(j, 3) {
			rep(k, n) {
				if (b[k] == bingo[i][j])flag[i][j] = true;
			}
		}
	}
	rep(i, 3) {
		if (flag[i][0] == true && flag[i][1] == true && flag[i][2] == true)ans = true;
		if (flag[0][i] == true && flag[1][i] == true && flag[2][i] == true)ans = true;
		if (flag[0][0] == true && flag[1][1] == true && flag[2][2] == true)ans = true;
		if (flag[2][0] == true && flag[1][1] == true && flag[0][2] == true)ans = true;
	}
	if (ans)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;

namespace ALDS1_2_C {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            string[] A = Console.ReadLine().Split(' ');
            string[] B = (string[])A.Clone();

            // BubbleSort(A)
            for (int i = 0; i < n; i++) {
                for (int j = n - 1; j > i; j--) {
                    if (A[j][1] < A[j - 1][1]) {
                        string temp = A[j];
                        A[j] = A[j - 1];
                        A[j - 1] = temp;
                    }
                }
            }

            // SelectionSort(B)
            for (int i = 0; i < n; i++) {
                int minj = i;
                for (int j = i; j < n; j++) {
                    if (B[j][1] < B[minj][1])
                        minj = j;
                }
                string temp = B[i];
                B[i] = B[minj];
                B[minj] = temp;
            }
            
            Print(A);
            Console.WriteLine("Stable");
            Print(B);
            Console.WriteLine(B.SequenceEqual(A) ? "Stable" : "Not stable");
        }

        static void Print(string[] arr) {
            StringBuilder sb = new StringBuilder();
            sb.Append(arr[0]);
            for (int i = 1; i < arr.Length; i++) {
                sb.AppendFormat(" {0}", arr[i]);
            }
            Console.WriteLine(sb.ToString());
        }
    }
}

Measured memory_bytes: 9288
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <stack>
using namespace std;
#define ll int64_t
const long mod = 1e9 + 7;


const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}




int main() {

  long n, k;
  string s;

  cin >> n >> k;
  cin >> s;

  // なんとなくdpっぽい

  // dp[i] = i回までの指示で逆立ちさせる人を並ばせる最大の数のstring
  // dp[i] = i人目までで逆立ちさせる人を並ばせる最大の数のstring

  //局所最適性はあるのか？

  //左から白いポイントをvector<long>に保存する

  vector<long> p;
  if (s[0] == '0')p.push_back(0);
  for (int i = 1; i < n; ++i) {
    if (s[i - 1] == '1' && s[i] == '0') {
      p.push_back(i);
    }
  }

  //pは最大10^5こ
  vector<pair<long, long>> lb(p.size());
  for (int i = 0; i < p.size(); ++i) {
    long lp = 0;

    for (int k = p[i] - 1; k >= 0; k--) {
      // cerr << k <<[k] << "," ;
      if (s[k] == '0') {
        lp = k + 1;
        break;
      }
    } cerr << endl;

    long rp = 0;
    bool isz = false;
    bool fnd = false;
    for (int k = p[i] + 1; k < n; k++) {
      if (s[k] == '0') {
        if (isz == true) {
          rp = k - 1;
          fnd = true;
          break;
        }
      }
      if (s[k] == '1') {
        isz = true;
      }
    }
    if (!fnd)rp = n - 1;

    lb[i] = make_pair( lp, rp  );
  }

  for (int i = 0; i < p.size(); i++) {
    cerr << p[i] << " left " << lb[i].first << " right " << lb[i].second << endl;
  }


  long ans = 0;
  k--;
  long i = 0;
  if (i + k >= p.size()) {
    ans = n;
  }


  for (int i = 0; i + k < p.size(); ++i) {
    long tmp = 0;
    tmp = lb[i + k].second - lb[i].first + 1 ;
    if (tmp > ans) {
      ans = tmp;
    }
  }





  cout << ans << endl;

}




















Measured memory_bytes: 1656
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

using Pii = pair<int, int>;

constexpr int INF = 1 << 30;

template<typename T>class BIT {
    public:
    int n;
    vector<T> bit;
    
    BIT(int n): n(n){
        bit.resize(n);
        fill(bit.begin(), bit.end(), (T)0);
    }

    void add(int idx, T x){
        for(int i=idx;i<=this->n;i+=i&-i) bit[i] += x;
    }

    //bit[1]からbit[end]までの和 (閉区間)
    T sum(int end){
        T ret = (T)0;
        for(int i=end;i>=1;i-=i&-i) ret += bit[i];
        return ret;
    }

    T count_swap(vector<int> &v){
        T ret = (T)0;
        int m = v.size();
        for(int i=1;i<=m;++i){
            add(v[i-1], 1);
            ret += i - sum(v[i-1]);
        }
        return ret;
    }
};


int main() {
    int n;
    cin >> n;
    vector<Pii> a(n);
    for(int i=0;i<n;++i) cin >> a[i].first;
    for(int i=0;i<n;++i) cin >> a[i].second;

    int ans = INF;
    for(unsigned int bi=0;bi<(1<<n);++bi) { // カードを裏返す/裏返さないの組み合わせ
        if(__builtin_popcount(bi) % 2) continue; // 裏返っているカードの数が奇数にはならない

        vector<Pii> v[2];   // v[0]: 偶数番目に配置されるべきカード, v[1]: 奇数番目に配置されるべきカード
        {
            vector<Pii> tmp_v(n);
            for(int i=0;i<n;++i) {
                if(bi & (1 << i)) {
                    tmp_v[i] = Pii(a[i].second, i);
                } else {
                    tmp_v[i] = Pii(a[i].first, i);
                }
            }
            sort(tmp_v.begin(), tmp_v.end());
            for(int i=0;i<n;++i) {
                v[((tmp_v[i].second%2)^((bi >> tmp_v[i].second) & 1))?1:0].emplace_back(tmp_v[i].first, tmp_v[i].second);
            }
        }

        bool is_ok = true;
        int prev_v = -1;
        vector<int> u(n);
        for(int i=0;i<n;++i) {
            if(i/2 >= v[i%2].size() || prev_v > v[i%2][i/2].first) {
                is_ok = false;
                break;
            }
            prev_v = v[i%2][i/2].first;
            u[i] = v[i%2][i/2].second + 1;
        }
        if(!is_ok) continue;

        BIT<int> tree(100);
        ans = min(ans, tree.count_swap(u));
    }

    cout << ((ans == INF)?-1:ans) << endl;
}


Measured memory_bytes: 256
N=int(input())
S=list(map(int,input().split()))
DP=[100000000]*100010

DP[0]=0
DP[1]=abs(S[1]-S[0])
for i in range(2,N):
    if DP[i-2]+abs(S[i]-S[i-2])<DP[i-1]+abs(S[i]-S[i-1]):
        DP[i]=DP[i-2]+abs(S[i]-S[i-2])
    else:
        DP[i]=abs(S[i]-S[i-1])+DP[i-1]


print(DP[N-1])

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

int main() {
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)cin>>a[i];
   int prefix[n],suffix[n];
   prefix[0] = a[0];
   for(int i=1;i<n;i++){
       prefix[i] = max(prefix[i-1],a[i]);
   }
   suffix[n-1] = a[n-1];
   for(int i=n-2;i>=0;i--){
       suffix[i] = max(suffix[i+1],a[i]);
   }
   for(int i=0;i<n;i++){
       if(i == 0){
           cout<<suffix[1]<<"\n";
       }else if(i == n-1){
           cout<<prefix[n-2]<<"\n";
       }else{
           cout<<max(prefix[i-1],suffix[i+1])<<"\n";
       }
   }
   return 0;
}


Measured memory_bytes: 3968
from functools import reduce

n, start = map(int, input().split())
x = list(map(int, input().split()))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

sa = [0] * n
for i in range(n):
    sa[i] = abs(start - x[i])

print(reduce(gcd, sa))


Measured memory_bytes: 14596
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
  string s;
  cin>>s;
  vector<int> charlist(26);
  for(int i=0;i<s.size();i++){
      charlist[s[i]-'a']=1;
  }
  bool f=false;
  for(int i=0;i<26;i++){
      if(charlist[i]==0)f=true;
  }
  vector<int> usedlist(26);
  for(int i=0;i<26;i++)usedlist[i]=0;
  if(!f){
      int i;
      for(i=1;i<s.size();i++){
          usedlist[s[s.size()-i]-'a']=1;
          if(s[s.size()-1-i]<s[s.size()-i]){
              for(int j=s[s.size()-1-i]-'a';j<26;j++){
                  if(usedlist[j]==1){
                      char addchar=j+'a';
                      cout<<s.substr(0,s.size()-1-i)+addchar<<endl;
                      return 0;
                  }
              }
          }
      }
      if(i==s.size()){
          cout<<-1<<endl;
          return 0;
      }
  }else{
      char nextchar='a';
      for(int i=0;i<26;i++){
          if(charlist[i]==0){
              nextchar='a'+i;
              break;
          }
      }
      cout<<s+nextchar<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String [] args) {
		
		LinkedList<String> names = new LinkedList<String>();
		LinkedList<Integer> times = new LinkedList<Integer>();
		Scanner in = new Scanner(System.in);
		int numLines = in.nextInt();
		int t = in.nextInt();
		int totalTime = 0;
	
		for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		}
	}
	
}



Measured memory_bytes: 75240
function main(input) {

	var answer = 0;
	var num_people = parseInt(input.split('\n')[0].split(' ')[0]);
	var num_candy = parseInt(input.split('\n')[0].split(' ')[1]);
	var num_demands = input.split('\n')[1].split(' ');

	//少ない順に並び替え、お菓子の総量を超えるまでで足し続ける。

	//昇順に並び替え
	num_demands.sort(function(a, b) {
	  return a - b;
	});

	var sum_candy = 0;
	for (var i = 0; i < num_people; i++) {
	  	answer = i;
	  	sum_candy += parseInt(num_demands[i]);

	  	//需要が供給を上回ったとき
	  	if(sum_candy > num_candy){
			console.log(answer);
			return;
		} else if (sum_candy == num_candy) {
			answer +=1;
		}

		 	
	}

	
	console.log(answer);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
template<class T> void verr(const vector<T>& v){ for(auto& a : v) cout << a << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    bool isz = true;
    rep(i, N) if (A[i] > N-1) isz = false;
    if(isz){
        cout << 0 << endl;
        return 0;
    }

    bool sf = false;
    ll cnt = 0;
    vl C(N);
    while(!sf){
        rep(i, N) C[i] = A[i] / N;
        ll sum = accumulate(all(C), 0ll);

        rep(i, N){
            A[i] -= C[i] * N;
            A[i] += (sum - C[i]);
        }
        bool isok = true;
        rep(i, N) if (A[i] > N - 1) isok = false;
        if (isok) sf = true;

        cnt+=sum;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    map<ll,int> m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ll l=a[i]+i;
        m[l]++;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ll r=i-a[i];
        ans+=m[r];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 27312
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

int n,q;
vector<int> Graph[MAX];
int vis[  200005] ;
int cnt[200005] ;

void dfs(int i,int total){

    vis[i] = true;
    int tmp = total;
    total += cnt[i];
    cnt[i] += tmp;

    itrfor(itr,Graph[i]){
        if(vis[*itr]) continue;
        dfs(*itr,total);
    }

}



signed main(){

    cin >> n >> q;
    REP(i,n){
        vis[i] = false;
        cnt[i] = 0;
    }
    
    REP(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        Graph[a].push_back(b);
        Graph[b].push_back(a);
    }
    REP(i,q){
        int x,p;
        cin >> p >> x;
        p --;
        cnt[p] += x;
    }




    dfs(0,0);
    REP(i,n){
        cout << cnt[i] << " ";

    }
    cout << endl;



}

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

int main() {
  int h, n;
  cin >> h >> n;
  int all = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    all += a;
  }
  
  if (h <= all) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256