akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define NIL -1
typedef struct List
{
    int parent;
    int leftchild;
    int rightchild;
}List;
int TreeHeight(int ID, List* Tree)
{
    int leftheight = 0, rightheight = 0;
    if(Tree[ID].leftchild==NIL&&Tree[ID].rightchild==NIL){return 0;}
    if(Tree[ID].leftchild!=NIL){leftheight=TreeHeight(Tree[ID].leftchild,Tree);}
    if(Tree[ID].rightchild!=NIL){rightheight=TreeHeight(Tree[ID].rightchild,Tree);}
    return leftheight >= rightheight? leftheight + 1:rightheight + 1;
}
int CountDepth(List* l, int ID)
{
    int counter=0;
    while(l[ID].parent!=NIL)
    {
        counter++;
        ID = l[ID].parent;
    }
    return counter;
}

int main(int argc, const char * argv[]) {
    int n, nodeID=0;
    scanf("%d", &n);
    List* Tree = (List*)malloc(n*sizeof(List));
    for(int i=0;i<n;i++){Tree[i].parent=NIL;}
    for(int i=0;i<n;i++)
    {
        scanf("%d", &nodeID);
        scanf("%d %d", &Tree[nodeID].leftchild, &Tree[nodeID].rightchild);
        Tree[Tree[nodeID].leftchild].parent=nodeID;
        Tree[Tree[nodeID].rightchild].parent=nodeID;
    }
    for(int i=0;i<n;i++)
    {
        printf("node %d: parent = %d, ", i, Tree[i].parent);
        if(Tree[i].parent == NIL){printf("sibling = -1, ");}
        else if(Tree[Tree[i].parent].rightchild==i)
            {printf("sibling = %d, ", Tree[Tree[i].parent].leftchild);}
        else{printf("sibling = %d, ", Tree[Tree[i].parent].rightchild);}
        if(Tree[i].leftchild==NIL&&Tree[i].rightchild==NIL){printf("degree = 0, ");}
        else if(Tree[i].leftchild!=NIL&&Tree[i].rightchild!=NIL){printf("degree = 2, ");}
        else{printf("degree = 1, ");}
        printf("depth = %d, ", CountDepth(Tree, i));
        printf("height = %d, ", TreeHeight(i, Tree));
        if(Tree[i].parent==NIL){printf("root\n");}
        else if(Tree[i].leftchild==NIL&&Tree[i].rightchild==NIL){printf("leaf\n");}
        else{printf("internal node\n");}
    }
    free(Tree);
    return 0;
}



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

