akhauriyash/Code-Regression huggingface dataset:
# DP
def frog_dp():
    cost = [0] * N
    for cs in range(1, N):
        if cs == 1:
            cost[cs] = abs(h[cs]-h[cs-1])
        else:
            cost[cs] = min(cost[cs-1] + abs(h[cs]-h[cs-1]), cost[cs-2] + abs(h[cs] - h[cs-2]))
    return cost[-1]


N = int(input())
h = list(map(int, input().split()))
ans = frog_dp()
print(ans)

Measured memory_bytes: 13980
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A); repp(i,0,A) cin >> p[i]; sort(p.begin(), p.end(), greater<int>());
    vector<ll> q(B); repp(i,0,B) cin >> q[i]; sort(q.begin(), q.end(), greater<int>());
    vector<ll> r(C); repp(i,0,C) cin >> r[i]; sort(r.begin(), r.end(), greater<int>());
    vector<ll> t;
    repp(i,0,X) t.push_back(p[i]);
    repp(i,0,Y) t.push_back(q[i]);
    sort(t.begin(), t.end());
    repp(i,0,C) {
        if (i > X+Y) break;
        if (t[i] < r[i])  t[i] = r[i];
    }
    ll res = 0;
    repp(i,0,X+Y) res += t[i];
    cout << res << endl;
}


Measured memory_bytes: 4724
#include <iostream>
#include <cmath>
#include <complex>
#include <tuple>
#include <vector>
using namespace std;

using vec = complex<double>;
using line = pair<vec,vec>;
using polygon = vector<vec>;
const double eps = 0.0000001;

double inner_product(vec u,vec v){
    return real(u*conj(v));
}
double cross_product(vec u,vec v){
    return imag(conj(u)*v);
}

vec projection(line l,vec p){//p???l???????°???±
    vec s=l.first, t=l.second;
    double k = inner_product(t-s,p-s)/inner_product(t-s,t-s);
    return (1.0-k)*s+k*t;
}

vec reflection(line l,vec p){
    return 2.0*projection(l,p)-p;
}

int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    double o = cross_product(ab,ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(inner_product(ab,ac)<0){
        return 2; //C-A-B
    }else{
        if(inner_product(ab,ab)<inner_product(ac,ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

bool isIntersect(line l0, line l1){
    int s = ccw(l0.first,l0.second,l1.first)*ccw(l0.first,l0.second,l1.second);
    if(s!=0&&s!=-1&&s!=-4) return false;
    s=ccw(l1.first,l1.second,l0.first)*ccw(l1.first,l1.second,l0.second);
    if(s!=0&&s!=-1&&s!=-4) return false;
    else return true;
}

vec interSection(line l0, line l1){
    vec s0, t0, s1, t1;
    tie(s0,t0)=l0; tie(s1,t1)=l1;
    double k = cross_product(t1-s1,s1-s0)/cross_product(t1-s1,t0-s0);
    return s0+(t0-s0)*k;
}

double segLength(line l){
    return abs(l.first-l.second);
}

double distLine2point(line l, vec p){
    return abs(cross_product(l.second-l.first,p-l.first))/abs(l.second-l.first);
}

double distSeg2Point(line l, vec p){
    vec x = projection(l,p);
    double L = segLength(l);
    if(abs(x-l.first)<L&&abs(x-l.second)<L){
        return abs(x-p);
    }else{
        return min(abs(l.first-p),abs(l.second-p));
    }
}

double distSeg2Seg(line l1, line l2){
    if(isIntersect(l1,l2)) return 0;
    double ret = 1e20;
    ret = min(ret,distSeg2Point(l1,l2.first));
    ret = min(ret,distSeg2Point(l1,l2.second));
    swap(l1,l2);
    ret = min(ret,distSeg2Point(l1,l2.first));
    ret = min(ret,distSeg2Point(l1,l2.second));
    return ret;
}

double area(polygon& g){
    double S=0;
    for(auto i = g.begin()+1; i!=g.end();++i){
        S += cross_product(*(i-1),*i);
    }
    S/=2;
    return S;
}

//???????????§???????????????


int main(){
    int n;
    cin >> n;
    polygon g;
    while(n--){
        int x,y;
        cin>>x>>y;
        g.emplace_back(x,y);
    }
    g.push_back(g.front());
    cout.precision(1);
    cout << fixed;
    cout << area(g) << endl;
    return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i];
    B = A;
    sort(ALL(A));
    ll mx = A[N-1], mx2 = A[N-2];
    rep(i,N){
        if(B[i] == mx) pr(mx2);
        else pr(mx);
    }
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void setIO(string name = "a") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
}

int main() {
    //setIO();
    string s1, s2, s3; cin >> s1 >> s2 >> s3;
    cout << "A" << s2[0] << "C" << "\n";
}

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

typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

bool palin(string s){
    int n=s.size();
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-1-i])return 0;
    }
    return 1;
}

