akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int num[3];
    int fiv=0,sev=0;
    for(int i=0;i<3;i++){
        cin>>num[i];
    }
    
    for(int j=0;j<3;j++){
        if(num[j]==5) fiv++;
    }
    
    for(int k=0;k<3;k++){
        if(num[k]==7) sev++;
    }
    
    if(sev==1&&fiv==2) cout<<"YES";
    else cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
typedef long long ll;
const int mod=1e9+7;
#define lol(i,n) for(int i=0;i<n;i++)
#define tot(i,n) for(int i=1;i<=n;i++)
using namespace std;
string s;
int main () {
    cin >> s ;
    int a,b;
    a=b=0;
    int k=s.length();
    lol(i,k){
        if(s[i]=='0')a++;
        if(s[i]=='1')b++;
    }
    cout << min(a,b)*2<< endl;
}

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

int main() {
  long long H;
  cin >> H;
  
  int count = 0;
  while (H / 2 != 0){
    count++;
    H = H / 2;
  }
  
  long long sum = 1;
  while (count != 0){
    count--;
    sum = sum * 2 + 1;
  }
  cout << sum << endl;
}
  

Measured memory_bytes: 256
s = input()
s=s[::-1] #文字列の反転
words = ["maerd", "remaerd", "esare", "resare"]
while len(s) > 4:
    if s[:5] == 'maerd':
        s = s[5:]
        continue
    elif s[:7] == 'remaerd':
        s = s[7:]
        continue
    elif s[:5] == 'esare':
        s = s[5:]
        continue
    elif s[:6] == 'resare':
        s = s[6:]
        continue
    else:
        break
if len(s) > 0:
    print('NO')
else:
    print('YES')


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

using namespace std;

int main() {
  int N, L;
  cin >> N >> L;

  vector<string> v(N);
  for (int i = 0; i < N; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  for (const auto& e : v)
    cout << e;
  cout << endl;

  return 0;
}


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


bool linearSearch(int A[], int n, int key)
{
	A[n] = key;
	int i = 0;
	while (A[i] != key) i++;
	if (i == n) return false;
	return true;
}

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

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

	int q, C = 0;
	cin >> q;
	int T[500];
	for(int i = 0; i < q; i++)
	{
		cin >> T[i];
		if (linearSearch(S, n, T[i])) C++;
	}

	cout << C << endl;

    return 0;
}


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

int main() {
	
	int n, min = 1000000, max = -1000000, a;
	long sum=0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a < min)min = a;
		if (a > max)max = a;
		sum += a;
	}

	

	cout << min << " " << max << " " << sum << "\n";

	return 0;

}

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

//.define
// #define FILE_IN_OUT
#define RET(_x)    return cout << (_x) << '\n', 0;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
constexpr int MAXN = 3000;

int gr[MAXN][MAXN];
ll dp[MAXN][MAXN][4];

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n, m, k;
    cin >> n >> m >> k;
    loop(k) {
        int x, y, w;
        cin >> x >> y >> w;
        --x; --y;
        gr[x][y] = w;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (j > 0) {
                dp[i][j][0] = dp[i][j - 1][0];
                dp[i][j][1] = dp[i][j - 1][1];
                dp[i][j][2] = dp[i][j - 1][2];
                dp[i][j][3] = dp[i][j - 1][3];
                if (gr[i][j] > 0) {
                    dp[i][j][1] = max(dp[i][j][1], dp[i][j - 1][0] + gr[i][j]);
                    dp[i][j][2] = max(dp[i][j][2], dp[i][j - 1][1] + gr[i][j]);
                    dp[i][j][3] = max(dp[i][j][3], dp[i][j - 1][2] + gr[i][j]);
                }
            } else {
                if (gr[i][j] > 0) {
                    dp[i][j][1] = gr[i][j];
                }
            }
            if (i > 0) {
                ll val = *max_element(dp[i - 1][j], dp[i - 1][j] + 4);
                dp[i][j][0] = max(dp[i][j][0], val);
                if (gr[i][j] > 0) {
                    dp[i][j][1] = max(dp[i][j][1], val + gr[i][j]);
                }
            }
        }
    }
    cout << *max_element(dp[n - 1][m - 1], dp[n - 1][m - 1] + 4) << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 319940
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> v;

