akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

double dp[310][310][310];
int n;
 
double find(int a, int b, int c) {
	if (a < 0 || b < 0 || c < 0) return 0;
	if (a == 0 && b == 0 && c == 0) return 0;
	if (dp[a][b][c] == 0) {
		dp[a][b][c] = n + a*find(a - 1, b, c) + b*find(a + 1, b - 1, c) + c*find(a, b + 1, c - 1);
		dp[a][b][c] /= a + b + c;
	}
	return dp[a][b][c];
}
 
int main() {
  	cin >> n;
  	int cnt[5] = {};
  	cout << setprecision(10) << fixed;
	rep(i,n){
    	int a;
    	cin >> a;
    	cnt[a]++;
  	}
 
  cout << find(cnt[1], cnt[2], cnt[3]) << '\n';
 
  return 0;
}

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

int main(){
  int x;
  cin >> x;
  
  int a1,a2,a3,a4;
  
  a1 = x/1000;
  a2 = x/100 - 10 * a1;
  a3 = x/10 - 10 * a2 - 100 * a1;
  a4 = x - 10 * a3 - 100 * a2 - 1000 * a1;
  
  if (a1 + a2 + a3 + a4 == 7){
    cout << a1 << '+' << a2 << '+' << a3 << '+' << a4 << "=7" << endl;
  }else if(a1 + a2 + a3 - a4 == 7){
    cout << a1 << '+' << a2 << '+' << a3 << '-' << a4 << "=7" << endl;    
  }else if(a1 + a2 - a3 + a4 == 7){
    cout << a1 << '+' << a2 << '-' << a3 << '+' << a4 << "=7" << endl;
  }else if(a1 - a2 + a3 + a4 == 7){
    cout << a1 << '-' << a2 << '+' << a3 << '+' << a4 << "=7" << endl;
  }else if(a1 - a2 - a3 + a4 == 7){
    cout << a1 << '-' << a2 << '-' << a3 << '+' << a4 << "=7" << endl;
  }else if(a1 + a2 - a3 - a4 == 7){
    cout << a1 << '+' << a2 << '-' << a3 << '-' << a4 << "=7" << endl;
  }else if(a1 - a2 + a3 - a4 == 7){
    cout << a1 << '-' << a2 << '+' << a3 << '-' << a4 << "=7" << endl;
  }else if(a1 - a2 - a3 - a4 == 7){
    cout << a1 << '-' << a2 << '-' << a3 << '-' << a4 << "=7" << endl;
  }
}

Measured memory_bytes: 256
/*
对应原理
其实每次只有两种选择，所有这个题的对拍很好写
怎么确定能不能达到最大值呢
跑步的速度是可以加快的，每次贪心选择能行吗
有一些能够拿两次，最终答案一定是要将什么拿两次的

最快的办法当然是永不回头，但是最慢的办法并不是一步一回头
我们要积累7+7+1=15
顺时针能够拿两次
为了把很大的一个数拿两次，必须他的补集中有能够回去的，并且那个数字一定是我右边紧邻的那个
为了拿到这一个7两次，顺时针必须留一个，
就意味着逆时针3次对应顺时针1次
并且必须先逆3
为了拿到这个4两次，顺时针留一个
则逆2顺2 且逆先
为了拿到3两次，顺时针留一个
逆1顺3

i n-i
当i<n-i时
左i 右(i+1)减去最左边 最后一次是顺时针 a[1...i]*2+((i+1)*2*n-a[i+1...i+i+1]*2)-(n-a[i+1])
左i减去最右边 右i 最后一次是逆时针     a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i]

i=n-i时
左i右i 减去左或减去右   a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i]/a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i+1]
i>n-i时
左n-i+1减去最右边 右n-i
左n-i，右n-i减去最左边
*/
#include<bits/stdc++.h>
#define MAXN 200005
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
typedef long long ll;
const ll INF=1e18;
ll l,n,x,sum[MAXN],a[MAXN],fin;
int main()
{
//    freopen("c://duipai//939cdata.txt", "r", stdin);
//    freopen("c://duipai//939cwa.txt", "w", stdout);
    while(~scanf("%lld",&l))
    {
//        string str;
//        cin>>str;
//        cout<<str<<endl;
        scanf("%lld",&n);
        memset(sum,0,sizeof(sum));
        fin=0;
        for(ll i=1;i<=n;i++)
        {
            scanf("%lld",&x);
            a[i]=x;
            sum[i]=sum[i-1]+x;
        }
        if(n==1)
        {
            printf("%lld\n",max(a[1],l-a[1]));
            continue;
        }
        for(ll i=1;i<n;i++)
        {
            ll ans1,ans2;
            if(i<n-i)
            {
                ans1=sum[i]*2+((i+1)*2*l-(sum[i+i+1]-sum[i])*2)-(l-a[i+1]);
                ans2=sum[i]*2+(i*2*l-(sum[i+i]-sum[i])*2)-a[i];
            }
            else if(i==n-i)
            {
                ans1=sum[i]*2+(i*2*l-(sum[i+i]-sum[i])*2)-(l-a[i+1]);
                ans2=sum[i]*2+(i*2*l-(sum[i+i]-sum[i])*2)-a[i];
            }
            else
            {
                ans1=(sum[i]-sum[i-(n-i)-1])*2+((n-i)*2*l-(sum[n]-sum[i])*2)-(a[i]);
                ans2=(sum[i]-sum[i-(n-i)])*2+((n-i)*2*l-(sum[n]-sum[i])*2)-(l-a[i+1]);
            }
           // printf("%lld %lld\n",ans1,ans2);
            ll ans=max(ans1,ans2);
            fin=max(fin,ans);
        }
        fin=max(fin,a[n]);
        fin=max(fin,l-a[1]);
        printf("%lld\n",fin);
    }
}
/*
*/


