akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

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

int vsum[2001][2001];
int esum[2001][2001][4];

int getVSum(int x1, int y1, int x2, int y2)
{
    return vsum[x2+1][y2+1]-vsum[x1][y2+1]-vsum[x2+1][y1]+vsum[x1][y1];
}

int getESum(int x1, int y1, int x2, int y2, int dir)
{
    return esum[x2+1][y2+1][dir]-esum[x1][y2+1][dir]-esum[x2+1][y1][dir]+esum[x1][y1][dir];
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,Q; cin>>N>>M>>Q;

    auto inside = [&](int y, int x){
        if (0<=y&&y<N&&0<=x&&x<M) return true;
        return false;
    };

    vector<string> f(N);
    rep(i,N) cin>>f[i];
    rep(i,N)rep(j,M){
        if (f[i][j]=='1'){
            vsum[i+1][j+1]=1;
            rep(k,4){
                int ni = i+dy[k];
                int nj = j+dx[k];
                if (!inside(ni,nj)) continue;
                if (f[ni][nj]=='1') esum[i+1][j+1][k]++;
            }
        }
    }
    rep(i,N)rep(j,M+1){
        vsum[i+1][j] += vsum[i][j];
        rep(k,4){
            esum[i+1][j][k] += esum[i][j][k];
        }
    }
    rep(j,M)rep(i,N+1){
        vsum[i][j+1] += vsum[i][j];
        rep(k,4){
            esum[i][j+1][k] += esum[i][j][k];
        }
    }

    while(Q--){
        int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
        x1--; y1--; x2--; y2--;
        int V = getVSum(x1,y1,x2,y2);
        int E = 0;
        E += getESum(x1,y1,x2-1,y2,0);
        E += getESum(x1,y1,x2,y2-1,1);
        E += getESum(x1+1,y1,x2,y2,2);
        E += getESum(x1,y1+1,x2,y2,3);
        E/=2;
        cout<<V-E<<"\n";
    }
    return 0;
}


Measured memory_bytes: 85772
#include<cstdio>
#include<set>
#include<cstring>
using namespace std;
const int MAXN = 500005;
int N;
char s[MAXN];
set <int> dec, pos[10];
void change(int x, char ch)
{
	pos[s[x] - '0'].erase(x);
	dec.erase(x);
	dec.erase(x - 1);
	s[x] = ch;
	pos[s[x] - '0'].insert(x);
	if (x < N - 1 && s[x] > s[x + 1])
		dec.insert(x);
	if (x && s[x - 1] > s[x])
		dec.insert(x - 1);
}
int main()
{
	scanf("%s", s);
	N = strlen(s);
	for (int i = 0; i < N; i++)
		pos[s[i] - '0'].insert(i);
	for (int i = 0; i < N - 1; i++)
		if (s[i] > s[i + 1])
			dec.insert(i);
	int sol = 1, last = -1;
	while (!dec.empty())
	{
		int curr = *dec.begin(), prev = *pos[s[curr] - '0'].begin(), it = N - 1;
		for (; it > curr && s[it] == '9'; it--)
			change(it, '0');
		change(it, s[it] + 1);
		for (int i = prev; i > last; i--)
			change(i, '0');
		last = prev;
		sol++;
	}
	printf("%d",sol);
}

Measured memory_bytes: 36480
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	string s;
	int p;
	long long int total = 0;
	long long int point = 0;

	cin >> s;
	p = s.size();
	
	if (p != 1) {
		FOR(i, 0, pow(2, p - 1) - 1) {
			bitset<10> bit(i);

			FOR(q, 0, p - 2) {
				if (bit[q] == false) {
					point = point * 10 + (s[q] - '0');
					if (q == p - 2) {
						point = point * 10 + (s[q + 1] - '0');
						total += point;
						point = 0;
					}
				}
				else {
					point = point * 10 + (s[q] - '0');
					if (q == p - 2) {
						point += s[q + 1] - '0';
					}
					total += point;
					point = 0;
				}
			}
		}
		cout << total << endl;
	}
	else {
		cout << s << endl;
	}
	

	
	return 0;
}

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

using namespace std;

int main() {
    int n = 0, k = 0;
    string s;

    cin >> n >> k;
    cin >> s;

    k--;

    if (s[k] == 'A') {
        s[k] = 'a';
    } else if( s[k] == 'B')
    {
        s[k] = 'b';
    } else if ( s[k] == 'C') {
        s[k] = 'c';
    }

    cout << s << endl;


    return 0;
}

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

