akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int> A(N);
    rep(n,0,N) cin>>A.at(n);

    double sum=accumulate(ToEnd(A),0);
    double avg=round(sum/N);

    int64_t ans=0;
    for(auto a:A){
        ans+=pow(a-avg,2);
    }

    cout<<ans<<endl;
}

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

typedef unsigned long long ll;
ll n,fig[101],dp[101][21];

ll rec(int idx,int sum){
  if(sum < 0 || sum > 20) return 0;
  if(idx == n-1) return sum == fig[idx]? 1 : 0;
  if(dp[idx][sum] != -1) return dp[idx][sum];
  return dp[idx][sum] = (rec(idx+1,sum+fig[idx]) + rec(idx+1,sum-fig[idx]));
}

int main(){
  cin >> n;
  memset(dp,-1,sizeof(dp));
  for(int i=0;i<n;i++) cin >> fig[i];
  cout << rec(1,fig[0]) << endl;
}

Measured memory_bytes: 1180
#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
	int a, b, c, count=0, sum = 0, day = 0;

	cin >> a >> b >> c;

	while (sum < c) {
		sum += a;
		count++;
		day++;
		if (count == 7) {
			sum += b;
			count = 0;
		}
	}

	cout << day << endl;

	return 0;
}


Measured memory_bytes: 3096
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 mod=1e9+7;

int main(){
    ll d;
    cin >> d;
    vector<ll> c(26);
    rep(i,26){
        cin >> c[i];
    }
    vector<vector<ll>> s(d,vector<ll>(26));
    rep(i,d){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    vector<ll> ans(d);
    rep(i,d){
        pll ind=make_pair(-1,-1);
        rep(j,26){
            if(s[i][j]>ind.fi){
                ind.fi=s[i][j];
                ind.se=j+1;
            }
        }
        cout << ind.se << endl;
    }
    
    return 0;
} 

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MAXN 2000
#define MOD 1000000007

int N, K;
LL C[MAXN + 3][MAXN + 3];

int main() {
    for (int n = 0; n <= MAXN; n++) C[n][0] = 1;
    for (int k = 1; k <= MAXN; k++) C[0][k] = 0;
    for (int n = 1; n <= MAXN; n++) {
        for (int k = 1; k <= MAXN; k++) {
            C[n][k] = (C[n - 1][k] + C[n - 1][k - 1])%MOD;
        }
    }

    cin >> N >> K;
    for (int i = 1; i <= K; i++) {
        LL first = C[K - 1][i - 1];
        LL second = C[N - K + 1][i];

        cout << (first * second)%MOD << endl;
    }
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    if(s[0] == '9' || s[1] == '9') cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    string t;
    for(int i=0; i<q; i++){
        int ty;
        cin >> ty;
        if(ty==1){
            swap(s,t);
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(f==1){
                t+=c;
            }else{
                s+=c;
            }
        }
    }
    reverse(t.begin(),t.end());
    t += s;
    cout << t << endl;
    return 0;
}




Measured memory_bytes: 1128
// https://atcoder.jp/contests/abc145/tasks/abc145_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    REP(i, N) { cin >> A[i].first >> A[i].second; }
    double sum = 0;
    int cnt = 0;
    REP(i, N) {
        REP(j, N) {
            if (i != j) {
                sum +=
                    hypot(A[i].first - A[j].first, A[i].second - A[j].second);
                cnt++;
            }
        }
    }
    cout << setprecision(10) << (N - 1) * sum / cnt << endl;

    return 0;
}


