akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main() {
	int n, x, tmp, z=0; cin >> n >> x;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		z += tmp;
		if (z <= x)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    D = int(input())
    C = list(map(int,input().split()))
    S = [list(map(int,input().split())) for _ in range(D)]

    ret = [0] * (D + 1)
    before = [-1] * 26
    for i in range(D):
        t = int(input()) - 1
        ret[i] += S[i][t]
        before[t] = i
        for j,c in enumerate(C):
            ret[i] -= (i - before[j]) * c
        ret[i + 1] += ret[i]
    print('\n'.join(map(str,ret[:-1])))
if __name__ == '__main__':
    main()


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll h = in(), w = in();
    if (h % 3 == 0 || w % 3 == 0)
    {
        cout << 0 << endl;
        return;
    }
    ll ans = min(h, w);

    for (ll i = 1; i < h; ++i)
    {
        ll s1 = w * i;
        ll s2 = (h - i) * (w / 2);
        ll s3 = (h - i) * (w - (w / 2));
        ll smax = max({s1, s2, s3});
        ll smin = min({s1, s2, s3});
        ans = min(ans, (smax - smin));
    }
    for (ll i = 1; i < w; ++i)
    {
        ll s1 = h * i;
        ll s2 = (w - i) * (h / 2);
        ll s3 = (w - i) * (h - (h / 2));
        ll smax = max({s1, s2, s3});
        ll smin = min({s1, s2, s3});
        ans = min(ans, (smax - smin));
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
AB=n3(n)
A=[x[0] for x in AB]
B=[x[1] for x in AB]

A.sort()
B.sort()

if n%2==0:
    a1,a2=A[n//2-1],A[n//2]
    b1,b2=B[n//2-1],B[n//2]
    a=(a1+a2)/2
    b=(b1+b2)/2
    ans=int((b-a+0.5)*2)
else:
    a=A[n//2]
    b=B[n//2]
    ans=b-a+1
print(ans)

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int a, b;
    char op;
    cin >> a >> op >> b;
    cout << (op == '+' ? a + b : a - b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;
string s;
int a[27], cnt=0;
int main()
{
	cin>>s;
	int l=s.size();
	for(int i=0; i<l; i++)
	{
		a[s[i]-'A']++;
	}
	for(int i=0; i<=25; i++)
	{
		if(a[i]==2)
			cnt++;
	}
	if(cnt==2)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, k, i, p[200101];
    double dkitai[200100]={0}, ans=-1, kitai=0, mesum=0;
    cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> p[i];
    }
    for(i=0;i<n;i++){
        mesum=(p[i]*(p[i]+1))/2.0;
        dkitai[i]=mesum/p[i];
    }
    for(i=0;i<n;i++){
        if(i<k) kitai+=dkitai[i];
        else{
            kitai=kitai-dkitai[i-k]+dkitai[i];
        }
        ans=max(ans, kitai);
    }
    printf("%.12f\n", ans);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 5000000;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 998244353;
//ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,idx,ans;
ll x[500005],y[500005],z[500005];
bool used[500005];
char s[500005];

int main(){
    cin >> n;
    cin >> s;
    if(n % 2 == 1){
        Yes(0);
        return 0;
    }
    bool dame = false;
    for(int i=0;i<n/2;i++){
        if(s[i] != s[i + n / 2]){
            dame = true;
        }
    }
    Yes(!dame);
    return 0;
}


















Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n, k;
  cin >> n >> k;
  VEC<int> x(n);
  REP(i, 0, n) { cin >> x[i]; }
  LL sum = 0;
  REP(i, 0, n) { sum += min(2 * abs(x[i]), 2 * abs(k - x[i])); }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 384
N = ARGF.readline.strip.to_i

plan = [[0,0,0]]
N.times do
  t, x, y = ARGF.readline.strip.split(' ').map(&:to_i)
  plan << [t, x, y]
end

accept = plan[0..-2].zip(plan[1..-1]).all? do |current, next_|
  time_delta = next_[0] - current[0]
  diff = (next_[1] - current[1]).abs + (next_[2] - current[2]).abs
  if time_delta < diff
    false
  else
    (time_delta - diff) % 2 == 0
  end
end

if accept
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 12156
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
using graph = vector<vector<int>>;

int main(){
    double l; cin >> l;
    double v = 0;
    v = l * l * l / 27.0;
    cout << fixed << setprecision(15) << v << endl;
    return 0;
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N,M; cin >> N >> M;
  ll sum = 0;
  for(ll i = 0; i < M; i++){
    ll tmp; cin >> tmp;
    sum += tmp;
  }
  cout << ( (N >= sum) ? (N - sum) : -1) << endl;
}


Measured memory_bytes: 3564
using namespace std;
#include<bits/stdc++.h>
#define debug(x) clog<<#x<<" = "<<x<<'\n'
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define sz(c) ((int)c.size())
#define all(c) (c).begin(),(c).end()
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define fn "D"  /// ___FILE_NAME_HERE___
#define rep(c,it) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define __rep(c,it) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();it++)

template <class T,class U>
void maximize(T &x,U y)
{
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y)
{
    if(x > y)x=y;
}
template <class T>
T Abs(T x)
{
    return (x < 0 ? -x : x);
}
template <class T>
T safe_sqrt(T x)
{
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD)
{
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD)
{
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD)
{
    return (ll)x*y%MOD;
}
/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

const int N=60;
const int base=1e9+7;
int dp[N][3][3];
char s1[N],s2[N];
int n;

void solve()
{
    scanf("%d",&n);
    scanf("%s%s",&s1,&s2);
    for(int i=0;i<3;++i)
        for(int j=0;j<3;++j)
    {
        if((s1[0]==s2[0]) ^ (i == j))continue;
        dp[0][i][j]=1;
    }
    for(int i=0;i<n-1;++i)
        for(int c1=0;c1<3;++c1)
          for(int c2=0;c2<3;++c2)
    {
        if(!dp[i][c1][c2])continue;
        for(int nc1=0;nc1<3;++nc1)
            for(int nc2=0;nc2<3;++nc2)
        {
            if((s1[i] == s1[i+1])^(c1 == nc1))continue;
            if((s2[i] == s2[i+1])^(c2 == nc2))continue;
            if((s1[i+1] == s2[i+1])^(nc1 == nc2))continue;
            dp[i+1][nc1][nc2]=addmod(dp[i+1][nc1][nc2],dp[i][c1][c2],base);
        }
    }
    int ans=0;
    for(int c1=0;c1<3;++c1)
        for(int c2=0;c2<3;++c2)
          ans=addmod(ans,dp[n-1][c1][c2],base);
    printf("%d\n",ans);
}}

int main(void)
{

    task::solve();
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;



int main(){
	string s;
	cin >> s;
	int i, j;
	for ( i = 0;; i++) {
		if (s[i] == 'A')
			break;
	}
	for ( j = s.length() - 1;; j--) {
		if (s[j] == 'Z')
			break;
	}
	cout << j - i + 1 << endl;

	return 0;
}


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

int main(){
	int hills[10];
	for (int i=0; i<10; i++){
		cin >> hills[i];
	}


	for (int i=9; i>=1; i--){
		for (int j=1; j<10; j++){
			if (hills[j-1] < hills[j]){
				swap(hills[j-1], hills[j]);
			}
		}
	}

	for (int i=0; i<3; i++){
		cout << hills[i] << endl;
	}
	return 0;
}


  

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14

int main(){
    ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;
    ll aa, bb;
    if (a==b) cout << "YES" << endl;
    else if (v<=w) cout << "NO" << endl;
    else{
        if (abs(a-b)<=t*(v-w)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
int n,k;
vector<ll> a;
ll dp[110][100010];
ll mod = 1000000007;

int main(){
 cin >> n >> k;
 a.resize(n);
 for(int i = 0; i < n; ++i) cin >> a[i];
 for(int i = 0; i <= n; ++i) dp[i][0] = 1; //i人目までに0個配る方法は1通り

 for(int i = 1; i <= n; ++i){
   for(int j = 1; j <= k; ++j){
     dp[i][j] = (dp[i - 1][j] + dp[i][j - 1])%mod;
     if(j - a[i - 1] - 1 >= 0){
       dp[i][j] = (dp[i][j] + mod - dp[i - 1][j - a[i - 1] - 1])%mod;
     }
   }
 }
 cout << dp[n][k] << endl;
 return 0;
}

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

const string YES = "Possible";
const string NO = "Impossible";

void solve(long long A, long long B){
    if(A%3==0 || B%3==0 || (A+B)%3==0) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    cin >> s;
    ll ans = 0, n = s.size()-1;
    for(ll bit = 0; bit < (1<<n); bit++){
        ll add = 0;
        for(ll i = 0; i < n+1; i++){
            add = add * 10 + (s[i] - '0');
            if(bit & (1<<i)){
                ans += add;
                add = 0;
            }   
        }
        ans += add;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100003];
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		int t;
		cin >> t;
		a[t]++;
		a[t + 1]++;
		a[t + 2]++;
	}
	cout << *max_element(a + 2, a + 100000) << endl;
	return 0;
}

Measured memory_bytes: 3864
n = int(input())
#s = input()
#n, m = map(int, input().split())
#s, t = input().split()
#n, m, l = map(int, input().split())
#s, t, r = input().split()
t = list(map(int, input().split()))
#a = input().split()
#a = [int(input()) for _ in range(n)]
#a = [input() for _ in range(n)]

#t = input()
m = int(input())
#p, q = map(int, input().split())
#p, q = input().split()
#p, q, r = map(int, input().split())
#p, q, r = input().split()
#b = map(int, input().split())
#b = input().split()
#b = [int(input()) for _ in range(m)]
#b = [input() for _ in range(m)]
cnt, ans, mx, mn = 0, 0, 0, 100000000
for i in range(m):
    p, x = map(int, input().split())
    print(sum(t) - t[p - 1] + x)



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

bool is_leap(int x){
	if(x%400==0) return true;
	if(x%100==0) return false;
	if(x%4==0) return true;
	return false;
}

int main(){
	bool first = true;
	int a,b;
	while(cin>>a>>b,a||b){
		bool ok=false;
		if(!first) cout<<endl;
		first=false;
		for(int i=a;i<b+1;i++){
			if(is_leap(i)){
				cout<<i<<endl;
				ok=true;
			}
		}
		if(!ok){
			cout<<"NA"<<endl;
		}
	}
}

Measured memory_bytes: 3076
#include<iostream>

int main(){
    long long N, K;
    std::cin >> N >> K;
    
    long long tmp = N % K;
    long long tmp2 = K - tmp;
    if(tmp > tmp2){
        std::cout << tmp2 << std::endl;
    }else{
        std::cout << tmp << std::endl;
    }
    
    return 0;
    
}



Measured memory_bytes: 256
// author:  Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
	fastio;
	/*#ifndef ONLINE_JUDGE 
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif*/
	ll n=0,w=0;
	cin>>n>>w;
	vector<ll>wt(n),val(n);
	for(ll i=0;i<n;++i){
		cin>>wt[i]>>val[i];
	}
	ll dp[n+1][w+1];
	for(ll i=0;i<=n;++i)
	{
		for(ll j=0;j<=w;++j)
		{		
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(wt[i-1]<=j)
				dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][w];
   return 0;
}

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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e9)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

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

const int N = 3001;
const int M = 998244353;
int a, b, c, d;
int dp[N][N];

int inv(){
    int p = M-2;
    int x = 2;
    int ans = 1;
    while(p){
        if(p&1)ans = (ans*x)%M;
        x = (x*x)%M;
        p >>= 1;
    }
    return ans;
}

int fun(int R, int C){
    // cout << R << " " << C << endl;
    if(R == a && C == b)return 1;
    if(R < a || C < b)return 0;
    if(dp[R][C] != -1)return dp[R][C];
    dp[R][C] = fun(R-1, C)*(C)%M;
    dp[R][C] += fun(R, C-1)*(R)%M;
    dp[R][C] %= M;
    dp[R][C] -= (fun(R-1, C-1)*(C-1)*(R-1))%M;
    if(dp[R][C] < 0)dp[R][C] += M;
    dp[R][C] %= M;
    return dp[R][C];
}

void solve(int &test) {
    cin >> a >> b >> c >> d;
    memset(dp, -1, sizeof(dp));
    // cout << fun(c, d) << endl;
    cout << fun(c, d) << endl;
}

signed main(){

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

    int t = 1;

    start = clock(); 

    cout << fixed << setprecision(20);
    
    
   
    // cin >> t;
     
    for(int i = 1; i <= t; ++i){
        solve(i);
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 74312
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


K, X = _li()

ans = []
for i in range(X-K+1, X+K):
    ans.append(i)
print(*ans)


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

using namespace std;

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

    string s;
    cin >> s;

    int n = s.size();
    vector<int> ans(n , 0) , left(n , 0) , right(n , n);

    for (int i = 1 ;i < n ;i++) {
        if (s[i] == 'L') {
            if (s[i - 1] == 'L')
                left[i] = left[i - 1];
            else
                left[i] = i;
        }
    }

    for (int i = n - 2 ;i >= 0 ;i--) {
        if (s[i] == 'R') {
            if (s[i + 1] == 'R')
                right[i] = right[i + 1];
            else
                right[i] = i;
        }
    }


    for (int i = 0 ;i < n ;i++) {
        if (s[i] == 'R') {
            if (right[i] == n - 1) {
                ans[right[i]]++;
                continue;
            }
            int c = right[i] - i;
            if (c&1)
                ans[right[i] + 1]++;
            else
                ans[right[i]]++;
        } else {
            if (left[i] == 0) {
                ans[left[i]]++;
                continue;
            }
            int c = i - left[i];
            if (c&1)
                ans[left[i] - 1]++;
            else
                ans[left[i]]++;
        }
    }

    for (int c : ans)
        cout << c << ' ';
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
ll fw[100005];
int n,q;
ll k;
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>k>>q;
    int a;
    for(int i=0;i<q;i++)
    {
        cin>>a;
        ++fw[a];
    }
    for(int i=1;i<=n;i++)
    {
        if(-q+fw[i]+k>0) cout<<"Yes\n"; else cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

vector<int> to[100005];
int dist[100005][3];

int main() {
    int n, m;
    cin >> n >> m;
    rep(i,m) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;
    rep(i,n)rep(j,3) dist[i][j] = INF;
    dist[s][0] = 0;
    queue<P> q;
    q.emplace(s,0);
    while (!q.empty()) {
        int v = q.front().first, id = q.front().second;
        q.pop();
        int d = dist[v][id];
        int nid = (id+1)%3;
        for (int u : to[v]) {
            if (dist[u][nid] <= d+1) continue;
            dist[u][nid] = d+1;
            q.emplace(u,nid);
        }
    } 
    if (dist[t][0] == INF) {
        cout << -1 << endl;
        return 0;
    }
    dist[t][0] /= 3;
    cout << dist[t][0] << endl;
    return 0;
}

Measured memory_bytes: 10236
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int size=1<<20,mod=998244353;
struct nobe
{
	int to,ne;
}e[400400];
int len=0,hea[400400];
inline void adde(int x,int y)
{
	e[++len]=(nobe){y,hea[x]};
	hea[x]=len;
}
inline void upd(int &x)
{
	x+=x>>31&mod;
}
inline long long poww(long long a,long long b=mod-2)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res;
}
int n,m,f[100100],sum[3][100100],sz[3],g[100100],num,ans,fir,inv=poww(fir=poww(10,18));
signed main()
{
	scanf("%lld",&n);
	int graph=0,i=1,j=1,k=0;
	while(graph<3)
	{
		if(len)
		{
			memset(hea,0,sizeof(hea));
			len=0;
		}
		scanf("%d",&m);
		j=1;
		int x,y;
		while(j<=m)
		{
			scanf("%lld%lld",&x,&y);
			if(x>y) swap(x,y);
			adde(x,y);
			++j;
		}
		int now=poww(fir,n);
		i=n;
		while(i)
		{
			++num;
			k=hea[i];
			while(k)
			{
				g[f[e[k].to]]=num;
				k=e[k].ne;
			}
			f[i]=0;
			while(g[f[i]]==num) ++f[i];
			sz[graph]=max(sz[graph],f[i]);
			sum[graph][f[i]]+=now-mod;
			sum[graph][f[i]]%=mod;
			now=(long long)now*inv%mod;
			--i;
		}
		++graph;
	}
	i=0;
	while(i<=sz[0])
	{
		j=0;
		k=0;
		while(j<=sz[1])
		{
			k=i^j;
			ans+=(long long)sum[0][i]*sum[1][j]%mod*sum[2][k]%mod-mod;
			ans%=mod;
			++j;
		}
		++i;
	}
	ans+=mod;
	ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  int num1=0, num2=0;
  for(int i=0; i<N; i++){
    int l=0, r=0;
    cin>>l>>r;
    num2=r-l+1;
    num1+=num2;
  }
  cout<<num1<<endl;
    
}


Measured memory_bytes: 3616
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define FOR(VAR,ST,END) for(int VAR=ST; VAR<END; ++VAR)
#define FORI(VAR,ST,END) for(int VAR=ST; VAR<=END; ++VAR)
#define ROF(VAR,ST,END) for(int VAR=ST; VAR>END; --VAR)
#define ROFI(VAR,ST,END) for(int VAR=ST; VAR>=END; --VAR)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define MAXI(a,b) (a=(a>b?a:b))
#define MINI(a,b) (a=(a<b?a:b))
#define ABS(a) ((a)>0?(a):-(a))
#define MINI_NZ(a,b) {if(a==0) a = b; else a = a<b?a:b;}
#define SWAP_IF(type,x,y,cond) if(cond) {type tmp=x; x=y; y=tmp;}
#define SWAP(type,x,y) {type tmp=x; x=y; y=tmp;}
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define MAX_NP1 (MAX_N+1)
#define MAX_NP2 (MAX_N+2)

using namespace std;

#define MAX_N 100000

int coor[MAX_NP2];

int main()
{
    int n;
    cin >> n;
    FORI(i, 1, n)
        cin >> coor[i];

    int tc = 0;
    FORI(i, 1, n+1)
        tc += ABS(coor[i] - coor[i - 1]);

    FORI(i, 1, n)
    {
        cout << tc - ABS(coor[i]-coor[i-1]) - ABS(coor[i+1] - coor[i]) + ABS(coor[i+1]-coor[i-1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
using System;
using System.Linq;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int yamaCount = int.Parse(Reader.ReadLine());
        Yama[] yamaList = new Yama[yamaCount];

        long[] inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray();

        yamaList[0] = new Yama(inpt[0], inpt[0]);
        for(int i=1; i<inpt.Length; i++) {
            if(inpt[i-1] <inpt[i]) {
                yamaList[i] = new Yama(inpt[i], inpt[i]);
            } else {
                yamaList[i] = new Yama(inpt[i]);
            }
        }


        inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).Reverse().ToArray();
        yamaList = yamaList.Reverse().ToArray();
        long ans = 0;
        if(yamaList[0].Max < inpt[0]) {
            ans = -1;
        }  else if(yamaList[0].Max == yamaList[0].Min && yamaList[0].Max != inpt[0]) {
            ans = -1;

        }  else {
            yamaList[0].Max = inpt[0];
            yamaList[0].Min = inpt[0];
        }
        
        for(int i=1; i<inpt.Length; i++) {
            if(ans < 0) {
                break;
            }
            if(inpt[i-1] <inpt[i]) {
                if(yamaList[i].Min == yamaList[i].Max) {
                    if(yamaList[i].Min != inpt[i]) {
                        ans = -1;
                    }
                } else if(yamaList[i].Max < inpt[i]) {
                    ans = -1;
                }
                if(ans>=0) {
                    yamaList[i] = new Yama(inpt[i], inpt[i]);
                }
            } else if(yamaList[i].Min == yamaList[i].Max) {
                if(inpt[i] < yamaList[i].Max) {
                    ans = -1;
                }
            } else {
                yamaList[i].Max = Math.Min(yamaList[i].Max, inpt[i]);
            }
        }
        if(ans == -1) {
            ans = 0;
        } else {
            ans = 1;
            long div = 1000000000 + 7;
            yamaList.Where(a=>a.Max != a.Min).ToList().ForEach(a=>{
                ans*=a.Max;
                ans=ans % div;
            });
        }
        Console.WriteLine(ans);
    }

    public class Yama {
        public long Max = 1;
        public long Min = 1;
        public Yama(long max) {
            this.Max = max;

        }
        public Yama(long max, long min) {
            this.Max = max;
            this.Min = min;
        }
    }

    public class Reader {
        public static bool IsDebug = true;

        private static string Input = @"

1
1
17
        ";

        private static System.IO.StringReader rd;
        public static string ReadLine() {
            if(!IsDebug) {
                return Console.ReadLine();
            }
            if(rd == null) {
                rd = new System.IO.StringReader(Input.Trim());
            }
            return rd.ReadLine();
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 33704
// this line is here for a reason
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
  return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
  template <class C>
  static char test(typename C::const_iterator*);
  template <class C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '{';
  for (auto it = c.begin(); it != c.end();)
    o << *it << (++it != c.end() ? ", " : "}");
  return o;
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
  return o << '(' << p.fi << ", " << p.se << ')';
}

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

    int n;
    cin >> n;

    vi a(n), b(n), c(n);
    F0R(i, n) cin >> a[i] >> b[i] >> c[i];

    vector<array<int, 3>> dp(n + 1);
    dp[0][0] = dp[0][1] = dp[0][2];
    F0R(i, n) {
        dp[i + 1][0] = a[i] + max(dp[i][1], dp[i][2]);
        dp[i + 1][1] = b[i] + max(dp[i][0], dp[i][2]);
        dp[i + 1][2] = c[i] + max(dp[i][0], dp[i][1]);
    }
    cout << *max_element(ALL(dp[n])) << endl;

}



Measured memory_bytes: 2560
#include <stdio.h>
main(){
  int n,a,b,c,d,i=0;
  while(scanf("%d",&n)!=EOF){
    for(a=9;a>=0;a--){
      for(b=9;b>=0;b--){
	for(c=9;c>=0;c--){
	  for(d=9;d>=0;d--){
	    if(a + b + c + d == n){
	      i=i+1;
	    }
	  }
	}
      }
    }
    printf("%d\n",i);
    i=0;
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <math.h>
using namespace std;
typedef long long LL;
LL a,b;
LL gcd(LL x,LL y){
    if(x>y){
        LL t=x;
        x=y;
        y=t;
    }if(x==0) return y;
    return gcd(y%x,x);
}
int main(){
    cin>>a>>b;
    LL G=gcd(a,b);
    LL ans=0LL,g=G;
    for(LL x=2;x<=sqrt(g)&&G!=1;x++){
        bool B=false;
        while(G%x==0){
            G/=x;
            B=true;
        }
        if(B)ans++;
    }if(G!=1)ans++;
    cout<<ans+1<<endl;
    return 0;
}

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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
int a[100005],b[100005];
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int dp[5005];rep(i,0,5005)dp[i]=0;
    int n,m;
    cin >> n >> m;
    rep(i,0,n){
        cin >> a[i];
    }
    rep(i,0,m){
        cin >> b[i];
    }
    int ans=0;
    //rep(i,0,n){
        rep(j,0,m){
            //if(a[i]==b[j]){
            int len=0;
            //if(j>0)len=dp[j-1];
            int h=0;
            int k=j;
            while(1){
            for(;h<n;h++){
                if(a[h]==b[k]){len++;break;}
            }
            if(h==n)break;
            else {h++;k++;}
            }
            ans=max(ans,len);
           // if(h==n)len=0;
        }
    //}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long int i=0;i<n;i++)
#define foi(i,a,n) for(long long int i=a;i<n;i++)
#define el "\n"

const int INF = 2e9+5;
const int MAX = 1e5+5;
const int mod = 1e9+7;
using ll = long long int;

void solve(){
	int n;cin>>n;
  	vector<double> dp(n+1);
  	dp[0]=1;
  	rep(i,n){
    	double p;cin>>p;
      	for(int j=i+1;j>=0;j--){
        	dp[j]=(j==0?0:dp[j-1])*p+dp[j]*(1-p);
        }
    }
  	double ans=0;
  	
  	foi(i,(n/2)+1,n+1) ans+=dp[i];
  	cout<<fixed<<setprecision(9)<<ans;
}

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

Measured memory_bytes: 3816
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
	int a, b;
	cin >> a >> b;
	cout << (b % a == 0 ? a + b : b - a) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int r = sc.nextInt();
            if(n == 0 && r == 0){
                break;
            }
            int[] num = new int[n];
            for(int i = 0; i < n; i++){
                num[i] = i+1;
            }
            for(int i = 0; i < r; i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                int[] stock = new int[n];
                for(int j = 0; j < n; j++){
                    stock[j] = num[j];
                }
                for(int j = 0; j < c; j++){
                    num[j] = stock[p-1+j];
                }
                for(int j = c; j < p+c-1; j++){
                    num[j] = stock[j-c];
                }
            }
            System.out.println((n+1-num[0]));
        }
    }    
}


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

pair_num = 0
for a_i in range(a+1):
    for b_i in range(b+1):
        for c_i in range(c+1):
            if (500*a_i + 100*b_i + 50*c_i) == x:
                pair_num += 1

print(pair_num)

Measured memory_bytes: 3060
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [str(i) for i in input().split()]
    count = 0
    s = "CODEFESTIVAL2016"
    for i in range(16):
        if a[0][i] != s[i]:
            count +=1
    print(count)
        

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  int ans = 1001001001;
  rep(i,100) {
    int ni = i+1;
    int tot=0;
    rep(j,n) {
      tot+= (x[j]-ni)*(x[j]-ni);
    }
    ans = min(ans,tot);
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }eni(!=) cerr  << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
} sim dor(rge<c> d) { *this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
#define err(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll=long long;
using vi=vector<int>;



int main()
{
    ios::sync_with_stdio (false), cin.tie (0);
    int n;
    cin >> n;
    vi a (n);
    for (int & i : a)
        cin >>i;
    vector< ll > dp (n + 1 , 0);
    if (n >= 2)
    {
        dp[1] = abs (a[1] - a[0]);
        for (int i = 2; i < n; i++)
        {
            dp[i] = min( dp[i - 1] + abs( a[i] - a[i - 1] ) , dp[i - 2] + abs( a[i] - a[i - 2] ) );
            debug() << err(dp[i]);
        }
    }
        debug() << err(dp);
    cout << dp[n - 1] << '\n';
    return 0;
}



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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 998244353

int mpow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1) res = (int64_t) res * a % MOD;
		a = (int64_t) a * a % MOD;
	}
	return res;
}
int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	std::vector<int64_t> cnt(1000001);
	for (int i = 0; i < n; i++) cnt[a[i]] += a[i];
	for (int i = 0; i <= 1000000; i++) cnt[i] %= MOD;
	
	auto converted = cnt;
	for (int x = 1; x <= 1000000; x++) {
		for (int y = 2; y <= 1000000 / x; y++) converted[x] += converted[x * y];
		converted[x] %= MOD;
	}
	for (auto &i : converted) i %= MOD, i *= i, i %= MOD;
	for (int x = 1000000; x >= 1; x--) {
		for (int y = 2; y <= 1000000 / x; y++) converted[x] -= converted[x * y];
		converted[x] %= MOD;
	}
	for (int i = 0; i < n; i++) converted[a[i]] -= (int64_t) a[i] * a[i];
	int64_t ans = 0;
	for (int i = 1; i <= 1000000; i++) {
		converted[i] = converted[i] % MOD + MOD;
		if (converted[i] >= MOD) converted[i] -= MOD;
		ans += (int64_t) converted[i] * 499122177 % MOD * mpow(i, MOD - 2) % MOD;
	}
	std::cout << ans % MOD << std::endl;
	
	return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 200010;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}


ll dp[N];
int c[N],A[N],pre[N],lst[N];
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j,m;
    cin>>n;
    rep(i,1,2e5)pre[i]=-1;
    rep(i,1,n){cin>>c[i];}
    int len = 0;
    
    rep(i,1,n)if(c[i]!=c[i-1]){
        A[++len]=c[i];
        lst[len]= pre[c[i]];
        pre[c[i]]=len;
    }
    n = len;
    dp[0]=1;
    rep(i,1,n){
        if(lst[i]==-1)dp[i] = dp[i-1];
        else dp[i]=(dp[i-1]+dp[lst[i]])%mod;
    }
    cout<<dp[n]<<"\n";







    
    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
int main(){
   int n;
   cin >> n;
   int summed = 0;
   int i = 1;
   while(i <= n){
	   summed += i;
	   ++i;
   }
   cout << summed;
}














Measured memory_bytes: 256
n = int(input())
arr1 = [0 for i in range(n+1)]

partialsum = 0
ans = 0
for i in range(n):
    a = int(input())
    partialsum += a
    if a == 0:
        ans += partialsum//2
        partialsum = 0

ans += partialsum//2
print(ans)


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

int main(){
    int count[4][3][10]={{{}}};
    int N, b, f, r, v;
    cin >> N;
    for (int n=0; n<N; n++){
        cin >> b >> f >> r >> v;
        count[b-1][f-1][r-1] += v;
    }   
    for (int b=0; b<4; b++){
        for (int f=0; f<3; f++){
            for (int r=0; r<10; r++){
                cout << " " << count[b][f][r];
            }   
            cout << endl;
        }   
        if (b==3) break;
        cout << "####################" << endl;
    }   
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
#define boost ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

int main(){
	boost;
	int a,b;
	cin>>a>>b;
	if(a/10==0 && b/10==0){
		cout<<a*b<<'\n';
	}else{
		cout<<-1<<'\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n,m; cin>>n>>m;
	VL a(m),b(m),c(m,0L);
	rep(i,m){
		cin>>a[i]>>b[i];
		rep(j,b[i]){
			int t; cin>>t; t--;	c[i]+=(1<<t);
		}
	}
	ll dp[m+5][(1<<n)+5]; memset(dp,INF,sizeof(dp));
	dp[0][0]=0;

	rep(i,m){
		rep(j,1<<n){
		  chmin(dp[i+1][j],dp[i][j]);
			chmin(dp[i+1][j|c[i]],dp[i][j]+a[i]);
		}
	}

	cout<<(dp[m][(1<<n)-1]<INF ? dp[m][(1<<n)-1] : -1)<<endl;
	
	return 0;
}


Measured memory_bytes: 32512
combi = gets.strip.split(' ').map(&:to_i)
MAX = 16

target = 0
MAX.times do |i|
  combi[target] -= 1
  target = target == 0 ? 1 : 0
end

if combi[0] < 1 && combi[1] < 1
  puts 'Yay!'
else
  puts ':('
end

Measured memory_bytes: 1788