bool used[101010];
int main(){
    int n,k;
    cin>>n>>k;
    pair<int,int> a[n];
    for(int i=0;i<n;i++)cin>>a[i].second>>a[i].first;
    sort(a,a+n);
    reverse(a,a+n);

    priority_queue<int,vector<int>,greater<int>> que;
    long long cnt=0, sum=0;
    for(int i=0;i<k;i++){
        sum+=a[i].first;
        if(!used[a[i].second]){
            ++cnt;
            used[a[i].second]=true;
        }
        else que.push(a[i].first);
    }
    long long ans=sum+cnt*cnt;
    for(int i=k;i<n;++i){
        if(cnt>=k)break;
        if(used[a[i].second])continue;
        ++cnt;
        used[a[i].second]=true;
        int mini=que.top();que.pop();
        sum-=mini;
        sum+=a[i].first;
        ans=max(ans,sum+cnt*cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1536
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
ll in(){ ll x; cin >> x; return x; }
vector<ll> in(size_t n){ vector<ll> v(n); each(x, v) cin >> x; return v; }
/* ]]] */

ll n;
ll a[200000];
ll b[200000];

int main(){
  cin >> n;
  rep(i, n) cin >> a[i], a[i]--;
  rep(i, n) b[a[i]] = i;
  set<ll> s{-1, n};
  ll res = 0;
  rep(i, n){
    ll l = *--s.lower_bound(b[i]);
    ll r = *s.lower_bound(b[i]);
    res += (b[i] - l) * (r - b[i]) * (i + 1);
    s.insert(b[i]);
  }
  cout << res << endl;
}


Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	string s;
	cin >> s;

	map<char, int>  str;
	rep(i, 4) {
		str[s[i]]++;
	}
	if (str.size() != 2) {
		cout << "No\n";
		return 0;
	}
	rep(i, 4) {
		if (str[s[i]] != 2) {
			cout << "No\\n";
			return 0;
		}
	}
	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 3544
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

for i, pattern in enumerate(itertools.permutations(range(1, n + 1), r=n)):
    if pattern == p:
        a = i
    if pattern == q:
        b = i
print(abs(a - b))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=1000000007;
ll MOD=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int v,E;
    cin >> v >> E;
    vector<vector<pp>> e(v+1,vector<pp>(0));
    rep(i,E){
        int f,g,h;
        cin >> f >> g >> h;
        e[f].push_back(mk(g,h));
        e[g].push_back(mk(f,h));
    } 
    rep(i,v) {
        int f;
        cin >> f;
    }
    int t;
    cin >> t;
    rep(i,100){
        cout << -1 << endl;
        t--;
        if (t==0) return 0;
    }
    queue<int> q;
    q.push(1);
    while(true){
        int f=q.front();
        int u=rand()%e[f].size();
        q.pop();
        q.push(e[f][u].first);
        rep(i,e[f][u].second){
            cout << e[f][u].first << endl;
            t--;
            if (t==0) return 0;
        }
    }
}


Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200, lg = 21;
int vi[lg], tol[lg][maxn], tor[lg][maxn], a[maxn];
int n, v, stk;
int dpl[lg][maxn], dpr[lg][maxn];
int main(){
	cin >> n >> v;
	while(v){
		vi[stk++] = v;
		v /= 2;
	}
	vi[stk++] = 0;
	reverse(vi, vi + stk);
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int j = 0; j < stk; j++){
		for(int i = 1; i <= n; i++){
			if(i == 1 || a[i] - a[i - 1] > vi[j]) tol[j][i] = i;
			else tol[j][i] = tol[j][i-1];
		}
		for(int i = n; i >= 1; i--){
			if(i == n || a[i + 1] - a[i] > vi[j]) tor[j][i] = i;
			else tor[j][i] = tor[j][i+1];
		}
	}
	const int full = (1<<30) - 1;
	auto merge = [&](int a, int b){
		if(__builtin_popcount(a) + __builtin_popcount(b) > stk) return full;
		while(a & b) b <<= 1;
		return a | b;
	};
	auto combine = [&](int a, int b){
		if(__builtin_popcount(a) + __builtin_popcount(b) > stk) return full;
		while(b){
			int l = b & - b;
			a = merge(a, l);
			b ^= l;
		}
		return a;
	};
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < stk; j++) dpl[j][i] = full;
		for(int j = 0; j < stk; j++){
			for(int k = 0; k < stk; k++){
				int q = merge(dpl[k][tol[j][i]-1], 1<<j);
				int cn = min(lg - 1, __builtin_popcount(q));
				dpl[cn][i] = min(dpl[cn][i], q);
			}
		}
	}
	for(int i = n; i >= 1; i--){
		for(int j = 0; j < stk; j++) dpr[j][i] = full;
		for(int j = 0; j < stk; j++){
			for(int k = 0; k < stk; k++){
				int q = merge(dpr[k][tor[j][i]+1], 1<<j);
				int cn = min(lg - 1, __builtin_popcount(q));
				dpr[cn][i] = min(dpr[cn][i], q);
			}	
		}
	}
	for(int i = 1, j = 1; i <= n; i = j){
		while(j + 1 <= n && a[j + 1] - a[j] <= vi[stk - 1]) j++;
		bool possible = false;
		for(int k0 = 0; k0 < stk; k0++){
			for(int k1 = 0; k1 < stk; k1++){	
				int a = dpl[k0][i - 1], b = dpr[k1][j + 1];
				a = min(combine(a, b), combine(b, a));
				possible |= __builtin_popcount(a) < stk && a < (1<<(stk - 1));
			}
		}
		for(int k = i; k <= j; k++){
			if(possible) cout << "Possible\n";
			else cout << "Impossible\n";
		}
		j++;
	}
	return 0;
}