Measured memory_bytes: 3820
#include<algorithm>
#include<cstdio>
#define M 2002
#define N 1001
using namespace std;
int A[M],B[M],C[M],D[M],a[N],b[M<<1],c[M<<1],d[M<<1],e[N],f[N][10],g[N][10],i,j,l,m,n,o,q[N],r,t,u,v,x,y,z;long long s;bool E[M];
inline bool cmp(int u,int v){return C[u]<C[v];}
int find(int u){return e[u]?e[u]=find(e[u]):u;}
inline void add(int u,int v,int w){b[++t]=a[u],c[a[u]=t]=v,d[t]=w,b[++t]=a[v],c[a[v]=t]=u,d[t]=w;}
int main()
{
	scanf("%d%d%lld",&n,&m,&s);
	for(i=l=r=1;i<=m;i++)scanf("%d%d%d",A+i,B+i,C+i),D[i]=i;
	sort(D+1,D+m+1,cmp);
	for(i=1;i<=m;i++)if(find(A[D[i]])!=find(B[D[i]]))E[D[i]]=true,s-=C[D[i]],e[find(A[D[i]])]=find(B[D[i]]),add(A[D[i]],B[D[i]],C[D[i]]);
	for(q[r++]=1,e[1]=0;l<r;)for(i=a[u=q[l++]];i;i=b[i])if(c[i]!=*f[u])e[q[r++]=c[i]]=e[u]+1,*f[c[i]]=u,*g[c[i]]=d[i];
	for(i=1;i<=n;i++)for(u=q[i],j=1;1<<j<=e[u];f[u][j]=f[f[u][j-1]][j-1],j++)g[u][j]=max(g[f[u][j-1]][j-1],g[u][j-1]);
	for(x=s?0:n-2,i=y=1;i<=m;i++)if(!E[i])
	{
		for(u=A[i],v=B[i],e[u]<e[v]?u^=v^=u^=v:0,j=o=0;e[u]-e[v];j++)if(e[u]-e[v]>>j&1)o=max(o,g[u][j]),u=f[u][j];
		if(u==v)
		{
			s<=C[i]-o?C[i]-o==s?x++:y++:0;
			continue;
		}
		for(j=9;j>=0;j--)if(f[u][j]!=f[v][j])o=max(o,max(g[u][j],g[v][j])),u=f[u][j],v=f[v][j];
		o=max(o,max(*g[u],*g[v])),s<=C[i]-o?C[i]-o==s?x++:y++:0;
	}
	for(i=z=0;i<x;i++)z=(z<<1|1)<1000000007?z<<1|1:(z<<1|1)-1000000007;
	for(i=0;i<y;i++)z=z<<1<1000000007?z<<1:(z<<1)-1000000007;
	return 0*printf("%d\n",z);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
        int temperature = sc.nextInt();
        
        if(temperature >= 30) {
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }
	}

}

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

int main(){
	int n, a;
	scanf("%d%d", &n, &a);
	if(n%500 <= a)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
def check(n,s,x):
    cnt=0
    f=0
    for i in range(n):
        if i%2==0:
            if (s[i]+f)*x<=0:
                cnt+=abs(x-s[i]-f)
                f+=x-s[i]-f
        else:
            if (s[i]+f)*x>=0:
                cnt+=abs(-x-s[i]-f)
                f+=-x-s[i]-f
    return cnt

def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    s=[a[0]]*n
    for i in range(1,n):
        s[i]=s[i-1]+a[i]

    cnt1=check(n,s,1)
    cnt2=check(n,s,-1)
    print(min(cnt1,cnt2))

if __name__=="__main__":
    main()

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
int main(){
    string s;
    cin>>s;
    int n;
    cin>>n;
    int cnt =0;
    int state=0;
    string sl,sr;
    rep(i,n){
        int q;
        cin>>q;

        if(q==1){
            cnt ++;
        }else if (q==2){
            
            int f;
            cin >>f;
            string c;
            cin>>c;
            if ((f+cnt)%2==0){
                sr=sr+c;
            }else if ((f+cnt)%2==1){
                sl=c+sl;
            }
        }
    }
    s=sl+s+sr;
    if(cnt%2==1) reverse(s.begin(),s.end());
    cout <<s;
}

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++) {
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    char c = s[s.length() - 1];
    s.pop_back();
    s.insert(s.begin(), c);
  }
  cout << "No" << endl;
  return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    int num[3] = {};
    rep(i, n) {
        int a;
        cin >> a;
        if (a % 4 == 0) num[0]++;
        else if (a % 2 == 0) num[1]++;
        else num[2]++;
    }
    if ((num[1] != 0 && num[0] < num[2]) || (num[1] == 0 && num[0] + 1 < num[2])) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import bisect

def input():
    return sys.stdin.readline()
def lis(n, A):
    L = [0 for i in range(n + 1)]
    L[0] = A[0]
    length = 1
    for i in range(1, n):
        if L[length - 1] < A[i]:
            L[length] = A[i]
            length += 1
        else:
            index = bisect.bisect_left(L, A[i], 0, length)
            L[index] = A[i]
    return length
if __name__=="__main__":
    n = int(input())
    A = [int(input()) for _ in range(n)]
    print(lis(n,A))


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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=list(S())

  for i,x in enumerate(s):
    if i%2==0:
      if x in ['R','U','D']:
        pass
      else:
        return 'No'
    else:
      if x in ['L','U','D']:
        pass
      else:
        return 'No'
  return 'Yes'

# main()
print(main())


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