int N;
int main () {
    cin >> N;
    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        x--;
        v.push_back(x);
    }
    int ans = 0;
    for(int i=0; i<N-1; i++) {
        if( v[i] == i ) {
            swap(v[i],v[i+1]);
            ans++;
        }
    }
    if( v[N-1] == N-1 ) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include <stdio.h>
int n, x;
long long a[100001];
long long ans = 1, p = 1000000007;
int main() {
	scanf("%d", &n);
	a[0] = 3;
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		x++;
		ans *= (a[x - 1] - a[x]);
		ans %= p;
		a[x]++;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int dp[2][100002],n;
vector <int> edge[100002];
int mod=1000000007;
void dfs(int x){
	dp[1][x]=dp[0][x]=1;
	
	for(int i=0; i< edge[x].size(); i++){
		if(dp[1][edge[x][i]]!=0) continue;
		
		dfs(edge[x][i]);
		
		dp[1][x] = (dp[1][x] *dp[0][edge[x][i]])%mod;
		
		dp[0][x] = (dp[0][x] * (dp[0][edge[x][i]] + dp[1][edge[x][i]])) %mod;
		
	}
}
main(){
	int n,x,y;
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>x>>y;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	
	dfs(1);
	cout<<(dp[1][1] + dp[0][1])%mod;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int M = 3 * N;
  vector<int> a(M);
  for (int i = 0; i < M; i++) cin >> a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int64_t S = 0;
  
  for (int i = 0; i < 2 * N; i++) if (i % 2 == 1) S += a.at(i);
  
  cout << S << endl;
      
    
}

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

int main(){
  int n;
  int t[105];
  int m;
  int p[105],x[105];
  int i,j;

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

  scanf("%d", &m);
  for(i = 0;i < m;i++) scanf("%d %d", &p[i], &x[i]);

  ll mn = 100100100100;
  int s;
  for(i = 0;i < m;i++){
    ll sum = 0;
    for(j = 1;j <= n;j++){
      if(p[i] == j) sum += x[i];

      else sum += t[j];
    }

    printf("%lld\n", sum);
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    // 1-indexed
    int n, k; cin>>n>>k;
    vector<vector<int>> g(n+1);
    vector<P> edge;
    for(int i=1; i<=8; i++){
        int num=(1<<(i-1));
        if(n<num) break;
        for(int j=1; j<=n; j++){
            if(i==j) continue;
            if(num & j){
                g[i].push_back(j);
                g[j].push_back(i);
                edge.push_back(P(i, j));
            }
        }
    }

    cout << edge.size() << endl;
    for(int i=0; i<edge.size(); i++){
        cout << edge[i].fs << " " << edge[i].sc << endl;
    }

    while(k){
        string s;
        int sum=0;
        for(int i=1; i<=8; i++){
            int num=(1<<(i-1));
            if(n<num) break;

            // i ビット目が立っているか
            cout << i << endl;
            cin>>s;
            if(s=="Yes"){
                k--;
                goto END;
            }
            if(s=="Near"){
                sum+=num;
            }
        }
        cout << sum << endl;
        cin>>s;
        k--;
        END:;
    }
}


Measured memory_bytes: 3360
#include <stdio.h>

int main(void){
  int N;
  int T;
  int c[100];
  int t[100];
  int i, j, k;
  int min = 10000;

  scanf("%d %d", &N, &T);
  for(i = 0; i < N; i++){
    scanf("%d %d", &c[i], &t[i]);
  }

  for(i = 0; i < N; i++){
    if(t[i] <= T && c[i] < min){
      min = c[i];
    }
  }

  if(min < 10000){
    printf("%d\n", min);
  }else{
    printf("TLE\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,k;
 sc(n);sc(k);
 map<ll,ll>map;
 ll cnt=0,a,mx=0;
 rep(i,0,n){
  sc(a);mx=max(mx,a);
  if(map[a]==0)cnt++;
  map[a]++;
 }
 llpvec pair(mx);
 rep(i,1,mx+1)pair[i-1]={map[i],i};
 sort(all(pair));
 
 ans=0;
 for(i=0;cnt>k;i++){
  if(pair[i].first!=0){
   ans+=pair[i].first;cnt--;
  }
 }
 pr(ans);
 return 0;}



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

struct edge {
    int to, cost;
};

class dijkstra {
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<P>> que;

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    int find(int e) {
        return d[e];
    }
};

int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

bool prime(int a) {
    if (a == 1) return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}

class Union_Find {
private:
    vector<int> t, s;

public:
    Union_Find(int max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(int x, int y) {
        if (same(x, y)) return;
        int tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        } else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        } else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        } else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }

    int Find(int n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(int x, int y) {
        return Find(x) == Find(y);
    }

    int get_Size(int a) {
        return s[a];
    }
};

vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}

signed main() {
    int p,q,r;
    cin>>p>>q>>r;
    cout<<min({p+q,q+r,r+p})<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> A(N),B(N);
  for(int &i:A)cin>>i;
  for(int &i:B)cin>>i;
  int cnta=0,cntb=0,suma=0,sumb=0;
  for(int i=0;i<N;i++)
    suma+=A[i],sumb+=B[i],cnta+=(max(B[i]-A[i],0LL)+1)/2,cntb+=max(A[i]-B[i],0LL);
  if(suma>sumb || sumb-suma<max(cnta,cntb))puts("No");
  else puts("Yes");
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int h, w, n;
  cin >> h >> w >> n;

  vector<int> mn(w + 5, 1e7);
  vector<pair<int, int>> ob(n);
  map<pair<int, int>, int> obs;
  mn[1] = 0;
   
  for (int i = 0; i < n; ++i) {
    cin >> ob[i].first >> ob[i].second;
    obs[ob[i]] = 1;
  }

  int x = 1, y = 1, steps = 0;
  while (x <= h && y <= w) {
    x++;
    if (obs.count({x, y+1}) == 0) y++;
    mn[y] = min(mn[y], ++steps);  
  }

  int ans = h;
  for (int i = 0; i < n; ++i) {
    if (ob[i].first < ob[i].second || ob[i].first - 1 <= mn[ob[i].second]) continue;
    // if (ob[i].first - 2 == mn[ob[i].second]) ans = min(ans, ob[i].first - 1);
    ans = min(ans, ob[i].first - 1);
  }

  cout << ans << '\n';
}


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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if ((A <= C && C <= B) || (B <= C && C <= A)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  bool ans = false; 

  int x;
  for (int i = 0; i < A; i++) {
    x=B*(i+1)+C;
    if (x%A == 0){
        ans=true;
        break;
    }
  }
  if (ans) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
from collections import*
n,k=[int(i) for i in input().split()]
l=input().split()
a=Counter(l)
ca=a.most_common()
val=len(set(l))
s=0
if val < k:
	k=val
for i in range(k):
	s +=ca[i][1]
print(n-s)

Measured memory_bytes: 57496
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    s = int(input())

    v = 10**9

    x = (v-s%v)%v
    y = (s+x)//v

    print(0,0,10**9,1,x,y)

if __name__=='__main__':
    main()

Measured memory_bytes: 9192
#include<iostream>
using namespace std;
int main(){
	int a1,a2,b1,b2;
	cin>>a1>>a2>>b1>>b2;
	do{
	   b1=b1-a2;
	   if(b1<=0){
	      cout<<"Yes"<<endl;
	      return 0;
	   }
	   a1=a1-b2;
	   if(a1<=0){
	   	  cout<<"No"<<endl;
	   	  return 0;
	   }
	}while(1==1);
	return 0;
}

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

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

	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int K; 
  cin >> K;

  int N = 50;
  vector<int> A(N);
  REP(i, N) A[i] = i+K/N;

  K %= N;
  while(K-- > 0){
    pair<int, int> MIN = {INF, -INF};
    REP(i, N){
      A[i]--;
      if(MIN.first > A[i]) MIN = {A[i], i};
    }
    A[MIN.second] += N+1;
  }

  cout << N << endl;
  REP(i, N){
    cout << A[i]; SPBR(i, N);
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll n;cin>>n;
    ll h[n];rep(i,0,n-1)cin>>h[i];
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    rep(i,2,n-1){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
void sort_bubble(char a[][2], int n) {
	for (int i = 0; i < n; i++) {
		int flag = 0;
		for (int j = 0; j < n-i-1; j++) {
			if (a[j][1] > a[j + 1][1]) {
				swap(a[j], a[j + 1]);
				flag = 1;
			}
		}
		if (!flag) break;
	}
}
void sort_select(char a[][2], int n) {
	for (int i = 0; i < n; i++) {
		int k = i; 
		int  min = a[i][1];
		for (int j = i; j < n; j++) {
			if (a[j][1] < min) {
				min = a[j][1];
				k = j;
			}
		}
		swap(a[i], a[k]); 
	}
}
int is_stable(char a[][2], char b[][2],int n) {
	for (int i = 0; i < n; i++) {
		if (a[i][0] != b[i][0] || a[i][1] != b[i][1]) return 0;
	}
	return 1;
}
int main(void) {
	int n;
	cin >> n;
	char a[36][2];
	char b[36][2];
	for (int i = 0; i < n; i++) {
		cin >> a[i][0]>>a[i][1];
		b[i][0] = a[i][0];
		b[i][1] = a[i][1];
	}
	sort_bubble(a, n);
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << a[i][0] << a[i][1];
	}
	cout << endl<<"Stable"<<endl;
	sort_select(b, n);
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << b[i][0] << b[i][1];
	}
	if (is_stable(a, b, n)) cout <<endl <<"Stable" << endl;
	else cout <<endl<< "Not stable" << endl;
}


Measured memory_bytes: 3088
import sys

#+++++

		
def main():
	h , w = map(int, input().split())
	mm=[input() for _ in range(h)]
	
	rr_lr=[[0]*(w) for _ in range(h)]
	rr_rl=[[0]*(w) for _ in range(h)]
	rr_ud=[[0]*(w) for _ in range(h)]
	rr_du=[[0]*(w) for _ in range(h)]
							
	for hi in range(h):
		ll=0
		rl=0
		for wj in range(w):
			if mm[hi][wj] == '.':
				ll+=1
				rr_lr[hi][wj]=ll
			else:
				ll=0				
				
			if mm[hi][w-1-wj] == '.':
				rl+=1
				rr_rl[hi][w-1-wj]=rl
			else:
				rl=0				
					
	for wi in range(w):
		ll=0
		rl=0
		for hj in range(h):
			if mm[hj][wi] == '.':
				ll+=1
				rr_ud[hj][wi]=ll
			else:
				ll=0
				
			if mm[(h-1)-hj][wi] == '.':
				rl+=1
				rr_du[(h-1)-hj][wi]=rl
			else:
				rl=0
				
	ret=0
	for i in range(w):
		for j in range(h):
			vv=rr_lr[j][i]-3
			vv+=rr_rl[j][i]
			vv+=rr_du[j][i]
			vv+=rr_ud[j][i]
			ret = max(ret,vv)
	
	return ret

	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)


Measured memory_bytes: 177928
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    vi a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int cnt = 0;
    bool q = true;
    while(q){
        int l = -1, r = -1;
        for(int i = 0; i < n; i++){
            if(a[i] > 0){
                l = i;
                break;
            }
        }
        if(l == -1) break;
        for(int i = l; i < n; i++){
            if(a[i] == 0){
                r = i - 1;
                break;
            }
        }
        if(r == -1) r = n-1;
        int mn = (*min_element(a.begin() + l, a.begin() + r + 1));
        for(int i = l; i <= r; i++){
            a[i] -= mn;
        }
        cnt += mn;
    }
    cout << cnt;
}

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

int main()
{
  int n_persons;
  std::cin >> n_persons;
  
  std::vector<std::size_t> n_of_bukas(n_persons);
  for (std::size_t i=0; i<n_persons-1; ++i) {
    int josi;
    std::cin >> josi;
    ++n_of_bukas[--josi];
  }
  for (auto&& n_buka : n_of_bukas) {
    std::cout << n_buka << std::endl;
  }
}




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

using namespace std;

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

const double PI=3.14159265358979323846;

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

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

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

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

// ABC075 C
using P = pair<int, int>;
int n;
vector< vs32 > g;


void dfs(int u, const P& e, vector<bool>& reached)
{
    reached[u] = true;
    for (auto v : g[u])
    {
        P e1 = {u, v};
        P e2 = {v, u};
        if (!reached[v] && e1 != e && e2 != e)
        {
            dfs(v, e, reached);
        }
    }
}

bool solve(const P& e)
{
    int ret = 0;
    vector<bool> reached(n, false);
    rep (i, n)
    {
        if (!reached[i])
        {
            dfs(i, e, reached);
            ++ret;
        }
    }
    return ret > 1;
}

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

    int m;
    cin >> n >> m;
    g.resize(n);
    vs32 a(m), b(m);
    rep (i, m)
    {
        cin >> a[i] >> b[i];
        --a[i]; --b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    int ans = 0;
    rep (i, m)
    {
        if (solve(P{a[i], b[i]})) ++ans;
    }

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



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <string.h>
#include <iostream>
#include<algorithm>
#include <queue>
#include <vector>
#include<string>
//******************************************************
#define lrt (rt*2)
#define rrt  (rt*2+1)
#define LL long long
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define exp 1e-8
const double temp=(1+sqrt(5))/2;
//***************************************************
#define eps             1e-8
#define inf             0x3f3f3f3f
#define INF             2e18
#define LL              long long
#define ULL             unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair

#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define SQR(a)          ((a)*(a))
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define Iterator(a)     __typeof__(a.begin())
#define rIterator(a)    __typeof__(a.rbegin())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define CasePrint       pc(‘C‘); pc(‘a‘); pc(‘s‘); pc(‘e‘); pc(‘ ‘); write(qq++,false); pc(‘:‘); pc(‘ ‘)
#define vi              vector <int>
#define vL              vector <LL>
#define For(I,A,B)      for(int I = (A); I < (B); ++I)
#define rFor(I,A,B)     for(int I = (A); I >= (B); --I)
#define Rep(I,N)        For(I,0,N)
using namespace std;
const int maxn=1e5+10;
typedef pair<int, int>P;
struct edge
{
    int to,d,cost;
};
int n,m,d[maxn],sum[maxn];
vector<edge>G[maxn];
void Dijkstra(int s)
{
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+n+1,inf);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty())
    {
        P p=que.top();  que.pop();
        int v=p.second;
        if(d[v]<p.first)    continue;
        for(int i=0;i<G[v].size();i++)
        {
            edge e=G[v][i];
            if(d[e.to]>=d[v]+e.d)
            {
                if(d[e.to]==d[v]+e.d)   sum[e.to]=min(sum[e.to],e.cost);
                else    sum[e.to]=e.cost;
            d[e.to]=d[v]+e.d;
            que.push(P{d[e.to],e.to});
            }
        }

    }
}
int main()
{
    while(cin>>n>>m)
    {
        if(m+n==0)  break;
        int u,v,dis,c;
        memset(sum,0,sizeof(sum));
        for(int i=1;i<=n;i++)   G[i].clear();
        for(int i=0;i<m;i++)
        {
            scanf("%d %d %d %d",&u,&v,&dis,&c);
            G[u].push_back(edge{v,dis,c});
            G[v].push_back(edge{u,dis,c});
        }
        Dijkstra(1);
        int ans=0;
        for(int i=2;i<=n;i++)
        {
            ans+=sum[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 7576
#include <stdio.h>
int main(void){
    long long l,r,i,j,ans=10000000000;
    scanf("%lld%lld",&l,&r);
    if(r-l>=2019) ans = 0;
    else{
        for(i=l;i<r;i++){
            for(j=i+1;j<=r;j++){
                if(ans>i*j%2019) ans=i*j%2019;
            }
        }
    }
    printf("%lld",ans);
    return 0;
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

using pii = pair<int, int>;

inline void Main() {
  // code
  int n,b[99],r=0;
  cin>>n;
  rep(i,n-1) cin>>b[i];

  r += b[0] + b[n-2];
  rep(i,n-2){
    r += min(b[i], b[i+1]);
  }
  cout<<r<<endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
ary_1 = gets.split(" ").map(&:to_i)
ary_2 = gets.split(" ").map(&:to_i)
max = 0

n.times do |i|
  if max < ary_1[0..i].inject(:+) + ary_2[i..-1].inject(:+)
    max = ary_1[0..i].inject(:+) + ary_2[i..-1].inject(:+)
  end
end

puts max

Measured memory_bytes: 1916
#include <cstdio>
#include <utility>
using namespace std;

using i64 = long long;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

i64 D[13];
i64 E[13];
const i64 M = 1000000007;
signed main() {
	D[0] = 1;
	while(true) {
		char c = getchar_unlocked();
		if (c == '\n') {
			break;
		} else if (c == '?') {
			REP(r, 13) {
				i64 s = 0;
				REP(j, 10) {
					s += D[(j - r + 13) * 9 % 13];
				}
				E[r] = s % M;
			}
		} else {
			i64 d = c - '0';
			REP(r, 13) {
				E[r] = D[(d - r + 13) * 9 % 13];
			}
		}
		swap(D, E);
	}
	printf("%d", D[5]);
}


Measured memory_bytes: 128
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getLine >>= print

solve :: String -> Int
solve s = p2 - p1
  where
    n = length s
    p1 = length $ filter (== 'p') s
    p2 = n `div` 2


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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int h, w, n;
    cin >> h >> w >> n;
    vector<vector<char>> ml(h + 2, vector<char>(w + 2, '.'));
    REP (i, 1, h + 1) REP (j, 1, w + 1) cin >> ml[i][j];
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    auto del = [w, h, n, dx, dy] (vector<vector<char>> &ml) -> void {
        bool run = true;
        while (run) {
            run = false;
            REP (j, 1, w + 1) {
                auto work = vector<char>(h + 2, '.');
                int pos = h;
                for (int i = h; i >= 1; i--) {
                    if (ml[i][j] != '.') work[pos--] = ml[i][j];
                }
                REP (i, 0, h + 2) ml[i][j] = work[i];
            }

            vector<vector<bool>> memo(h + 2, vector<bool>(w + 2, false));
            REP (i, 1, h + 1) REP (j, 1, w + 1) {
                if (ml[i][j] == '.') continue;
                REP (k, 0, 4) {
                    int y = i, x = j;
                    int len = 0;
                    char c = ml[y][x];
                    while (ml[y][x] == c) {
                        len++;
                        y += dy[k];
                        x += dx[k];
                    }
                    if (len >= n) {
                        y = i, x = j;
                        run = true;
                        while (ml[y][x] == c) {
                            memo[y][x] = true;
                            y += dy[k];
                            x += dx[k];
                        }
                    }
                }
            }
            REP (i, 1, h + 1) REP (j, 1, w + 1) if (memo[i][j]) ml[i][j] = '.';
        }
    };
    auto check = [h, w] (vector<vector<char>> &ml) -> bool {
        REP (i, 0, h + 2) REP (j, 0, w + 2) if (ml[i][j] != '.') return false;
        return true;
    };

    bool res = false;
    REP (i, 1, h + 1) REP (j, 1, w) {
        if (ml[i][j] == ml[i][j + 1]) continue;
        auto cp = ml;
        swap(cp[i][j], cp[i][j + 1]);
        del(cp);
        res |= check(cp);
    }

    cout << (res ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

vector<int> dp(mx,-1);
vector<int> v[mx];

int rec(int x){
  if(dp[x]!=-1) return dp[x];
  int tmp = 0;
  for(auto it:v[x]){
    tmp = max(tmp, rec(it)+1);
  }
  return dp[x] = tmp; 
}

int main(){
  int n,m;
  cin >> n >> m;
  
  rep(i,m){
    int x,y; cin >> x >> y; x--; y--;
    v[x].emplace_back(y);
  }
  
  int ans = 0;
  rep(i,n){
    ans = max(ans, rec(i));
  }
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 8192
s = input()
count = 0
a = 0
q = s.count('?')
c = 3 * s.count('C') + q
p = pow(3, q-3)
for i in range(len(s)):
    if s[i] == 'A':
        a += 3
    elif s[i] == 'C':
        c -= 3
    elif s[i] == 'B':
        count += 3*a*c
    else:
        c -= 1
        count += a*c
        a += 1
print(int(count*p) % 1000000007)

Measured memory_bytes: 3188
n, m = gets.split.map(&:to_i)

pena = Array.new(n, 0)
correct = Array.new(n, 0)

m.times do
  p, s = gets.chomp.split
  if s == 'WA'
    if correct[p.to_i-1] == 0
      pena[p.to_i-1] += 1
    end
  else
    if correct[p.to_i-1] == 0
      correct[p.to_i-1] = 1
    end
  end
end

correct.length.times do |i|
  if correct[i] == 0
    pena[i] = 0
  end
end

print "#{correct.inject(&:+)} #{pena.inject(&:+)}"

Measured memory_bytes: 3324
#include <stdio.h>
int main(void)
{
  // ↓↓ テストブロック ↓↓
  // char *str = "sippuu";
  // char *str = "iphone";
  // char *str = "coffee";
  // ↑↑ テストブロック ↑↑
  char str[10];
  scanf("%s",str);
  if ((str[2] == str[3]) && (str[4] == str[5])) {
    printf("Yes\n");
  }
  else
  {
   printf("No\n"); 
  }
  
  return 0;
}

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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lep(j, n) for (int j = 0; j < (n); j++)
#define reps(i, n) for (int i = 1; i < (n); i++)
#define leps(i, n) for (int j = 1; j < (n); j++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define int long long
#define gsort(x, n) sort((x), (x) + (n), greater<int>());
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

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

   string s;
   string a = "CODEFESTIVAL2016";
   cin >> s;
   int cnt = 0;
   rep(i, s.size())
   {
      if (s[i] != a[i])
         cnt++;
   }
   cout << cnt << '\n';
}

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

long long lcm(long long x, long long y){
  long long xx=max(x,y), yy=min(x,y);
  long long r;
  while(yy){
    r=xx%yy;
    xx=yy;
    yy=r;
  }
  return x*y/xx;
}

int main(){
  long long A,B; cin >> A >> B;
  cout << lcm(A,B) << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /* 標準入力数値配列用 long */
    static long[] inputLongArr() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        long[] longarray = new long[strarray.length];
        for (int i = 0; i < longarray.length; i++) {
            longarray[i] = Integer.parseInt(strarray[i]);
        }
        return longarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /*標準入力long*/
    static long inputLong() throws Exception {
        return Long.parseLong(br.readLine());
    }

    /*標準入力long*/
    static int inputInt() throws Exception {
        return Integer.parseInt(br.readLine());
    }



    public static void main(String[] args) throws Exception {
        // write your code here
        int n = inputInt();
        long [] al = inputLongArr();
        boolean increase = false;
        boolean decrease = false;
        long ans = 0;

        for (int i = 0; i<(n-1); i++){
            if (al[i] == al [i+1]){
                continue;
            }else if (al[i] > al [i+1]){
                decrease = true;
                if (increase){
                    ans ++;
                    increase = false;
                    decrease = false;
                }
            }else if (al[i] < al [i+1]){
                increase = true;
                if(decrease){
                    ans ++;
                    increase = false;
                    decrease = false;
                }
            }

        }

        System.out.println(ans+1);





    }

}



Measured memory_bytes: 46296
// ref. https://img.atcoder.jp/agc016/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }

  ll minA = INF;
  ll maxA = -INF;
  rep(i, n) {
    chmin(minA, a[i]);
    chmax(maxA, a[i]);
  }

  if (maxA - minA >= 2) { // invalid
    cout << "No" << endl;
  } else if (maxA - minA == 1) {
    ll total = maxA; // total number of types
    ll x = 0; // alone
    ll y = 0; // not alone
    rep(i, n) {
      if (a[i] == minA) { // a[i] is alone
        ++x;
      } else {
        ++y;
      }
    }
    if (x < total && 2*(total-x) <= y) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else { // maxA == minA
    if (minA == n-1) { // all a is alone
      cout << "Yes" << endl;
    } else if (2*a[0] <= n) { // all a is not alone
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1024
#  Copyright: this code was written at 2019. for AtCoder by Silviase
s = input()
tf = [True, False]
f = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for m in range(2):
                    tmp = ""
                    if tf[i]:
                        tmp += "A"
                    tmp += "KIH"
                    if tf[k]:
                        tmp += "A"
                    tmp += "B"
                    if tf[l]:
                        tmp += "A"
                    tmp += "R"
                    if tf[m]:
                        tmp += "A"
                    if tmp == s:
                        f = True
print("YES" if f else "NO")


Measured memory_bytes: 38292
eval'K,X,Y='+`dd`.split*?,
x,y,*s=X.abs,Y.abs
d=x+y
x,y=y,x if f=x<y
K%2-d%2<0&&p(-1)+exit
d!=K&&(L=[~-d/K,1].max+1
L+=1&d-K*L
v=K>(t=K*L-d>>1)?0:t-t=K
a=K-t
2.upto(L){s<<[a,-t]
a+=q=[x+v-a,K].min
t-=K-q})
s<<[x,y]
p s.size
s.map{|a,b|a,b=b,a if f
p a*=X<=>0.1,b*=Y<=>0.1}

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

typedef long long LL;
const int N = 205, M = 60, mod = 1000000007;

int n;
LL ans, K, a[N], b[N], c[N];

int min_popc(LL l, LL r) {
	if (!l) return 0;
	LL now = 0; int ret = 0;
	for (int i = 59; ~i; --i) {
		LL nxt = now | 1LL << i;
		if (nxt >= l && nxt <= r)
			return ret + 1;
		if (nxt < l) ++ret, now = nxt;
	}
	return assert(0), -1;
}

int idx, rk[M * N];
std::vector<LL> d[M * N];
std::pair<LL, LL> r[M * N], range[M * N];

void solve(int k) {
	b[0] = -1; for (int i = 1; i <= n; ++i) b[i] = a[i] & ~(-1LL << k);
	int tot = (std::sort(b + 1, b + n + 1), std::unique(b + 1, b + n + 1) - b - 1);
	for (int i = 1; i <= tot; ++i) if (b[i] <= a[1]) {
		LL rem = K - (k + min_popc(b[i - 1] + 1, b[i]));
		if (rem < 0) continue; d[idx].resize(n - 1);
		for (int j = 1; j <= n; ++j) c[j] = a[j] - b[i] >> k;
		for (int j = 1; j < n; ++j) d[idx][j - 1] = c[j + 1] - c[j];
		r[idx] = std::make_pair(std::max(0LL, c[1] - rem), c[1]);
		rk[idx] = idx, idx++;
	} else break;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> K;
	for (int i = 1; i <= n; ++i) std::cin >> a[i];
	std::sort(a + 1, a + n + 1);
	for (int i = 0; i <= 60; ++i) solve(i);
	std::sort(rk, rk + idx, [] (int x, int y) {return d[x] < d[y];});
	for (int i = 0; i < idx; ++i) range[i] = r[rk[i]];
	for (int l = 0, r = 0; l < idx; l = r) {
		while (r < idx && (l == r || d[rk[l]] == d[rk[r]])) ++r;
		std::sort(range + l, range + r); LL lst = -1;
		for (int i = l; i < r; ++i) if (range[i].second > lst) {
			ans += (range[i].second - std::max(range[i].first - 1, lst)) % mod;
			lst = range[i].second;
		}
	}
	std::cout << ans % mod << '\n';
	return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    int cnt[n];
    rep(i,n) cnt[i] = 0;
    bool ok = true;
    mint out=1;
    if(n%2==0){
        rep(i,n){
            int num = a[i];
            if(num%2==0 || cnt[num]>1){
                ok = false;
                break;
            }
            if(num==0){
                ok = false;
                break;                
            }
            cnt[num]++;
        }
        if(!ok) cout << 0 << endl;
        else{
            rep(i,n/2){
                out *= 2;
            }
            cout << out << endl;
        }
    }else{
        rep(i,n){
            int num = a[i];
            if(num%2==1 || cnt[num]>1){
                ok = false;
                break;
            }
            if(num==0 && cnt[num]>0){
                ok = false;
                break;                
            }
            cnt[num]++;
        }
        if(!ok) cout << 0 << endl;
        else{
            rep(i,n/2){
                out *= 2;
            }
            cout << out << endl;
        }

    }
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>

int n, k;

int main(){
    scanf("%d %d", &n, &k);

    int ans = 1;
    for(int i = 0; i < n; i++){
        if(ans * 2 < ans + k){
            ans *= 2;
        }else{
            ans += k;
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
void ABC50(void);
void ABC52(void);
void ABC53(void);
void ABC54(void);
void ABC55(void);
void ABC56(void);
void ABC57(void);
void ABC58(void);
void ABC59(void);

int main(void){
    ABC57();
    return 0;
}

void ABC57(void){
    int a,b;
    cin>>a>>b;
    if(a+b<24)cout<<a+b<<endl;
    else cout<<a+b-24<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007
#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

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

#define nmax 100010

int n, W;
int w[nmax], v[nmax];

ll dp[nmax];

int main()
{
    scanf("%d %d", &n, &W);

    int sum = 0;

    for (int i = 1; i <= n; i++) {

        scanf("%d %d", &w[i], &v[i]); sum += v[i];
    }

    for (int i = 1; i <= sum; i++) dp[i] = LL_INF;

    dp[0] = 0;

    for (int i = 1; i <= n; i++) {

        for (int j = sum - v[i]; j >= 0; j--)
            if (dp[j] != LL_INF) dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
    }

    for (int i = sum; i >= 0; i--)
        if (dp[i] <= W) {

            printf("%d", i); return 0;
        }

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 1024