Measured memory_bytes: 67968
'use strict';
const main = val => {
  const n = parseInt(val[0], 10);
  const a = val[1].split(' ').map(p => parseInt(p, 10));
  const b = val[2].split(' ').map(p => parseInt(p, 10));
  const c = val[3].split(' ').map(p => parseInt(p, 10));
  var ans = 0;
  b.map(val => ans += val);
  for (let i = 0; i < a.length - 1; i++) {
    ans += a[i+1]-a[i] == 1 ? c[a[i]-1] : 0;
  }
  console.log(ans);
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 22084
package main

import (
	"fmt"
	"os"
	"sort"
)

func main() {
	var a, b, c int
	_, err := fmt.Fscanf(os.Stdin, "%d %d %d", &a, &b, &c)
	if err != nil {
		panic(err)
	}
	array := []int{a, b, c}
	sort.Ints(array)
	if array[0] == array[1] {
		fmt.Println(array[2])
	} else {
		fmt.Println(array[0])
	}
}


Measured memory_bytes: 512
n, x = map(int, input().split())


def pi(n):
    return 2**(n+1)-1


def ai(n):
    return 2**(n+2) - 3


def f(n, x):
    if n == 0:
        return 1
    else:
        if x == 1:
            return 0
        elif (1 < x) and (x <= 1 + ai(n-1)):
            return f(n - 1, x - 1)
        elif x == 2 + ai(n - 1):
            return pi(n - 1) + 1
        elif (2 + ai(n - 1) < x) and (x <= 2 + 2 * ai(n - 1)):
            return pi(n-1) + 1 + f(n-1, x-2-ai(n-1))
        elif x >= ai(n):
            return pi(n)


print(f(n, x))


Measured memory_bytes: 3064
import math
while 1:
    num = int(input())
    if num == 0:
        break
    a = [int(_) for _ in input().split()]
    ave = 0
    dev = 0
    for i in range(num):
        ave += a[i]
    else:
        ave /= num
    for i in range(num):
        dev +=math.pow(a[i]-ave,2)
    else:
        dev = math.sqrt(dev/num)
    print(dev)


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

int main(){
  int a, b;
  cin >> a >> b;
  int ans;
  int c = a - b;
  ans = ((c + 1) * c / 2) - a;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        long R = nextInt();
        long G = nextInt();
        long B = nextInt();
        
        int K = nextInt();
        
        int K_G = 0;

        if(G<=R){
            for (int i=1; i<=K; i++) {
                G = G*2;
                if(G>R){
                    K_G = i;
                    break;
                }
            }
            if(K_G==0){
                System.out.println("No");
                return;
            }
        }
        
        int K_B = 0;
   
        if(B<=G){
            for (int i=1; i<=K; i++) {
                B = B*2;
                if(B>G){
                    K_B = i;
                    break;
                }
            }
            if(K_B==0){
                System.out.println("No");
                return;
            }
        }

        if(K_G + K_B <=K){
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
 
        
    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}


Measured memory_bytes: 32660
#include<iostream>
#include<cstdlib>
#include<queue>
#define MAX 22
#define BLOCK 1
#define START 2
#define GOAL 3
#define REP(i,a,e) for(int i=(a);i<=(e);++i)
#define REPD(i,a,e) for(int i=(a);i>=(e);--i)
using namespace std;
struct Map{
	Map(){
		REP(i,0,MAX-1)REP(j,0,MAX-1)map[i][j]=0;
	}
	int h,w;
	char map[MAX][MAX];
	int depth;
	pair<int, int> stone;
};
int BFS(Map &m){
	queue<Map> q;
	
	q.push( m );
	while( !q.empty() ){
		Map t = q.front();
		q.pop();

		/* up */
		REPD(i,t.stone.first,0){
			if( t.map[i][ t.stone.second ] == BLOCK ){
				if( abs(i-t.stone.first) > 1 ){
					Map tt = t;
					tt.map[ i ][ t.stone.second ] = 0;
					tt.stone = make_pair( i + 1, t.stone.second );
					if( ++tt.depth < 10 )
						q.push( tt );
				}
				break;
			}else if( t.map[i][ t.stone.second ] == GOAL ){
				return t.depth+1;
			}
		}
		/* down */
		REP(i,t.stone.first,t.h+1){
			if( t.map[i][ t.stone.second ] == BLOCK ){
				if( abs(i-t.stone.first) > 1 ){
					Map tt = t;
					tt.map[ i ][ t.stone.second ] = 0;
					tt.stone = make_pair( i - 1, t.stone.second );
					if( ++tt.depth < 10 )
						q.push( tt );
				}
				break;
			}else if( t.map[i][ t.stone.second ] == GOAL ){
				return t.depth+1;
			}
		}
		/* right */
		REP(j,t.stone.second,t.w+1){
			if( t.map[ t.stone.first ][ j ] == BLOCK ){
				if( abs(j-t.stone.second) > 1 ){
					Map tt = t;
					tt.map[ t.stone.first ][ j ] = 0;
					tt.stone = make_pair( t.stone.first, j - 1 );
					if( ++tt.depth < 10 )
						q.push( tt );
				}
				break;
			}else if( t.map[ t.stone.first ][ j ] == GOAL ){
				return t.depth+1;
			}
		}
		/* left */
		REPD(j,t.stone.second,0){
			if( t.map[ t.stone.first ][ j ] == BLOCK ){
				if( abs(j-t.stone.second) > 1 ){
					Map tt = t;
					tt.map[ t.stone.first ][ j ] = 0;
					tt.stone = make_pair( t.stone.first, j + 1 );
					if( ++tt.depth < 10 )
						q.push( tt );
				}
				break;
			}else if( t.map[ t.stone.first ][ j ] == GOAL ){
				return t.depth+1;
			}
		}
	}
	return -1;
}
int main(){
	while(true){
		Map m;
		scanf("%d%d", &m.w, &m.h);
		if( m.w==0 && m.h==0 )break;

		REP(i,1,m.h)REP(j,1,m.w){
			scanf("%d", &m.map[i][j]);
			if( m.map[i][j] == START ){
				m.stone=make_pair(i,j);
			}
		}
		m.depth = 0;

		printf("%d\n", BFS( m ));
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  int y,d,d1,sum=0;
  while(cin >> d){
    sum = 0;    
    d1 = d;
    for(;d<600;d+=d1){
      y = d*d*d1;
      sum += y;
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int n;
string s;
int suffR[4001], suffG[4001], suffB[4001];

void input(){
    scanf("%d", &n);
    cin >> s;
}

void prepare(){
    for (int i = s.length() - 1; i >= 0; i--){
        if (s[i] == 'R'){
            suffR[i] = suffR[i+1] + 1;
            suffG[i] = suffG[i+1];
            suffB[i] = suffB[i+1];
        } else if (s[i] == 'G'){
            suffR[i] = suffR[i+1];
            suffG[i] = suffG[i+1] + 1;
            suffB[i] = suffB[i+1];
        } else if (s[i] == 'B'){
            suffR[i] = suffR[i+1];
            suffG[i] = suffG[i+1];
            suffB[i] = suffB[i+1] + 1;
        }
    }
}

void solve(){
    long long int ans = 0;
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'R'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'G'){
                    ans += suffB[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'B'){
                        ans--;
                    }
                }
            }
        }
    }
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'R'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'B'){
                    ans += suffG[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'G'){
                        ans--;
                    }
                }
            }
        }
    }
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'G'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'R'){
                    ans += suffB[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'B'){
                        ans--;
                    }
                }
            }
        }
    }

    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'G'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'B'){
                    ans += suffR[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'R'){
                        ans--;
                    }
                }
            }
        }
    }

    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'B'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'R'){
                    ans += suffG[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'G'){
                        ans--;
                    }
                }
            }
        }
    }

    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'B'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'G'){
                    ans += suffR[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'R'){
                        ans--;
                    }
                }
            }
        }
    }

    cout << ans << endl;
}