int main(void){
    int n,a,b,c;
    cin >> n;
    a = n / 100;
    b = n / 10 - a * 10;
    c = n - 100 * a - 10 * b;

    if(a == 7 || b == 7 || c == 7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

 return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  int n;
  cin>>n;
  vector<int> a(n), b(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  sort(b.rbegin(),b.rend());
  vector<int> c(200005);
  rep(i,n) c[a[i]]++;
  rep(i,n) c[b[i]]++;
  priority_queue<P> q;
  rep(i,200005) if (c[i]) q.emplace(c[i],i);
  if (q.top().first > n) {
      cout<<"No"<<endl;
      return 0;
  }
  cout<<"Yes"<<endl;
  rep(i,n){
    if(a[i]!=b[i])continue;
    else{
        rep(j,n){
          if(a[i]!=b[j]&&a[j]!=b[i]){
            swap(b[i],b[j]);
            break;
          }
        }
    }
  }
  rep(i,n)cout<<b[i]<<" ";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 9648
/// ITNOG :)))
/// SAliB
#include <bits/stdc++.h>

using namespace std;

#define pb                      push_back
#define pp                      pop_back
#define mp                      make_pair
#define fi                      first
#define sec                     second
#define xmax(x,y)               ((x) = max((x),(y)))
#define xmin(x,y)               ((x) = min((x),(y)))
#define all(x)                  (x).begin(),(x).end()
#define mem(x , y)              memset(x , y , sizeof(x))
#define _                       ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define debug1(a)               cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n';
#define debug2(a , b)           cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n';
#define debug3(a , b , c)       cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n' << #c << " ---> " << c << '\n';
#define debug4(a , b , c , d)   cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n' << #c << " ---> " << c << '\n' << #d << " ---> " << d << '\n';
#define connect(a , b , c)      a[b].pb(c) , a[c].pb(b)
//
typedef long long int ll            ;
typedef unsigned long long int ull  ;
typedef unsigned int uint           ;
typedef long double ld              ;
typedef string str                  ;
typedef pair < int , int > pii      ;
typedef pair < pii , int > ppi      ;
typedef pair < int , pii > pip      ;
typedef pair < ll , ll> pll         ;
typedef pair < ll , pll> plp        ;
typedef pair < pll , ll> ppl        ;
typedef vector < ll > vl            ;
typedef vector < ld > vld           ;
typedef vector < int > vi           ;
typedef vector < str > vs           ;
//
inline int   iin()  { int x   ; scanf("%d" , &x)   ;  return x; }
inline ll    lin()  { ll  x   ; scanf("%lld" , &x) ;  return x; }
inline ll    Lin()  { ll  x   ; scanf("%I64d" , &x);  return x; }
//
inline int   iout(int  x)  { printf("%d" , x)   ;  }
inline ll    lout(ll   x)  { printf("%lld" , x) ;  }
inline ll    Lout(ll   x)  { printf("%I64d" , x);  }
//
const int maxn4 = 1e4 + 85 , maxn5 = 1e5 + 69 , maxn6 = 1e6 + 85 , maxn7 = 1e7 + 69 , maxn8 = 1e8 + 85 , maxn9 = 1e9 + 69 , modi1 = 1e7 + 7 , modi2 = 1e9 + 7;
const ll mod1 = 1e7 + 7 , mod2 = 1e9 + 7;
int mn = INT_MAX , mx = INT_MIN;
//
int a[maxn5];
unordered_map<int,int> chain;
int main()
{
	int n , ans = 0; cin >> n;
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i];
		chain[a[i]] = (i & 1);
	}
    sort(a , a + n);
	for(int i = 0 ; i < n ; i++)
		if(chain.at(a[i]) != (i % 2))
			ans++;
	cout << ans / 2;
	return 0;
}


Measured memory_bytes: 4772
import java.util.*;

public class Main {

    public void main(Scanner sc) {
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long h[] = new long[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextLong();
        }

        long l = 1;
        long r = 1_000_000_000;
        while (l != r) {
            long mid = (l + r) / 2;
            if (count(mid, h, a, b) <= mid) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }

        System.out.println(l);
    }

    private long count(long mid, long h[], long a, long b) {
        long sa = a - b;

        long cnt = 0;
        for (int i = 0; i < h.length; i++) {
            cnt += Math.max((h[i] - mid * b + sa - 1) / sa, 0);
        }

        return cnt;
    }

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


Measured memory_bytes: 50908
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 1e5 + 5, M = 1e9 + 7;
ll dp[105][N], wt[105], v[105];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int n, w;
    cin >> n >> w;
    for (ll i = 0; i < n; i++)
        cin >> wt[i] >> v[i];
    for (ll i = wt[0]; i <= w; i++)
        dp[0][i] = v[0];
    for (ll i = 1; i < n; i++)
        for (ll j = 0; j <= w; j++)
            dp[i][j] = max(dp[i - 1][j], ((j < wt[i]) ? 0ll : (dp[i - 1][j - wt[i]] + v[i])));
    cout << dp[n - 1][w];
}

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

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

int main(){
    int y1,y2,m1,m2,d1,d2;
    cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
    int y=y1,d=d1,m=m1;
    int e1=0,e2=y1-y2;
    int ans=0;
    if (m2>m1 || (m1==m2 && d1<d2)) e2--;
    //cout << e2 << endl;
    for (int t=0;t<400*366;t++){
        d++;
        if (m==4 || m==6 || m==9 || m==11){
            if (d==31) {d=1;m++;}
        }
        else if (m==2){
            if (y%4==0 && (y%100!=0 || y%400==0)) {
                if (d==30) {d=1;m++;}
            }
            else {
                if (d==29) {d=1;m++;}
            }
        }
        else {
            if (d==32) {d=1;m++;}
        }
        if (m==13) {d=1;m=1;y++;}
    if (m==m1 && d==d1) e1++;
    if (m==m2 && d==d2) e2++;
    if (y%4!=0 || (y%100==0 && y%400!=0)) {
        if (m1==2 && d1==29 && m==3 && d==1) e1++;
    }
    if (y%4!=0 || (y%100==0 && y%400!=0)) {
        if (m2==2 && d2==29 && m==3 && d==1) e2++;
    }

    ans=max(ans,e1-e2);
    ans=max(ans,e2-e1);
    //cout << " " << ans << endl;
}
cout << ans << endl;
}


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

int main() {
    int n, a;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        mp[a]++;
    }
    cout << mp.size() << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから
void solve(){
  int h,w;
  cin>>h>>w;
  vector<int>c(26);
  rep(i,h){
    string s;
    cin>>s;
    rep(j,w){
      c[s[j]-'a']++;
    }
  }
  bool ng=false;
  if(h%2==0&&w%2==0){
    rep(i,26){
      c[i]%=4;
      if(c[i])ng=true;
    }
  }
  else if(h%2==1&&w%2==1){
    int cnt=0,one=0;
    rep(i,26){
      c[i]%=4;
      if(c[i]==1)++one;
      else if(c[i]==3)++one,++cnt;
      else if(c[i]==2)++cnt;
    }
    if(cnt>w/2+h/2)ng=true;
    if(one!=1)ng=true;
  }
  else {
    int cnt=0;
    rep(i,26){
      c[i]%=4;
      if(c[i]==2)++cnt;
      else if(c[i])ng=true;
    }
    if(h%2==1){
      if(cnt>w/2)ng=true;
    }
    else {
      if(cnt>h/2)ng=true;
    }
  }
  if(ng)cout<<"No";
  else cout<<"Yes";
}

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


Measured memory_bytes: 256
N,Y = map(int,input().split())
Y //= 1000
found = False
for a in range(Y//10+1):
   for b in range(Y//5-2*a+1):
      c = Y - 10*a - 5*b
      if a + b + c == N:
         print('{} {} {}'.format(a,b,c))
         found = True
         break
      if a + b + c < N:
         break
   if found:
      break
else:
   print('-1 -1 -1')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    ll c = n / i;
    ans += i * (c * (c + 1) - i * i);
  }
  cout << ans << endl;
}

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

using namespace std;

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

typedef long long ll;

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

int main () {
	string S; cin >> S;
	int mon = stoi(S.substr(5,2));
	if (mon < 5) cout << "Heisei" << endl;
	else cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define lll pair<ll,ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vi vector<int>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define ppb() pop_back()
#define mkp(a,b) make_pair(a,b)
#define vs vector<string>
#define vc vector<char>
#define deb1(a) cout<<#a<<" "<<a<<"\n"
#define deb2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n"
#define mms0(a) memset(a,0,sizeof(a))
#define mms1(a) memset(a,-1,sizeof(a))
#define FOR(a,b,c) for(int i=(a);i<(b);i+=(c))
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define _ 0
using namespace std;




void solve(){
   string a,b;
   cin>>a>>b;

   int N =a.size(),M = b.size();

   int dp[N+1][M+1];
   mms0(dp);

   for(int i=1;i<=N;i++){
      for(int j=1;j<=M;j++){
         if(a[i-1] == b[j-1]){
            dp[i][j] = 1 + dp[i-1][j-1];
         }else{
            dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
         }
      }
   }

   // for(int i=0;i<=N;i++){
   //    for(int j=0;j<=M;j++) cout<<dp[i][j]<<" ";cout<<"\n";
   // }
   string ans ="";
   int row = N,col = M;
   while(row>0 && col>0){
      if(dp[row][col] == dp[row-1][col]){
         row--;
      }else if(dp[row][col] == dp[row][col-1]){
         col--;
      }else{
         ans+=a[row-1];
         row--;col--;
      }
   }
   reverse(ans.begin(),ans.end());
   cout<<ans;
}




int main(){
   int t = 1;
  // cin>>t;
   while(t--){
      solve();
   }
   return 0;
}

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

int main(void) {
    int a,b,c; cin >> a >> b >> c;
    int diffA,diffB,diffC;
    diffA = abs(a-b);
    diffB = abs(b-c);
    diffC = abs(c-a);
    cout << (diffA + diffB + diffC - max(max(diffA,diffB),diffC)) << endl;
}

Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0)
typedef long long ll;


ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

//#######################################


int main(){
  boost;
  
  string s;
  cin>>s;
  int count=0,mx=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='R'){
      count++;
    }
    else{
      count=0;
    }
    mx=max(mx,count);
  }
  cout<<mx;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; 
	long long int A[114514] = {}; 
	cin >> N; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	long long int pos = 0; long long int neg = 0; 
	long long int Sp = 0; long long int Sn = 0; 
	for(int i = 0; i < N; i++){
		Sp += A[i]; 
		if(i % 2 == 0 && Sp <= 0){
			pos += 1 - Sp; Sp = 1; 
		}
		if(i % 2 == 1 && Sp >= 0){
			pos += 1 + Sp; Sp = -1; 
		}
	}
	for(int i = 0; i < N; i++){
		Sn += A[i]; 
		if(i % 2 == 1 && Sn <= 0){
			neg += 1 - Sn; Sn = 1; 
		}
		if(i % 2 == 0 && Sn >= 0){
			neg += 1 + Sn; Sn = -1; 
		}
	}
	cout << min(pos, neg) << endl; 
}