Measured memory_bytes: 3328
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


int main() {
  int n, k;
  cin >> n >> k;
  cout << (((n + 1) / 2 >= k)?"YES":"NO") << endl;

  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int n = s.length();

    vector<int> cntR(n);
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (s.at(i) == 'R')
        {
            cnt++;
        }
        else
        {
            cnt = 0;
        }
        cntR.at(i) = cnt;
    }

    vector<int> cntL(n);
    cnt = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if (s.at(i) == 'L')
        {
            cnt++;
        }
        else
        {
            cnt = 0;
        }
        cntL.at(i) = cnt;
    }

    vector<int> res(n, 0);
    for (int i = 0; i < n - 1; i++)
    {
        if (cntR.at(i) > 0 && cntR.at(i + 1) == 0)
        {
            res.at(i) += (cntR.at(i) + 1) / 2;
            res.at(i + 1) += cntR.at(i) / 2;
        }
    }
    for (int i = n - 1; i > 0; i--)
    {
        if (cntL.at(i) > 0 && cntL.at(i - 1) == 0)
        {
            res.at(i) += (cntL.at(i) + 1) / 2;
            res.at(i - 1) += cntL.at(i) / 2;
        }
    }

    for (int i = 0; i < n; i++)
    {
        cout << res.at(i) << " ";
    }
    cout << endl;
}

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

using namespace std;

template <typename T>
class Bit{
public:
  Bit(int size):bit(vector<T>(size+1)),size(size){}
  T sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  void add(int i,T x){
    while(i<=size){
      bit[i]+=x;
      i+=i&-i;
    }
  }
private:
  Bit();
  vector<T> bit;
  int size;
};

pair<int,pair<int,int> > v[300010];

int main(){ _;
  int N,M;cin>>N>>M;
  int l,r;
  REP(i,N){
    cin>>l>>r;
    v[i]=make_pair(r-l+1,make_pair(l,r));
  }
  sort(v,v+N);
  Bit<int> b(M+1);
  for(int i=1, j=0;i<=M;i++){
    int ans=0;
    while(j<N){
      if(v[j].first>=i)break;
      b.add(v[j].second.first,1);
      b.add(v[j].second.second+1,-1);
      j++;
    }
    ans+=N-j;
    for(int k=0;k<=M;k+=i)ans+=b.sum(k);
    cout<<ans<<endl;
  }
}


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

int main() {
	int n,k;
	string s;
	cin>>n;
	cin>>s;
	cin>>k;
	char p = s[k-1];
	int count = 0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=p)s[i]='*';
	}
	cout<<s<<endl;
}


Measured memory_bytes: 256
def counting_sort(A):
    K = max(A) + 1
    N = len(A)
    C = [0] * K
    for a in A:
        C[a] += 1
    for k in range(1, K):
        C[k] = C[k - 1] + C[k]
    B = []
    b = 0
    for n in range(N):
        while n >= C[b]:
            b += 1
        B.append(b)
    return B


n = int(input())
*A, = map(int, input().split())
B = counting_sort(A)
print(*B)


Measured memory_bytes: 224380
//
// Created by 李青坪 on 2018/11/13.
//

#include <cstdio>
#include <vector>
#include <algorithm>

#define NIL -1
#define MAXN 500000
using namespace std;

class Node {
public:
    int location;
    int p, l, r;

    Node(int p, int l, int r) {
        this->p = NIL;
        this->l = NIL;
        this->r = NIL;
    }
};

class Point {
public:
    int id, x, y;

    Point() {}

    Point(int id, int x, int y) {
        this->id = id;
        this->x = x;
        this->y = y;
    }

    bool operator < (const Point &point) const {
        return id < point.id;
    }
};


bool cmpX(Point &point1, Point &point2){
    return point1.x < point2.x;
}
bool cmpY(Point &point1, Point &point2){
    return point1.y < point2.y;
}

int position = 0;
int n, q;
vector<Point> P;
vector<Point> result;