int main(){
    input();
    prepare();
    solve();
}


Measured memory_bytes: 3684
yesno 0 = "YES"
yesno 2 = "YES"
yesno _ = "NO"

count :: [Int] -> Int
count xs = snd $ foldl step (1, 0) xs
    where step (k, a) i = (k+1, a + (if k == i then 0 else 1))

main = do
  n <- readLn :: IO Int
  p <- map read . words <$> getLine :: IO [Int]
  putStrLn $ yesno $ count p


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

using namespace std;
typedef long long ll;

const int MAXN = 1e5+2;
int x[MAXN] = {0};
int y[MAXN] = {0};
int t[MAXN] = {0};
int N;
void solve(){
	cin>>N;
	x[0]=y[0]=t[0]=0;
	for (int i=1;i<=N;i++){
		cin>>t[i]>>x[i]>>y[i];
	}
	for (int i=1;i<=N;i++){
		int dx = abs(x[i]-x[i-1]) + abs(y[i] - y[i-1]);
		int dt = t[i] - t[i-1];
		if (dx % 2 != dt % 2 || dx > dt){
//			cout<<i<<' '<<dx<<' '<<dt;
			cout<<"No"<<endl;
			return;
		}
	}

	cout<<"Yes"<<endl;
}

int main(){
// 	freopen("in.txt","r",stdin);
// 	freopen("out.txt","w",stdout);
	std::ios::sync_with_stdio(false);

		solve();

	return 0;
}



Measured memory_bytes: 1408
import sys
# from collections import defaultdict, deque
import math
 
# import copy
# from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
 
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 998244353
 
def solve():
    a, b, c, d = getList()
    dp = [[1 for i in range(d + 1)] for j in range(c + 1)]
 
    for i in range(a + 1, c + 1):
        dp[i][b] = (dp[i - 1][b] * b) % MOD
    for i in range(b + 1, d + 1):
        dp[a][i] = (dp[a][i - 1] * a) % MOD
 
    for cx in range(a + 1, c + 1):
        for cy in range(b + 1, d + 1):
            dp[cx][cy] = (dp[cx - 1][cy] * cy + dp[cx][cy - 1] * cx - dp[cx - 1][cy - 1] * ((cx - 1) * (cy - 1))) % MOD
            
 
    print(dp[-1][-1])
 
 