Measured memory_bytes: 1152
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(scanner.nextLine());

		String line = scanner.nextLine();
		String[] ab = line.split(" ");
		int a = Integer.parseInt(ab[0]);
		int b = Integer.parseInt(ab[1]);

		Integer[] p = new Integer[n];

		for (int i = 0; i < n; i++) {
			p[i] = Integer.parseInt(scanner.next());
		}

		Arrays.sort(p);

		Integer[] num = {0, 0, 0};

		for (int tmp : p) {
			if (tmp <= a) {
				num[0]++;
			} else if (tmp >= (a + 1) && tmp <= b) {
				num[1]++;
			} else if (tmp >= (b + 1)) {
				num[2]++;
			}
		}

		int min = num[0];

		for (int tmp : num) {
			if (tmp < min) {
				min = tmp;
			}
		}

		System.out.println(min);

	}

}

Measured memory_bytes: 24020
#include <iostream>

using namespace std;

int main(){
	int n,a,b,pa,pb;

	while(1){
		cin >> n;
		if(n != 0){
			pa = pb = 0;

			for(; n > 0; n--){
				cin >> a;
				cin >> b;

				if(a > b){
					pa += a + b;
				}else if(a < b){
					pb += a + b;
				}else{
					pa += a;
					pb += b;
				}
			}

			cout << pa << " " << pb << endl;
		}else{
			break;
		}
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int count = 0;
  vector<int> r(n);
  for (int i = 0; i < n; i++) {
    cin >> r.at(i);
    
    if (r.at(i) % 2 == 1 && (i+1) % 2 == 1) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n, m;
		int location[];
		int count;
		boolean flag;

		n = scanner.nextInt();
		m = scanner.nextInt();
		while (n + m != 0) {
			location = new int[m];
			count = n;
			flag = true;
			for (int i = 0; i < m; i++) {
				location[i] = 0;
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					location[j] += scanner.nextInt();
				}
			}
			while (0 <= count) {
				for (int i = 0; i < m; i++) {
					if (location[i] == count) {
						if (flag) {
							System.out.print(i + 1);
							flag = false;
						} else {
							System.out.print(" " + (i + 1));
						}
					}
				}
				count--;
			}
			System.out.println();
			n = scanner.nextInt();
			m = scanner.nextInt();
		}
	}
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int func(long long N, std::vector<long long> B) {
    // cout << fixed << setprecision(8);

    // 競プロ参戦記 #63 Second Sum | ABC 140 - Qiita
    // https:  // qiita.com/vain0x/items/7ed6bfde477f0ce479b8
    // Aの最大値の条件を導く
    // 一般化すると
    // A(1) ≤ B(1)
    // A(i) ≤ min(B(i-1), B(i)) (i∈{2, ..., N-1})
    // A(N) ≤ B(N-1)
    // （これを0-indexに合わせるため-1する。）

    ll ans;
    // A[0]を入れる。
    ans = B[0];
    // A[N-1]を足す。
    ans += B[N - 2];
    // A[i]を合計する。
    for (int i = 1; i <= N - 2; i++) {
        ans += min(B[i - 1], B[i]);
    }
    cout << ans << endl;

    return 0;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> B(N - 1);
    for (int i = 0; i < N - 1; i++) {
        scanf("%lld", &B[i]);
    }

    func(N, std::move(B));

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	if ((A + B)%2 == 0) {
    		System.out.println((A + B)/2);
    	} else {
    		System.out.println("IMPOSSIBLE");
    	}
    }
}

