akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/practice2/tasks/practice2_a

#include <bits/stdc++.h>

using namespace std;

class DisjointSet {
 private:
  class Node {
    friend DisjointSet;

    std::size_t parent;
    std::size_t size;

    Node(const std::size_t parent, const std::size_t size) : parent(parent), size(size) {}
  };

  std::vector<Node> nodes;

 public:
  DisjointSet(const std::size_t n) : nodes(n, Node(n, 1)) {}

  std::size_t size() { return nodes.size(); }

  std::size_t root(const std::size_t x) {
    if (nodes[x].parent == size()) return x;
    return nodes[x].parent = root(nodes[x].parent);
  }

  bool is_same(const std::size_t x, const std::size_t y) { return root(x) == root(y); }

  std::size_t size(const std::size_t x) { return nodes[root(x)].size; }

  bool unite(const std::size_t x, const std::size_t y) {
    std::size_t rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (nodes[rx].size < nodes[ry].size) std::swap(rx, ry);
    nodes[rx].size += nodes[ry].size;
    nodes[ry].parent = rx;
    return true;
  }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, Q;
  std::cin >> N >> Q;
  DisjointSet ds(N);
  for (int i = 0; i < Q; i++) {
    int t, u, v;
    std::cin >> t >> u >> v;
    if (t == 0) {
      ds.unite(u, v);
    } else {
      if (ds.is_same(u, v)) {
        std::cout << 1 << '\n';
      } else {
        std::cout << 0 << '\n';
      }
    }
  }
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    int ans=0, c=0;
    rep(i,s.size()) {
        if ((s.at(i) == 'A')||(s.at(i) == 'C')||(s.at(i) == 'G')||(s.at(i) == 'T')) c++;
        else ans = max(ans, c), c=0;
    }
    ans = max(ans, c);
    printf("%d\n", ans);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC158B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NAB = Console.ReadLine().Split(' ');
            long N = long.Parse(NAB[0]);
            long A = long.Parse(NAB[1]);
            long B = long.Parse(NAB[2]);
            long num = N/(A+B);
            long ans = A * num + Math.Min(A, N - (A + B) * num);
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 27468
def factorization(n):
    ret=[]
    if n==1:
        ret.append(1)
    else:
        for l in range(1,int(n**0.5)+1):
            if n%l==0:
                ret.append(l)
                ret.append(n//l)
    return ret

a,b=map(int,input().split())
A,B=factorization(a),factorization(b)
disjoint=[]
ans=0
A.sort()
for i in A:
    flag=True
    if i not in B:
        flag=False
    for j in disjoint:
        if i%j==0 and j!=1:
            flag=False
    if flag:
        disjoint.append(i)
        ans+=1
        
print(ans)

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

using namespace std;

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }

  int answer = 0;
  for (int a = 0; a < N; a++) {
    for (int b = a + 1; b < N; b++) {
      int d2 = 0;
      for (int i = 0; i < D; i++) {
        d2 += pow(X[a][i] - X[b][i], 2);
      }
      int d = sqrt(d2);
      if (d2 == d * d) {
        answer++;
      }
    }
  }
  cout << answer;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
s=list()
strlist=list()
for i in range(n):
  s.append(input())
  strlist.append(list(s[i]))
  strlist[i].sort()
  s[i]="".join(strlist[i])

s.sort()

ans=0
coun=1
for i in range(n-1):
  if s[i]==s[i+1]:
    coun=coun+1
  else:
    ans=ans+coun*(coun-1)/2
    #print(coun*(coun-1)/2)
    coun=1
ans=ans+coun*(coun-1)/2

print(int(ans))

Measured memory_bytes: 31792
N = int(raw_input())
C, S, F = [], [], []
for i in range(N-1):
	C_S_F = [int(num) for num in raw_input().split()]
	C.append(C_S_F[0])
	S.append(C_S_F[1])
	F.append(C_S_F[2])

def calc_time(i):
	Y = S[i] + C[i]
	for point in range(i, N-2):
		#print point, Y[point]
		Y = max((Y / F[point+1] + int((Y % F[point+1]) != 0)) * F[point+1], 
			S[point+1]) + C[point+1]
		#print i, point+1, Y[point+1], C[point+1]
	return Y

for i in range(N-1):
	print calc_time(i)

print 0

Measured memory_bytes: 2692
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		//文字列を読み込む
		int[] L1 = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int N = L1[0];
		int M = L1[1];
		
		//各桁の数値を格納する配列
		int[] digits = new int[N];
		