def main():
    n = getN()
    for _ in range(n):
        solve()
 
 
if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 152728
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

void ans(ll i,ll n,ll a[],vector<ll> adj[],bool vis[],set<ll>& ma,vector<ll>& v){
	vis[i]=true;
	auto it=ma.lower_bound(a[i]);
	ll val=-1;
	if(it!=ma.end()){
		val=*it;
		ma.erase(it);
	}
	ma.insert(a[i]);
	v[i]=ma.size()-1;
	for(auto j:adj[i]){
		if(vis[j])
			continue;
		ans(j,n,a,adj,vis,ma,v);
	}
	ma.erase(a[i]);
	ma.insert(val);
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll val[n+1];
		val[0]=0;
		for(ll i=1;i<=n;i++)
			cin>>val[i];
		std::vector<ll> adj[n+1];
		for(ll i=0;i<n-1;i++){
			ll p,q;
			cin>>p>>q;
			adj[p].push_back(q);
			adj[q].push_back(p);
		}
		vector<ll> v(n+1);
		bool vis[n+1];
		memset(vis,false,sizeof(vis));
		set<ll> s;
		s.insert(-1);
		ans(1,n,val,adj,vis,s,v);
		for(ll i=1;i<=n;i++){
			cout<<v[i]<<endl;
		}

	}
	return 0;
}

Measured memory_bytes: 40276
#include <cstdio>
#include <cstring>
using namespace std;

int main(void)
{
	unsigned long long res = 0, num = 0;
	char str[128];
	bool flag = true;
	
	while (scanf("%s", str) != EOF){
		int len = strlen(str);
		for (int i = 0; i < len; i++){
			if ('0' <= str[i] && str[i] <= '9'){
				for (int j = i; j < len; j++){
					if ('0' <= str[i] && str[i] <= '9') {
						num *= 10;
						num += str[i] - '0';
						i++;
					}
					else break;
				}
			}
			res += num;
			num = 0;
		}
	}
	
	printf("%llu\n", res);
	
	return (0);
}

Measured memory_bytes: 0
#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 sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
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;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N;
string S;

int main(){
    cin >> N >> S;
    int ct = 0;
    rrep(i,sz(S)){
        if(S[i] == ')') ct++;
        if(ct && S[i] == '(') ct--;
    }
    rep(i,ct) S = '(' + S;
    
    ct = 0;
    rep(i,sz(S)){
        if(S[i] == '(') ct++;
        else ct--;
    }
    
    rep(i,ct) S += ')';
    
    cout << S << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
/*
#define min(a, b, c) (a < b ? (a < c ? a : ((b < c) ? b : c)) : (b < c ? b : (a < c ? a : c )))
#define max(a, b, c) (a > b ? (a > c ? a : ((b > c) ? b : c)) : (b > c ? b : (a > c ? a : c )))
*/
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

long diffS(int h, int w, long s) {
	int i;
	long a, b, minDiff = LONG_MAX, diffh, diffw;
	a = (long)(h+1)/2*w;
	b = (long)h*w - a;
	diffh = max(a, s) - min(b, s);
//	printf("%ld %ld %ld diff:%ld\n", s, a, b, diffh);
	a = (long)(w+1)/2*h;
	b = (long)w*h - a;
	diffw = max(a, s) - min(b, s);
//	printf("%ld %ld %ld diff:%ld\n", s, a, b, diffw);
/*	for (i = 0; i <= (h+1)/2; i++) {
		a = (long)i * w;
		b = (long)(h - i) * w;
		diff = max(a, b, s) - min(a, b, s);
		if (minDiff > diff) {
			minDiff = diff;
		}
	}
	for (i = 0; i <= (w+1)/2; i++) {
		a = (long)i * h;
		b = (long)(w - i) * h;
		diff = max(a, b, s) - min(a, b, s);
		if (minDiff > diff) {
			minDiff = diff;
		}
	}
*/
	return min(diffh, diffw);
}

int main(void) {
	int H, W, i;
	long diff, minDiff = LONG_MAX;
	scanf("%d %d", &H, &W);
	for (i = 1; i <= (H+1)/2; i++) {
		diff = diffS(H - i, W, (long)i * W);
		if (minDiff > diff) {
			minDiff = diff;
		}
	}
	for (i = 1; i <= (W+1)/2; i++) {
		diff = diffS(H, W - i, (long)i * H);
		if (minDiff > diff) {
			minDiff = diff;
		}
	}
	printf("%ld\n", minDiff);
	return 0;
}


Measured memory_bytes: 128
h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
p = 10 ** 9 + 7

"""
dp[y][x]: y行x列に到達する方法の数
"""
dp = [[0]*w for _ in range(h)]
dp[0][0] = 1
for y in range(h):
    for x in range(w):
        if y+1<h and maze[y+1][x] == ".":
            dp[y+1][x] = (dp[y+1][x] + dp[y][x]) % p
        if x+1<w and maze[y][x+1] == ".":
            dp[y][x+1] = (dp[y][x+1] + dp[y][x]) % p
print(dp[h-1][w-1])


Measured memory_bytes: 88816
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;

ll a, b, c, d, e, f, g, h, i, k, l;
ll N;

void input()
{
    cin >> N >> i;
}
void solve()
{
}

int main()
{
    input();
    solve();
    cout << N - i + 1 << endl;
}

Measured memory_bytes: 256
N, C, K = map(int, input().split())
T = sorted([int(input()) for _ in range(N)])

cnt = 1
time = 0
capa = 1
pre = T[0]

for i in range(1, N):
    capa += 1
    time += T[i]-pre
    if capa>C or time>K:  # 次のバスを用意
        cnt += 1
        time = 0
        capa = 1

    pre = T[i]

print(cnt)

Measured memory_bytes: 8280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 3e5;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int INF = 0;
const int LG = 21;

void solve()
{
	long double a, b;
	cin >> a >> b;
	int ans = a * b;
	cout << ans << endl;
}
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

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

Measured memory_bytes: 3744
A, B, C, X, Y = map(int, input().split(' '))

candidate = []

candidate.append(C * X * 2 if X >= Y else C * X * 2 + B * (Y - X))
candidate.append(C * Y * 2 if X <= Y else C * Y * 2 + A *(X - Y))
candidate.append(A * X + B * Y)

print(min(candidate))

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

int a,b,c,d[3];

int main(){
  cin>>a>>b>>c;
  d[0]=abs(b-a);
  d[1]=abs(c-b);
  d[2]=abs(c-a);
  sort(d,d+3);
  cout<<d[1]+d[0];
  return 0;
}

Measured memory_bytes: 256
def warshall_floyd():
    inf=float("inf")
    v,e=map(int,input().split())
    #頂点集合、始点、終点
    dp=[[[inf]*v for i in range(v)] for j in range(v+1)]

    #initialize
    for i in range(v):
        dp[0][i][i]=0
    for _ in range(e):
        s,t,d=map(int,input().split())
        dp[0][s][t]=d
    
    for i in range(1,v+1):
        for j in range(v):
            for k in range(v):
                dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j][i-1]+dp[i-1][i-1][k])
    
    #負閉路判定
    for i in range(v):
        if dp[v][i][i]<0 :
            print("NEGATIVE CYCLE")
            return None
    
    for i in range(v):
        print(" ".join(["INF" if x ==inf else str(x) for x in dp[v][i]]))