Measured memory_bytes: 21840
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
#define  aryout(ary) rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n");
#define  arysort(v) sort(v.begin(), v.end())
#define  aryreverse(v) reverse(v.begin(),v.end())
#define  arysum(v) accumulate(v.begin(), v.end(), 0)
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> cnt(n+100, 0);
  vector<stack<pair<int, int>>> node(n+100);

  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a -= 1; b -= 1;
    cnt[a] += 1; cnt[b] += 1;

    pair<int, int> tmp;
    tmp.first = i;
    tmp.second = b;
    node[a].push(tmp);
    tmp.second = a;
    node[b].push(tmp);
  }

  int ans = 0;
  rep(i, n-1) ans = max(ans, cnt[i]);
  cout << ans << endl;

  vector<int> par(n+100, -1);
  vector<int> color(n+100, -1);
  queue<int> q;
  q.push(0);

  while (!q.empty()) {

    int next = q.front();
    q.pop();
    int cnt = 0;

    while (!node[next].empty()) {
      pair<int, int> tmp = node[next].top();

      if (color[tmp.first] == -1) {
        if (cnt == par[next]) cnt += 1;
        color[tmp.first] = cnt;
        par[tmp.second] = cnt;
        q.push(tmp.second);
        cnt += 1;
      }
      node[next].pop();
    }
  }
  //rep(i, n-1) cout << i << ": " << color[i] + 1 << endl;
  rep(i, n-1) cout << color[i] + 1 << endl;
  
  return 0;
}


Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int n = (int)1e6 + 77;
const double pi = 3.14159265359;
int main() {
ll n;
cin>>n;
ll m=n%1000;
if(m==0)
    cout<<0;
else
    cout<<1000-m;
return 0;
}