class KDTree {
private:
    vector<Node> tree;  //构建二叉搜索树，将排序之后的P中的点的下标构建成一颗二叉搜索树，这样根结点左边的结点对应的P中的值都小于根结点对应的P中的值
public:
    KDTree() {}

    void insertNode(Node node) {
        tree.push_back(node);
    }

    int make2DTree(int l, int r, int depth) {
        if (!(l < r)) return NIL;
        if (depth % 2 == 0) {
            sort(P.begin()+l, P.begin()+r, cmpX);
        } else {
            sort(P.begin()+l, P.begin()+r, cmpY);
        }
        int mid = (l + r) / 2;
        int t = position++;  //二叉树的第t个结点
        tree[t].location = mid;  //第t个结点在P中对应的位置
        tree[t].l = make2DTree(l, mid, depth + 1);
        tree[t].r = make2DTree(mid + 1, r, depth + 1);
        return t;
    }
    void findPoint(int v, int sx, int tx, int sy, int ty, int depth){
        // v表示二叉树中的某个结点
        int x = P[tree[v].location].x;
        int y = P[tree[v].location].y;
        if (sx <= x && x <= tx && sy <= y && y <= ty){
            result.push_back(P[tree[v].location]);
        }
        if (depth %2 ==0){
            if (tree[v].l != NIL && sx <= x){
                findPoint(tree[v].l, sx, tx, sy, ty, depth+1);
            }
            if (tree[v].r != NIL && x <= tx){
                findPoint(tree[v].r, sx, tx, sy, ty, depth+1);
            }
        } else{
            if (tree[v].l != NIL && sy <= y){
                findPoint(tree[v].l, sx, tx, sy, ty, depth+1);
            }
            if (tree[v].r != NIL && y <= ty){
                findPoint(tree[v].r, sx, tx, sy, ty, depth+1);
            }
        }
    }
};

int main() {
    KDTree kdTree;
    scanf("%d", &n);
    int x, y;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &x, &y);
        P.push_back(Point(i, x, y));
        kdTree.insertNode(Node(NIL, NIL, NIL));
    }
    kdTree.make2DTree(0, n, 0);
    scanf("%d", &q);
    int sx, tx, sy, ty;
    for (int j = 0; j < q; ++j) {
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        kdTree.findPoint(0, sx, tx, sy, ty, 0);
        sort(result.begin(), result.end());
        vector<Point>::iterator it;
        for (it = result.begin(); it != result.end(); ++it){
            printf("%d\n", (*it).id);
        }
        result.erase(result.begin(), result.end());
        printf("\n");
    }
}/*
6
2 1
2 2
4 2
6 2
3 3
5 4
2
2 4 0 4
4 10 2 5

 */


Measured memory_bytes: 15804
fun main(){
    readLine()!!.toInt()
    var A = readLine()!!.split(" ").map{it.toLong()}

    var mul: Long = 1L

    if(A.contains(0L)){ mul = 0L ;println(mul); return}
    for(a in A) {
        try {
            mul = Math.multiplyExact(mul, a)
            if (mul > Math.pow(10.0, 18.0).toLong()) {
                println(-1)
                return
            }
        } catch(e: ArithmeticException) {
            println(-1)
            return
        }
    }
    println(mul)
}

Measured memory_bytes: 63172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 1e9+7;
void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(b*c>=a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3656
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let n: isize = read();
    let s: String = read();

    let ans: usize = s.as_str().matches("ABC").collect::<Vec<&str>>().len();

    println!("{:?}", ans);
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
	int ab,bb;
	int a = 0;
	int b = 0;
	int i;
	for(i = 0; i < 4; i++){
		scanf("%d",&ab);
		a += ab;
	}
	for(i = 0; i < 4; i++){
		scanf("%d",&bb);
		b += bb;
	}
	printf("%d\n", a >= b ? a : b);
	return 0;
}

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

int main(){

    int n,k;
    int cnt=0;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h.at(i);
        if(h.at(i)>=k) cnt++;
    }
    cout<<cnt<<endl;






    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    string s;
    cin>>s;
    int q;
    cin>>q;
    int rev=0;
    string f="";
    string b="";
    int flg=0;
    for(int i=0;i<q;i++){
        int a;
        cin>>a;
        if(a==1){
            flg=1-flg;
        }
        else{
            cin>>a;
            string c;
            cin>>c;
            if(a==1){
                if(flg==0){f=f+c;}
                else{b=b+c;}
            }
            else{
                if(flg==0){b=b+c;}
                else{f=f+c;}
            }
        }
    }
    if(flg==1){
        reverse(s.begin(),s.end());
        reverse(b.begin(),b.end());
        s=b+s+f;
    }
    else{
        reverse(f.begin(),f.end());
        s=f+s+b;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 1596
import java.util.*;

class Main{

    public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      	long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
      	
      	long num = c - a -b ;
      	if (num < 0){
            System.out.println("No");    	        
        
        }
      else{
      	if( (4*a*b) < num*num){
	        System.out.println("Yes");    	
        }
      	else{
	        System.out.println("No");    	        
        }
      }

    }
}