void solve(){
    string s;
    cin>>s;
    int n=s.size();
    if(palin(s) && palin(s.substr(0,(n-1)/2)) && palin(s.substr((n+3)/2-1,(n-3)/2+1)))cout<<"Yes";
    else cout<<"No";
}

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

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

int main()
{
	int n;
	cin>>n;
	vector<int> p(n);
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	vector<int> minm(n);
	minm[0] = 10000000;
	for(int i=1;i<n;i++){
		if(p[i-1]<minm[i-1]){
			minm[i] = p[i-1];
		}else{
			minm[i] = minm[i-1];
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		if(p[i]<=minm[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
}


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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define FOR(i, a, b) for (ll i = (a), i < (N): i++)
#define all(A) (A).begin(), (A).end()

int main(){
    ll N;
    cin >> N;
    ll ans = N - 1;
    ll tmp;
    tmp = sqrt(N) + 10;
    rep (i, tmp) {
        if (N % (i + 1) == 0) {
            ans = min(ans, (i + 1) + (N / (i + 1)) - 2);
        }
    }  
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  int a,b,c,k; cin >> a >> b >> c >> k;
  while(a >= b){
    if(k == 0) break;
    k--;
    b *= 2;
  }
  while(b >= c){
    if(k == 0) break;
    k--;
    c *= 2;
  }
  if(a < b && b < c) cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 3520
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/
const ll MOD=1000000007;

ll min(ll a, ll b){
	if(a>=b){
		return b;
	}
	else{
		return a;
	}
}
/*
bool over(ll a,ll b){
	ll p=a*b;
	if(p/a==b){
		return false;
	}
	else{
		return true;
	}
}
*/
void solve(){

	ull n;
	cin>>n;
	vector<ull> a(n,0);
	bool zero=false;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==0){
			zero=true;
		}
	}

	if(zero){
		cout<<0<<endl;
	}
	else{
		ull ans=1;
		bool check=true;
		for(ll i=0;i<n;i++){
	
				if(ans>1000000000000000000/a[i]){
					check=false;
					break;
				}
				else{
					ans*=a[i];
				}
			
		}

		if(check){
			cout<<ans<<endl;
		}
		else{
			cout<<-1<<endl;
		}
	}
	
}


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


Measured memory_bytes: 4052
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint hani(vector<int>&in,int L,int R){return UBI(in,R)-LBI(in,L);}
int main(void){
	//これ累積和でもいけたりします、やらないけど
	int i,j,x,y,H,W;cin>>H>>W;
	//特殊な解き方をしません
	vector<string>iro(H);
	for(i=0;i<H;i++){cin>>iro[i];}
	vector<pair<int,int>>que;
	int ans=0;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(iro[i][j]=='#'){que.pub(mp(i,j));}
			iro[i][j]='.';
		}
	}
	while(que.size()){
		ans++;
		vector<pair<int,int>>aaa;
		for(auto it:que){
			tie(y,x)=it;
			if(y<0||y>=H||x<0||x>=W){continue;}
			if(iro[y][x]=='#'){continue;}
			iro[y][x]='#';
			aaa.pub(mp(y+1,x));
			aaa.pub(mp(y-1,x));
			aaa.pub(mp(y,x+1));
			aaa.pub(mp(y,x-1));
			
		}
		que=move(aaa);
		aaa.clear();
	}
	cout<<ans-2<<endl;
	return 0;
}


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

int main() {
    int S;
    int h, m, se;
    cin >> S;

    h = S / 3600;
    m = ( S - h * 3600 ) / 60;
    se = S - h * 3600 - m * 60;

    cout << h << ":" << m << ":" << se << endl;
}


Measured memory_bytes: 3092
using System;
class aoj
{
    static void Main()
    {
        decimal[] a = new decimal[5];
        for(int i = 0; i < 5; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        decimal A = 0, B = 0;
        A = a[0] * a[4];
        if (a[4] > a[2])
            B += a[1] + (a[4] - a[2]) * a[3];
        else
            B += a[1];
        if (A < B)
            Console.WriteLine(A);
        else
            Console.WriteLine(B);
    }
}

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin>>S;
  sort(S.begin(),S.end());
  if(S=="abc"){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  //ツイッターフォローよろしく！
}


Measured memory_bytes: 3620
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

inline double sqrt2(double a) {
	double b = a;
	for (int i = 0; i < 30; i++) {
		b = (b * b + a) / (2 * b);
	}
	return b;
}

inline double dist(pair<double, double> a, pair<double, double> b) {
	return sqrt2((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

pair<double, double> calc_c(pair<double, double> a, pair<double, double>b, pair<double, double>c, double& r) {
	pair<double, double> e, f, g;
	e.first = (a.first + b.first) / 2;
	e.second = (a.second + b.second) / 2;
	f.first = (b.first + c.first) / 2;
	f.second = (b.second + c.second) / 2;
	double tan_a, tan_b;
	tan_a = tan(atan((b.second - a.second) / (b.first - a.first)) + PI / 2);
	tan_b = tan(atan((c.second - b.second) / (c.first - b.first)) + PI / 2);
	g.first = (e.second - f.second - e.first * tan_a + f.first * tan_b) / (tan_b - tan_a);
	g.second = e.second - (e.first - g.first) * tan_a;
	r = dist(a, g);
	return g;
}

pair<double, double> calc_c(pair<double, double> a, pair<double, double>b, double& r) {
	pair<double, double> g;
	g.first = (a.first + b.first) / 2;
	g.second = (a.second + b.second) / 2;
	r = dist(a, g);
	return g;
}

bool is_inner(pair<double, double> c, pair<double, double>p, double r) {
	return dist(c, p) <= (r + 1e-5);
}

int main() {
	io_init;
	int N;
	cin >> N;
	vector<pair<double, double>> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i].first >> a[i].second;
	}
	double ans = INF;
	if (N != 2) {
		for (int i = 0; i < N - 2; i++) {
			for (int j = i + 1; j < N - 1; j++) {
				for (int k = j + 1; k < N; k++) {
					//cout << i << " " << j << " " << k << endl;
					double r;
					auto c = calc_c(a[i], a[j], a[k], r);
					bool f = false;
					for (int s = 0; s < N; s++) {
						if (!is_inner(c, a[s], r))f = true;
					}
					if (!f)ans = min(ans, r);
				}
			}
		}
	}
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			if (i == j) continue;
			double r;
			auto c = calc_c(a[i], a[j], r);
			bool f = false;
			for (int k = 0; k < N; k++) {
				if (!is_inner(c, a[k], r))f = true;
			}
			if (!f)ans = min(ans, r);
		}
	}
	cout << ans << endl;
}

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

int main(void){
    int a[3];
    for(int i = 0;i < 3;i++)cin >> a[i];
    sort(a,a+3,greater<int>());
    if(a[0] == a[1] + a[2])cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
int main() {
    unsigned long long a, b;
    char s[6];
 
    scanf("%lld%s", &a, s);
    b = (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0'); 
 
    printf("%llu\n", a*b/100);
 
    return 0;

}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a; i<=b; ++i)

/// easy access -------------
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<int, int, int> tp;
typedef vector<vector<int>> vv;
///-------------------------
const int MAXN = 2e5+5;
int dem[MAXN];
int cha[MAXN];

int Find(int x){
    if (cha[x]!=x) cha[x] = Find(cha[x]);
    return cha[x];
}

void init(int n){
    for(int i=0; i<n; ++i){
        cha[i] = i;
        dem[i] = 1;
    }
}

int main()
{
    Phuong_; /// <3333
    int n,m;
    cin >> n >> m;
    init(n);
    while (m--){
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        int x = Find(u);
        int y = Find(v);
        if (x==y) continue;
        if (rand() &1) swap(x,y);
        cha[x] = y;
        dem[y] += dem[x];
    }
    int maxx=0;
    for(int i=0; i<n; ++i) if (cha[i]==i) maxx = max(maxx, dem[i]);
    cout << maxx;
    return 0;
}


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

using namespace std;

int main()
{
	int t; cin >> t;
	map<string, int>arr;

	while (t--) {
		string s; cin >> s;
		arr[s]++;
	}
	int maxv = 0;
	for (auto a : arr) {
		if (a.second > maxv)maxv = a.second;
	}
	for (auto a : arr) {
		if (a.second == maxv) {
			cout << a.first << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 25216
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long int;
const ll mod = 998244353;

ll mod_pow(ll n, ll k, ll m=mod) {
    ll res = 1;
    for(; k>0; k>>=1) {
        if(k & 1) (res *= n) %= m;
        (n *= n) %= m;
    }
    return res;
}

template <typename NumType>
struct LagrangePolynomial {
    vector<NumType> x, y, f_table;
    LagrangePolynomial() {}
    LagrangePolynomial(vector<NumType> x_,
                       vector<NumType> y_) : x(x_), y(y_) {
        int N = x.size();
        for(int i=0; i<N; i++) {
            f_table.emplace_back(f(i, x[i]));
        }
    }

    NumType f(int i, NumType p) {
        int N = x.size();
        NumType res(1);
        for(int k=0; k<N; k++) {
            if(i == k) continue;
            (res *= NumType(p - x[k])) %= mod;
            if(res < 0) (res += mod);
        }
        return res;
    }

    NumType interpolate(NumType p) {
        int N = x.size();
        NumType res(0);
        for(int i=0; i<N; i++) {
            NumType inv = mod_pow(f_table[i], mod-2, mod);
            (res += y[i] * f(i, p) % mod * inv % mod) %= mod;
        }
        return res;
    }
};

ll solve_small(ll N, ll S, ll K) {
    ll res = 0;
    for(int k=0; k<=K; k++) {
        ll add = 0;
        if(k % 2 == 1) {
            (add += mod_pow(S-k+1, N-1) - mod_pow(S-k, N-1)) %= mod;
        }
        else {
            (add -= mod_pow(S-k+1, N-1) - mod_pow(S-k, N-1)) %= mod;
        }
        if(add < 0) add += mod;
        (res += add) %= mod;
    }
    return res;
}

int main() {
    ll N, S; cin >> N >> S;
    ll ans = mod_pow(S+1, N, mod);
    // fprintf(stderr, "ans: %lld\n", ans);

    int p = S % 2;
    vector<ll> x(N), y(N);
    for(int i=0; i<N; i++) {
        int k = 2*i + p;
        x[i] = k;
        y[i] = solve_small(N, S, k);
        // fprintf(stderr, "x = %lld: y = %lld\n", x[i], y[i]);
    }

    LagrangePolynomial<ll> lp(x, y);
    (ans += lp.interpolate(S)) %= mod;
    // fprintf(stderr, "interpolate: %lld\n", lp.interpolate(S));
    (ans *= mod_pow(2, mod-2)) %= mod;
    cout << ans << endl;
}



Measured memory_bytes: 3212
# -*- coding: utf-8 -*-
import sys

def main():
	N = int(input())
	tmp = input()
	S = list(tmp)
	
	ans_max = 0
	for i, val in enumerate(S):
		ans = 0
		S1 = []
		S2 = []
		if i == N-1:
			continue
			
		for j, vol in enumerate(S):
			if i < j:
				S2.append(vol)
			else:
				S1.append(vol)
			
		strings = []
		for i in S1:
			for j in S2:
				if i == j:
					strings.append(i)
		l_unique = list(set(strings))
		ans = len(l_unique)
		if ans_max < ans:
			ans_max = ans
				
	print(ans_max)
		
if __name__ == "__main__":
	main()
	

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

struct num{
    int a;
    int b;
    bool operator<(const num& right) const{
        if(b-a>=0){
            if(right.b - right.a<0) return true;
            if(a == right.a) return b > right.b;
            return a < right.a;
        }
        if(right.b - right.a>=0) return false;
        return b > right.b;
    }
};

int main(void)
{
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i=0;i<N;i++) {
        cin >> S[i];
    }
    // A, B
    vector<num> numV(N);
    for(int i=0;i<N;i++){
        string s = S[i];
        int a=0, b=0;
        for(unsigned int j=0;j<s.size();j++){
            if(s[j] == '(')b++;
            else {
                if(b==0) a++;
                else b--;
            }
        }
        num n = {a, b};
        numV[i] = n;
    }
    sort(numV.begin(), numV.end());
    //  check
    ll total_b = 0;
    for(int i=0;i<N;i++){
        total_b -= ll(numV[i].a);
        if (total_b<0){
            cout << "No" << endl;
            return 0;
        }
        total_b += ll(numV[i].b);
    }
    if(total_b==0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 42332
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>k(m);
    vector<vector<int>> s(m,vector<int>(n));
    for(int i=0;i<m;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++){
            int sj;
            cin>>sj;
            sj--;
            s[i][sj]++;
        }
    }
    vector<int> p(m);
    for(int i=0;i<m;i++){
        cin>>p[i];
    }
    int ans=0;
    for(int bit=0;bit<1<<n;bit++){
        vector<int> ons(n);
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                ons[i]++;
            }
        }
        int onsum=0;
        for(int i=0;i<m;i++){
            int temp=0;
            for(int j=0;j<n;j++){
                if(s[i][j]>0&ons[j]>0){
                    temp++;
                }
            }
            if(p[i]==temp%2) onsum++;
        }
        if(onsum==m){
            ans++;
        }        
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    n = raw_input(); n = int(n);
    if n==0: break
    s = raw_input()
    for i in range(n):
        ns = ""
        cnt = 1
        for j in range(len(s)-1):
            if s[j+1]==s[j]: cnt += 1
            else:
                ns += str(cnt) + s[j]
                cnt = 1
        ns += str(cnt) + s[len(s)-1]
        s = ns
    print s

Measured memory_bytes: 7240
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int dp[110][110][2];

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(i,h+2) rep(j,w+2) rep(k,2) {
        dp[i][j][k] = 10000;
    }
    dp[0][1][0] = dp[1][0][0] = 0;
    rep(i,h) {
        rep(j,w) {
            if (s[i][j]=='#') {
                chmin(dp[i+1][j+1][1], dp[i][j+1][1]);
                chmin(dp[i+1][j+1][1], dp[i][j+1][0]+1);
                chmin(dp[i+1][j+1][1], dp[i+1][j][1]);
                chmin(dp[i+1][j+1][1], dp[i+1][j][0]+1);
            } else {
                chmin(dp[i+1][j+1][0], dp[i][j+1][1]);
                chmin(dp[i+1][j+1][0], dp[i][j+1][0]);
                chmin(dp[i+1][j+1][0], dp[i+1][j][1]);
                chmin(dp[i+1][j+1][0], dp[i+1][j][0]);
            }
        }
    }
    
    cout << min(dp[h][w][0], dp[h][w][1]) << endl;
    return 0;
}

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

int main() {
	int c[3][3];
	int minA=100, minB=100, minC=100;
	
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> c[i][j];
		}
	}

	for (int i = 0; i < 3; ++i) {
		if (minA > c[i][0]) minA = c[i][0];
		if (minB > c[i][1]) minB = c[i][1];
		if (minC > c[i][2]) minC = c[i][2];
	}
	
	for (int i = 0; i < 3; ++i) {
		c[i][0] -= minA;
		c[i][1] -= minB;
		c[i][2] -= minC;
	}

	if ((c[0][0] == c[0][1] && c[0][1] == c[0][2]) && (c[1][0] == c[1][1] && c[1][1] == c[1][2]) && (c[2][0] == c[2][1] && c[2][1] == c[2][2])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	bulbs2 := make([]int, M)
	for i := 0; i < M; i++ {
		var k int
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			var s uint
			fmt.Scan(&s)
			bulbs2[i] += 1 << (s - 1)
		}
	}
	p := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&p[i])
	}

	// O(1024)
	ans := 0
	for i := 0; i < int(math.Pow(2, float64(N))); i++ {
		oncount := 0
		for j := 0; j < M; j++ {
			count := OnesCount(uint(bulbs2[j] & i))
			if (count+p[j])%2 == 0 {
				oncount++
			}
		}
		if oncount == M {
			ans++
		}
	}
	fmt.Println(ans)
}