Measured memory_bytes: 3628
N = int(input())
a = list(map(int, input().split()))

ans = []
for i in range(N - 1, -1, -2):
    ans.append(a[i])
    
tmp_ans = []
for i in range(N - 2, -1, -2):
    tmp_ans.append(a[i])
tmp_ans.reverse()
ans += tmp_ans 
print(" ".join(map(str, ans)))

Measured memory_bytes: 30404
N = int(raw_input())
S = list(raw_input())
S = ['X']+S+['X']
D = [[0, 0]]
W = [0] * (N+2)
E = [0] * (N+2)
for i in range(1,N+2):
 W[i] = W[i-1]+(1 if S[i-1]== 'W' else 0)
for i in range(N+1)[::-1]:
 E[i] = E[i+1]+(1 if S[i+1]== 'E' else 0)
ans = N
for i in range(N):
  if W[i+1]+E[i+1] < ans:
   ans = W[i+1]+E[i+1]
print ans


Measured memory_bytes: 33520
N,M = map(int,input().split())
LRD = [(lambda x: [int(x[0])-1,int(x[1])-1,int(x[2])])(input().split()) for _ in [0]*M]

connect = [[] for _ in range(N)]
for L,R,D in LRD:
    connect[L].append([R,D])
    connect[R].append([L,-D])

ans = True
n = [None] * N
n0 = 0
while ans:
    q = [n0]
    n[n0] = 0
    for i in q:
        for j,d in connect[i]:
            if n[j] == None:
                n[j] = n[i] + d
                q.append(j)
            elif n[j]-n[i] != d:
                ans = False
                break
        if not ans:
            break
    for i in range(n0,N):
        if n[i] == None:
            n0 = i
            break
    else:
        break

if ans:
    print("Yes")
else:
    print("No")

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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define per(i,a,b)	for(ll i=a;i>b;i--)

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

ll mod = 1000000007;

using namespace std;
int main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in", "r", stdin);
	//freopen("outputf.in", "w", stdout);
	//#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n,k;
	cin>>n>>k;
	ll i=ceil((float)n/2);
	ll j=i+1;
	ll p=k;
	set<ll>s;
	while(i<j){
		if(j-i==n-j+i||s.find(j-i)!=s.end()||s.find(n-j+i)!=s.end()){
			i--;
			continue;
		}
		s.insert(j-i);
		s.insert(n-j+i);
		cout<<i<<" "<<j<<"\n";
		i--;
		j++;
		k--;
		if(k==0)
			break;
	}


	return 0;
}