warshall_floyd()    



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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == b) && (b == c)) {
		cout << "1" << endl;
	}
	else if (((a == b) && (b != c)) || ((b == c) && (c != a)) ||
		((c == a) && (a != b))) {
		cout << "2" << endl;
	}
	else {
		cout << "3" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int n;
	cin >> n;
	int ns = n % 10;
	if (ns == 0) {
		cout << "pon" << endl;
	}
	if (ns == 1) {
		cout << "pon" << endl;
	}
	if (ns == 2) {
		cout << "hon" << endl;
	}
	if (ns == 3) {
		cout << "bon" << endl;
	}
	if (ns == 4) {
		cout << "hon" << endl;
	}
	if (ns == 5) {
		cout << "hon" << endl;
	}
	if (ns == 6) {
		cout << "pon" << endl;
	}
	if (ns == 7) {
		cout << "hon" << endl;
	}
	if (ns == 8) {
		cout << "pon" << endl;
	}
	if (ns == 9) {
		cout << "hon" << endl;
	}
}

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

#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define fi first
#define se second

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())

#define PF(a) push_front(a)
#define PB(a) push_back(a)
#define EMPF(...) emplace_front(__VA_ARGS__)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))

#define PW(n) (1LL << (n))
#define NUM(x) char(x + '0')
#define ALP(x) char(x + 'a')

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> void SORT(vector<T> &a) { sort(a.begin(), a.end()); }
template <class T> void SORTR(vector<T> &a) { sort(a.rbegin(), a.rend()); }
template <class T> void UNIQUE(vector<T> &a) { a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N, K;
int A[100010];
const int MAX_M = 50;
int dp[MAX_M+1][2];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  REP(i, N) cin >> A[i];
  MINUS(dp);
  dp[0][0] = 0;
  REP(i, MAX_M) {
    int mask = PW(MAX_M-i-1);
    int bit = K & mask;
    int num = 0;
    REP(k, N) if (A[k] & mask) num++;
    int cost0 = mask * num;
    int cost1 = mask * (N-num);
    if (dp[i][0] != -1) {
      CHMAX(dp[i+1][0], dp[i][0] + (bit ? cost1 : cost0));
    }
    if (dp[i][0] != -1) {
      if (bit) CHMAX(dp[i+1][1], dp[i][0] + cost0);
    }
    if (dp[i][1] != -1) {
      CHMAX(dp[i+1][1], dp[i][1] + max(cost0, cost1));
    }
  }
  cout << max(dp[MAX_M][0], dp[MAX_M][1]) << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> data(n);
	ff(i, 0, n)cin >> data[i];
	int ans = 0;

	ff(i, 1, n - 1) {
		vector<int> com = { data[i - 1],data[i],data[i + 1] };
		st(com);
		if (com[1] == data[i])ans++;
	}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	string s, t;
	cin>>s>>t;
	int ans=0;
	REP(i, 3){
		if(s[i]==t[i]){
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
S = input()
PossiblePaper = 0
Score = 0
for s in S:
    if s == "g":
        if PossiblePaper == 0:
            Score += 0
            PossiblePaper += 1
        else:
            Score += 1
            PossiblePaper -= 1
    else:
        if PossiblePaper == 0:
            Score -= 1
            PossiblePaper += 1
        else:
            Score += 0
            PossiblePaper -= 1
print(Score)


Measured memory_bytes: 3316
/***
 **   A S M Atikur Rahman
 **   Update: 14-11-2019
***/

//#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<math.h>
#include<algorithm>
#include<string>
#include<utility>
#include<stack>
#include<cstring>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<iomanip> ///setprecision


#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sci(x) scanf("%d%*c", &(x))
#define scll(x) scanf("%lld%*c", &(x))
#define scd(x) scanf("%lf%*c", &(x))
#define scstr(x) scanf("%s", x)
#define pfi(x) printf("%d", (x))
#define pfll(x) printf("%lld", (x))
#define pfd(x) printf("%f", (x))
#define pfstr(x) printf("%s", (x))
#define ps printf(" ")
#define pn printf("\n")
#define pfdot printf("..")

#define For(i,a,n) for(int i=(a); i<(n); i++)
#define rFor(i,n,a) for(int i=n-1; i>=0; i--)
#define trav(a,x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define pi  (2*acos(0))


using namespace std;

using ll=long long;
using pii= pair<int,int>;
using pll= pair<long long, long long>;
using pcc= pair<char, char>;
using pdd= pair<double, double>;

#define V(a) vector<a>
using vi= vector<int>;
using vs= vector<string>;
using vll= vector<ll>;
using vpii= vector<pii>;
using vc= vector<char>;
using vd= vector<double>;

//ll POW(ll a,ll b){if(b==0)return 1;ll x=POW(a,b/2);x=(x*x);if(b&1)x=(x*a);return x;}




int main( int argc, char *argv[] )
{
//    fropen("input.txt", "r", stdin);
//    fropen("output.txt", "w", stout);

    map<string, int>day;
    day["SUN"]=7;
    day["MON"]=6;
    day["TUE"]=5;
    day["WED"]=4;
    day["THU"]=3;
    day["FRI"]=2;
    day["SAT"]=1;
    string s;
    cin>>s;
    cout<<day[s]<<endl;

    return 0;
}














Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vi h(n);
  rep(i, n) {
    cin >> h[i];
  }

  vi dp(n);

  dp[1] = abs(h[0] - h[1]);

  rep(i, n-2) {
    dp[i+2] = min(dp[i] + abs(h[i+2] - h[i]), dp[i+1] + abs(h[i+2] - h[i+1]));
  }

  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;



int main() {
	int N, K, S;
	cin >> N >> K >> S;

	if (S != 1000000000) {
		for (int i = 0; i < K; i++) {
			cout << S << " ";
		}
		for (int i = 0; i < N - K; i++) {
			cout << "1000000000 ";
		}
	}
	else {
		for (int i = 0; i < K; i++) {
			cout << S << " ";
		}
		for (int i = 0; i < N - K; i++) {
			cout << "1 ";
		}
	}
}

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

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


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

struct Edge{
    int to, cap, rev;
};

vector<Edge> G[110];
bool seen[110];

void add_edge( int from, int to, int cap ){
    G[from].push_back( Edge{ to, cap, (int)G[to].size() } );
    G[to].push_back( Edge{ from, 0, (int)G[from].size() - 1 } );
}

int dfs( int v, int t, int f ){
    if( v == t ) return f;
    seen[v] = true;
    for( auto& nv : G[v] ){
        if( !seen[nv.to] && nv.cap > 0 ){
            int d = dfs( nv.to, t, min( f, nv.cap ) );
            if( d > 0 ){
                nv.cap -= d;
                G[nv.to][nv.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow( int s, int t ){
    int flow = 0;
    while( 1 ){
        fill( seen, seen + 110, false );
        int f = dfs( s, t, INF );
        if( f == 0 ) return flow;
        flow += f;
    }
}

signed main(){
    int V, E; cin >> V >> E;
    REP( i, E ){
        int from, to, cap;
        cin >> from >> to >> cap;
        add_edge( from, to, cap );
    }

    cout << max_flow( 0, V - 1 ) << endl;
}



Measured memory_bytes: 3256
#include<bits/stdc++.h>
#include<iostream>
#define mod 1000000007
using namespace std;

int main()
{
    long long a1,p,b,a;
    while(cin>>a>>b)
    {
        a1 = a%mod;
        p = 1;
        while (b > 0)
        {
            if (b%2==1)
            {
                p *= a1;
                p = p%mod;
            }
            b /= 2;
            a1 = (a1 * a1)%mod;
        }
        cout<<p<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
N, K = map(int, input().split())
sample = [1*i for i in range(10)]
D = list(map(int,input().split()))

sa = set(sample) - set(D)
sa_list = list(sa)

total_fee = N
while 1:
    list_total_fee = list(map(int, str(total_fee)))
    if set(list_total_fee).issubset(sa_list):
        print(total_fee)
        exit(0)
    else:
        total_fee += 1

Measured memory_bytes: 41196
main(n){for(;~scanf("%d",&n);)printf("%d\n","%%%%%%3.)%%-('%%4/4/+1,.0+<72-(<72-(GB=;6A<=8@GBHCADA<=AOJE@;OJE@;ZUPNITOPKSe`[VQb]XSQmhc^Ymhc^Yxsnl"[n]-37);}

Measured memory_bytes: 0
def gcd(a, b):
    if (a % b) == 0:
        return b
    return gcd(b, a%b)

def lcd(a, b):
    return a * b // gcd(a, b)


while True:
    try:
        nums = list(map(int, input().split()))
        print(gcd(nums[0], nums[1]), lcd(nums[0], nums[1]))

    except EOFError:
        break

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

const ll mod = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

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

    mint ans;
    vector<mint> dp(s + 1);
    rep(i,n){
        dp[0] += 1;
        vector<mint> nextdp(s + 1);
        rep(j,s+1){
            nextdp[j] += dp[j];
            if(j+a[i] <= s){
                nextdp[j + a[i]] += dp[j];
            }
        }
        dp = nextdp;
        ans += dp[s];
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 3664
x = int(input())

if x >= 400 and x <= 599:
    print(8)
elif x >= 600 and x <= 799:
    print(7)
elif x >= 800 and x <= 999:
    print(6)
elif x >= 1000 and x <= 1199:
    print(5)
elif x >= 1200 and x <= 1399:
    print(4)
elif x >= 1400 and x <= 1599:
    print(3)
elif x >= 1600 and x <= 1799:
    print(2)
elif x >= 1800 and x <= 1999:
    print(1)

Measured memory_bytes: 9192
#include<stdio.h>
#define mod 1000000007
#define llinf 4154118101919364364

long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}

long long power(long long a,long long b){
  long long x=1,y=a;
  while(b>0){
    if(b&1ll){
      x=(x*y)%mod;
    }
    y=(y*y)%mod;
    b>>=1;
  }
  return x%mod;
}

long long modular_inverse(long long n){
  return power(n,mod-2);
}

long long mod_nomalize(long long x){
  if(x>=0){return x%mod;}
  x*=-1;x%=mod;x=mod-x;
  if(x==mod){x=0;}
  return x;
}

//dp[seg][flag(Should the undermost RBRB... or BRBR...? 1...yes 0...free)]
long long dp[128][128][2];
long long h[128];
long long inv2;
long long rep(long long st,long long fi,long long pch){
  long long i,dvd=llinf,mxm=-llinf,ns,ndt=fi-st+1;
  dp[st][fi][0]=1;
  dp[st][fi][1]=1;
  for(i=st;i<=fi;i++){
    dvd=llmin(h[i],dvd);
    mxm=llmax(h[i],mxm);
  }
  ns=st;
  for(i=st;i<=fi+1;i++){
    if(h[i]==dvd || i==fi+1){
      if(ns<=i-1){
        rep(ns,i-1,dvd);
        ndt-=((i-1)-ns+1);
        dp[st][fi][1]*=(dp[ns][i-1][1]);
        dp[st][fi][1]%=mod;
        dp[st][fi][0]*=(dp[ns][i-1][0]+dp[ns][i-1][1]);
        dp[st][fi][0]%=mod;
      }
      ns=i+1;
    }
  }

  //free : 2^(now determine)
  dp[st][fi][0]*=power(2,ndt);dp[st][fi][0]%=mod;
  //RBRB... or BRBR... Already counted = 2
  //                   Should be counted = 2^(height)
  dp[st][fi][0]+=mod_nomalize(dp[st][fi][1]*mod_nomalize(power(2,dvd-pch)-2));dp[st][fi][0]%=mod;

  //RBRB... or BRBR... : 2^height
  dp[st][fi][1]*=power(2,dvd-pch);dp[st][fi][1]%=mod;
  return dp[st][fi][0];
}

int main(){
  inv2=modular_inverse(2);
  long long i,j;
  long long n;
  long long dp[128]={0},k;
  long long tg[128],tgc,p,sig;
  scanf("%lld",&n);
  //for(i=0;i<128;i++){
  //  dp[i][j][0]=-1;
  //  dp[i][j][1]=-1;
  //}
  for(i=1;i<=n;i++){
    scanf("%lld",&h[i]);
  }
  printf("%lld\n",rep(1,n,0));
  return 0;
}


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

int main() {
  string A,B;
  cin>>A>>B;
  if(A.at(0)==B.at(2)&&A.at(1)==B.at(1)&&A.at(2)==B.at(0)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256