func OnesCount(n uint) int {
	count := 0
	for i := 0; i < 11; i++ {
		if n%2 == 1 {
			count++
		}
		n >>= 1
	}
	return count
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;

class Program
{
    static int[] ReadInts()
        => Console.ReadLine()
            .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
            .Select(s => int.Parse(s))
            .ToArray();

    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        if (s == "ABC")
        {
            Console.WriteLine("ARC");
        }
        else
        {
            Console.WriteLine("ABC");
        }
    }
}


Measured memory_bytes: 25676
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Debug.Trace
import Data.List
import Control.Monad
import Data.Vector.Unboxed as UV


main = do
    n <- UV.head . UV.unfoldr BS.readInt <$> BS.getLine
    p <- UV.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let l = UV.length $ UV.filter not $ UV.zipWith (==) p (UV.fromList [1..n])
    putStrLn $ if l <= 2 then "YES" else "NO"


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int n,a,b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  rep(i,s.size()){
    if(s[i] == 'c'){
      cout << "No" << endl;
      continue;
    }
    if (a == 0 && b == 0)
    {
      cout << "No" << endl;
    }else{
      if (s[i] == 'a')
      {
        if (a == 0)
        {
          b--;
          cout << "Yes" << endl;
        }
        else
        {
          a--;
          cout << "Yes" << endl;
        }
      }
      else
      {
        if (b == 0)
        {
          cout << "No" << endl;
        }
        else
        {
          cout << "Yes" << endl;
          b--;
        }
      }
    }

  }
}