Measured memory_bytes: 11976
ina = input()
inb = input()
inc = input()
 
next = "a"
 
while True:
    if next == "a":
        if ina == "":
            break
        next = ina[0]
        ina = ina[1:]
    elif next == "b":
        if inb == "":
            break
        next = inb[0]
        inb = inb[1:]
    else:
        if inc == "":
            break
        next = inc[0]
        inc = inc[1:]
print(next.upper())

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var S, T string
	fmt.Scan(&S, &T)

	N := len(S)
	M1 := make(map[uint8]uint8, 26)
	M2 := make(map[uint8]uint8, 26)

	for i := 0; i < N; i++ {
		if t, ok := M1[S[i]]; ok {
			if T[i] != t {
				fmt.Println("No")
				return
			}
		} else {
			M1[S[i]] = T[i]
			if s, ok := M2[T[i]]; ok {
				if S[i] != s {
					fmt.Println("No")
					return
				}
			} else {
				M2[T[i]] = S[i]
			}
		}
	}
	fmt.Println("Yes")
}


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

int main(){
    int m,h;
    string str;
    string right;
    while(1){
        cin >> str;
        if(str[0] == '-') break;
        cin >> m;
        for(int i = 0; i < m; ++i){
            cin >> h;
            string right = str.substr(0, h);
            string left = str.substr(h, str.length() - h);
            str = left + right;
        }
        cout << str << endl;
    }
    return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
ll a,b,c,d;
unordered_map<ll,ll> mp;
unordered_map<ll,bool> v;

ll rec(ll x){
    if(v[x])
        return mp[x];
    v[x]=true;
    ll s{LLONG_MAX};
    if(x<LLONG_MAX/d) s=x*d;
    chmin(s,rec(x/2)+a+x%2*d);
    if(x%2) chmin(s,rec(x/2+1)+a+d);
    chmin(s,rec(x/3)+b+x%3*d);
    if(x%3) chmin(s,rec(x/3+1)+b+(3-x%3)*d);
    chmin(s,rec(x/5)+c+x%5*d);
    if(x%5) chmin(s,rec(x/5+1)+c+(5-x%5)*d);
    //cout<<x<<" "<<s<<endl;
    return mp[x]=s;
}

void solve(){
    ll n;
    cin>>n>>a>>b>>c>>d;
    mp.clear();
    v.clear();
    v[0]=true;
    mp[0]=0;
    cout<<rec(n)<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    fr(_,t) solve();
}

Measured memory_bytes: 4632
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
string calculate_winner(int n,int k,vector <int> &v)
{
    vector <bool> dp(n+1,false);
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<k;j++)
        {
            if(i-v[j]<0)
            {
                break;
            }
            if(dp[i-v[j]]==0)
            {
                dp[i]=true;
                break;
            }
        }
    }
    string ans="";
    if(dp[n]==0)
        ans = "Second";
    else
        ans = "First";
    return ans;
}
int main()
{
    int k;
    int n;
    cin>>k>>n;
    vector <int> v(k);
    for(int i=0;i<k;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    string s = calculate_winner(n,k,v);
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3624
n = int(input())
a = list(map(int, input().split()))

ans = [0] * (n + 1)
ans[0], ans[1] = a[0] * 2, 0
temp = 0
for num, con in enumerate(a[1:]):
    temp += con
    ans[num+2] = temp * 2
    temp *= -1

diff = (ans[-2] + ans[0]) // 2 - a[-1]

sign = -1
for i in range(n):
    ans[i] += sign * diff
    sign *= -1

print(*ans[:-1])

Measured memory_bytes: 15044
//https://atcoder.jp/contests/dp/tasks/dp_a
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int N;
LL h[112345];
LL dp[112345];
int main(){
    cin>>N;
    for(int i:range(N))cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i:range(2,N)){
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
long long x, y, z;
int main() {
    DAU
    cin >> x >> y >> z;
    if (y * z >= x)
        cout << "Yes";
    else cout << "No";
    PLEC
}


Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

void dijkstra(int n, vector<vector<edge> >& G, vector<int>& t, int s, vector<ll>& d, vector<int>& prev) {
	fill(d.begin(), d.end(), LLONG_MAX); d[s] = 0;
	fill(prev.begin(), prev.end(), -1);
	priority_queue<ll_i, vector<ll_i>, greater<ll_i> > q;
	q.push(ll_i(0, s));
	while (!q.empty()) {
		ll_i p = q.top(); q.pop();
		int u = p.second;
		if (p.first > d[u]) continue;
		for (int i = 0; i < G[u].size(); i++) {
			edge e = G[u][i];
			if (d[e.v] >= d[u] + e.w)
				if (d[e.v] > d[u] + e.w || prev[e.v] == -1 || t[prev[e.v]] > t[u])
					prev[e.v] = u;
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				q.push(ll_i(d[e.v], e.v));
			}
		}
	}
}

int parent[20][100000];
int depth[100000];
 
void init(int N) {
	for (int k = 0; k + 1 < 20; k++)
		for (int v = 0; v < N; v++)
			if (parent[k][v] < 0) parent[k + 1][v] = -1;
			else parent[k + 1][v] = parent[k][parent[k][v]];
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> t(N);
	for (int u = 0; u < N; u++)
		scanf("%d", &t[u]);
	vector<vector<edge> > G(N);
	while (M--) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		a--; b--; ll w = (ll)c * 1000000 + 1;
		G[a].push_back(edge{a, b, w});
		G[b].push_back(edge{b, a, w});
	}
	vector<ll> d(N);
	vector<int> prev(N);
	dijkstra(N, G, t, 0, d, prev);
	for (int u = 0; u < N; u++) {
		parent[0][u] = prev[u];
		depth[u] = d[u] % 1000000;
	}
	init(N);
	int K; cin >> K;
	while (K--) {
		int x, day, p; scanf("%d%d%d", &x, &day, &p);
		x--;
		int y = x, up = max(0, depth[x] - day);
		for (int k = 0; k < 20; k++)
			if (up>>k & 1)
				y = parent[k][y];
		printf("%lld\n", d[x] / 1000000 - d[y] / 1000000 + max(0LL, d[y] / 1000000 - p));
	}
}

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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e17;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
	string s;
	cin >> s;
	int ans = 0;
	for (char c : s) ans += c - '0';
	cout << (ans % 9 ? "No" : "Yes");
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 3716
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N, 0), y(M, 0);
    for (int i = 0; i < N; i++)
        cin >> x[i];
    for (int j = 0; j < M; j++)
        cin >> y[j];

    sort(all(x)); sort(all(y));

    string ans = "War";
    for (int z = X+1; z <= Y; z++) {
        if (z > x[N-1] && z <= y[0]) {
            ans = "No War";
            break;
        }
    }

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


