akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    int a,b,x,y,n,i,j;
    while(1){
        int map[17][17]={0};
        int dp[17][17]={0};
        dp[1][1]=1;
        scanf("%d %d",&a,&b);
        if(a==0&&b==0)break;
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%d %d",&x,&y);
            map[x][y]=-1;
        }
        for(i=1;i<=b;i++){
            for(j=1;j<=a;j++){
                if(map[j][i]==0)dp[j][i]+=(dp[j-1][i]+dp[j][i-1]);
            }
        }
        printf("%d\n",dp[a][b]);
    }
    return 0;
}

Measured memory_bytes: 604
#include <iostream>

using namespace std;

long long en[200000],me[200000][2];
int vi[200000][2];
int n;

long long dp(int ac, int v){
	if(ac<0)return 0;
	if(vi[ac][v])return me[ac][v];
	vi[ac][v]=1;
	if(v)return me[ac][v] = en[ac] + dp(ac-2,v);
	if(ac%2){
		return me[ac][v] = max(dp(ac-1,1), en[ac] + dp(ac-2,v));
	}
	if(ac==0)return me[ac][v]=0;
	
	return me[ac][v] = max(dp(ac-1,v),en[ac] + dp(ac-2,v));
}
int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>en[i];
	}
	cout<<dp(n-1,0);
	
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n, m;
	cin >> n >> m;

	vector<ll> x(m);
	for (auto &v : x) {
		cin >> v;
	}
	sort(begin(x), end(x));

	vector<ll> diff(m - 1);
	for (ll i = 0; i < m - 1; i++) {
		diff[i] = abs(x[i] - x[i + 1]);
	}
	sort(begin(diff), end(diff));

	ll deleteCnt = n - 1LL;
	ll ans = 0;
	for (ll i = 0; i < (ll)(diff.size()) - deleteCnt; i++) {
		ans += diff[i];
	}

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


Measured memory_bytes: 1792
s = input()

