akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int N;
string S;

long long solve() {
    vector<int> R, G;
    set<int> B;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'R') R.push_back(i);
        else if (S[i] == 'G') G.push_back(i);
        else B.insert(i);
    }
    long long all = (long long)R.size() * (long long)G.size() 
        * (long long)B.size();
    long long sub = 0;
    for (auto r : R) {
        for (auto g : G) {
            if (B.count(r*2-g)) ++sub;
            if ((r+g) % 2 == 0 && B.count((r+g)/2)) ++sub;
            if (B.count(g*2-r)) ++sub;
        }
    }

/*
    COUT(R);
    COUT(G);
    COUT(B);
    COUT(all);
    COUT(sub);
    */

    return all - sub;
}

int main() {
    while (cin >> N >> S) {
        cout << solve() << endl;
    }
}

















Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main()
{
  
  int n;
  cin>>n;
  map<string,int> mp;
  for(int i=0;i<n;i++)
  {
  string str;
    cin>>str;
    mp[str]++;
  }
  vector<string>xxx;
  int maxx=0;
  for(auto it=mp.begin();it!=mp.end();it++)
  {
  maxx=max(maxx,it->second);
  }
  
  for(auto it=mp.begin();it!=mp.end();it++)
  {
  if(it->second==maxx)
    xxx.push_back(it->first);
  }
  sort(xxx.begin(),xxx.end());
  
  for(auto it: xxx)
    cout<<it<<endl;
  
 }
  

Measured memory_bytes: 26868
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var nm=(Arr.shift()).split(" ").map(Number);
   var n=nm[0];
   var m=nm[1];
   if(n==0)break;
   var obj={};
   for(var i=0;i<n;i++){
      var arr=(Arr.shift()).split(" ");
      var v=arr[0].replace(/\*/g,"");
      obj[v]=arr[1]-0;
   }
   var sum=0;
   for(var i=0;i<m;i++){
      var v=Arr.shift();
      for(var k in obj){
         if(k==v.slice(-1*k.length))sum+=obj[k];
      }
   }
   console.log(sum);
}

Measured memory_bytes: 13684
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INARR(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

int a, b, c;

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> a >> b >> c;
	
}