Measured memory_bytes: 384
#include<stdio.h>

int main(void){
  long int i,x,y,z;
  scanf("%ld%ld%ld",&x,&y,&z);
  for(i=0;;i++){
    if(x<y*i+z*(i+1)) break;
  }
  printf("%ld\n",i-1);
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
public class Main {
	static final long C =  1000000007;
	static final int CY = 1000000000;
	StringBuilder sb;
	public void calc() {
		sb = new StringBuilder();


		FastScanner sc = new FastScanner();

		char[] s = sc.next().toCharArray();
		char[] n = "CODEFESTIVAL2016".toCharArray();

		int ans = 0;

		for (int i=0; i < s.length; i++) {
			if (s[i] != n[i]) {
				ans ++;
			}
		}


		System.out.println(ans);
	}



	public static void main(String[] args) {
		Main main = new Main();
		main.calc();

	}
	static class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			}else{
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
		private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
		private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
		private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true){
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				}else if(b == -1 || !isPrintableChar(b)){
					return minus ? -n : n;
				}else{
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
		public int nextInt() {
			if (!hasNext()) throw new NoSuchElementException();
			int n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true){
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				}else if(b == -1 || !isPrintableChar(b)){
					return minus ? -n : n;
				}else{
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 8148
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //Compute c1 = new Compute();//calc

        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();
        long ans = 0;

        //input
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int d = sc.nextInt();

        for (int i = 1;i<=m;++i)
        {
            for (int j = 1;j<=d;++j)
            {
                if (j<10)
                {
                    continue;
                }
                int d2 = j/10;
                int d1 = j-(d2*10);
                int dd = d2*d1;
                if (dd==i)
                {
                    if (d1>=2 && d2>=2)
                    {
                        ++count;
                    }
                }
            }
        }
        //output
        System.out.println(count);
        //System.out.println(String.format("%.0f",answer));
    }
}

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

#define INF (1 << 30)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s == "Sunny"){
        out("Cloudy");
    }
    if(s == "Cloudy"){
        out("Rainy");
    }
    if(s == "Rainy"){
        out("Sunny");
    }
    return 0;
}

Measured memory_bytes: 256