Measured memory_bytes: 896
def solve(L):
    global H, W, K
    N = len(L)
    SL = [[0] * (W + 1) for _ in range(N)]
    for i in range(N):
        for j in range(W):
            SL[i][j + 1] = SL[i][j] + L[i][j]

    offset = [0] * N
    base = 0
    cnt = 0
    j = 0
    while j < W:
        if any([SL[x][j + 1] - offset[x] > K for x in range(N)]):
            if base == j:
                return -1
            else:
                base = j
                offset = [SL[x][j] for x in range(N)]
                cnt += 1
        else:
            j += 1
    return cnt


H, W, K = map(int, input().split())

S = [list(map(int, list(input()))) for _ in range(H)]

ans = H + W
for bit in range(pow(2, H - 1)):
    bit <<= 1
    L = [[0] * W for _ in range(H)]
    k = 0
    for i in range(H):
        if (bit >> i) & 1:
            k += 1
        for j in range(W):
            if S[i][j]:
                L[k][j] += 1
    horizontal = solve(L)
    if horizontal >= 0:
        vertical = bin(bit).count('1')
        ans = min(ans, horizontal + vertical)

print(ans)


Measured memory_bytes: 63708
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
 
 
ll n,l,t;
ll x[100001],w[100001],afx[100001],change[100001];
 