		//答えがあるか判定する変数
		bool answerExists = true;
		
		for(int i=0; i<M; i++){
				int[] L2 = Console.ReadLine().Split(' ').Select(j => int.Parse(j)).ToArray();
				int si = L2[0] - 1;
				int ci = L2[1];
				
				if(digits[si] == 0){
						digits[si] = ci;
				}
				else if(digits[si] != ci){
						answerExists = false;
						break;
				}
				
				if(N !=1 && si == 0 && ci == 0){
						answerExists = false;
						break;
				}
		}
		
		if(N != 1 && digits[0] == 0){
				digits[0] = 1;
		}
		
        if(answerExists)
		{
			string answer = "";
			for(int i=0; i<N; i++){
					answer += digits[i].ToString();
			}
			Console.WriteLine(answer);
		}else{
			Console.WriteLine("-1");
		}
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
const int MN=100000+5;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n;
int fa[MN];
set<int>h[MN];
set<int>::iterator it;
map<pii,int>mp;
queue<pii>q;pii e;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void add(int u,int v){
	if(u>v)swap(u,v);
	h[u].insert(v),h[v].insert(u);mp[pii(u,v)]++;
	if(mp[pii(u,v)]==2)q.push(pii(u,v));
}
void input(){
	IN(n);
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1,u,v;i<=2*n-2;++i)IN(u),IN(v),add(u,v);
	for(int i=1,u,v;i<n;++i){
		while(1){
			if(q.empty())return puts("NO"),void();
			e=q.front();q.pop();u=find(e.first),v=find(e.second);
			if(u!=v)break;
		}
		if(h[u].size()>h[v].size())swap(u,v);
		fa[u]=v;mp.erase(e),h[v].erase(u);
		for(it=h[u].begin();it!=h[u].end();it++){
			int x=find(*it);if(x==v)continue;
			add(x,v);
		}
	}
	puts("YES");
}
int main(){
	input();
	return 0;
}


Measured memory_bytes: 45952
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
// a^b mod MOD
ll powmod(ll a,ll b,ll m=1000000007){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
int main(){
	string s;
	cin>>s;
	int n=s.size();
	vvi co(3,vi(n+1));
	rep(i,n){
		if(s[i]=='A')co[0][i+1]++;
		if(s[i]=='C')co[1][i+1]++;
		if(s[i]=='?')co[2][i+1]++;
		rep(j,3)co[j][i+1]+=co[j][i];
	}
	
	ll out=0,MOD=1000000007;
	rep(i,n)if(s[i]=='B'||s[i]=='?'){
		int a=co[0][i]-co[0][0];
		int b=co[1][n]-co[1][i+1];
		int l=co[2][i]-co[2][0];
		int r=co[2][n]-co[2][i+1];
		(out+=(ll)powmod(3,l+r)*a%MOD*b%MOD)%=MOD;
		if(l)(out+=(ll)powmod(3,l+r-1)*l%MOD*b%MOD)%=MOD;
		if(r)(out+=(ll)powmod(3,l+r-1)*a%MOD*r%MOD)%=MOD;
		if(l&&r)(out+=(ll)powmod(3,l+r-2)*l%MOD*r%MOD)%=MOD;
	}
	cout<<out<<endl;
}






Measured memory_bytes: 2048
#include<bits/stdc++.h>   //取り敢えず書く
using namespace std;      //取り敢えず書く
int main(){  int a,b,c;
           cin>>a>>b>>c;
           if(a<b&&b<c){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}//取り敢えず書く
 /* コード */              //今までやったようにコードを書く
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define NAME "G"
#define vt vector
#define ll long long
#define fi first
#define se second
#define pb push_back
#define time ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

void init()
{
    freopen(NAME".inp","r",stdin);
    freopen(NAME".out","w",stdout);
    time
}

const int N=1e5+5;
int n,m;
vt<vt<int> > a(N);
int Res=0,vet[N] {0},f[N] {0},d[N] {0};

void inp()
{
    scanf("%d%d",&n,&m);
    int x,y;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        a[y].pb(x);
        d[x]=1;
    }
}

void dfs(int u)
{
    vet[u]=1;
    for(int i=0;i<a[u].size();i++)
    {
        int v=a[u][i];
        if(vet[v]==0) dfs(v);
        f[u]=max(f[v]+1,f[u]),Res=max(Res,f[u]);
    }
}

void out()
{
    for(int i=1;i<=n;i++) if(d[i]==0) dfs(i);
    printf("%d",Res);
}

int main()
{
   // init();
    inp();
    out();
}


Measured memory_bytes: 11520
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }

////////////////////////////////////////////////////////////////

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = pow(10, 9) + 7;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};


////////////////////////////////////////////////////////////////

int main(void) {

	string s;
	cin >> s;
	int num = s.size();

	bool ans = true;
	for(int i=0; i<num/2; i++){
		if(s[i] != s[s.size()-1-i]) ans = false;
		//cout << "i = " << i  << ": " <<  ans << endl;
	}

	int j=0;
	while(true){
		int right  = (num-1)/2 - 1 - j;
		if(s[j] != s[right]) ans = false;
		//cout << "j = " << j  << ": " <<  ans << endl;
		j++;
		if(j >= right) break;
	}

	int k=0;
	while(true){
		int left = (num+3)/2 -1 + k;
		int right = num - 1 - k;
		if(s[left] != s[right]) ans = false;
		//cout << "k = " << k  << ": " <<  ans << endl;
		k++;
		if(left >= right) break;
	}


	if(ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}




Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
h = list(map(int, input().split()))
dp = [10**18]*N
dp[0] = 0

for i in range(N):
    if i-1>=0:
        dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]))
    
    if i-2>=0:
        dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])

Measured memory_bytes: 50324
#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	string str2;
	cin >> str >> str2;
	for(int i = 0;i<(int)max(str.size(),str2.size());i++){
		if(str.size() > i)
			cout<<str[i];
		if(str2.size() > i)
			cout<<str2[i];
	
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
    vector<string> ans;
    for (int i = 0; i < 3; i++)
    {
        string tmp;
        cin >> tmp;
        ans.push_back(tmp);
    }
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i][i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
h,n=map(int,input().split())
lis=[list(map(int,input().split())) for i in range(n)]

dp=[float('inf') for i in range(h+10**4+1)] # dp[i]は、総ダメージiの時の最小コスト
dp[0]=0

for i in range(1,h+10**4+1):
    for j in range(n): # 技ループ
        if i>=lis[j][0]:
            dp[i]=min(dp[i],dp[i-lis[j][0]]+lis[j][1])
print(min(dp[h:])) # 総ダメージh以上の最小

Measured memory_bytes: 45020
#include <bits/stdc++.h>
#include <iostream>
#define ll long long int
#define ld long double
using namespace std;

int main(){
    	map<string,int>mp;
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		mp[s]++;
	}
	int ma=0;
	for(auto u:mp) 
      if(u.second>ma)ma=u.second;
	for(auto u:mp)
      if(u.second==ma) 
        cout<<u.first<<endl;
  return 0;
}

Measured memory_bytes: 25216
# 写経

n=int(input())

def dfs(s):
    if int(s)>n:return 0
    
    ret=1 if all(s.count(c)>0 for c in '753') else 0
    for c in '753':
        ret+=dfs(s+c)
    return ret

print(dfs('0'))

Measured memory_bytes: 3060
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type,
less<T>, rb_tree_tag, 
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int m, k;
    cin >> m >> k;
    if (k >= (1 << m) || (m == 1 && m == k))
        cout << -1, exit(0);
    if (!k) {
        for (int i = 0; i < (1 << m); ++i)
            cout << i << " " << i << " ";
        return 0;
    }
    cout << "0 " << k << " 0 ";
    for (int i = 1; i < (1 << m); ++i)
        if (i != k)
            cout << i << " ";
    cout << k << " ";
    for (int i = (1 << m) - 1; i > 0; --i)
        if (i != k)
            cout << i << " ";
    return 0;
}

Measured memory_bytes: 1792
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const n = stdin.split('\n')[0]
const a = stdin
  .trim()
  .split('\n')[1]
  .split(' ')
  .map(Number)

const ans = _ => {
  const min = Math.min(...a)
  const max = Math.max(...a)

  return Math.abs(max - min)
}

console.log(ans())


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

int main(){
    int N; cin >> N;
    int cnt;
    if(N%2!=0) cnt=N/2;
    else cnt=cnt=N/2-1;
    cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }

ll solve(int n, int k, vector<int> const & t, vector<ll> const & d) {
    map<int, int> max_d;
    REP (i, n) {
        if (not max_d.count(t[i]) or d[max_d[t[i]]] < d[i]) {
            max_d[t[i]] = i;
        }
    }

    reversed_priority_queue<pair<ll, int> > que;
    ll sum = 0;
    for (auto it : max_d) {
        int i = it.second;
        que.emplace(d[i], i);
        sum += d[i];
    }
    int que_size = que.size();

    vector<bool> used(n);
    int cnt_used = 0;
    auto update_que = [&]() {
        while (que_size > k) {
            assert (not que.empty());
            int i = que.top().second;
            que.pop();
            if (used[t[i]]) continue;
            -- que_size;
            sum -= d[i];
        }
    };

    vector<int> order(n);
    iota(ALL(order), 0);
    sort(ALL(order), [&](int i, int j) {
        return d[i] > d[j];
    });

    ll answer = 0;
    ll acc = 0;
    for (int i : order) {
        if (not k) break;
        if (not used[t[i]]) {
            // use i trivially
            acc += d[i];
            sum -= d[i];
            used[t[i]] = true;
            ++ cnt_used;
            -- que_size;
            -- k;

        } else {
            // ignore i
            update_que();
            chmax(answer, acc + sum + (ll)que.size() * que.size());

            // use i
            acc += d[i];
            -- k;
        }
    }
    update_que();
    chmax(answer, acc + sum + (ll)(cnt_used + que_size) * (cnt_used + que_size));
    return answer;
}

int main() {
    int n, k; cin >> n >> k;
    vector<int> t(n);
    vector<ll> d(n);
    REP (i, n) {
        cin >> t[i] >> d[i];
        -- t[i];
    }
    cout << solve(n, k, t, d) << endl;
    return 0;
}


Measured memory_bytes: 8308
/*author - Ashutosh Chitranshi*/
#include<bits/stdc++.h>
using namespace std;
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define mp make_pair
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef vector< vl > vvl;
typedef pair< int,int > ii;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;
typedef map< int,int> mii;
void update(ll bit[],ll index,ll value,ll n)
{
	index++;
	while(index<=n)
	{
		bit[index] += value;
		index += (index&(-index));
	}
}
ll pointQuery(ll bit[],ll index)
{
	ll val = 0ll;
	index++;
	while(index>0)
	{
		val += bit[index];
		index -= (index&(-index));
	}
	return val;
}
void rangeUpdate(ll bit[],ll l,ll r,ll value,ll n)
{
	update(bit,l,value,n);
	update(bit,r+1,-value,n);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin >> n >> k;
    ll ar[n];
    for(int i=0;i<n;i++)
    {
    	cin >> ar[i];
    }
    while(k--)
    {
    	ll bit[n+1];
    	memset(bit,0ll,sizeof(bit));
    	for(int i=0;i<n;i++)
    	{
    		ll j = min(i+ar[i],n-1);
    		rangeUpdate(bit,i,j,1,n);
    		j = max(i-ar[i],0ll);
    		if(i-j>0)
    			rangeUpdate(bit,j,i-1,1,n);
    	}
    	ll count = 0ll;
    	for(int i=0;i<n;i++)
    	{
    		ar[i] = pointQuery(bit,i);
    		if(ar[i] >=n)
    		{
    			ar[i] = n;
    			count++;
    		}
    	}
    	if(count == n)
    		break;
    }
    for(int i=0;i<n;i++)
    	cout << ar[i] << " ";
    return 0;
}

Measured memory_bytes: 6772
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n-2):
    if p[i]<p[i+1] and p[i+1]<p[i+2]:
        cnt+=1
    elif p[i]>p[i+1] and p[i+1]>p[i+2]:
        cnt+=1
    else:
        continue

print(cnt)

Measured memory_bytes: 3064
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
ans = 0
cnt = 0
for i in ab:
    a, b = i[0], i[1]
    if cnt + b >= m:
        print(ans + (m - cnt) * a)
        exit()
    else:
        ans += a * b
        cnt += b


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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e12

int const N = 1e3+5;