Measured memory_bytes: 23892
//https://atcoder.jp/contests/dwacon5th-prelims/tasks/dwacon5th_prelims_b
//B - Sum AND Subarrays
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,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 (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,K; cin>>N>>K;
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }
    dump(an);
    vector<ll> sums(N+1);//累積和
    FOR(i,0,N){
        sums.at(i+1) = sums.at(i)+an.at(i);
    }
    dump(sums);

    //vector<ll> sv;
    //sv.reserve(N*(N+1)/2);
    priority_queue<ll> base;
    FOR(i,0,N){
        FOR(j,i+1,N+1){
            //dump(i,j);
            auto v = sums.at(j)-sums.at(i);
            //sv.push_back(v);
            base.push(v);
        }
    }

    //こっから貪欲.
    auto mx_bit =[](ll v)->ll{
        ll p=0;
        while((1LL<<p)<=v){
            ++p;
        }
        return p;
    };
    ll maxv=base.top();
    ll p=mx_bit(maxv);
    ll tmp=1LL<<p;
    dump(p,tmp);
    ll ans=0;
    for(ll i=p;i>=0;--i){
        ll mask = 1LL<<i;
        ll cnt=0;
        auto pq = base;
        priority_queue<ll> nx;
        while(pq.size()>0){
            auto v = pq.top();
            pq.pop();
            if(v&mask){
                ++cnt;
               nx.push(v); 
            }
        }
        if(cnt>=K){
            base=nx;
            ans |= mask;
        }else{
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10020
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

string k;

int d,s;

ll dp[10005][105],mod=1e9+7;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> k >> d;
    for(int i=1;i<=k.lg;i++){
        for(int j=0;j<d;j++){
            for(int t=0;t<=9;t++){
                dp[i][j]+=dp[i-1][((j-t)%d+d)%d];
                if(t<k[i-1]-'0' && (s+t)%d==j) dp[i][j]++;
            }
            dp[i][j]%=mod;
        }
        s+=k[i-1]-'0'; s%=d;
    }
    if(s%d==0) dp[k.lg][0]++;
    cout << (dp[k.lg][0]-1+mod)%mod << '\n';
}


Measured memory_bytes: 8448
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            int a = Integer.parseInt(strArr[0]);
            int b = Integer.parseInt(strArr[1]);
            int c = Integer.parseInt(strArr[2]);
            if (c >= a && b >= c) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 20948
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
s = x
count = 0
max_a = x/500 < a ? x/500 : a
i = 0
for i in 0..max_a
    x = s
    if (x - 500*i) == 0
        count += 1
        break
    else 
        x = x - 500*i
    end
    if x > 0
        t = x
        max_b = x/100 < b ? x/100 : b
        j = 0
        for j in 0..max_b
            x = t
            if (x - 100*j) == 0
                count += 1
                break
            else
                x = x - 100*j
            end
            if x > 0
                u = x
                max_c = x/50 < c ? x/50 : c
                k = 0
                for k in 0..max_c
                    x = u
                    if (x - 50*k) == 0
                        count += 1
                        break
                    else
                        x = x - 50*k
                    end
                end
            end
        end
    end
end

print count


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
typedef struct P
{
    char a;
    int b;
    int n;
} P;
int getPosition(P a[],int p,int r)
{
    return r;
}
void swap(P a[],int x,int y)
{
    P t = a[x];
    a[x] = a[y];
    a[y] = t;
}
int partition(P a[],int p,int r)
{
    int i,j,x = getPosition(a,p,r);
    swap(a,x,r);
    i = p-1;
    for(j=p;j<r;j++)
    {
        if(a[j].b<=a[r].b)
        {
            i++;
            swap(a,i,j);
        }
    }
    swap(a,i+1,r);
    return i+1;

}
void QS(P a[],int p ,int r)
{
    if(p<r)
    {
        int q;
        q = partition(a,p,r);
        QS(a,p,q-1);
        QS(a,q+1,r);
    }
}
void QuickSort(P a[],int n)
{
    QS(a,0,n-1);
}

int main()
{
    int n,i;
    P a[100000];
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i].a>>a[i].b;
        a[i].n = i;
    }
    QuickSort(a,n);
    for(i=0;i<n-1;i++)
    {
        if(a[i].b==a[i+1].b&&a[i].n>=a[i+1].n)
            break;
    }
    if(i==n-1)
        cout<<"Stable"<<endl;
    else
        cout<<"Not stable"<<endl;
    for(i=0;i<n;i++)
    {
        cout<<a[i].a<<' '<<a[i].b<<endl;
    }
    return 0;
}

Measured memory_bytes: 4168
from collections import deque
sa = deque(input())
sb = deque(input())
sc = deque(input())