int main(void){
    scanf("%lld%lld%lld",&n,&l,&t);
 
    REP(i,n){
        scanf("%lld%lld",&x[i],&w[i]);
    }
 
    REP(i,n){
        ll a;
        if(w[i] == 1)
            a = 1;
        else
            a = -1;
        afx[i] = (x[i] + t * a) % l;
        if(afx[i] < 0)
            afx[i] += l;
    }
    
    FOR(i,1,n){
        if(w[0] == w[i]){
            change[i] = 0;
        }else{
            ll d = t * 2;
            
            ll b,c;
            
            if(w[0] == 1){
                b = x[0];c = x[i];
            }else{
                b = x[i];c = x[0];
            }
            change[i] = 0;
            if(c >= b){
                 d -= c - b;
            }else{
                d -= l - b +c;
            }
            if(d >= 0)
            change[i]++;
            else
                d = 0;
            change[i] += d / l;
        }
    }
    
    ll sum = 0;
    
    FOR(i,1,n){
        sum += change[i];
    }
    sum %= n;
    if(w[0] == 2)
        sum = (n - sum) % n;
        
    ll rem = afx[0];
    
    sort(afx,afx + n);
    
    ll start;
    afx[n] = -1000;
    REP(i,n){
        if(afx[i] == rem && afx[(i + 1) % n] != rem){
            start = i;
            break;
        }
        else if(afx[i] == rem && afx[(i + 1) % n] == rem){
            if(w[0] == 1)
                start = i + 1;
            else
                start = i;
            break;
        }
    }
    
    start = (n + start - sum) % n;
    
    REP(i,n){
        printf("%lld\n",afx[start++]);
        if(start == n)
            start = 0;
    }
    
    return 0;
}