if len(s) % 2 == 0:
    zenhan = s[:len(s)//2]
    kohan = s[len(s)//2:]
else:
    zenhan = s[:len(s)//2+1]
    kohan = s[len(s)//2+1:]

point = 0
for c in zenhan:
    if c == 'p':
        point -= 1

for c in kohan:
    if c == 'g':
        point += 1

print(point)


Measured memory_bytes: 3316
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

bool fn(int a, int b) {
    if (a > b) return true;
    
    return false;
}


int main() {
	int N = 10;
	int height;
	vector<int> mountains;
	
	while (N--) {
	    scanf("%d", &height);
	    
	    mountains.push_back(height);
	}
	
    sort(mountains.begin(), mountains.end(), fn);
    
    printf("%d\n", mountains.at(0));
    printf("%d\n", mountains.at(1));
    printf("%d\n", mountains.at(2));
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int P[N];
  rep(i, N) cin >> P[i];
  int min_p = P[0];
  int ans = 1;
  rep(i, N-1){
    if (min_p >= P[i+1]){
      min_p = P[i+1];
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
string find(string s1,string s2){
  ll n1=s1.length();
  ll n2=s2.length();
  if(n2!=(n1+1))
    return "No";
  string d=s2.substr(0,n1);
  if(d!=s1)
    return "No";
  return "Yes";
}
int main(){
  string s1,s2;
  cin>>s1;
  cin>>s2;
  cout<<find(s1,s2)<<"\n";
}


Measured memory_bytes: 3636
# incert sort
N = int(input())
list_num = list(map(int, input().split(" ")))
print(" ".join(map(str, list_num)))

for i_incert in range(1, N):
    num_incert = list_num[i_incert]
    i_cmpr = i_incert - 1
    
    while i_cmpr >= 0 and list_num[i_cmpr] > num_incert:
        list_num[i_cmpr + 1] = list_num[i_cmpr]  # 一つ右にcopy(元のはnum_incertとして保持済)
        i_cmpr -= 1
    list_num[i_cmpr + 1] = num_incert
    print(" ".join(map(str, list_num)))


Measured memory_bytes: 5596
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		int one = Integer.parseInt(s.split(" ")[0]), two = Integer.parseInt(s.split(" ")[1]),
				three = Integer.parseInt(s.split(" ")[2]), four = Integer.parseInt(s.split(" ")[3]),
				five = Integer.parseInt(s.split(" ")[4]), six = Integer.parseInt(s.split(" ")[5]);
		s = scan.nextLine();
		int one2 = Integer.parseInt(s.split(" ")[0]), two2 = Integer.parseInt(s.split(" ")[1]),
				three2 = Integer.parseInt(s.split(" ")[2]), four2 = Integer.parseInt(s.split(" ")[3]),
				five2 = Integer.parseInt(s.split(" ")[4]), six2 = Integer.parseInt(s.split(" ")[5]);
		s = "EEEENEEEENEEEESSSEEEENESEEEENWWSEEEE";
		// int tmpCnt = Integer.parseInt(scan.nextLine());
		// for(int j = 0;j<s.length();j++){
		// String tmpStr = scan.nextLine();
		// int x = Integer.parseInt(tmpStr.split(" ")[0]);
		// int y = Integer.parseInt(tmpStr.split(" ")[1]);
		for (int i = 0; i < s.length(); i++) {
			int tmp;
			if (s.charAt(i) == 'E') {
				tmp = one;
				one = four;
				four = six;
				six = three;
				three = tmp;
			} else if (s.charAt(i) == 'N') {
				tmp = one;
				one = two;
				two = six;
				six = five;
				five = tmp;
			} else if (s.charAt(i) == 'S') {
				tmp = one;
				one = five;
				five = six;
				six = two;
				two = tmp;
			} else if (s.charAt(i) == 'W') {
				tmp = one;
				one = three;
				three = six;
				six = four;
				four = tmp;
			}
			if (one == one2 && two == two2 && three == three2 && four == four2 && five == five2) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
		// if(two == y){
		// System.out.println(three);
		// }else if(three == y){
		// System.out.println(five);
		// }else if(four == y){
		// System.out.println(two);
		// }else if(five == y){
		// System.out.println(four);
		// }
		// System.out.println(one);
	}
}
// }



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

using namespace std;

void hawawa(){
	int n, k;
	cin >> n >> k;
	vector<long long> cnt(k, n / k);
	for (int i = 1; i <= n % k; i++) {
		cnt[i]++;
	}
	long long ans = 0;
	for (int i = 0; i < k; i++) {
		if (!i) {
			ans += cnt[0] * cnt[0] * cnt[0];
		}
		if (i * 2 == k) {
			ans += cnt[i] * cnt[i] * cnt[i];
		}
	}
	cout << ans << "\n";
}

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


Measured memory_bytes: 1792
n, k = map(int, input().split())
A = [int(x) - 1 for x in input().split()]

B = [0]
visited = [False] * n
for i, b in enumerate(B):
    if visited[b]:
        break
    visited[b] = True
    B.append(A[b])

j = B.index(b)
r = (k - j) % (i - j)
ans = B[j:][r] + 1 if k >= j else B[k] + 1

print(ans)


Measured memory_bytes: 32304
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

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

	int curr_min = n + 1;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (perm[i] <= curr_min) {
			++ans;
		}

		curr_min = min(curr_min, perm[i]);
	}

	cout << ans << "\n";

	return 0;

}

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

int main()
{
    int a,b,X;

    cin>>a>>b;
    
    int d=1;
    while(1){
        if(d>b)break;
        d*=10;
    }

    X=a*d+b;

    for(int i=1;i<=X/2;i++){
        if(i*i==X){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in) ;

		for(int t=1;;t++) {
			int num=sc.nextInt();

			if(num==0) {
				break;
			}else {
				System.out.println("Case "+t+":"+" "+num);
			}
		}


	}
}



Measured memory_bytes: 42232
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	std::vector<P> xy(n);
	REP(i, 0, n) scanf("%ld %ld", &xy[i].fi, &xy[i].se);
	
	std::map<P, int> mp;
	REP(i, 0, n) REP(j, 0, n) if(i!=j) {
		ll dx = xy[i].fi-xy[j].fi, dy = xy[i].se-xy[j].se;
		mp[P(dx,dy)]++;
	}

	int ans = n;
	for(auto pd: mp){
		ans = std::min(ans, n-pd.se);
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main(void) {
    int a;
    int b;
    cin >> a >> b;
    if (a < b) {
        cout << "a < b" << endl;
    } else if (a > b) {
        cout << "a > b" << endl;
    } else if (a == b) {
        cout << "a == b" << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cmath>
#define range(i,a,b) for(int i = (a); i <= (b); i++)
#define rrange(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,b) for(int i = 1; i <= (b); i++)
#define rrep(i,b) for(int i = (b); i >= 1; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=2e5+11;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001LL;
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; }
pair<int,int> a[N];
int n,Max,Min,mx,mn;
ll ans;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();
	mx=-INF;mn=INF;
	rep(i,n){
		a[i].first=read();a[i].second=read();
		if(a[i].first>a[i].second) swap(a[i].first,a[i].second);
		mx=max(mx,a[i].second);
		mn=min(mn,a[i].second);
	}
	sort(a+1,a+1+n);
	ans=(ll)(mx-mn)*(a[n].first-a[1].first);
	Min=Max=a[1].second;
	range(i,2,n){
		ans=min(ans,(ll)(mx-a[1].first)*(max(Max,a[n].first)-min(Min,a[i].first)));
		Min=min(Min,a[i].second);
		Max=max(Max,a[i].second);
	}
	printf("%lld",ans);
	return 0;
}

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

int main()
{
    int a,b,c;

    while(cin>>a>>b>>c)
    {
        int counter=1;

        if(b!=a) counter++;

        if(c!=a && c!=b) counter++;

        cout<<counter<<endl;
    }    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define EPS 1e-9
#define SYNC std::ios::sync_with_stdio(false)
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
	SYNC;
	ll n, a, b, k; 
	pair<ll,ll> arr[100000 + 5];
	cin >> n >> k;
	FOR0(i, n) {
		cin >> a >> b;
		arr[i] = mp(a, b);
	}
	sort(arr, arr+n);
	ll x = 0;
	FOR0(i, n) {
		x += arr[i].ss;
		if(x >= k) {
			cout << arr[i].ff << endl;
			break;
		}
	}
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_N 100005
ll N,M,R,Q;
struct edge {ll to,cost;};
vector< edge > G[MAX_N+100];
 
ll d[11][MAX_N+100];
typedef pair<ll,ll> P;
 
void dijkstra(int si,ll d[MAX_N+100]){
  si+=MAX_N;
  fill(d,d+MAX_N+100, (1LL<<60) );
  d[si]=0;
  priority_queue< P , vector<P> , greater<P> > Q;
  Q.push( P(0,si) );
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    ll cost=p.first;
    ll pos=p.second;
    if(d[pos]<cost)continue;
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(d[e.to]<=cost+e.cost)continue;
      d[e.to]=cost+e.cost;
      Q.push( P(d[e.to],e.to) );
    }
  }
}
 
int main(){
  scanf("%lld %lld %lld %lld",&N,&M,&R,&Q);
  for(int i=0;i<M;i++){
    ll a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    G[b].push_back( (edge){a,c} );
  }
  for(ll i=1;i<=N;i++){
    G[MAX_N+i%R].push_back( (edge){i,0} );
  }
  for(int i=0;i<R;i++)dijkstra(i,d[i]);
 
  ll ans=0;
  while(Q--){
    ll x,y,z;
    scanf("%lld %lld %lld",&x,&y,&z);
    ll mini=(1LL<<60);
    for(int i=0;i<R;i++){
      mini=min(mini, d[i][x]+d[i][y]);
    }
    if(mini<z){
      ans+=(z-mini);
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 20172
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b  && b == c && a == c) printf("No\n");
    else if (a != b && a != c && b != c) printf("No\n");
    else printf("Yes\n"); 
    return 0;
}

Measured memory_bytes: 888
// AOJ 1295: Cubist Artwork
// 2017.10.16 bal4u@uu

#include <stdio.h>
#include <string.h>

int f[22];

int main()
{
	int w, d, h, ans;

	while (scanf("%d%d", &w, &d) && w > 0) {
		memset(f, 0, sizeof(f));
		ans = 0; while (w-- > 0) {
			scanf("%d", &h);
			ans += h, f[h]++;
		}
		while (d-- > 0) {
			scanf("%d", &h);
			if (f[h]) f[h]--;
			else ans += h;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1748
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string s;
  cin >> s;
  cout << s[0] << s.size() - 2 << s.back() << endl;
}



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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  vll a(3);
  rep(i,3) cin>>a[i];
  vsort(a);
  ll s=0;
  rep(i,2) s+=a[i];
  if(s==a[2]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int K,A,B;
  scanf("%d%d%d",&K,&A,&B);
  if(A/K!=B/K)
    printf("OK\n");
  else if(A%K==0)
    printf("OK\n");
  else
    printf("NG\n");
  return 0;
}

Measured memory_bytes: 1644
#include <stdio.h>
#include <math.h>
main(){
  int i,x;
  double sum,sum1,res;
  double a[1000];
  while(1){
    scanf("%d",&x);
    if(x==0)
      break;
    sum=0;
    sum1=0;
    for(i=0;i<x;i++){
      scanf("%lf",&a[i]);
      sum1+=pow(a[i],2);
      sum+=a[i];
    }
    printf("%f\n",sqrt((double)sum1/x-(double)sum/x*sum/x));
  }
  return 0;
}

Measured memory_bytes: 664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int n,m,v,p,a[maxn],l,r,mid;

bool check(int x){
	if(x<=p-1) return true;
	if(a[x]+m<a[p-1]) return false;
	if(v<=p-1+n-x) return true;
	int tmp=v-(p-1+n-x);
	int cnt=0;
	rep2(i,p-1,x) cnt+=a[x]+m-a[i];
	return m*tmp<=cnt;
}

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> m >> v >> p;
	rep(n) cin >> a[i];
	sort(a,a+n);
	reverse(a,a+n);
	l=0,r=n-1;
	while(l!=r){
		mid=l+r+1>>1;
		if(check(mid)) l=mid;
		else r=mid-1;
	}
	print1(l+1);
	return 0;
}

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


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    while(cin >> n) {
        int cnt = 0;
        rep(a, 10) {
            rep(b, 10) {
                rep(c, 10) {
                    rep(d, 10) {
                        if (a + b + c + d == n) {
                            cnt++;
                        }
                    }
                }
            }
        }
        cout << cnt << "\n";
    }
	return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define f(a,j,k) for(int i = a ; i < j ; i += k)
#define f1(a,j,k) for(int i = a ; i > j ; i -= k)
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
typedef pair<int,int> pri;
typedef pair<long long,long long> prl;
ll cnt[200001];
int a[200001];
int main() {
	std::ios::sync_with_stdio(false);
	ll x;
	cin >> x;
	cout << x / 500 * 1000 + (x % 500) / 5 * 5 << endl;
	return 0;
}


Measured memory_bytes: 256
//C++
//#pragma comment(linker, "/STACK:102400000,102400000")
//G++
//#define OPENSTACK
#define ONLINE_JUDGE
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cctype>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MOD = 998244353;
const int N = 1e6 + 10, M = N;//刻意开大会消耗时间.


int main()
{
    #ifdef OPENSTACK
    int size = 64 << 20; // 64MB
    char *p = (char*)malloc(size) + size;
    #if (defined _WIN64) or (defined __unix)
        __asm__("movq %0, %%rsp\n" :: "r"(p));
    #else
        __asm__("movl %0, %%esp\n" :: "r"(p));
    #endif
    #endif
    #ifndef ONLINE_JUDGE
        freopen("../put/a.input","r",stdin);
        freopen("../put/a.output","w",stdout);
    #endif
    clock_t c1 = clock();
    //coding here......

    int n, x, t;
    cin >> n >> x >> t;
    int m = (n % x) != 0 ? 1 : 0;
    cout << (n / x + m) * t << endl;

    //finish here......
    #ifndef ONLINE_JUDGE
        std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
    #endif
    #ifdef OPENSTACK
        exit(0);
    #else
        return 0;
    #endif
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

struct Bridge{
  ll w,s,e;
  bool operator<(const Bridge& b){
    if(s == b.s) return e < b.e;
    return s < b.s;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,w,s,e;
  while(cin >> n && n){
    vector<Bridge> b(n);
    rep(i,n){
      cin >> b[i].w >> b[i].s >> b[i].e;
    }
    sort(all(b));
    w = 0,s = 0, e = 0;
    vector<pll> decr;
    bool f = true;
    rep(i,n){
      if(s <= b[i].s){
        w += b[i].w;
        decr.push_back(make_pair(b[i].w,b[i].e));
        s = b[i].s;
        rep(j,decr.size()){
          if( s >= decr[j].se){
            w -= decr[j].fi;
            decr[j].se = inf;
            decr[j].fi = 0;
          }
        }
      }
      if(w > 150){
        f = false;
        break;
      }
    }
    if(f) cout << "OK"<<endl;
    else cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 3128
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#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<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-20;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[1100];
int q[1100];
int t[1100];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		scanf("%d%d",p+i,q+i);
		t[i]=max(0,a-p[i]);
	}
	std::sort(t,t+b);
	int ret=0;
	for(int i=0;i<b-1;i++)ret+=t[i];printf("%d\n",ret);
}


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

using namespace std;

#ifdef Adrian
#include "debug.h"
#else
#define debug(...)
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second
#define ii pair<int,int>


int main()
{
	#ifdef Adrian
		freopen("a.txt", "r", stdin);
		//freopen("business.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n,t;
	cin>>n>>t;

	vector<int> v(t+10);

	for(int i=0; i<n; i++)
	{
		int l,r;
		cin>>l>>r;
		++v[l];
		--v[r];
	}

	for(int i=1; i<v.size(); i++)
		v[i] += v[i-1];

	int ans = 0;
	for(auto &i:v)
		ans = max(ans,i);

	cout<<ans<<'\n';


	return 0;
}



Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<queue>
#include<map>
using namespace std;
queue<pair<string,int> > Q;

void Sw(string st,int x)
{
	int i;
	int pos,npos;
	int d[4]={-3,3,-1,1};
	string st1;
	
	for(i=0;i<=8;i++)
	{
		if(st[i]=='0')
		{
			pos=i;
			break;
		}
	}
	for(i=0;i<=3;i++)
	{
		st1=st;
		if(i==2 && pos%3==0) continue;
		if(i==3 && pos%3==2) continue;
		npos=pos+d[i];
		if(npos>=9 || npos<=-1) continue;
		swap(st1[pos],st1[npos]);
		Q.push(pair<string,int>(st1,x+1));
	}
}

int main()
{
	string puzzle="";
	string goal="123456780";
	map<string,bool> M;
	int i,x;
	string P;
	
	for(i=0;i<=8;i++)
	{
		cin >> x;
		puzzle+='0'+x;
	}
	Q.push(pair<string,int>(puzzle,0));
	while(1)
	{
		pair<string,int> p=Q.front();
		Q.pop();
		P=p.first;
		x=p.second;
		if(P==goal)
		{
			cout << x << endl;
			break;
		}
		if(M[P]) continue;
		else M[P]=1;
		Sw(P,x);
	}
	return 0;
}

Measured memory_bytes: 24464
// 2014/07/15 Tazoe

#include <iostream>
using namespace std;

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

	int cnt = 0;

	for(int i=a; i<=b; i++){
		if(c%i==0){
			cnt++;
		}
	}

	cout << cnt << '\n';

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void)
{
  
  int x,y,s,a[1000],b[1000],c[1000],d[1000],e[1000],A[1000],B[1000],i,t,M;
  

  while (1) {
    
    M=0;
    scanf("%d %d %d", &x,&y,&s);
    if (x == 0 && y == 0 && s == 0) {
      break;
    }

    for(i = 0;i < 1000; i++){
      a[i] = 0;
      b[i] = 0;
      c[i] = 0;
      d[i] = 0;
      e[i] = 0;
      A[i] = 0;
      B[i] = 0;
    }
    x = 100 + x;
    y = 100 + y;
    t = 100 * s;
    for(i = 0;i < s-1; i++){
      a[i] = (i+1) * 100;
      b[i] = t - a[i];
      A[i] = a[i]/100;
      B[i] = b[i]/100;
    }
    for(i = 0;i < s-1; i++){
      if(a[i] % x == 0)
	a[i] = a[i]/x;
      else
	a[i] = (a[i]/x)+1;
      
      if(b[i] % x == 0)
	b[i] = b[i]/x;
      else
	b[i] = (b[i]/x)+1;
      d[i] = a[i];
      e[i] = b[i];
    }
    for(i = 0;i < s-1; i++){
      if(d[i]*x/100 == A[i] && e[i]*x/100 == B[i]){
	a[i] = a[i]*y/100;
	b[i] = b[i]*y/100;
	c[i] = a[i]+b[i];
	/*    printf("%d→ %d→ %d  %d→ %d → %d\n", A[i],d[i],a[i],B[i],e[i],b[i]);   */
	if(c[i] > M)
	  M = c[i];
      }
    } 
    printf("%d\n", M);
    
  }
  
  return 0;
}

Measured memory_bytes: 624
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int a = in.ni(), b = in.ni(), c = in.ni(), d = in.ni();
    int x = (a + d - 1) / d;
    int y = (c + b - 1) / b;
    out.println(x >= y ? "Yes" : "No");
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 32668
a=int(input())
b=int(input())
c=int(input())
x=int(input())

count = 0
for i in range(0,a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if x==i*500+j*100+k*50:
                count +=1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long n;
long long a[100010],b[100010];
long long s=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n+1;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<=n;i++){
		if(b[i]>a[i]){
			s+=a[i];
			b[i]-=a[i];
			a[i]=0;
			if(b[i]>a[i+1]){
				s+=a[i+1];
				a[i+1]=0;
			}
			else{
				s+=b[i];
				a[i+1]-=b[i];
			}
		}
		else s+=b[i];
	}
	cout<<s<<endl;
	return 0;
}

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

int n,y;
long long a,b,c,d,mn=1000000000;
map<long long, pair<long long,long long>> m;
vector<pair<long long,long long>> students;
vector<int> ans;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	for(int i=0;i<y;i++){
		cin>>c>>d;
		m[i+1]=make_pair(c,d);
	}

	for(auto it=students.begin();it!=students.end();++it){
		mn=1000000000;
		int temp;
		for(auto i=m.begin();i!=m.end();++i){
			if(mn>abs(it->first-((i->second).first))+abs(it->second-((i->second).second))){
				mn=abs(it->first-((i->second).first))+abs(it->second-((i->second).second));
				temp=i->first;
			}
		}
		ans.push_back(temp);
	}

	for(auto it=ans.begin();it!=ans.end();++it)
		cout<<*it<<endl;
	return 0;
}

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

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> p(n);
  for (int i = 0; i < n; ++i)
    std::cin >> p[i];
  int x = 0;
  for (int i = 1; i < (n - 1); ++i) {
    if (p[i - 1] > p[i] && p[i] > p[i + 1])
      ++x;
    else if (p[i - 1] < p[i] && p[i] < p[i + 1])
      ++x;
  }
  std::cout << x << std::endl;
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n,m;
  cin >> n >> m;
  ll sum = 0;
  rep(i,m)
  {
    ll a;
    cin >> a ;
    sum += a;
  }

  if(sum > n) cout << -1 << endl;
  else cout << n - sum << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

int N;
int L[200];

int main(){
    INPUT(N);
    REP1(i,2*N) INPUT(L[i]);
    
    sort(L,L+2*N);
    
    int sum = 0;
    
    REP1(i,N){
        sum += min(L[2*i],L[2*i+1]);
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,i,j,k,l,q,p[101],m[101][101];

  scanf("%d",&n);

  for(i=1; i<=n; i++)
    scanf("%d%d",&p[i-1],&p[i]);

  for(i=1; i<=n; i++)
    m[i][i] = 0;

  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i + l -1;
      m[i][j] = 100000;
      for(k=i; k<=j-1; k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	if(m[i][j] >= q)
	  m[i][j] = q;
      }
    }
  }

  printf("%d\n",m[1][n]);
  
  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define END system("PAUSE");return 0
int n, k, a[111];
int taro_win[111111], jiro_win[111111];
bool taro(int x);
bool jiro(int x);
bool taro(int x) {
	if (taro_win[x] == 1)return true;
	if (taro_win[x] == 2)return false;
	rep(i, n) {
		if (a[i] > x)continue;
		if (!jiro(x - a[i])) {
			taro_win[x] = 1;
			return true;
		}
	}
	taro_win[x] = 2;
	return false;
}
bool jiro(int x) {
	if (jiro_win[x] == 1)return true;
	if (jiro_win[x] == 2)return false;
	rep(i, n) {
		if (a[i] > x)continue;
		if (!taro(x - a[i])) {
			jiro_win[x] = 1;
			return true;
		}
	}
	jiro_win[x] = 2;
	return false;
}
signed main() {
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	taro_win[0] = jiro_win[0] = 2;
	if (taro(k))puts("First");
	else puts("Second");
	END;
}


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

int32_t main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;

    for(int i=2;i<=n;i++){
    	if(i==2){
    		dp[i]=abs(a[i-1]-a[i-2]);
    		continue;
    	}
    	dp[i] = min(dp[i-1]+abs(a[i-2]-a[i-1]),dp[i-2]+abs(a[i-3]-a[i-1]));
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 5200
N = int(input())

def divisor(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret

ans = 0
for i in range(1, N+1):
  if i % 2 == 1 and len(divisor(i)) == 8:
    ans += 1

print(ans)

Measured memory_bytes: 38384
N,P = map(int, input().split())

count = 1
ans = 0

if N == 1:
    print(P)
    exit()

if N > 1000001:
    print(1)
    exit()

while True:

    if count**N > P:
        break

    if P % count**N == 0:
        ans = count

    count += 1
 
print(ans)


Measured memory_bytes: 3060
n, k = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)

def bfs(start, x):
	vis = [-1 for _ in range(n)]
	vis[start] = 0
	s = [start]
	cnt = 0
	while s:
		l = s.pop()
		cnt += 1
		if vis[l] < x:
			for c in adj[l]:
				if vis[c] < 0:
					s.append(c)
					vis[c] = vis[l] + 1
	return n - cnt

def bfs2(start, nxt, x):
	vis = [-1 for _ in range(n)]
	vis[start] = 0
	vis[nxt] = 0
	s = [start, nxt]
	cnt = 0
	while s:
		l = s.pop()
		cnt += 1
		if vis[l] < x:
			for c in adj[l]:
				if vis[c] < 0:
					s.append(c)
					vis[c] = vis[l] + 1
	return n - cnt

ans = n-2
if k%2 == 0:
	for i in range(n):
		ans = min(ans, bfs(i, k//2))
else:
	for i in range(n):
		for j in adj[i]:
			ans = min(ans, bfs2(i, j, k//2))

print(ans)

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, x;

int main() {
  cin >> n >> x;
  vector<int> a(n);
  range(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  int sum = 0;
  range(i, 0, n) {
    sum += a[i];
    if(sum > x) {
      cout << i;
      return 0;
    }
  }
  cout << n - 1 + (sum == x);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    	public static void main(String[] args) {
        	Scanner sc = new Scanner(System.in);
	        int a = sc.nextInt();
	        int[] x = new int[a];
       		int[] y = new int[a];
	        for (int i = 0; i < a; i++) {
           		x[i] = sc.nextInt();
        	}
        	for (int j = 0; j < a; j++) {
            		y[j] = sc.nextInt();
        	}

	        double n = 0;
	        double m = 0;
	        double l = 0;
	        double o = 0;
       		for (int i = 0; i < a; i++) {
            		n += Math.abs(x[i] - y[i]);
            		m += Math.pow(Math.abs(x[i] - y[i]), 2);
            		l += Math.pow(Math.abs(x[i] - y[i]), 3);
            		if(o < Math.abs(x[i] - y[i])) {
                		o = Math.abs(x[i] - y[i]);
            		}
        	}
        	m = Math.pow(m, 1.0 / 2.0);
        	l = Math.pow(l, 1.0 / 3.0);
         
        	System.out.println(n);
        	System.out.println(m);
        	System.out.println(l);
        	System.out.println(o);
    	}
}

Measured memory_bytes: 20504
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int siz=s.size();
    for(int i=0;i<siz;i++)s[i]-='0';
    int m=0;
    int pow=1;
    int mod[2019]={};
    mod[0]=1;
    for(int i=siz-1;i>=0;i--){
        m+=s[i]*pow;
        m%=2019;
        mod[m]++;
        pow*=10;
        pow%=2019;
    }
    long long x=0;
    for(int i=0;i<2019;i++){
        x+=mod[i]*(mod[i]-1)/2;
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 3732
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=5e4;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
char a[N],b[N];
int f[N],g[N],R[N];
int inv[N];
int INV;
const int mod=998244353;
int w0[20][N],w1[20][N];
inline int qpow(int x,int y) {
	int ans=1;
	while (y) {
		if (y&1) ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}
inline void DFT(int *a,int n,int f) {
	int i,o,k,x,y,t,*w,*wn;
	for (i=0;i<n;i++) if (R[i]<i) swap(a[i],a[R[i]]);
	for (i=1,t=0;i<n;i<<=1,t++)
		for (o=0,wn=f==1?w0[t]:w1[t];o<n;o+=i<<1)
			for (k=0,w=wn;k<i;k++,w++) {
				x=a[o+k],y=1LL*a[o+k+i]**w%mod;
				a[o+k]=(x+y)%mod;
				a[o+k+i]=(x-y)%mod;
			}
}
int main()
{
	scanf("%s",a+1);
	scanf("%s",b+1);
	int n=strlen(a+1),i,k,e=0,m=0,len,L=0,G,t;
	for (i=2,inv[0]=inv[1]=1;i<=n;i++) inv[i]=mod-1LL*(mod/i)*inv[mod%i]%mod;
	for (i=3;i<=n;i++) inv[i]=1LL*inv[i]*inv[i-1]%mod;
	for (i=1;i<=n;i++) if (a[i]=='1') b[i]=='1'?m++:e++;

	for (len=1;len<=(m<<1);len<<=1,L++) {
		G=qpow(3,(mod-1)/(len<<1));
		for (i=w0[L][0]=1;i<=len;i++) w0[L][i]=1LL*w0[L][i-1]*G%mod;
		w1[L][len]=w0[L][len];
		for (i=len;i;i--) w1[L][i-1]=1LL*w1[L][i]*G%mod;
	}
	for (i=0,L--;i<len;i++) R[i]=R[i>>1]>>1|(i&1)<<L;
	INV=qpow(len,mod-2);

	for (i=0;i<=m;i++) f[i]=!i,g[i]=inv[i+1];
	for (t=e;t;t>>=1) {
		for (i=m+1;i<len;i++) g[i]=0;
		DFT(g,len,1);
		if (t&1) {
			for (i=m+1;i<len;i++) f[i]=0;
			DFT(f,len,1);
			for (i=0;i<len;i++) f[i]=1LL*f[i]*g[i]%mod;
			DFT(f,len,-1);
			for (i=0;i<=m;i++) f[i]=1LL*f[i]*INV%mod;
		}
		for (i=0;i<len;i++) g[i]=1LL*g[i]*g[i]%mod;
		DFT(g,len,-1);
		for (i=0;i<=m;i++) g[i]=1LL*g[i]*INV%mod;
	}
	for (i=k=0;i<=m;i++) (k+=f[i])%=mod;

	for (i=m+e;i;i--) k=1LL*k*i%mod;
	for (i=m;i;i--) k=1LL*k*i%mod;
	for (i=e;i;i--) k=1LL*k*i%mod;
	printf("%d\n",(k+mod)%mod);
	return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
char ch;
int a,b;
int main(){
	while (scanf("%d %c %d",&a,&ch,&b)==3)
	switch(ch){
		case '+':printf("%d\n",a+b);break;
		case '*':printf("%d\n",a*b);break;
		case '-':printf("%d\n",a-b);break;
		case '/':printf("%d\n",a/b);break;
	}
	return 0;
}


Measured memory_bytes: 3240
# -*- coding: utf-8 -*-

def solve():
    NAB, NBA, NB_, N_A = 0, 0, 0, 0
    for _ in range(int(input())):
        S = input()
        NAB += S.replace('AB', '-').count('-')
        b, a = S.startswith('B'), S.endswith('A')
        NBA += (b and a)
        NB_ += (b and (not a))
        N_A += ((not b) and a)
    res = NAB + max(NBA-1, 0) + (NB_>=1 and NBA>=1) + (N_A>=1 and NBA>=1) + max(min(NB_, N_A)-(NBA>=1), 0)

    return str(res)

if __name__ == '__main__':
    print(solve())




Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++) cin >> d[i];
    sort(d, d+N);
    int t = N/2 - 1;
    cout << d[t+1] - d[t] << endl;
    return 0;
}


Measured memory_bytes: 768
import sys
input = sys.stdin.readline
n=int(input())

l=[[0,0] for _ in range(n)]
for i in range(n):
    l[i][1],l[i][0]=map(int,input().split())
l.sort()
c=0
for i in range(n):
    c+=l[i][1]
    if l[i][0]<c:
        print('No')
        break
else:
    print('Yes')

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

using namespace std;

#define int long long
#define N 100005
#define MOD 1000000007


int32_t main()
{

    int n;
    cin>>n;

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

    sort(a.begin(), a.end());

    cout<<a[n-1]<<" ";

    int x = 0;
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        int cur = min(a[i], a[n-1]-a[i]);
        if ( cur > x)
        {
            x = cur;
            ans = a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a[1000000],b,c,cmp,data,m,h,w,x,y,xcmp,ycmp,sum=0;

string s;

vector<int> z;

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

       cin >> n >> x;
       rep(i,n){
           cin >> a[i];
       }
       if(a[0]>x){
           ans=a[0]-x;
           a[0]=x;
       }
       rep(i,n-1){
           if(a[i]+a[i+1]>x){
               cmp=a[i+1];
               a[i+1]=x-a[i];
               ans+=cmp-a[i+1];
           }
       }
       Cout(ans);
return 0;
}


Measured memory_bytes: 1024
#include <iostream>


int main(void) {
	int K, X;
	std::cin >> K >> X;

	if (K == 1 && X == 100) {
		std::cout << 100;
		printf("\n");
	}
	else {
		for (int i = K - 1; i > 0; i--) {
			std::cout << X - i << " ";
		}

		std::cout << X << " ";

		for (int i = 1; i < K; i++) {
			std::cout << X + i << " ";
		}

		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256