cur = "a"
while True:
    if cur == "a":
        if len(sa) == 0:
            ans = "A"
            break
        cur = sa.popleft()
    elif cur == "b":
        if len(sb) == 0:
            ans = "B"
            break
        cur = sb.popleft()
    else:
        if len(sc) == 0:
            ans = "C"
            break
        cur = sc.popleft()
print(ans)

Measured memory_bytes: 3316
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####		
def main():
	N = I()
	A = LM(lambda x:x/2, LI())
	_A = [i%2==0 for i in A]

	if sum(_A) == N:
		ans=1
		while sum(_A)==N:
			ans+=1
			A = [i/2 for i in A]
			_A = [i%2==0 for i in A]

	else:
		ans=0
	
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3444
n = int(input())
p = list(map(int, input().split()))
res = 0
for i in range(1, len(p) - 1):
    if min(p[i - 1], p[i], p[i + 1]) != p[i] and max(p[i - 1], p[i], p[i + 1]) != p[i]:
        res += 1
print(res)


Measured memory_bytes: 9028
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] x=new int[n];
        int[] y=new int[n];
        for(int i=0;i<n;i++){
            x[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++){
            y[i]=sc.nextInt();
        }
        double D1=0,D2=0,D3=0,D=0;
        for(int i=0;i<n;i++){
            int d=Math.abs(x[i]-y[i]);
            D1+=d;
            D2+=d*d;
            D3+=d*d*d;
            if(D<d){
                D=d;
            }
        }
        System.out.printf("%.6f\n", D1);
        System.out.printf("%.6f\n", Math.sqrt(D2));
        System.out.printf("%.6f\n", Math.cbrt(D3));
        System.out.printf("%.6f\n", D);
    }
}


Measured memory_bytes: 26680
#include <iostream>
#include <string>
#include <array>
#include <locale>
#include <cstdlib>
#include <algorithm>

using namespace std;
using lli = long long int;