int main ()
{
    string s; cin >> s;
    if (s == "Sunny")
        cout << "Cloudy" << endl;
    else if (s == "Cloudy")
        cout << "Rainy" << endl;
    else if (s == "Rainy")
        cout << "Sunny" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int ask(int pos){
	cout << pos << endl;
	string ans;
	cin >> ans;
	return (ans == "Vacant" ? -1 : (ans == "Male" ? 0:1));
}

int main(){
	int n;
	
	cin >> n;
	
	int fst = ask(0);
	
	if(fst == -1){
		return 0;
	}
	
	int st = 0,dr = n - 1;
	
	while(dr - st > 1){
		int mid = (st + dr) / 2;
		int tmp = ask(mid);
		
		if(tmp == -1){
			return 0;
		}
		
		if(tmp == (fst ^ (mid & 1))){
			st = mid;
		}			
		else{
			dr = mid;
		}
	}
	
	ask(dr);
	
	
	return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	int n;
	while(cin >> n){
		if(!n)
			break;
		string str;
		cin >> str;
		for(int i=0;i<n;i++){
			int count = 1;
			string tmp = "";
			for(unsigned j=0;j<str.size();j++){
				if(str[j] != str[j+1] || j == str.size()-1){
					stringstream sst;
					sst << count;
					string a;
					sst >> a;
					tmp += a;
					tmp += str[j];
					count = 1;
				}else{
					count++;
				}
			}
			str = tmp;
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC143A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int a = input[0];
            int b = input[1];

            if (a - 2 * b < 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(a - 2 * b);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (1ll*a*b)/gcd(a, b);}
#define MOD 100000000;
#define EPS 0.001
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n; cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    int ans = 0;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            ans+=a[i]*a[j];
        }
    }
    cout<<ans;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  long long sum=0;
  for(int i=1;i<N;i++){
    if(A.at(i-1)>A.at(i)){
      sum+=A.at(i-1)-A.at(i);
      A.at(i)=A.at(i-1);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib> 
#include <string>
#include <iomanip>

using namespace std;

int main() {
	int n;
	cin >>n;
	vector <double> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v.at(i);
	}

	for (int i = 0; i < n-1; i++)
	{
		sort(v.begin(),v.end(),std::greater<int>());

		v.at(v.size()-2) = (v.at(v.size()-2)+v.at(v.size()-1))/2;
		v.pop_back();
	}

	cout << v.at(0);
	
	
}

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

int main(){
	int N;
	cin >> N;
	vector<int> s(N);
	int min=101;
	long sum=0;
	for (int i = 0; i < N; i++){
		int si;
		cin >> si;
		s[i] = si;
		if (si% 10 != 0 && si<min){
			min = si;
		}
		sum += si;
	}
	if (sum % 10 != 0){
		cout << sum << endl;
		return 0;
	}
	if (min==101){
		cout << 0 << endl;
		return 0;
	}
	cout << sum - min << endl;
	return 0;
	
}

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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int N,M;
	bool open = false;
	std::string T;
	getline(cin, T);
	N = atoi(T.c_str());
	std::string *u = new std::string[ N ];
	for (int i = 0; i < N; i++) {
		getline(cin, u[i]);
	}
	getline(cin, T);
	M = atoi(T.c_str());
	for (int i = 0; i < M; i++) {
		bool find = false;
		getline(cin, T);
		for (int j = 0; j < N && (!find); j++) {
			if (T == u[j]) {
				find = true;
			}
		}
		if (find) {
			if (!open) {
				cout << "Opened by " << T << endl;
				open = true;
			}else {
				cout << "Closed by " << T << endl;
				open = false;
			}
		}else {
			cout << "Unknown " << T << endl;
		}
	}
	delete[] u;
	return 0;
}

Measured memory_bytes: 3204
#include <stdio.h>

int main(){
	int r,c;
	int i,j;
	int A[150][150];

	scanf("%d", &r);
	scanf("%d", &c);
	for(i=0; i<r; i++){
		for(j=0; j<c; j++){
			scanf("%d",&A[i][j]);
		}
	}
	for( i=0; i<r; i++){
		for( j=0; j<c; j++){
			A[i][c] += A[i][j];
		}
	}
	for( j=0; j<=c; j++){
		for( i=0; i<r; i++){
			A[r][j] += A[i][j];
		}
	}
	for(i=0; i<r+1; i++){
		for(j=0; j<c+1; j++){
			printf("%d", A[i][j]);
			if(j!=c)
				printf(" ");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 664
#include <cstdio>
#include <climits>

int convert(int p, int size, int n){
    for(int i=1;i<size;i++)p+=n--;
    return p;
}

int multipulication(int *r, int *c, int *count, int p, int size, int n){
    if(size==1)return 0;
    int id = convert(p,size,n);
    if(count[id])return count[id];
    int mlt = INT_MAX;
    int i, tmp;
    for(i=1;i<size;i++){
        tmp = r[p]*r[p+i]*c[p+size-1] + multipulication(r,c,count,p,i,n) + multipulication(r,c,count,p+i,size-i,n);
        if(tmp<mlt)mlt=tmp;
    }
    count[id] = mlt;
    return mlt;
}

int main(){
    int i, n;
    scanf("%d",&n);
    int r[n];
    int c[n];
    int count[n*(n+1)/2];
    for(i=0;i<n*(n+1)/2;i++)count[i]=0;
    for(i=0;i<n;i++)scanf("%d %d",r+i,c+i);
    printf("%d\n",multipulication(r,c,count,0,n,n));
    return 0;
}



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

using namespace std;

int main() {
    int N;
    bool ans = false;

    scanf("%d", &N);
    while (N) {
        if (N % 10 == 7)
            ans = true;
        N /= 10;
    }

    if (ans) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 3684
a,b=map(int,input().split())
ans=0

for i in range(1,10000):
    pa=int(i*0.08)
    pb=int(i*0.10)
    if pa>100 or pb >100:
        break
    if pa==a and pb==b:
        print(i)
        ans=1
        break
if ans==0:
    print(-1)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>



#include <iostream>
#include <algorithm>
#include <vector>

int main()
{
	std::vector<long long> n(5);
	long long k,ans; std::cin >> k;
	for (int i = 0;i < 5;i++) { std::cin >> n[i]; }

	ans = (k-1) / *(std::min_element(n.begin(), n.end())) + 5;

	std::cout << ans << std::endl;

	return 0;
}



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

int A;
int B;


int main(){
    cin >> A;
    cin >> B;
int add = A + B;
int subtract = A - B;
int multiply = A * B;

if (add > subtract && add > multiply){
    cout << add;
} else if (subtract > multiply && subtract > add){
    cout << subtract;
} else if (multiply > add && multiply > subtract){
    cout << multiply;
} else {
    cout << add;
}

return 0;
}

Measured memory_bytes: 256
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

readInt :: BS.ByteString -> Int
readInt s = case BS.readInt s of
              Just (x, _) -> x

readInt64 :: BS.ByteString -> Int64
readInt64 s = case BS.readInteger s of
              Just (x, _) -> fromInteger x

main = do
  n <- readInt <$> BS.getLine
  xs <- U.fromListN n . map readInt64 . BS.words <$> BS.getLine
  let negatives = U.filter (<= 0) xs
  if even (U.length negatives)
    then print $ U.sum $ U.map abs xs
    else let positives = U.filter (> 0) xs
             mn = U.maximum negatives
             mp = U.minimum positives
         in if U.null positives || abs mp > abs mn
            then print $ (U.sum $ U.map abs xs) + 2 * mn
            else print $ (U.sum $ U.map abs xs) - 2 * mp


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

int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  if (b - a < 2) {
    cout << 1 + k << endl;
    return 0;
  }
  ll ans = 0;
  if (k - (a - 1) < 2) {
    cout << 1 + a - 1 + (k - (a - 1)) << endl;
    return 0;
  } else {
    ans += (k - (a - 1)) / 2 * (b - a) + a;
    if ((k - (a - 1)) % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
def bubble_sort(sequence):
    for i in range(len(sequence)):
        for j in range(len(sequence)-1, i, -1):
            if int(sequence[j-1][1]) > int(sequence[j][1]):
                sequence[j], sequence[j-1] \
                    = sequence[j-1], sequence[j]
    return sequence


def selection_sort(sequence):
    for i in range(len(sequence)):
        mini = i
        for j in range(i, len(sequence)):
            if int(sequence[j][1]) < int(sequence[mini][1]):
                mini = j
        sequence[i], sequence[mini] = sequence[mini], sequence[i]
    return sequence   


def main():
    input()
    cards = input().split()
    bubble = bubble_sort(cards[:])
    selection = selection_sort(cards[:])
    stable = sorted(cards, key=lambda card: int(card[1]))
    print(' '.join(bubble))
    print('Stable' if bubble == stable else 'Not stable')
    print(' '.join(selection))
    print('Stable' if selection == stable else 'Not stable')


if __name__ == "__main__":
    main()



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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    string ans = "No";
    int nn[4] = {n%10, n/10%10, n/100%10, n/1000%10};
    if(nn[0] == nn[1] && nn[1] == nn[2]) ans = "Yes";
    if(nn[1] == nn[2] && nn[2] == nn[3]) ans = "Yes";
    cout << ans << endl;
    return 0;
}


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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    string s;
    cin>>s;
    n=s.length();
    ll ans[n+1]={0};
    for(i=0;i<n;)
    {
        ll cnt=0;
        ll cnt1=0;
        ll ind1,ind2;
        while(s[i]=='R')
        {
            cnt++;
            i++;
        }
        ind1=i-1;
        while(s[i]=='L' && i<n)
        {
            cnt1++;
            i++;
        }
        ind2=ind1+1;
        swap(cnt,cnt1);
        ans[ind1]=cnt/2+(cnt1+1)/2;
        ans[ind2]=(cnt+1)/2+cnt1/2;
    }
    for(i=0;i<n;i++)
    cout<<ans[i]<<" ";
    return 0;
}

Measured memory_bytes: 1488
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll n, a, b;
    cin >> n >> a >> b;
    ll c = n / (a + b), r = n % (a + b);
    ll ans = c * a + min(r, a);
    cout << ans << endl;
    return 0;
}


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

int N, M, Q;

int A[10];
int a[50], b[50], c[50], d[50];
long res = 0;

void dfs(int depth, int num) {
  if (depth == N) {
    long tmp = 0;
    for (int i = 0; i < Q; i++) {
      if (A[b[i]]-A[a[i]] == c[i]) tmp += d[i];
    }
    res = tmp > res ? tmp : res;
    return;
  }
  
  for (int i = num; i <= M; i++) {
    A[depth] = i;
    dfs(depth+1, i);
  }
  return;
}

int main() {
  cin >> N >> M >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--; b[i]--;
  }
  dfs(0, 1);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int in;
    int a[32]={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};
    scanf("%d",&in);
    printf("%d",a[in-1]);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"

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

#define rep(i,n) for (ll i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

int main()
{
	int n,x,y;
	cin >> n >> x >> y;
	map<int, int> m;	// 距離, 個数

	int ss, se;

	if (x < y) {
		ss = x;
		se = y;
	}
	else {
		ss = y;
		se = x;
	}

	for (int s = 1; s < n; s++) {
		for (int e = s + 1; e < n+1; e++) {
			int l;

			if (x != y) {
				int l1 = abs(ss - s) + 1 + abs(se - e);
				int l2 = e - s;
				l = min(l1,l2);
			}
			else {
				l = e - s;
			}

			if (m.find(l) != m.end()) {
				m[l]++;
			}
			else {
				m.insert(make_pair(l, 1));
			}
		}
	}

	rep(i, n - 1) {

		cout << m[i+1] << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef float ld;
typedef int _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	doin();
	ll n, a[5], t = 0;
	cin >> n;
	for(int i = 0; i < 5; i++) cin >> a[i];
	for(int i = 0; i < 5; i++) {
		t = max(t, ((a[i]+n-1)/a[i]) + 4);
	}
	cout <<t;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int n;
int a[100003];
int b[100003];
int c[100003];

int main()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d%d", &a[i], &b[i], &c[i]);

		a[i] += max(b[i - 1], c[i - 1]);
		b[i] += max(a[i - 1], c[i - 1]);
		c[i] += max(b[i - 1], a[i - 1]);
	}

	cout << max(max(a[n], b[n]), c[n]);

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 810114514
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int long long 

signed main(){
    int X;
    bool beki[1005]={};
    int Ans=0;
    beki[0]=1;beki[1]=1;
    cin >> X;
    
    for(int i=2;i<=1000;i++){
        int G=i*i;
        while(G<=1000){
            beki[G]=1;
            G*=i;
        }
    }
    REP(i,X+1){
        if(beki[i]==1){
            Ans=i;
        }
    }
    cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define fin for(i=0;i<n;i++)
#define vec vector<ll>
#define pb push_back
#define vecit vector<ll>::iterator
#define vecp vector<pair<ll,ll> >
#define vecpit vector<pair<ll,ll> >::iterator
#define mapp map<ll,ll>
#define mapr map<ll,pair<ll,ll> >
#define maprit map<ll,pair<ll,ll> >::iterator
#define mapit map<ll,ll>::iterator
#define mod1 1000000007
#define INF 10000000000
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll i,j,k,l;
    vec v;
    fin
    {
        cin>>j;
        v.pb(j);
    }
    ll a[n+1];
    a[0]=0;
    a[1]=abs(v[1]-v[0]);
    for(i=2;i<n;i++)
    {
        ll p=abs(v[i]-v[i-2])+a[i-2];
        ll q=abs(v[i]-v[i-1])+a[i-1];
        a[i]=min(p,q);
    }
    cout<<a[n-1];
}



Measured memory_bytes: 4816
/*
___ is a raging sadist.
*/

//Destroy all WA at test 2

#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define PI 3.14159265
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
using namespace std;

ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  

        y = y>>1; 

        if (x<=100000000)
        x = (long long)(x*x);

        //cout<<x<<'\n'; 
    } 
    return res; 
} 



ll b[200005];


int main()
{

#ifndef ONLINE_JUDGE    
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

fastio();

ll n;
cin>>n;

ll a[n];

For(i,0,n)
{
    cin>>a[i];
}

ll pre[n]={0};  ll suf[n]={0};

pre[0]=a[0];

for(int i=1;i<n;i++)
{
    pre[i]=a[i]^pre[i-1];
}

suf[n-1]=a[n-1];

for(int i=n-2;i>=0;i--)
{
    suf[i]=a[i]^suf[i+1];
}

b[0]=suf[1];
b[n-1]=pre[n-2];

for(int i=1;i<=n-2;i++)
{
    b[i]=pre[i-1]^suf[i+1];
}

for(int i=0;i<n;i++)
cout<<b[i]<<' ';

return 0;
}

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

int main(void){
    int N;
    cin>>N;
    
    list<int> li;
    
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        if((N-i)%2==1)li.push_front(a);
        else li.push_back(a);
    }
    
    for(int i=0;i<N;i++){
        cout<<li.front();
        li.pop_front();
        if(i!=N-1)cout<<" ";
        else cout<<endl;
    }
}


Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int K;
double R,L,P,E,T;

double Search (double L, double R, int depth) {
  if (T - E < L && R < T + E) {
    return 1.0;
  }

  if (T < L - E || R + E < T) {
    return 0.0;
  }

  double H = (R + L) / 2.0;

  if (depth >= K) {
    return (abs(H - T) < E) ? 1.0 : 0.0;
  }

  if (T < H) {
    return P * Search(H, R, depth + 1) + (1.0 - P) * Search(L, H, depth + 1);
  }
  return (1.0 - P) * Search(H, R, depth + 1) +  P * Search(L, H, depth + 1);
}

void Solve(void) {
  printf("%.9f\n", Search(R, L, 0));
}

signed main(void) {
  cin >> K >> R >> L >> P >> E >> T;

  Solve();
}



Measured memory_bytes: 3280
s = input()
l = [0]
m = [0]
a = 0
b = 0
arr = []
for i in range(len(s)):
  if s[i] == '<':
    a += 1
  else:
    a = 0
  l.append(a)

  if s[len(s) - i - 1] == '>':
    b += 1
  else:
    b = 0
  m.append(b)
m = m[::-1]

for i in range(len(l)):
  arr.append(max(l[i], m[i]))
ans = sum(arr)
print(ans)

Measured memory_bytes: 36884
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 10;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m, k;
    char ch[MAXN][MAXN], ch2[MAXN][MAXN];
    cin >> n >> m >> k;
    FOR(i,1,n) FOR(j,1,m) cin >> ch[i][j];

    int res = 0;
    FOR(mask,0,(1<<n)-1) {
        FOR(mask2,0,(1<<m)-1) {
            FOR(i,1,n) FOR(j,1,m) ch2[i][j] = ch[i][j];
            FOR(i,1,n)
                FOR(j,1,m) {
                    if (mask & (1<<(i-1))) ch2[i][j] = 'R';
                    if (mask2 & (1<<(j-1))) ch2[i][j] = 'R';
                }
            int cnt = 0;
            FOR(i,1,n) FOR(j,1,m) cnt += ch2[i][j] == '#';
            res += cnt == k;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n , y;
    cin >> n >> y;
    for( ll i = 0 ; i <= n ; i++ ) {
        for( ll j = 0 ;  j <= n - i ; j++ ) {
            if ( i * 10000 + j * 5000 + ( n - i - j ) * 1000 == y ) {
                cout << i << " " << j << " " << n - i - j;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1";
}



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

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M;
	cin >> N >> M;
	vector<vector<int>> W(M);
    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        A = M - A;
        if (A >= 0) {
            W[A].push_back(B);
        }
    }
    multiset<int> S;
    int Ans = 0;
    for (int i = M - 1; i > -1; --i) {
        for (auto &V : W[i]) {
            S.insert(V);
        }
        if (!S.empty()) {
            Ans += *S.rbegin();
            S.erase(S.find(*S.rbegin()));
        }
    }
    cout << Ans;
	return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
using namespace std;
int a, b, c, n, m, ans;
main()
{
  cin >> a >> b >> c >> n >> m;
  c *= 2;
  int s = min(n, m);
  if(a+b>=c)
    ans += c * s;
    else
      ans += (a + b) * s;
    n -= s;
    m -= s;
    if(n==0){
      if(b>=c)
        ans += c * m;
        else
          ans += b * m;
    }else{
      if(a>=c)
        ans += c * n;
        else
          ans += a * n;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256