int main() {
  int a, b, c;
  cin >> a >> b;
  c = a * b % 2;
  if (c == 0) {
    cout << "Even" << endl;
  }
  else if (c == 1) {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
# 全部グーを出すことは可能、その時、スコアは　-(相手のパーの数)
# グーをパーに変更すると、-1->0 or 0->1  となる、
# すなわち、相手の手がなんであろうと点数が+1される
# グー、パー、グー、パー、...と出すのが最適
# -(相手のパーの数) + (N//2)

S = list(input())
N = len(S)
a = S.count("p")
b = N // 2
ans = -a + b
print(ans)


Measured memory_bytes: 70064
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int n,q,ans;
struct seg
{
	int tr[N<<2];
	void build(int k,int l,int r)
	{
		tr[k]=(k==1?n:1e9);
		if(l==r)
			return;
		int mid=l+r>>1;
		build(k<<1,l,mid);
		build(k<<1|1,mid+1,r);
	}
	void update(int k,int l,int r,int a,int b,int v)
	{
		if(l==a&&r==b)
		{
			tr[k]=min(tr[k],v);
			return;
		}
		int mid=l+r>>1;
		if(b<=mid) update(k<<1,l,mid,a,b,v);
		else if(a>mid) update(k<<1|1,mid+1,r,a,b,v);
		else update(k<<1,l,mid,a,mid,v),update(k<<1|1,mid+1,r,mid+1,b,v);
	}
	int query(int k,int l,int r,int x)
	{
		if(l==r)
			return tr[k];
		int mid=l+r>>1;
		if(x<=mid) return min(tr[k],query(k<<1,l,mid,x));
		else return min(tr[k],query(k<<1|1,mid+1,r,x));
	}
}t1,t2;
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	ans=(n-2)*(n-2);
	t1.build(1,1,n);
	t2.build(1,1,n);
	while(q--)
	{
		int t,x;
		cin>>t>>x;
		if(t==1)
		{
			int v=t2.query(1,1,n,x);
			ans-=v-2;
			t1.update(1,1,n,1,v,x);
		}
		else
		{
			int v=t1.query(1,1,n,x);
			ans-=v-2;
			t2.update(1,1,n,1,v,x);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11896
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inpl()
a = t[0]
b = t[1]
c = t[2]
k = t[3]
cnt = 0

if k == a + b + c:
    cnt = a - c

if k >= a + b and k < a + b + c:
    cnt = a - (k - (a + b))

if k >= a and k < a + b:
    cnt = a

if k < a:
    cnt = k

print(cnt)

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

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;

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

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

bool isKaibun(string s)
{
    for(int i = 0; i < s.length(); i++)
    {
        if(s[i] != s[s.length()-1-i]) return false;
    }
    return true;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    string s; cin >> s;
    if(isKaibun(s) && isKaibun(s.substr(0, (s.length())/2)) && isKaibun(s.substr((s.length())/2+1, (s.length())/2)))
    {
        cout << "Yes" << endl;
    }
    else 
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include<stdlib.h> 

using namespace std;

int main(){
	string s;
	cin >> s;
	char a1 =  (int)(s[0]);
	char a2 =  (int)(s[1]);
	char a3 =  (int)(s[2]);
	char a4 =  (int)(s[3]);
	int s1 = (a1-48)*10 + (a2-48);
	int s2 = (a3-48)*10 + (a4-48);
	//cout << a1 << a2 << a3 << a4 << endl; 
	//cout << s1 <<" " << s2 << endl; 
	if(s1>0 && s1<=12 && s2>0 && s2 <=12) cout << "AMBIGUOUS" << endl;
	else if((s1==0 || s1>12) && s2>0 && s2 <=12) cout << "YYMM" << endl;
	else if(s1>0 && s1<=12 && (s2==0 || s2 >12)) cout << "MMYY" << endl;
	else cout << "NA" << endl;
	return 0;
} 

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

template <typename T>
T smin(T x) {
	return x;
}
template <typename T, typename ...K>
T smin(T a, const K &...args) {
	return min(a, smin(args...));
}

const int N = 505;

const int mov[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int n;
int ans = 0;
int f[N][N];
int vis[N][N];
bool occupy[N][N];

queue<int> qx0, qy0, qx1, qy1;
void update(int x, int y) {
	static int dfc = 0;
	++dfc;
	qx0.push(x);
	qy0.push(y);
	while (!qx0.empty() || !qx1.empty()) {
		int ex = -1, ey = -1;
		if (!qx0.empty()) {
			ex = qx0.front();
			ey = qy0.front();
			qx0.pop();
			qy0.pop();
		} else {
			ex = qx1.front();
			ey = qy1.front();
			qx1.pop();
			qy1.pop();
		}
		if (vis[ex][ey] == dfc) {
			continue;
		}
		vis[ex][ey] = dfc;
		int w = f[ex][ey] + occupy[ex][ey];
		for (int i = 0; i < 4; i++) {
			int nx = ex + mov[i][0];
			int ny = ey + mov[i][1];
			if (nx >= 1 && nx <= n && ny >= 1 && ny <= n && w < f[nx][ny]) {
				f[nx][ny] = w;
				if (!occupy[ex][ey]) {
					qx0.push(nx);
					qy0.push(ny);
				} else {
					qx1.push(nx);
					qy1.push(ny);
				}
			}
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			f[i][j] = smin(i - 1, j - 1, n - i, n - j);
			occupy[i][j] = true;
		}
	}
	for (int i = 1, _ = n * n, t, x, y; i <= _; i++) {
		scanf("%d", &t);
		x = (t - 1) / n + 1;
		y = t - (x - 1) * n;
		ans += f[x][y];
		occupy[x][y] = false;
		update(x, y);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 6044
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    rep(i, n)
    {
        cin >> a[i + 1];
    }
    int cnt = 0;
    rep(i, n)
    {
        int tmp = 0;
        for (int j = n-i; j <= n; j += (n-i))
        {
            tmp += a[j];
        }
        if ((tmp % 2) != a[n-i])
        {
            a[n-i] = 1 - a[n-i];
        }
        if(a[n-i]==1)
            cnt++;
    }
    cout << cnt << endl;
    rep(i, n)
    {
        if(a[i+1]==1){
            cout << i + 1 << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 1792
h,n=map(int,input().split())

ab=[None]*n
for i in range(n):
    ab[i]=tuple(map(int,input().split()))

dp=[float('inf')]*(h+1)

for i in range(1,h+1):
    for a,b in ab:
        if 0 < i-a:
            dp[i]=min(dp[i], dp[i-a]+b)
        else:
            dp[i]=min(dp[i], b)
print(dp[h])

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t q;
    cin >> q;

    for (auto _ : irange(0L, q)) {
        int64_t a, b;
        cin >> a >> b;

        if (a > b) {
            swap(a, b);
        }

        auto c = a * b;

        int64_t s = sqrt(a * b);

        int64_t ans = 2 * s;

        if (s * s == c) {
            ans -= 2;
            --s;
        } else if (s * (s + 1) >= c) {
            --ans;
        }

        if (a <= s) {
            --ans;
        }

        cout << ans << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define ll long long
using namespace std;

int n;

void dfs(string s, char mx){
    if(s.size()==n) cout<<s<<endl;
    else{
        for(char i='a'; i<=mx; i++) dfs(s+i, ((i==mx) ? mx+1 : mx));
    }
}

int main(){
    cin>>n;
    dfs("",'a');
}

Measured memory_bytes: 3628
n,k,c = map(int, input().split())
s = input()

# 計算途中はi=0~n-1日とする

# [a,b] i日までで、限界まで働くとa回働けてb日まで働けない
pre = [[0,0] for i in range(n)]
if s[0]=='o':
    pre[0]=[1,c]
    for j in range(c):
        if 1+j < n:
            pre[1+j] = pre[0] + []

for i in range(1,n):
    if pre[i]==[0,0]:
        if s[i]=='o':
            pre[i][0]=pre[i-1][0]+1
            pre[i][1]+=i+c
            for j in range(c):
                if i+j+1<n:
                    pre[i+j+1]=pre[i]+[]
        else:
            pre[i]=pre[i-1]+[]

# i日以降で限界まで働くとa回働ける
post = [0 for i in range(n)]
if s[-1]=='o':
    post[-1]=1
    for j in range(c):
        if 0 <= n-1-j-1 < n:
            post[-1-j-1] = post[-1]

for i in range(1,n):
    if post[n-i-1]==0:
        if s[n-i-1]=='o':
            post[n-i-1]=post[n-i]+1
            for j in range(c):
                if 0<=n-i-1-j-1<n:
                    post[n-i-1-j-1]=post[n-i-1]
        else:
            post[n-i-1]=post[n-i]

# 0日、n+1日を追加。iを1~n日にする
pre = [[0,0]]+pre+[[0,0]]
post = [0]+post+[0]

# i日に休んだときに、働く回数がkに到達するか調べる
ans = []
for i in range(1,n+1):
    if s[i-1]=='o':
        work, rest = pre[i-1]
        day = min(max(rest,i)+1,n+1)
        work = work + post[day]
        if work<k:
            ans.append(i)

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 91112
#include <iostream>
#include <string>
#include <vector>
#include <utility>

template<long long MOD1 = 1000000007, long long MOD2 = 1000000009, class chartype = char>
class RollingHash{
	const std::string str;
	const size_t n;
	static constexpr long long base1 = 1009ll;
	static constexpr long long base2 = 1007ll;
	std::vector<long long> hash1;
	std::vector<long long> hash2;
	std::vector<long long> pow1;
	std::vector<long long> pow2;

	public:

	RollingHash(const std::string &s): str(s), n(s.size()), hash1(n+1,0), hash2(n+1,0), pow1(n+1,1), pow2(n+1,1){
		for(size_t i = 0; i < n; i++){
			hash1[i+1] = ((hash1[i]+(long long)str[i])*base1) % MOD1;
			hash2[i+1] = ((hash2[i]+(long long)str[i])*base2) % MOD2;
			pow1[i+1] = pow1[i] * base1 % MOD1;
			pow2[i+1] = pow2[i] * base2 % MOD2;
		}
	}

	std::pair<long, long> getKey(const size_t l, const size_t r)const{
		long long key1 = (hash1[r] - (hash1[l] * pow1[r-l] %MOD1) + MOD1) % MOD1;
		long long key2 = (hash2[r] - (hash2[l] * pow2[r-l] %MOD2) + MOD2) % MOD2;
		return std::make_pair(key1, key2);
	}

	bool match(const size_t l1, const size_t r1, const size_t l2, const size_t r2)const{
		return getKey(l1, r1) == getKey(l2, r2);
	}

};



	
std::ostream& operator<<(std::ostream &os, const std::pair<long long, long long> &t){
	os << t.first << ", " << t.second;
	return os;
}

signed main(){
	using namespace std;
	cin.tie(0);
	ios::sync_with_stdio(false);
	string t, p;
	cin >> t >> p;
	RollingHash<> tar(t), key(p);
	for(size_t i = 0; i + p.size() <= t.size(); i++){
//		cerr << i << ":" << tar.getKey(i, i+p.size()) << " | " << tar.getKey(0,p.size()) << endl;
		if(tar.getKey(i, i+p.size()) == key.getKey(0, p.size())){
			cout << i << endl;
		}
	}

	return 0;
}




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

int a[500][200000];

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    for(int i = 0; i < M; i++){
        int l, r;
        cin >> l >> r;
        l--; r--;
        a[l][r]++;
    }
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < 200000; j++){
            a[i][j] += a[i][j - 1];
        }
    }
    for(int i = 0; i < Q; i++){
        int p, q;
        cin >> p >> q;
        p--; q--;
        int ans = 0;
        for(int j = p; j <= q; j++){
            ans += a[j][q];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 391552
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;
#define def 0

int main() {
  ll n;
  cin >> n;
  vl a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  ll cnt = 0;
  for (int i = n - 1; i >= 0; i--) {
    ll ax = a[i] + cnt;
    if (ax % b[i] == 0) {
      continue;
    }
    cnt += b[i] - ax % b[i];
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
string answer = {};

void append(char x,int y){
	for(int i=0;i<y;i++){
		answer += x;
	}
}

int main(){
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	append('U',abs(ty-sy));
	append('R',abs(tx-sx));
	
	append('D',abs(ty-sy));
	append('L',abs(tx-sx));
	
	append('L',1);
	append('U',abs(ty-sy)+1);
	append('R',abs(tx-sx)+1);
	append('D',1);
	
	append('R',1);
	append('D',abs(ty-sy)+1);
	append('L',abs(tx-sx)+1);
	append('U',1);
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		String a=s.next(),b=s.next();
		
		if(a.equals(b)) {
			System.out.println("EQUAL");
			return;
		}
		
		int l=a.length()-b.length();
		
		if(l>0) {
			System.out.println("GREATER");
			return;
		}
		if(l<0) {
			System.out.println("LESS");
			return;
		}
		
		System.out.println(a.compareTo(b)>0?"GREATER":"LESS");
	}
}

Measured memory_bytes: 23892
#include<cstdio>
char*str[2]={"Second","First"};
struct edge{int to;edge*next;}E[200010],*ne,*first[100010];
int Q[100010],deg[100010];
void link(int u,int v){*ne=(edge){v,first[u]};first[u]=ne++;deg[v]++;}
bool del[100010];
int solve(){
	int N;scanf("%d",&N);ne=E;
	for(int i=1;i<=N;i++)first[i]=0,deg[i]=del[i]=0;
	for(int i=1,u,v;i<N;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
	int*h=Q,*t=Q;
	for(int i=1;i<=N;i++)if(deg[i]<2)*t++=i;
	for(;h<t;h++)if(!del[*h]){
		int x=-1;
		for(edge*e=first[*h];e&&x<0;e=e->next)
			if(!del[e->to])--deg[x=e->to];
		if(x<0)return 1;
		del[*h]=del[x]=1;
		for(edge*e=first[x];e;e=e->next)
			if(!del[e->to]&&--deg[e->to]==1)*t++=e->to;
	}
	return 0;
}
int main(){
	puts(str[solve()]);
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

void yes(){
   cout<<"Yes"<<endl;
   //exit (0);
}
void no(){
   cout<<"No"<<endl;
   //exit (0);   
}

int n, a[N], m;
string s, t;

int32_t main(){_
   
  cin >> n >> m;

  int sum=  0;

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

  long double match = (long double)sum / (long double)(4*m);
  for (int i = 0; i < n; ++i)
  {
    if (a[i] >= match){
       how++;
     } 
  }

  if (how >= m){
    yes();
  }
  else{
    no();
  }


   return 0;
}

Measured memory_bytes: 256
//#define DEBUG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))

#define fi first
#define sc second 
#define pb push_back


#ifdef DEBUG
    #define dbg(s) {s;}
    #define PRELUDE
#endif

#ifndef DEBUG 
    #define PRELUDE { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define dbg(s)
    #define endl "\n"
#endif

#define int ll
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).

#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;

// To remove randomization use 0 below:
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int x) { // from [0, n-1]
    return uniform_int_distribution<int>(0, x - 1)(rng);
}

inline ld rf() { // from [0, 1]
    return uniform_real_distribution<ld>(0, 1)(rng);
}

ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 

const ll mod = 1e9 + 7;

ll modexp(ll x, ll ex) {
    x = x%mod;
    ex = ex % (mod-1);
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int maxn = 1e5 + 7;

const ll inf = 1e9 + 7;

int ans[maxn];
int h[maxn];

void solve()
{
    int n;
    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>h[i];
    ans[1] = 0;
    for(int i=2;i<=n;i++)
    {
        if(i==2)
            ans[i] = ans[i-1] + abs(h[i]-h[i-1]);
        else
            ans[i] = min(ans[i-1] + abs(h[i]-h[i-1]),ans[i-2] + abs(h[i]-h[i-2]) );
    }

    cout<<ans[n]<<endl;
}

i32 main() {
    //freopen("<file>.in", "r", stdin);
    //freopen("<file>.out", "w", stdout);
    
    PRELUDE;
    int t = 1;
    //cin>>t;
    while(t--)
        solve();
}


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

int main(void){
  int n;
  cin >> n;
  vector<int> data; data.resize(n,0);
  
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    data[i] = x;
  }
  sort(data.begin(),data.end());
  
  int sum = 0;
  for(int i = 0; i < n; i++){
    if(i==n-1){
      sum += data[i]/2;
    }else{
      sum += data[i];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define LL long long

char ss[27]={"abcdefghijklmnopqrstuvwxyz"};
char s[200005];
int main()
{
    while (~scanf("%s",s))
    {
        LL ans;
        LL len= strlen(s);
        LL d[26];
        memset(d,0,sizeof(d));
        ans=len*(len-1)/2;
        ans++;
        for(LL i = 0;i < len; i++)
        {
            for(LL j = 0;j < 26; j++)
            {
                if(s[i]==ss[j])
                    d[j]++;
            }
        }
        for(LL j = 0;j < 26; j++)
        {
            for(LL k = d[j]-1;k >= 1; k--)
            {
                ans-=k;
            }
        }
        
        
        printf("%lld\n",ans);
        memset(s,0,sizeof(s));
    }
    
}

Measured memory_bytes: 384
Input = input().split()

Operator = ["+","-","*"]
stack = []

for i in Input:
    if i in Operator:
        y = stack.pop()
        x = stack.pop()
        tmp = eval(x+i+y)
        stack.append(str(tmp))

    else:
        stack.append(i)

print(stack.pop())



Measured memory_bytes: 5564
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    int K = scanner.nextInt() - 1;
    long res = 1;
    for (int i = 0; i < K; i++) {
      res = next(res);
    }
    System.out.println(res);
  }

  private static long next(long num) {
    List<Integer> digits = new ArrayList<>();
    while (num > 0) {
      digits.add((int) (num % 10));
      num /= 10;
    }
    int i = 0;
    while (i < digits.size() - 1 && (digits.get(i) > digits.get(i + 1) || digits.get(i) == 9)) i++;
    if (digits.get(i) != 9) {
      digits.set(i, digits.get(i) + 1);
    } else {
      digits.set(i, 0);
      digits.add(1);
    }
    while (i > 0) {
      digits.set(i - 1, Math.max(0, digits.get(i) - 1));
      i--;
    }
    long res = 0;
    long d = 1;
    for (int j = 0; j < digits.size(); j++) {
      res += digits.get(j) * d;
      d *= 10;
    }
    return res;
  }
}


Measured memory_bytes: 31608
#include<stdio.h>
int main(void)
{
    int x[10],i,n,y;
	for(i=0;i<10;i++){
	scanf("%d",&x[i]);
	}
	for(i=0;i<9;i++){
	    for(n=i+1;n<10;n++){
			if(x[i]<x[n]){
				y=x[i];
				x[i]=x[n];
				x[n]=y;
			}
		}
	}
	for(i=0;i<3;i++){
	printf("%d\n",x[i]);
	}
	return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int cnt = 0;
  int sum = 1;
  
  while (true) {
    
    if (b <= sum) {
      cout << cnt << endl;
      break;
    }
    sum += a;
    sum -= 1;
    cnt += 1;
  }
}

Measured memory_bytes: 384
N,M = map(int,input().split())

Seito = [tuple(map(int,input().split())) for i in range(N)]

Check = [tuple(map(int,input().split())) for i in range(M)]

for a,b in Seito:
	dist = [abs(a-c)+abs(b-d) for c,d in Check]
	print(dist.index(min(dist))+1)


Measured memory_bytes: 3060
s = input()
ans = float("inf")

for v in [1,2]:
  count = 0
  for i,c in enumerate(s):
    if (i+v) % 2 == 0:
      if c == "1":
        count += 1
    else:
      if c == "0":
        count += 1
  ans = min(count,ans)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    scanf("%d", &n);
    std::set<unsigned long int> s;
    for(int i=0; i<n; i++) {
        unsigned long int a;
        scanf("%lu", &a);
        if( s.find(a) != s.end() )
        {
            // 紙に数字が存在するとき
            s.erase(a);
        } else {
            s.insert(a);
        }
    }
    std::cout << s.size() << std::endl;
    return 0;
}

Measured memory_bytes: 4992
// atcoder/abc150/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }



int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> p(n);
    vector<int> q(n);
    cin >> p >> q;

    int a = 0;
    int b = 0;
    int cnt = 0;

    vector<int> v = p;
    sort(v.begin(), v.end());
    do {
      if (v == p) a = cnt;
      if (v == q) b = cnt;
      ++cnt;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a - b) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
 
public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int inpt = int.Parse(Reader.ReadLine());

        int ans = inpt*800 - (inpt/15)*200;
        Console.WriteLine(ans);
    }


    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"



20


";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 11092
N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]

from math import ceil

ng,ok = 0,10**9+1
while abs(ok-ng)>1:
    mid = (ng+ok)//2
    cnt = 0
    for i in range(N):
        cnt += max(ceil((H[i] - B*mid)/(A-B)) ,0)
    if cnt <= mid:
        ok = mid
    else:
        ng = mid

print(ok)

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

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

   int q, b; cin >> q >> b;
   if (10 <= q+b)
   {
      cout << "error\n";
//      cout << ans << '\n';
   }
   else
      cout << (q+b) << "\n";
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pair<int, int>>
#define er(n) cout<<"error "<<n<<endl;
int mod=1000000007;

int compute(string s){
    int ans=0;
    string temp;
    for (auto i:s){
        if (i=='+') {
            ans+=stoll(temp);
            temp="";
        }
        else temp+=i;
    }
    ans+=stoll(temp);
    return ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.size()-1, ans=0;
    for (int i=0 ; i<(1<<n) ; i++){
        int j=i;
        string temp;
        temp+=s[0];
        for (int k=1 ; k<=n ; k++){
            if ((j&1LL)==0) temp+=s[k];
            else temp=temp+"+"+s[k];
            j>>=1;
        }
        ans+=compute(temp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=100000+10;
int n,k;
int a[maxn];

int C(int m)
{
    int j=k;
    int i=0;

    while(j--)
    {
          int sum=0;
        while(sum+a[i]<=m)
        {
            sum+=a[i++];
            if(i==n) return n;
        }
    }
    return i;
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int left=0,right=maxn*10000;
    while(right-left>1)
    {
        int mid=(left+right)/2;
        if(C(mid)<n) left=mid;
        else right=mid;
    }
    printf("%d\n",right);


    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	char c = '1';
	int cur = 0;
	vi V;
	queue<int> Q;
	REP(i, N) {
		if (S[i] == c) {
			cur++;
		}
		else {
			V.push_back(cur);
			cur = 1;
			c = S[i];
		}
	}
	V.push_back(cur);
	int ind = 0;
	int sum = 0;
	int ans = 0;
	while (ind < SZ(V)) {
		chmax(ans, sum + V[ind]);
		if (ind == SZ(V) - 1)break;
		sum += V[ind] + V[ind + 1];
		Q.push(V[ind] + V[ind + 1]);
		if (SZ(Q) > K) {
			sum -= Q.front();
			Q.pop();
		}
		ind += 2;
	}
	chmax(ans, sum);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1020
N=input()
def waru(num):
    return int(num)//400
a = list(map(waru, input().split()))
b = []
num = 0
for i in a:
    if i >= 8:
        b.append(i)
minu = len(set(a)) - len(set(b))
if minu==0:
    minu = 1
    maxi = len(b)
else:
    maxi = len(b)+minu
print(minu, maxi)


Measured memory_bytes: 3060
#C問題
N = int(input())
H = list(map(int,input().split()))

count = 0
L = -1
R = N
M = max(H)
for i in range(M):
    wflag = 0
    for j in range(N):
        if H[j] >= 1:
            wflag = 1
            H[j]-=1
        else:
            if wflag == 1:
                count+=1
                wflag = 0
            else:
                pass
    if wflag == 1:
        count+=1
                
print(count)
                
        
                
                    

Measured memory_bytes: 3064
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end


N,K=gets.chomp.split(' ').map{|n| n.to_i}
S=gets.chomp.split(' ').map{|n| n.to_i}
if(N<K)
	puts 1
	exit(0)
end
puts 1+((N-K)*1.0/(K-1)).ceil


Measured memory_bytes: 8956
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		
		for(;;) {
			LinkedList<Character> stack = new LinkedList<Character>();
			boolean flg = true;
			String str = sc.nextLine();
			sc.useDelimiter("\\n");
			if(str.equals(".")) break;
//			System.out.println(str);
			for(int i=0;i<str.length();i++) {
				if( str.charAt(i) == '(' || str.charAt(i) == '[' ) 
					stack.addLast(str.charAt(i));
				else if (str.charAt(i) == ')') {
					if( !stack.isEmpty() && stack.removeLast() == '(' );
					else {
						flg = false;
						break;
					}
				}
				else if (str.charAt(i) == ']') {
					if( !stack.isEmpty() && stack.removeLast() == '[' );
					else {
						flg = false;
						break;
					}
				}
			}
			if(flg) {
				if( stack.isEmpty() ) System.out.println("yes");
				else System.out.println("no");
			}
			else {
				System.out.println("no");
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int n;
int c[500],s[500],f[500];

int solve(int pos){
  int t = 0;
  while(pos < n-1){
    if(t < s[pos]){
      t = s[pos] + c[pos];
      pos++;
    } else {
      int x = (t+f[pos]-1)/f[pos];
      t = x*f[pos] + c[pos];
      pos++;
    }
  }
  return t;
}

int main(){
  cin >> n;
  for(int i = 0; i < n-1; ++i){
    cin >> c[i] >> s[i] >> f[i];
  }
  for(int i = 0; i < n; ++i){
    cout << solve(i) << endl;
  }  
}



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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& vec){
    os << "[";
    for(const auto& v : vec){
        os << v << ",";
    }
    os << "]";
    return os;
}

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

int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(ALL(a));
    if(a[0]==5 and a[1]==5 and a[2]==7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

int main() {
    int i, j, k, N = 0;
    vector<vector<int> > vec;
    int arr[2];

    do {
        cin >> arr[0] >> arr[1];
        vec.push_back(vector<int>(arr, (arr+sizeof(int))));
        ++N;
    } while(arr[0] != 0 && arr[1] != 0);

    for(i=0; i<(N-1); ++i) {
        for(j=0; j<vec[i][0]; ++j) {
            for(k=0; k<vec[i][1]; ++k) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n,x;
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>x;
  int cnt=0;
  while(n){
    ++cnt;
    n/=x;
  }
  cout<<cnt<<'\n';
  return 0;
}

Measured memory_bytes: 256
import numpy as np

N, K = map(int, input().split())
H = list(map(int, input().split()))

if N > K != 0:
    H_array = np.array(H).reshape(-1)

    H_array_sorted = np.sort(H_array)

    H_remain = H_array_sorted[:(N - K)]

    H_sum = np.sum(H_remain)

    print(H_sum)
elif K == 0:
    print(sum(H))
else:
    print(0)


Measured memory_bytes: 34192
import math
a,b,ab,x,y = map(int,input().split())

if a+b<2*ab:
  print(a*x+b*y)
else:
  amount = min(min(x,y)*2*ab+ (abs(x-y))*(a if x>y else b),max(x,y)*2*ab)
  print(amount)

Measured memory_bytes: 3060
#include <iostream>
#include <map>
using namespace std;
int main(){
  char a,b;
  int n, m;

  while(true){
    map<char,char> mp;
    cin >> n;
    if( !n )
      break;
    while( n-- ){
      cin >> a >> b;
      mp[a] = b;
    }

    cin >> m;
    while( m-- ){
      cin >> a;
      if( mp.find(a) == mp.end() )
	cout << a;
      else
	cout << mp[a];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1192
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
    }

    int ans = 0;
    REP(i, 1, n - 1){
        if(p[i] == p[i - 1] + p[i] + p[i + 1] - max({p[i - 1], p[i], p[i + 1]}) - min({p[i - 1], p[i], p[i + 1]})){
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"



int main(int argc, char const *argv[])
{

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    string str;
    cin>>k;
    cin>>str;
    if(k>=str.length()){
        cout<<str;
    }
    else{
        cout<<str.substr(0,k)<<"...";
    }

    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)  //最大公約数
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

long power(long x, int n) { //x^n 計算量O(logn)
	long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

int choose(int n, int k) {
	return k == 0 ? 1 : (long long)choose(n - 1, k - 1) * n % MOD * power(k, MOD - 2) % MOD;
}

void bubble_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 0; i < n; i++)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = n - 1; j > i; j--)
		{
			if (a[j - 1] > a[j])
			{
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
		printf("\n");
	}
}

void selection_sort(int a[], int n)
{
	int i, j, tmp, min, key;

	for (i = 0; i < n - 1; i++)
	{
		min = i;
		key = a[i];

		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = i + 1; j < n; j++)
		{
			if (a[j] < a[min])
			{
				min = j;
				key = a[j];
			}
		}

		tmp = a[i];
		a[i] = a[min];
		a[min] = tmp;

		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

void insertion_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 1; i < n; i++)
	{
		j = i;

		while (j >= 1 && a[j - 1] > a[j])
		{
			tmp = a[j];
			a[j] = a[j - 1];
			a[j - 1] = tmp;
			j--;
		}
	}
}

void shell_sort(int a[], int n)
{
	int h, i, j;

	for (h = 1; h < n / 9; h = h * 3 + 1)
		;

	for (; h > 0; h /= 3)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (i = h; i < n; i++)
		{
			j = i;
			while (j >= h && a[j - h] > a[j])
			{
				swap(&a[j - h], &a[j]);
				j -= h;
			}
		}
		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

int partition(int a[], int l, int r)
{
	int i, j, pivot;

	i = l - 1;
	j = r;
	pivot = a[r];

	for (;;)
	{
		while (a[++i] < pivot)
			;
		while (i < j-- && pivot < a[j])
			;

		if (i >= j)
			break;

		swap(&a[i], &a[j]);
	}

	swap(&a[i], &a[r]);
	return i;
}

void quick_sort1(int a[], int l, int r)
{
	int v;

	if (l >= r)
		return;

	v = partition(a, l, r);

	quick_sort1(a, l, v - 1);
	quick_sort1(a, v + 1, r);
}

void quick_sort(int a[], int n)
{
	quick_sort1(a, 0, n - 1);
}

int keta(int a, int n)
{
	if (n == 1)
		return a % 10;

	for (int i = 0; i < n - 1; i++)
		a /= 10;

	return a % 10;
}

int main()
{
	int N,M, L, K;
	int a[50] = { 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", &K);
	
	

	printf("%d",a[K-1]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
	int n,sum=0;
	cin>>n;
	int y=n;
	while(n>0){
		sum+=n%10;
		n=n/10;
	}
	if(y%sum==0)
	  cout<<"Yes"<<endl;
	else
	  cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.*;

/**
 * Created by Seiya on 2016/10/16.
 */
public class Main {

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

        String t = scanner.next();
        String s = new String();


        String[] mozi = new String[4];

        mozi[0] = "dream";
        mozi[1] = "dreamer";
        mozi[2] = "erase";
        mozi[3] = "eraser";

        int ok = -1;
        String temp = new String();
        int min;
        int len = t.length();
        while(ok == -1){

            for (int i = 0; i < 4; i++) {
                min = Math.min(len, mozi[i].length());
                 temp = t.substring(len - min, len);
                if(temp.equals(mozi[i])){
                    len -= min;
                    ok = -1;
                    break;
                }
                ok = 0;
            }
            if(len == 0){
                ok = 1;
            }

        }
        if(ok == 0){
            System.out.println("NO");
        }else {
            System.out.println("YES");
        }


    }


    public static String reverse(String s){
        String ans = new String();

        for (int i = s.length() - 1; i >= 0; i--) {
            ans = ans + s.charAt(i);
        }

        return ans;
    }
}




Measured memory_bytes: 16148
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d[256];
  cin>>a>>b;
  if(a%3==0 || b%3==0){
    cout<<"Possible"<<'\n';
  }
  else if((a+b)%3==0){
    cout<<"Possible"<<'\n';
  }
  else{
    cout<<"Impossible"<<'\n';
  }
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
X = [int(i) for i in input().split()]
ans = 10000000000000000
for i in range(N-K+1):
  a = min(abs(X[i])+abs(X[i+K-1]-X[i]), abs(X[i+K-1])+abs(X[i]-X[i+K-1]))
  ans = min(a, ans)
print(ans)

Measured memory_bytes: 14224
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<string>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

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


ll COM(ll x) {
    return x * (x - 1) / 2;
}


int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h)cin >> s[i];
    int res = (w - 1) * (h - 1);
    for (uint i = 0; ((i >> (h - 1)) & 1) != 1; ++i) {
        vector<bool> yoko(h - 1);
        for (uint j = 0; j < h - 1; ++j) yoko[j] = (((i >> j) & 1) == 1);
        int yokoc = 0;
        int tatec = 0;
        rep(j, h - 1) if (yoko[j]) yokoc++;

        vector<int> inds(h);
        int indsc = 0;
        rep(j, h) {
            if (j == 0) inds[j] = 0;
            else if (yoko[j - 1]) {
                indsc++;
                inds[j] = indsc;
            }
            else inds[j] = inds[j - 1];
        }

        vector<int> cnts(indsc + 1);
        int last_tate = -1;
        for (int j = 0; j < w; ++j) {
            for (int p = 0; p < h; ++p) {
                if (s[p][j] == '1') cnts[inds[p]]++;
            }
            rep(p, indsc + 1) {
                if (cnts[p] > k) {
                    if (last_tate == j - 1) goto LOOPEND;
                    last_tate = j - 1;
                    tatec++;
                    rep(_p, indsc + 1) cnts[_p] = 0;
                    for (int _p = 0; _p < h; ++_p) {
                        if (s[_p][j] == '1') cnts[inds[_p]]++;
                    }
                    rep(_p, indsc + 1) if (cnts[_p] > k) goto LOOPEND;
                    break;
                }
            }
        }
        res = min(res, tatec + yokoc);
    LOOPEND:
        continue;
    }
    cout << res << endl;
    return 0;
}



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

int main(){
    int A[3],ans=0;
    for(int i=0;i<3;i++){
        cin>>A[i];
    }
    sort(A,A+3);
    for(int i=1;i<3;i++){
        ans+=A[i]-A[i-1];
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
const int N=2e5+5,mod=1e9+7;
#define ll long long
bool vis[N];
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(ll i=2;i<N;i++)if(!vis[i])
    {
        if(i>=n) return cout<<i<<endl,0;
        for(ll j=i*i;j<N;j+=i)
            vis[j]=1;
    }

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<math.h>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main(){
    int n;
    long long sum1=0,sum2=0;
    long long ans1=0,ans2=0;
    int a[100005];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        sum1+=a[i];
        sum2+=a[i];
        if(i%2==0){
            if(sum1<=0){
                ans1+=1-sum1;
                sum1=1;
            }
            if(sum2>=0){
                ans2+=sum2+1;
                sum2=-1;
            }
        }else{
            if(sum1>=0){
                ans1+=sum1+1;
                sum1=-1;
            }
            if(sum2<=0){
                ans2+=1-sum2;
                sum2=1;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
}


Measured memory_bytes: 640