int main()
{
    array<int, 26> alpha {0};

    string str;
    
    while (cin >> str)
    {
        for (const auto c : str)
        {
            if (isalpha(c))
                alpha[tolower(c) - 'a']++;
        }
    }

    for (int i = 0; i < 26; ++i)
    {
        cout << static_cast<char>('a' + i) << " : " << alpha[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3228
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int counter = 0;
  for(int i=0;i<s.length();i++){
  	if(s[i] == s[s.length() - 1 - i]){
    }else{
      counter++;
    }
  }
  cout<<counter/2;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

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

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }


int main() {
    int r;  cin >> r;
    print(3 * pow(r, 2));

    return 0;
}



Measured memory_bytes: 764
D,N = gets.split.map(&:to_i)

if D == 0
  if N!=100
    puts N
  else
    puts 101
  end
elsif D == 1
  if N!=100
    puts N*100
  else
    puts 10100
  end
else
  if N!=100
    puts N*10000
  else
    puts 1010000
  end
end

Measured memory_bytes: 1788
#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>;

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

    unsigned int A = 7 % K;
    for (unsigned int i = 0; i < 100000000; i++) {
        if (A == 0) {
            cout << i + 1 << endl;
            return 0;
        }
        A = (A * 10 + 7) % K;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    double r;
    cin >> r;
    cout << fixed << setprecision(20) << 2 * r * M_PI << "\n";
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll X[3][5000];

int main(){
    ll N;
    cin >> N;
    string S;
    cin >> S;

    map<char, int> F;
    F['R'] = 0;
    F['G'] = 1;
    F['B'] = 2;

    for(int i = N-1; i >= 0; i--){
        char c = S[i];
        if(c == 'R')
            X[0][i] = 1;
        else if(c == 'G')
            X[1][i] = 1;
        else 
            X[2][i] = 1;

        X[0][i] += X[0][i+1];
        X[1][i] += X[1][i+1];
        X[2][i] += X[2][i+1];
    }

    //cout << X[0][0] << endl;
    //cout << X[1][0] << endl;
    //cout << X[2][0] << endl;

    ll ans = 0;
    REP(left, N){
        REPi(mid, left+1, N){
            if(S[left] == S[mid]) continue;

            char c;
            if(S[left] == 'R' && S[mid] == 'G')
                c = 'B';
            else if(S[left] == 'G' && S[mid] == 'R')
                c = 'B';
            else if(S[left] == 'G' && S[mid] == 'B')
                c = 'R';
            else if(S[left] == 'B' && S[mid] == 'G')
                c = 'R';
            else if(S[left] == 'B' && S[mid] == 'R')
                c = 'G';
            else if(S[left] == 'R' && S[mid] == 'B')
                c = 'G';

            int idx = F[c];
            ll num = X[idx][mid+1]; 
            int diff = mid - left;
            if(mid+diff < N && S[mid + diff] == c)
                num--;

            ans += num;
        }
    }

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


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

int main(){
  int x,y;
  cin >> x >> y;

  if(y%2!=0){
    cout << "No" << endl;
    return 0;
  }
  rep(i,x+1){
    if(i==(y-2*x)/2){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout  << "No" << endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = Integer.parseInt(scan.nextLine());
			if(n == 0){
				break;
			}
			String[] str[] = new String[n+1][];
			for(int i = 0;i < n+1;i++){
				str[i] = scan.nextLine().split(" ");
			}
			int[] lim = new int[4];
			for(int i = 0;i < 4;i++){
				lim[i] = Integer.parseInt(str[n][i]);
			}
			int[] a = {4,9,4};
			boolean sw = true;
			for(int i = 0;i < n;i++){
				int ca = 0;
				for(int j = 1;j < 4;j++){
					int t = Integer.parseInt(str[i][j]);
					if(t > lim[j-1]){
						break;
					}
					ca += t*a[j-1];
					if(j == 3 && ca <= lim[3]){
						System.out.println(str[i][0]);
						sw = false;
					}
				}
			}
			if(sw){
				System.out.println("NA");
			}
		}
	}
}

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

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

    int ans[N];
    for(int i=0; i<N; i++){
        ans[A[i]-1]=i+1;
    }
    for(int i=0; i<N; i++) cout<<ans[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 4336
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int m;
        cin >> m;
        if(m == 0)
            return 0;

        vector<int> a(m), b(m);
        for(int i=0; i<m; ++i)
            cin >> a[i] >> b[i];

        vector<int> num(1001, 0);
        num[0] = 1;
        for(int i=0; i<m; ++i){
            for(int j=1000; j>=0; --j){
                for(int k=1; k<=b[i]; ++k){
                    int c = j + a[i] * k;
                    if(c <= 1000)
                        num[c] += num[j];
                }
            }
        }

        int g;
        cin >> g;
        for(int i=0; i<g; ++i){
            int n;
            cin >> n;
            cout << num[n] << endl;
        }
    }
}

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

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int x;
    cin >> x;
    int val = x * 360 / __gcd (x, 360);
    cout << val / x << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n, m, i, s[9], p[9];
	string c[9];
	for (i = 0; i < 9; i++)
	{
		cin >> c[i] >> n >> m;
		s[i] = n+m;
		p[i] = n*200 + m*300;
	}
	for (i = 0; i < 9; i++)
		cout << c[i] << " " << s[i] << " " << p[i] << endl;
}

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

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define repe_r(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e20;// 000000007;// 1e9 + 7
ll Pow(ll n, ll p) {
	if (p == 0)return 1;
	if (p == 1)return n;
	ll t = Pow(n, p / 2);
	if (p & 1) return (t * t % MOD) * n % MOD;
	else return t * t % MOD;
}
int main() {
	ll n, x; cin >> n >> x;
	ll a = Pow(2, n + 2) - 3;

	ll ans = 0;
	repe_r(i, 0, n) {
		if (x > a / 2 + 1) {
			ans += Pow(2, i);
			x -= Pow(2, i + 1) - 1;
		}
		else if (x < a / 2 + 1) {
			x--;
		}
		else {
			ans += Pow(2, i);
			break;
		}
		a = Pow(2, i + 1) - 3;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

   int n, m;
   cin >> n >> m;
   vector <vector <int>> adj(n + 1);
   for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
   }

   vector <int> dist(n + 1);
   vector <bool> vis(n + 1);

   function <void (int)> dfs = [&](int v) {
      vis[v] = true;
      for (auto u : adj[v]) {
         if (!vis[u]) {
            dfs(u);
         }
         dist[v] = max(dist[v], dist[u] + 1);
      }
   };

   for (int i = 1; i <= n; i++) {
      if (!vis[i])
         dfs(i);
   }

   int ans = *max_element(dist.begin(), dist.end());

   cout << ans << '\n';

   return 0;
}

Measured memory_bytes: 8832
#include <cstdio>

int main()
{
    int N, H, W;
    int ans = 0;

    scanf("%d%d%d", &N, &H, &W);
    for (int i = 0; i < N; ++i) {
        int Ai, Bi;
        scanf("%d%d", &Ai, &Bi);

        if (H <= Ai && W <= Bi) ++ans;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main(void){
	int n,i,j,answer;
	while(scanf("%d",&n) != EOF){
		answer = 0;
		if(n < 999997){
			for(i=2;i <= n;i++){
				for(j=2;j <= i;j++){
					if(i % j == 0 && i != j) break;
					if(sqrt(i) < j || i % j == 0 && i == j){
						answer++;
						break;
					}
				}
			}
			printf("%d\n",answer);
		}else{
			printf("78498\n");
		}
	}
	return 0;
}

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

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

        Integer n = Integer.parseInt(st.nextToken());

        int[] arr = new int[n];

        st = new StringTokenizer(br.readLine());
        HashSet<Integer> distinct = new HashSet<>();
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
            distinct.add(arr[i]);
        }
        int d = distinct.size();
        int ans = 0;
        if (n%2==1){
            if (d%2==1)
                ans = d;
            else
                ans = d-1;
        }
        else{
            if (d%2==0)
                ans = d;
            else
                ans = d-1;
        }
        System.out.println(ans);
    }


}


Measured memory_bytes: 44316
#include<bits/stdc++.h>
using namespace std;
const int mxn=1e5;
int  dp[mxn+2];
int h[mxn+2];
int func(int n)
{
    int k;
    if(n==1)return dp[1]=0;
if(dp[n]!=-1)return dp[n];
dp[n]=func(n-1)+abs(h[n]-h[n-1]);
if(n>2){
k=func(n-2)+abs(h[n]-h[n-2]);
dp[n]=min(k,dp[n]);}
return dp[n];


}


int main()
{memset(dp,-1,sizeof(dp));
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>h[i+1];
    cout<<func(n)<<endl;


}

Measured memory_bytes: 9096
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int a,b,c;

int main(){
  int ans=0;
  cin >> a >> b>>c;
  c-=(a-b);
  if (c<0)c=0;
  cout<<c<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}
int main(){
	ll A,B,C,D;
	scan(A>>B>>C>>D);
	ll Cnum,Dnum,CDnum;
	if(A%C==0) Cnum=(B/C-A/C+1);
	else Cnum=B/C-A/C;
	if(A%D==0) Dnum=(B/D-A/D+1);
	else Dnum=B/D-A/D;
	if(A%(lcm(C,D))==0) CDnum=(B/(lcm(C,D))-A/(lcm(C,D))+1);
	else CDnum=B/(lcm(C,D))-A/(lcm(C,D));
	prin(B-A+1-(Cnum+Dnum-CDnum));
	return 0;
}


Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int n;
    cin >> n;
    vl a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    ll mod = 1000000007;
    vector<vl> memo(3, vl(n + 1, 0));
    rep(i, n)
    {
        rep(j, 3)
        {
            memo[j][i + 1] = memo[j][i];
        }
        rep(j, 3)
        {
            if(memo[j][i] == a[i])
            {
                memo[j][i + 1] = memo[j][i] + 1;
                break;
            }
        }
    }
    ll count = 1;
    rep(i, n)
    {
        int temp = 0;
        rep(j, 3)
        {
            if(memo[j][i] == a[i])
            {
                temp++;
            }
        }
        count = (count * temp) % mod;
    }
    cout << count << endl;
}

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

using namespace std;

#define ll long long

ll n , m;

vector<ll>dv;

int main()
{
    cin >> n;
    if(n == 1)printf("Hello World\n");
    else{
        int a , b;cin >> a >> b;
        cout << a+b<< endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){ 
	vector<int> v;
	int n;
	scanf("%d",&n);
	for(int i=0;i<2*n;i++){
		int tmp;
		scanf("%d",&tmp);
		v.push_back(tmp);
	}
	sort(v.begin(),v.end());
	ll ans=0;
	for(int i=0;i<(int)v.size();i+=2){
		ans+=min(v[i],v[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

N, K = map(int,input().split())
A = list(map(int, input().split())) 
check = [0]*N
tele_lis = []
start = []
def tele(x):
    check[x-1] = 1
    tele_lis.append(x)
    if check[A[x-1]-1] == 0:
        tele(A[x-1])
    else:
        start.append(A[x-1])
        return
tele(1)
for i in range(N):
    if start[0] == tele_lis[i]:
        break
if i >= K:
    print(tele_lis[K])
else:
    print(tele_lis[i::][(K-i) % (sum(check)-i)])

Measured memory_bytes: 177248
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            String s = in.next(), t = in.next();
            int[][] matrix = new int[s.length() + 1][t.length() + 1];

            for (int i = 1; i <= s.length(); i++)
            { // row
                for (int j = 1; j <= t.length(); j++)
                { // column
                    if (s.charAt(i - 1) == t.charAt(j - 1))
                    {
                        matrix[i][j] = matrix[i - 1][j - 1] + 1;
                    } else
                    {
                        matrix[i][j] = Math.max(matrix[i - 1][j], matrix[i][j - 1]);
                    }
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            int posX = s.length();
            int posY = t.length();

            while (posX > 0 && posY > 0)
            {
                if (matrix[posX - 1][posY] == matrix[posX][posY])
                {
                    posX--;
                    continue;
                }
                if (matrix[posX][posY - 1] == matrix[posX][posY])
                {
                    posY--;
                    continue;
                }

                if (matrix[posX - 1][posY - 1] == matrix[posX][posY] - 1)
                { // matched element
                    stringBuilder.append(s.charAt(posX - 1));
                    posX--;
                    posY--;
                    continue;
                }
                posX--;
            }
            out.print(stringBuilder.reverse().toString());
        }

    }
}



Measured memory_bytes: 83020
#include <iostream>
 
using namespace std;
 
int main() {
   int n;
   cin >> n;
   int a[n];
   for(int i = 0; i < n; i++) {
       cin >> a[i];
   }
   int cost[n];
   cost[0] = 0;
   cost[1] = abs(a[1] - a[0]);
   for(int i = 2; i < n; i++) {
       cost[i] = min(cost[i - 2] + abs(a[i] - a[i - 2]), cost[i - 1] + abs(a[i] - a[i - 1]));
   }
   cout << cost[n - 1] << endl;
   
   return 0;
}

Measured memory_bytes: 3964
/*      Abhijith    */
#include<bits/stdc++.h>
#include<iomanip>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     lld n;
     cin>>n;
     vector<pair<string,pair<lld,lld> > > qn(n);
     rep(i,0,n-1)
     {
         string x;
         lld y;
         cin>>x>>y;
         qn[i].first=x;
         qn[i].second.first=101LL-y;
         qn[i].second.second=i+1LL;
     }
     sort(all(qn));
     rep(i,0,n-1)
     cout<<qn[i].second.second<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<numeric>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);

struct Team {
	Team(int id_, int P) {
		id = id_;
		times.resize(P, INF);
		penalties.resize(P, 0);
	}

	int id;
	vector<int> times;
	vector<int> penalties;

	pair<int, int> score() const{
		int solveNum = 0;
		int penalty = 0;

		for (int time : times) {
			if (time != INF) {
				solveNum++;
				penalty += time;
			}
		}
		REP(i, times.size()) {
			if (times[i] != INF) {
				penalty += 20 * penalties[i];
			}
		}

		return { -solveNum,penalty };
	}

	const bool operator < (const Team r)const {
		if (score() == r.score()) {
			return id > r.id;
		}
		else {
			return score() < r.score();
		}
	}
};

//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	while (true) {
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		if (M == 0)break;

		vector<Team> teams;
		REP(i, T) {
			teams.push_back(Team(i + 1, P));
		}
		REP(i, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--;
			p--;
			if (j == 0) {
				teams[t].times[p] = m;
			}
			else {
				teams[t].penalties[p]++;
			}
		}
		sort(teams.begin(), teams.end());

		//output
		REP(i, T) {
			cout << teams[i].id;
			if (i != T - 1) {
				if (teams[i].score() == teams[i + 1].score()) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
		}
		cout << endl;
	}
	//debug();
	
	return 0;
}



Measured memory_bytes: 3060
S=input()
count10=0
count01=0
def c10(s,n,count10):
    if ((n%2==0)and(s=="1"))or((n%2==1)and(s=="0")):
        count10=count10+1
    return count10
def c01(s,n,count01):
    if ((n%2==0)and(s=="0"))or((n%2==1)and(s=="1")):
        count01=count01+1
    return count01

for i in range(len(S)):
    count10=c10(S[i],i,count10)
    count01=c01(S[i],i,count01)
print(min(len(S)-count10,len(S)-count01))

Measured memory_bytes: 40944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a;
    string s;
    cin >> a >> s;
    if (a < 3200) cout << "red" << endl;
    else cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
using lint = long long;

lint a[MAXN];

int main(){
	int n, p;
	cin >> n >> p;
	lint sum = 0;
	for(int i=0; i<n; i++){
		int x, y; cin >> x >> y;
		a[i] = 1ll * (100 - p) * x + 1ll * p * y;
		sum += 1ll * p * y;
	}
	sort(a, a+n);
	reverse(a, a+n);
	for(int i=0; i<n; i++){
		sum -= a[i];
		if(sum <= 0){
			cout << i + 1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

def bfs(H, W, grid, src):
    """ BFS(グリッド、重みなし) """
    from collections import deque

    h, w = src
    directions = ((1,0),(-1,0),(0,1),(0,-1))
    que = deque([(h, w, 0)])
    dist = list2d(H+2, W+2, -1)
    while que:
        h, w, c = que.popleft()
        if dist[h][w] != -1:
            continue
        dist[h][w] = c
        for dh, dw in directions:
            h2 = h + dh
            w2 = w + dw
            if grid[h2][w2] == '#':
                continue
            que.append((h2, w2, c+1))
    return dist

H, W = MAP()
grid = build_grid(H, W, '#', str, space=0, padding=1)

ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if grid[i][j] != '#':
            res = bfs(H, W, grid, (i, j))
            for k in range(1, H+1):
                for l in range(1, W+1):
                    ans = max(ans, res[k][l])
print(ans)


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    // replace 

    int n;
    cin >> n;
    string s;
    cin >> s;
    int numWhite = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'W') numWhite++;
    }
    int moves = 0;
    for(int i = n - 1; i >= n - numWhite; i--) {
        if(s[i] == 'W') moves++;
    }
    cout << numWhite - moves << endl;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int f = 0;
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] == s[i + 1]) f = 1;
    }
    cout << (f ? "Bad" : "Good") << endl;
    return 0;
}

Measured memory_bytes: 764