void preprocess() {
	
	
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	cout << max(c-(a-b), 0) << endl;
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../inp.txt", "r", stdin);
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


Measured memory_bytes: 256
n = gets.to_i

count_ac = 0
count_wa = 0
count_tle = 0
count_re = 0

n.times do
  a = gets.chomp
  count_ac += 1 if a.match?(/^AC$/)
  count_wa += 1 if a.match?(/^WA$/)
  count_tle += 1 if a.match?(/^TLE$/)
  count_re += 1 if a.match?(/^RE$/)
end

puts "AC x #{count_ac}\nWA x #{count_wa}\nTLE x #{count_tle}\nRE x #{count_re}"

Measured memory_bytes: 14408
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;


int main()
{
	char buf[1024];
	cin.getline(buf, sizeof(buf));
	string s(buf);
	int i;
	while ((i = s.find("apple")) != string::npos)
		s.replace(i, 5, "hoget");
	while ((i = s.find("peach")) != string::npos)
		s.replace(i, 5, "apple");
	while ((i =s.find("hoget")) != string::npos)
		s.replace(i, 5, "peach");

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }


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

    int N;
    int ans = 0;
    int tmp = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        ans += tmp;
    }
    
    cout << ans - N << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s;
    while(cin >> s) {
        if (s == "-") break;
        int m, n = s.size();
        cin >> m;
        rep(i, m) {
            int a;
            cin >> a;
            string t;
            t = s.substr(0, a);
            s.erase(0, a);
            s += t;
        }
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

const int maxn = 1e4+10;
const int maxe = maxn*maxn/2 + 10;
typedef pair<int,int> Point;
struct edge{
	int u,v;
	double dis;	
	bool operator<(const edge &e)const
	{
		return 	dis > e.dis;
	}
	
};
Point p[maxn];
edge e[maxe];
int s[maxn];
int N,M;

double getdis(Point a, Point b)
{
	double x = a.first - b.first;
	double y = a.second - b.second;
	double dis = sqrt(x*x + y*y);
	return	dis;
}


int find(int x)
{
	if(s[x] < 0)
		return x;
	return s[x] = find(s[x]);
}

bool same(int x, int y)
{
	int a= find(x);
	int b= find(y);
	
	return a==b;
}


void unite(int x, int y)
{
	int a= find(x);
	int b= find(y);
	if(a==b)
		return;
	
	if(s[b] < s[a])
	{
		s[a] = b;
		return;
	}		
	if(s[b] == s[a])
		s[a]--;
		
	s[b] = a;	
	
}
double kruskal(double tot)
{
	memset(s,-1,sizeof(s));
	
	sort(e,e+M);
	
	double res = 0;
	for(int i =0 ; i< M; i++)
	{
		if(!same(e[i].u,e[i].v))
		{
			unite(e[i].u,e[i].v);
			res += e[i].dis;
		}
	}
	
	return tot-res;
	 
}

int main()
{
	//freopen("c:\\users\\administrator\\desktop\\in.txt","r",stdin);
	cin >> N >> M;
	for(int i = 0; i < N; i++)
	{
		int x,y;
		cin >> x  >> y;
		
		p[i].first  =x; p[i].second= y;				
	
	}	
	double tot = 0;
  	for(int i = 0; i < M; i++)
	{
		int u,v;
		cin >> u >> v;
		u--;v--;
		e[i].u = u;
		e[i].v= v;
		e[i].dis = getdis(p[u],p[v]);
		tot+= e[i].dis;
	}
	
	
	double res = kruskal(tot);
	printf("%0.3f\n",res);
	
	
} 

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
    	cin>>arr[i];
    }
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
    	if(arr[i]<arr[i-1])
    	{
    	ans=ans+arr[i-1]-arr[i];
    	arr[i]=arr[i-1];
    	}
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 5208
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    LL n, a, b, c, k, n2;
    vector<LL> v;
    string s;
    cin >> n;

    

    for (int i = 0; i < n; i++) {
        n2 = n;

        n2 -= (4 * i);
        if (n2 < 0) {
            continue;
        }
        
        if (n2 % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }

    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <time.h>

using namespace std;
typedef long long ll;

#define MOD 1000000007

class Combination
{
	vector<ll> fact;	//n!
	vector<ll> finv;	//n!の逆元
public:Combination(int n)
{
	vector<ll> inv(n + 1, 1);	//iの逆元
	fact.resize(n + 1, 1);
	finv.resize(n + 1, 1);
	for (int i = 2; i <= n; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

public:ll cmb(int n, int k)
{
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fact[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
};


int main()
{
	int K; cin >> K;
	string S; cin >> S;
	int len = K + S.size();
	Combination cmb = Combination(len);
	vector<ll> pow25(K + 1, 1), pow26(K + 1, 1);
	for (int i = 0; i < K; ++i) {
		pow25[i + 1] = pow25[i] * 25 % MOD;
		pow26[i + 1] = pow26[i] * 26 % MOD;
	}

	ll ans = 0;
	ll buf;
	//k文字を最後に置く。26**k通り
	//最後のk文字の前に固定の一文字
	//残りの文字の置き場所の選び方 cmb(len-k-1, S.size()-1) * 25**(K-k)
	for (int k = 0; k <= K; ++k) {
		//ans = ans + cmb.cmb(len - k - 1, S.size() - 1) * modpow(25, K - k) * modpow(26, k);
		buf = cmb.cmb(len - k - 1, S.size() - 1) * pow25[K - k] % MOD;
		buf = buf * pow26[k] % MOD;
		ans = (ans + buf) % MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 50740
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

struct edge{ int to, cap, rev;};
int INF = 100000000;
bool used[100];

int dfs(vector< vector <edge> > &G, int v, int t, int f){
  if(v == t) return f;
  used[v] = true;
  for(int i = 0; i < G[v].size(); ++i){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(G, e.to, t, min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(vector< vector <edge> > &G, int s, int t){
  int flow = 0;
  for(;;){
    memset(used, 0, sizeof(used));
    int f = dfs(G, s, t, INF);
    if(!f) return flow;
    flow += f;
  }
}


int main(){
  int V, E;
  cin >> V >> E;
  vector< vector <edge> > G(V);
  int u, v, c;
  for(int i = 0; i < E; ++i){
    cin >> u >> v >> c;
    G[u].push_back((edge){v,c,G[v].size()});
    G[v].push_back((edge){u,0,G[u].size()-1});
  }
  cout << max_flow(G, 0, V-1) << endl;;
  return 0;
}

Measured memory_bytes: 3164
N = STDIN.gets.to_i

towns = []

N.times do
  x, y = gets.split.map(&:to_i)
  towns << [x, y]
end

length = 0.0
size = 0
(0..(N-1)).to_a.permutation(N) do |p|
  size += 1
  (0..(N-2)).to_a.each do |i|
    x1 = towns[p[i]][0]
    y1 = towns[p[i]][1]
    x2 = towns[p[i + 1]][0]
    y2 = towns[p[i + 1]][1]

    # p "x1: #{x1} y1: #{y1} x2: #{x2} y2: #{y2} "
    # p "#{p[i]} -> #{p[i + 1]}"

    length += Math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
  end
end

puts length / size


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

int main(){
	int i,j,k,n,m,f,x,y,z; string s;
	cin >> n >> k;
	int l[55];
	rep(i, n) cin >> l[i];
	sort(l, l+n, greater<int>());
	x = 0;
	rep(i, k){
		x += l[i];
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
using namespace std;

int main(void){
  int n;
  vector<int> vec;
  double dp[100][100];

  cin >> n;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    vec.push_back(t);
  }
  sort(vec.begin(), vec.end());
  for (int i=1; i<=n; i++) dp[i][i] = vec[i-1];
  for (int s=2; s<=n; s++){
    for (int i=1; i+s-1<=n; i++){
      dp[i][i+s-1]=0;
      for (int j=1; j<=s; j++){
        dp[i][i+s-1]=MAX(dp[i][i+s-1], (dp[i][i+j-1]+dp[i+j][i+s-1])/2.0);
      }
    }
  }
  cout << dp[1][n] << endl;
  return 0;
}


Measured memory_bytes: 256
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

X,Y = map(int,input().split())
MOD = 10**9+7

ans = 0
if (X+Y)%3 != 0:
    pass
else:
    N = (X+Y)//3
    t = 2*N - X
    if t >= 0:
         if (N+t) == Y and t <= N:
             t = max(t,N-t)
             ans = cmb(N,t)
             ans = ans%MOD
print(ans)

Measured memory_bytes: 45940
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bisect
import collections


class VBoarder(object):

  def __init__(self, x1, x2, y):
    self.x1 = x1
    self.x2 = x2
    self.y = y


class HBoarder(object):

  def __init__(self, x, y1, y2):
    self.x = x
    self.y1 = y1
    self.y2 = y2


class Cell(object):

  def __init__(self, x1, y1, x2, y2):
    self.x1 = x1
    self.y1 = y1
    self.x2 = x2
    self.y2 = y2
    self.up = True
    self.down = True
    self.left = True
    self.right = True
    self.checked = False

  def area(self):
    return (self.x2 - self.x1) * (self.y2 - self.y1)

  def __str__(self):
    return '(({:2d},{:2d}),({:2d},{:2d})){}{}{}{}'.format(
      self.x1, self.y1, self.x2, self.y2,
      'Uu'[int(self.up)], 'Dd'[int(self.down)], 'Ll'[int(self.left)], 'Rr'[int(self.right)])


def main():
  N, M = map(int, input().split())
  vborders = [VBoarder(*map(int, input().split())) for _ in range(N)]
  hborders = [HBoarder(*map(int, input().split())) for _ in range(M)]

  y_axis = list(set([b.y for b in vborders]))
  y_axis.sort()
  y_axis = [y_axis[0] - 1] + y_axis + [y_axis[-1] + 1]
  x_axis = list(set([b.x for b in hborders]))
  x_axis.sort()
  x_axis = [x_axis[0] - 1] + x_axis + [x_axis[-1] + 1]

  cells = [[Cell(x1, y1, x2, y2)
            for x1, x2 in zip(x_axis[:-1], x_axis[1:])]
           for y1, y2 in zip(y_axis[:-1], y_axis[1:])]

  for b in vborders:
    y_idx = bisect.bisect_left(y_axis, b.y)
    x_idx1 = bisect.bisect_left(x_axis, b.x1)
    x_idx2 = bisect.bisect_right(x_axis, b.x2) - 1

    for x_idx in range(x_idx1, x_idx2):
      cells[y_idx - 1][x_idx].down = False
      cells[y_idx][x_idx].up = False

  for b in hborders:
    x_idx = bisect.bisect_left(x_axis, b.x)
    y_idx1 = bisect.bisect_left(y_axis, b.y1)
    y_idx2 = bisect.bisect_right(y_axis, b.y2) - 1

    for y_idx in range(y_idx1, y_idx2):
      cells[y_idx][x_idx - 1].right = False
      cells[y_idx][x_idx].left = False

  queue = collections.deque()
  area = 0

  x = bisect.bisect_right(x_axis, 0.5) - 1
  y = bisect.bisect_right(y_axis, 0.2) - 1
  queue.append((x, y))

  while len(queue) != 0:
    x, y = queue.popleft()

    if x == 0 or x == len(x_axis) - 1 or y == 0 or y == len(y_axis) - 1:
      print('INF')
      return

    c = cells[y][x]

    if c.checked:
      continue

    area += c.area()
    c.checked = True

    if c.up:
      queue.append((x, y - 1))

    if c.down:
      queue.append((x, y + 1))

    if c.left:
      queue.append((x - 1, y))

    if c.right:
      queue.append((x + 1, y))

  print(area)


if __name__ == '__main__':
  main()


Measured memory_bytes: 249128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n,k;
cin>>n>>k;
vector<int> x(n);
for(int i=0;i<n;i++){
  x.at(i)=1;
}
for(int i=0;i<k;i++){
  int d;
  cin>>d;
  for(int j=0;j<d;j++){
    int a;
    cin>>a;
    x.at(a-1)=0;
  }
}
int y=0;
for(int i=0;i<n;i++){
  y+=x.at(i);
}
cout<<y<<endl;
}

Measured memory_bytes: 3592
///=======================///
/// coder: Andy - Tohrumi ///
///=======================///

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)

using namespace std;

typedef pair<ll, ll> pll;	typedef pair<int, int> ii;
typedef vector<pll> vll;	typedef vector<string> vs;		typedef vector<ii> vii;
typedef vector<int> vi; 	typedef vector<ll> vl;

///======code start here======///

signed main() {
	fastio;
	int n; cin >> n;
	ll h[n + 1]; h[0] = 1000000000;
	rep(i, 1, n + 1) cin >> h[i];
	ll dp[n + 1]; dp[0] = 0; dp[1] = 0;
	rep(i, 2, n + 1) {
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
	}
	cout << dp[n] << endl;
	return 0;
}



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

using namespace std;

int main()
{
    long long int num,n;
    int digits;
    vector<long long int>vec;
    cin>>n;
    digits=int(floor(log10(n)+1));
    digits=(digits/2);
    for(int i = 1; i <=int(pow(10,(digits+1))); i++)
    {
        if(n % i == 0 && vec.size()==0)
            {vec.push_back(i);vec.push_back((n/i));}
        else if(n%i==0 && vec.size()!=0)
            {vec.push_back(i);vec.push_back((n/i));}
    }
    sort(vec.begin(),vec.end());
    num=(vec.size()/2);
    cout<<(vec[num-1]-1)+(vec[num]-1)<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int K = Integer.parseInt(S[1]);
    int[] candle = new int[N];
    String[] T = sc.nextLine().split(" ");
    for(int i = 0; i < N; i++){
      candle[i] = Integer.parseInt(T[i]);
    }
    
    int ans = 2000000000;
    for(int i = 0; i <= N-K; i++){
      int a = Math.abs(candle[i]) + Math.abs(candle[i] - candle[i+K-1]);
      int b = Math.abs(candle[i+K-1]) + Math.abs(candle[i+K-1] - candle[i]);
      int min = Math.min(a, b);
      ans = ans > min ? min : ans;
    }    
    System.out.println(ans);
  }
}

Measured memory_bytes: 50924
if __name__ == '__main__':
    n = int(input())
    h = list(map(int, input().split()))

    dp = [float('inf') for _ in range(10**5 + 7)]
    dp[0] = 0
 
    for i in range(1, n):
        dp[i] = min(dp[i], dp[i-1] + abs(h[i-1] - h[i]))
        if i > 1:
            dp[i] = min(dp[i], dp[i-2] + abs(h[i-2] - h[i]))
    print(dp[n-1])


Measured memory_bytes: 13928
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

bool is_prime(long long n)
{
    if (n == 1) {
        return false;
    }

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

long long gcd(long long a, long long b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

int main()
{
    long long a, b;
    std::cin >> a >> b;

    std::cout << a * b / gcd(a, b) << std::endl;
}


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

using namespace std;

const int max_n = 10111;

int n, ans[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    for (int x = 1; x * x <= n; ++x) {
        for (int y = 1; x * x + y * y + x * y <= n; ++y) {
            for (int z = 1; x * x + y * y + z * z + x * y + x * z + y * z <= n; ++z) {
                ++ans[x * x + y * y + z * z + x * y + x * z + y * z ];
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3600
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    if (k <= 1)
        cout << 0 << endl;
    else
        cout << n-k<< endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

def prime(N):
    L = [2]
    for i in range(2, N+1):
        for l in L:
            if i % l == 0:
                break
        else:
            L.append(i)
    return L

def factor(N):
    p = []
    for l in prime(N):
        while(N % l == 0):
            p.append(l)
            N //= l
    return p
L = []
for i in range(2, N+1):
    L += factor(i)
ans = 1
for p in prime(N):
    l = L.count(p)
    ans *= (l+1)
    ans %= 10**9+7
print(ans)


Measured memory_bytes: 3064
for i in range(4):
    t,n=map(int,input().split())
    if t==1:
        print(f'{6000*n}')
    elif t==2:
        print(f'{4000*n}')
    elif t==3:
        print(f'{3000*n}')
    elif t==4:
        print(f'{2000*n}')
    


Measured memory_bytes: 5604
n=int(input())
a=[]
for i in range(n):
  b=int(input())
  a.append(b)
roop=[False]*n
bottun=1
count=0
while bottun!=2:
  if roop[bottun-1]:
    count=-1
    break
  count+=1
  roop[bottun-1]=True
  bottun=a[bottun-1]
print(count)

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

using namespace std;

int main(){
	string left = "qwertasdfgzxcvb";
	while(true){
		string input;
		cin >> input;
		if(input == "#"){ break; }
		int current = -1, answer = -1;
		for(int i = 0; i < input.size(); ++i){
			int side = (left.find_first_of(input[i]) != string::npos) ? 0 : 1;
			if(current != side){ ++answer; }
			current = side;
		}
		cout << answer << endl;
	}
	return 0;
}

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

const int MAX_N = 100000;
int n;
int a[MAX_N];

void solve() {
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        m[a[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
        cout << m[i] + 1 << " ";
    }
    cout << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    solve();
}

Measured memory_bytes: 5888
#include <stdio.h>

#define N 100003
#define INF 1 << 29

int enqueue(long *queue, long data, int *head, int *tail){
	if(*head % N != (*tail+1) % N) {
		queue[(*tail)++ % N] = data;
		return *tail - *head;
	}else{
		return INF;
	}
}

long dequeue(long *queue, int *head, int * tail){
	if(*head != *tail) {
		return queue[(*head)++ % N];
	}else{
		return INF;
	}
}

void initQueue(long *queue, int *head, int *tail){
	for(long i=1; i <= 9; i++)
		enqueue(queue, i, head, tail);
}

int main(void){
	long queue[N], x;
	int k, head = 0, tail = 0;

	scanf("%d", &k);

	initQueue(queue, &head, &tail);
	for(int i=0; i < k; i++) {
		if(k <= tail-head) {
			for(int j=i; j < k-1; j++)
				dequeue(queue, &head, &tail);
			printf("%ld", dequeue(queue, &head, &tail));
			return 0;
		}
		if((x = dequeue(queue, &head, &tail)) == INF) {
			return 1;
		}else{
			for(int j=-1; j <= 1; j++) {
				int d = x%10;
				if((d==0 && j==-1) || (d==9 && j==1)) continue;
				if(enqueue(queue, 10*x+d+j, &head, &tail) == INF)
					return 1;
			}
		}
	}
    
	return 0;
}

Measured memory_bytes: 896
def valid?(a, b, c)
  a <= b + c && b <= c + a + 1 && c <= a + b + 1
end
 
def calc(rear, front, west, east, north, south, best)
  path = ''
  loop do
    a = rear + front
    b = west + east
    c = north + south
 
    return path if a + b + c == 0
 
    if east > 0 && valid?(b - 1, c, a)
      rear, front, west, east = east - 1, west, rear, front
      y = 69
    elsif north > 0 && valid?(c - 1, a, b)
      rear, front, north, south = north - 1, south, front, rear
      y = 78
    elsif south > 0 && valid?(c - 1, a, b)
      rear, front, north, south = south - 1, north, rear, front
      y = 83
    #elsif west > 0 && valid?(b - 1, c, a)
    else
      rear, front, west, east = west - 1, east, front, rear
      y = 87
    end
     
    if best
      x = best[path.size].ord
      return best if x < y
      best = nil if x > y
    end
    path << y  
  end
end
 
def find(target)
  best = nil
  target.permutation(6).to_a.uniq.each do |rear, front, west, east, north, south|
    a = rear + front
    b = west + east
    c = north + south
    if valid?(a, b, c)
      best = calc(rear, front, west, east, north, south, best)
    end
  end
  best
end
 
loop do
  target = gets.split.map!(&:to_i)
  break if target.all?(&:zero?)
  p, q = gets.split.map!(&:to_i)
  result = find(target)
  puts result ? result[p-1...q] : 'impossible'
end

Measured memory_bytes: 9200
N = int(input())
def q(i):
    print(i)
    r = input()[0]
    if r=='V':
        exit()
    return r

z = q(0)
def is_ok(k):
    s = q(k)
    if k%2:
        return z!=s
    else:
        return z==s
ok = 0
ng = N
while ng-ok > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m


Measured memory_bytes: 3660
import java.util.*;
import java.awt.Point;

public class Main {
	static int[] xSums;
	static int[] wSums;
	static int[][] map;
	static List<List<Point>> blocks;

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

		while (true) {
			int w = sc.nextInt();
			int h = sc.nextInt();

			if (w == 0 && h == 0)
				break;

			int[][] mapTemp = new int[h][w];

			for (int y = 0; y < h; y++) {
				String str = sc.next();
				for (int x = 0; x < w; x++) {
					char c = str.charAt(x);
					mapTemp[y][x] = c == '.' ? -1 : c - '0';
				}
			}
			
			map = new int[h][w];
			for (int i = 0; i < mapTemp.length; i++)
				Arrays.fill(map[i], -1);

			Deque<Point> queue = new ArrayDeque<Point>();
			blocks = new ArrayList<List<Point>>();
			int lowestIndex = -1;

			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					
					int me = mapTemp[y][x];
					if (me == -1)
						;
					else if (map[y][x] == -1) {
						queue.add(new Point(x, y));
						List<Point> block = new ArrayList<Point>();
						
						while (!queue.isEmpty()) {
							Point p = queue.pollFirst();
							if (block.contains(p))
								continue;

							if (p.y == h - 1)
								lowestIndex = blocks.size();

							map[p.y][p.x] = blocks.size();
							block.add(p);

							if (p.x > 0 && mapTemp[p.y][p.x - 1] == me)
								queue.add(new Point(p.x - 1, p.y));
							if (p.x < w - 1 && mapTemp[p.y][p.x + 1] == me)
								queue.add(new Point(p.x + 1, p.y));
							if (p.y > 0 && mapTemp[p.y - 1][p.x] == me)
								queue.add(new Point(p.x, p.y - 1));
							if (p.y < h - 1 && mapTemp[p.y + 1][p.x] == me)
								queue.add(new Point(p.x, p.y + 1));
						}
						blocks.add(block);
					}
				}
			}
			xSums = new int[blocks.size()];
			wSums = new int[blocks.size()];

			setMid(lowestIndex);

			boolean isStable = true;

			for (int i = 0; i < blocks.size(); i++) {
				double gp = (double) xSums[i] / wSums[i] + 0.5;
				List<Point> block = blocks.get(i);
				int left = 1000;
				int right = 0;
				
				for (int j = 0; j < block.size(); j++) {
					Point p = block.get(j);
					if (p.y == h - 1
							|| (map[p.y + 1][p.x] != -1 && map[p.y + 1][p.x] != i)) {
						if (p.x < left)
							left = p.x;
						if (p.x + 1 > right)
							right = p.x + 1;
					}
				}
				if (gp <= left || right <= gp) {
					isStable = false;
					break;
				}
			}

			System.out.println(isStable ? "STABLE" : "UNSTABLE");
		}

	}

	static void setMid(int index) {
		List<Point> block = blocks.get(index);
		boolean[] dejavu = new boolean[blocks.size()];

		for (Point p : block) {
			wSums[index]++;
			xSums[index] += p.x;
			if (p.y != 0) {
				int aboveIndex = map[p.y - 1][p.x];
				
				if (aboveIndex != -1 && aboveIndex != index && !dejavu[aboveIndex]) {
					if (wSums[aboveIndex] == 0)
						setMid(aboveIndex);
					dejavu[aboveIndex] = true;

					wSums[index] += wSums[aboveIndex];
					xSums[index] += xSums[aboveIndex];
				}
			}
		}
	}
}

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

using namespace std;

int main ()
{
    int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    scanf("%d", &k);
    printf("%d\n",  arr[k - 1]);

    return 0;
}


Measured memory_bytes: 256
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

unordered_map<ll,ll> ma;
vector<int> a;
ll ans = 0;
void solve()
{
    ll n; cin>>n;
    a.resize(n);
    rep(i,0,n)
    {
        ll x; cin>>x;
        ma[x]++;
        a[i] = x;
    }
    for(auto i:ma)
    {
        ans+=(i.S*i.S-i.S)/2;
    }
    rep(i,0,n)
    {
        cout<<ans-ma[a[i]]+1<<endl;
    }
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; /*cin>>t;*/ t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

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

int main() {
	int a[100000] = { 0 };
	int N = 0;
	int n = 0;
	int ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N);
	cout << (a[N / 2-1] - a[N / 2])*-1;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int main(){
	int n;
	ll a,b;
	cin>>n>>a>>b;
  ll h[n];
	REP(i,n)cin >> h[i];
	long long int sa=a-b;
	long long int mi=0,ma=1000000000,mid;
	while(ma-mi>1){
		mid=(mi+ma)/2;
		long long int cnt=0;
		for(int i=0;i<n;i++){
			if(h[i]>b*mid){
				cnt+=(h[i] - b * mid + a - b - 1) / (a-b);
			}
		}
		if(cnt>mid){
			mi=mid;
		}
		else{
			ma=mid;
		}
	}
	cout<<ma<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;

typedef long long ll;

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

ll dp(ll n,vector<ll> &memo){
    if(n==0) return 1;
    else if(n<0) return 0;
    if(memo[n]!=-1) return memo[n];
    return memo[n]=dp(n-1,memo)+dp(n-2,memo)+dp(n-3,memo);
}

int main(){
    int N;
    vector<ll> ans(999999,-1);
    for(int i=0; ;i++){
        vector<ll> memo(999999,-1);
        memo[0]=1,memo[1]=1;
        int a;
        cin>>a;
        if(a==0) break;
        else{
            ll num=dp(a,memo);
            if(num%10==0)num=num/10;
            else num=num/10+1;
            if(num%365==0)ans[i]=num/365;
            else ans[i]=num/365+1;
        }
    }
    for(int i=0; ;i++){
        if(ans[i]==-1) break;
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 18336
import sys,math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

n = int(input())
H = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if H[i] == max(H[:i+1]):
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
import math

def L(x1,y1,x2,y2):
	return math.sqrt((x1-x2)**2+(y1-y2)**2)
	
def S(a,b,c):
	s=(a+b+c)/2
	return math.sqrt(s*(s-a)*(s-b)*(s-c))
	
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a  = L(x1,y1,x2,y2)
        b  = L(x1,y1,x3,y3)
        c  = L(x2,y2,x3,y3)
        pa = L(x3,y3,xp,yp)
        pb = L(x2,y2,xp,yp)
        pc = L(x1,y1,xp,yp)
        if S(a,pb,pc)+S(b,pc,pa)+S(c,pa,pb)-S(a,b,c) > 0.0000001:
            print "NO"
        else:
            print "YES"
    except:
        break

Measured memory_bytes: 4436
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize, k: usize,
        s: chars,
    }
    let mut diff = 0;
    let mut cnt = 0;
    for i in 0..s.len() {
        if i > 0 {
            if s[i] != s[i - 1] {
                diff += 1;
            }
            if s[i] == 'L' && s[i - 1] == 'L' {
                cnt += 1;
            }
        }
        if i + 1 < n {
            if s[i] == 'R' && s[i + 1] == 'R' {
                cnt += 1;
            }
        }
    }

    if diff / 2 >= k {
        cnt += k * 2;
    } else {
        cnt += diff;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include<stdio.h>
int A[100];

//Output function
void printSequence(int length, int num){
    int i;
    for(i=0; i<length; i++){
        if(i!=0)printf(" ");
        printf("%d",A[i]);
    }

    printf("\n");
    printf("%d\n",num);

}

int main(){
    int key=0, num=0, length, i, j, minj;

    scanf("%d", &length);
    for(i=0; i<length; i++){
        scanf("%d",&A[i]);
    }


    //Bubble Sort Algo
    for(i=0; i<=length-2; i++){
        minj = i;
        for(j=i; j<=length-1; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }

        if(minj != i){
            key = A[i];
            A[i] = A[minj];
            A[minj] = key;
            num++;
        }
    }

    printSequence(length, num);

    return 0;
}

Measured memory_bytes: 604
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

@SuppressWarnings("unchecked")
public class Main {

  private void solve(Scanner in, PrintWriter out) {
    int N = in.nextInt();
    int M = in.nextInt();

    FenwickTree bit = new FenwickTree(M + 2);

    int[] l = new int[N];
    int[] r = new int[N];
    ArrayList<Integer>[] buckets = new ArrayList[M + 1];
    for (int i = 1; i <= M; i++) {
      buckets[i] = new ArrayList<>();
    }

    for (int i = 0; i < N; i++) {
      l[i] = in.nextInt();
      r[i] = in.nextInt();
      int w = r[i] - l[i] + 1;
      buckets[w].add(i);
    }

    int gone = 0;
    for (int d = 1; d <= M; d++) {
      for (int i : buckets[d]) {
        gone++;
        bit.add(l[i], 1);
        bit.add(r[i] + 1, -1);
      }

      int ans = N - gone;
      for (int m = d; m <= M; m += d) {
        ans += bit.sum(m + 1);
      }
      out.println(ans);
    }
  }

  public class FenwickTree {

    int N;
    long[] data;

    FenwickTree(int N) {
      this.N = N + 1;
      data = new long[N + 1];
    }

    void add(int k, long val) {
      for (int x = k; x < N; x |= x + 1) {
        data[x] += val;
      }
    }

    // [0, k)
    long sum(int k) {
      if (k >= N) {
        k = N - 1;
      }
      long ret = 0;
      for (int x = k - 1; x >= 0; x = (x & (x + 1)) - 1) {
        ret += data[x];
      }
      return ret;
    }
  }

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


Measured memory_bytes: 156464
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll data[100005];
  REP(i, n) { cin >> data[i]; }
  ll ans = 0;
  REP(i, n - 1) { ans += min(a * (data[i + 1] - data[i]), b); }
  cout << ans << endl;
}

Measured memory_bytes: 4420
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
  speed_up;
  ll n;
  cin>>n;
  if(n<7)
  {
      cout<<1<<endl;
      return 0;
  }
  ll a, x, ans = 2;
  x = (n - 7)/11;
  ans += x*2;
  a = 7 + x*11 + 5;
  if(n>=a)
  {
      ans++;
      cout<<ans<<endl;
      return 0;
  }
  cout<<ans<<endl;



return 0;
}



Measured memory_bytes: 3536
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0008
  * Sum of 4 Integers
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.toInt)
      .map((n) => {
        (for (a <- 0 to math.min(9, n); b <- 0 to math.min(9, n); c <- 0 to math.min(9, n); d <- 0 to math.min(9, n))
          yield {
            a + b + c + d
          })
          .count(_ == n)
      })
      .foreach(println)
  }
}

Measured memory_bytes: 74824
n=int(input());s=input()
ans = '';v = 0;vmin = 0
for s0 in s:
    if s0 == '(':
        v += 1
    else:
        v -= 1
        vmin = min(v,vmin)
left = '('; right = ')'
if vmin < 0:
    ans += left*(-1*vmin)
    v += (-1*vmin)
if v == 0:
    ans += s
elif v > 0:
    ans += s + right*v
else:
    ans += left*(-1*v) + s
print(ans)

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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long double db;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	int x; cin >> x;
	cout << (x ^ 1) << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;	
	return 0;
}


Measured memory_bytes: 3804
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // order_of_key, find_by_order

int main() {
	 ios::sync_with_stdio(0);
	 cin.tie(0);
	 cout.tie(0);
	 string s;
	 cin >> s;
	 ll ans =0, k = 0;
	 char p = 'W';
	 for(auto i : s) {
		 if(i == 'W') ans += k;
		 else k++;
		 p=i;
	 }
	 cout << ans << "\n";
}


Measured memory_bytes: 720
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int MOD = 1000000007;
		
		// 計算
		long result = 1;
		HashMap<Integer, Long> map = new HashMap<Integer, Long>();
		for(int i = 1; i <= n; i++){
		    int num = i;
		    for(int m = 2; m <= sqrt(num); m++){
		        if(num == 1) break;
		        if(num%m == 0){
		            while(num%m == 0){
		                num = num/m;
		                map.put(m, map.getOrDefault(m, 0L)+1);
		            }
		        }
		    }
		    if(num != 1) map.put(num, map.getOrDefault(num, 0L)+1);
		}
		for(Long l : map.values()){
		    result *= l+1;
		    result %= MOD;
		}
		
		// 出力
		System.out.println(result);
	}

	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 21716