Measured memory_bytes: 4352
def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid] + [INF]
    R = A[mid:right] + [INF]
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        cnt += 1

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

INF = 10000000000
n = int(input())
S = list(map(int,input().split()))
cnt = 0
mergeSort(S,0,n)
print(*S)
print(cnt)


Measured memory_bytes: 61644
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<" "<<to_string(head);
    debug(tail...);
}

int main(){
    int N=get_int();
    int count[100000]={};
    int c=1;
    FOR(i,N){
        int a=get_int();
        ++count[a];
    }
    if(N%2==0){
        for(int i=1;i<=N-1;i+=2){
            c=(c*2)%1000000007;
            if(count[i]!=2){
                c=0;
                break;
            }
        }
    }else{
        for(int i=2;i<=N-1;i+=2){
            c=(c*2)%1000000007;
            if(count[i]!=2){
                c=0;
                break;
            }
        }
        if(count[0]!=1){
            c=0;
        }
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 640
def d_init(n):
  c = 0
  A = D.items()[:]
  for i, e in A:
    c += 1
    for j, f in A[c:]:
      tmp = abs(e-f)
      D[(i, j)] = tmp
      D[(j, i)] = tmp
  return

def solve(idx, visited, weight):
  if visited == (1<<n)-1: return 0, name[idx]
  tmp1, tmp2 = dp[idx][visited]
  if tmp1 != 1e12: return tmp1, tmp2

  x1 = 1e12
  for i in range(n):
    i1 = 1<<i
    if (visited & i1) == 0:
      tmp1, tmp2 = solve(i, visited|i1, weight + W[i])
      tmp1 += D[(i, idx)] /2000.0*(weight+70.0)
      if x1 > tmp1:
        x1 = tmp1
        x2 = tmp2
  x2 = name[idx] + x2
  dp[idx][visited] = [x1, x2]
  return x1, x2

name = {}
D = {}
W = {}
n = input()
dp = [[[1e12,[]] for _ in [0]*(1<<n)] for _ in [0]*n]
for i in range(n):
  a, b, c = map(int, raw_input().split())
  name[i] = [a]
  D[i] = b
  W[i] = c*20
d_init(n)

ans1 = 1e12
route = []
for i, e in W.items():
  tmp1, tmp2 = solve(i, 1<<i, e)
  if ans1 > tmp1:
    ans1 = tmp1
    route = tmp2

for e in route[:-1]:
  print str(e),
print str(route[-1])

Measured memory_bytes: 118888
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    string ans;
    for(int i=0;i<3;i++){
        ans.push_back(s[i][0] - 32);
    }
    cout << ans << endl;
}


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

int main(void) {

    int n;
    string s;
    cin >> n >> s;
    int x = 0;
    int ans = 0;
    for(int i=0; i<n; i++){
        if( s[i] == 'I' ) x++;
        else if( s[i] == 'D' ) x--;

        ans = max(ans, x);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

int expression(string &s,int &pos);


int factor(string &s,int &pos){
	if(s[pos]=='('){
		pos++;
		int ret=expression(s,pos);
		assert(s[pos]==')');
		pos++;
		return ret;
	}else{
		assert(isdigit(s[pos]));
		int ret=s[pos]-'0';
		pos++;
		while(isdigit(s[pos])){
			ret*=10;
			ret+=s[pos]-'0';
			pos++;
		}
		return ret;
	}
}

int term(string &s,int &pos){
	int ret=factor(s,pos);
	while(s[pos]=='*'||s[pos]=='/'){
		char op=s[pos];
		pos++;
		if(op=='*'){
			ret*=factor(s,pos);
		}else{
			ret/=factor(s,pos);
		}
	}
	return ret;
}

int expression(string &s,int &pos){
	int ret=term(s,pos);
	while(s[pos]=='+'||s[pos]=='-'){
		char op=s[pos];
		pos++;
		if(op=='+'){
			ret+=term(s,pos);
		}else{
			ret-=term(s,pos);
		}
	}
	return ret;
}

int main(){
	int n;
	cin>>n;
	REP(i,n){
		string s;
		cin>>s;
		int pos=0;
		int ans=expression(s,pos);
		assert(s[pos]=='=');
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1212
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace A {
static class Extensions {
   public static int ToInt(this string str) {
      return int.Parse(str);
   }

   public static int[] readIntArr() {
      return ReadLine().Split(' ').Select(int.Parse).ToArray();
   }

   public static void Fill<T>(this List<T> a, T b) {
      for (var i = 0; i < a.Capacity; i++) {
         a.Add(b);
      }
   } 
}

class Program {
   public static void Main(string[] args) {
      var n = ReadLine().ToInt();
      var arr = new int[n][];
      
      for (var i = 0; i <  n; i++) {
         arr[i] = Extensions.readIntArr();
      }

      var dp = new int[n][];
      for (var i = 0; i < n; i++)
         dp[i] = new int[3];
      dp[0][0] = arr[0][0];
      dp[0][1] = arr[0][1];
      dp[0][2] = arr[0][2];


      for (var i = 1; i < n; i++) {
         dp[i][0] = Max(
            dp[i - 1][1] + arr[i][0],
            dp[i - 1][2] + arr[i][0]
         );
         dp[i][1] = Max(
            dp[i - 1][0] + arr[i][1],
            dp[i - 1][2] + arr[i][1]
         );
         dp[i][2] = Max(
            dp[i - 1][0] + arr[i][2],
            dp[i - 1][1] + arr[i][2]
         );
      }

      WriteLine(Max(
         dp[n - 1][0], Max(dp[n - 1][1], dp[n - 1][2])
      ));
   }
}

}


Measured memory_bytes: 30256
#include "bits/stdc++.h"
//#include "atcoder/all"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
//using namespace atcoder;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.rbegin(), t.rend());
	if(s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

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

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//






//入力
int N;
ll h[100010];

//DPテーブル
ll dp[100010];

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

        //初期化（最小化問題だからIMFで初期化する。)
        for(int i = 0; i < 100010; i++) dp[i] = IMF;

        //初期条件
        dp[0] = 0;

        //ループ
        for(int i = 1; i < N; i++){
                chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
                if(i>1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }

        //答え
        cout << dp[N-1] << endl;
}


















































Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var a = p[0];
		var b = p[1];
		if(a <= 5)
		{
			Console.WriteLine(0);
			return;
		}
		if(a <= 12)
		{
			Console.WriteLine(b/2);
			return;
		}
		Console.WriteLine(b);
	}


	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



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

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a*b)==(c*d))
    {
        cout<<a*b<<endl;
    }
    else if((a*b)>(c*d))
    {
       cout<<a*b<<endl;
    }
    else
    {
         cout<<c*d<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

long long int MOD = 1e9+7;
 long long int one = 1;
 long long int zero = 0;
 long long int two = 2;

int make_rooted_tree(std::vector<std::vector<long long int> > &G1, std::vector<std::vector<long long int> > &G, std::vector<long long int> &par, long long int root){
  
  for(long long int i = 0; i < G1[root].size(); i++){
    // not visited yet
    if(par[G1[root][i]] == -1){
      par[G1[root][i]] = root;
      G[root].push_back(G1[root][i]);
      make_rooted_tree(G1, G, par, G1[root][i]);
    }
  }
  
  return 0;
}

long long int fill_dp(std::vector<std::vector<long long int> > &G, std::vector<long long int> &dp, std::vector<long long int> &mod_table, long long int i, long long int K){
  long long int ans = 1;
  
  // if already investigated
  if(dp[i] >= 0){
    return dp[i];
  }
  
  long long int n, Gij;
  for(long long int j = 0; j < G[i].size(); j++){
    Gij = G[i][j];
    n = G[Gij].size();
    ans *= fill_dp(G, dp, mod_table, Gij, K);
    ans = (ans + MOD)%MOD;

    // if a child has too many childs

    if(n > K-2){
      dp[i] = 0;
      return 0;
    }
    else if(n > 0){
      ans *= mod_table[n-1];
      ans = (ans + MOD)%MOD;
    }
    /*else if(G[j].size == 0){
      ans *= 1;
    }*/
  }
  dp[i] = ans;
  return ans;
}

int main(){
  
  // read problem
  long long int N, K, tmp1, tmp2;
  scanf("%lld%lld", &N, &K);

  std::vector<std::vector<long long int> > G1(N);
  for(long long int i = 0; i < N-1; i++){
    scanf("%lld%lld", &tmp1, &tmp2);
    G1[tmp1-1].push_back(tmp2-1);
    G1[tmp2-1].push_back(tmp1-1);
  }
  
  // make rooted tree
  std::vector<std::vector<long long int> > G(N);
  std::vector<long long int> par;
  for(long long int i = 0; i < N; i++){
    par.push_back(-1);
  }
  
  par[0] = 0;
  make_rooted_tree(G1, G, par, 0);
  
  // solve problem
  // exception case
  if(K == one){
    if(N == one){
      std::cout << 1 << std::endl;
    }
    else{
      std::cout << 0 << std::endl;
    }
    return 0;
  }
  if(K == two){
    if(N <= two){
      std::cout << 2 << std::endl;
    }
    else{
      std::cout << 0 << std::endl;
    }
    return 0;
  }
  
  // table
  std::vector<long long int> mod_table(K-2);
  mod_table[0] = K-2;
  for(long long int i = 1; i < K-2; i++){
    mod_table[i] = ( mod_table[i-1] * (K-2-i) + MOD) % MOD;
  }
  
  std::vector<long long int> dp;
  for(long long int i = 0; i < N; i++){
    dp.push_back(-1);
  }
  
  fill_dp(G, dp, mod_table, 0, K);
  
  long long int ans = dp[0];
  
  if(G[0].size() > K-1){
    std::cout << 0 << std::endl;
    return 0;
  }
  else if(G[0].size() == 0){
    std::cout << K << std::endl;
  }
  else if(G[0].size() == one){
    ans *= K;
    ans = (ans+MOD)%MOD;
    ans *= K-1;
    ans = (ans+MOD)%MOD;
    std::cout << ans << std::endl;
  }
  else{
    ans *= K;
    ans = (ans+MOD)%MOD;
    ans *= K-1;
    ans = (ans+MOD)%MOD;
    ans *= mod_table[G[0].size()-2];
    ans = (ans+MOD)%MOD;
    std::cout << ans << std::endl;
  }

  return 0;

}



Measured memory_bytes: 21108
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

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

		if (n == 0)
		{
			break;
		}

		vector<int> a(n);
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &a.at(i));
		}

		int maxv = a.at(0);
		vector<int> sum;
		sum.push_back(0);
		for (int i = 0; i < n; i++)
		{
			int s = sum.back() + a.at(i);
			sum.push_back(s);


			for (int j = 0; j < sum.size() - 1; j++)
			{
				int x = sum.back() - sum.at(j);
				maxv = max(maxv, x);
			}
		}

		cout << maxv << endl;
	}
}


Measured memory_bytes: 3268