akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, x);
    constexpr int N = 120;
    for(ll a = -N; a <= N; a ++){
        for(ll b = -N; b <= N; b ++){
            if(a*a*a*a*a - b*b*b*b*b == x){
                Cout(a, " ", b);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> a;
  rep(i,32000){
    ll y=i+1;
    if(y*y>n)break;
    a.push_back(y);
    if(y!=n/y)a.push_back(n/y);
  }
  //cout << 1 << endl;
  sort(a.begin(),a.end());
  //cout << 1 << endl;
  vector<ll> b(a.size(),1);
  //cout << a.size() << endl;
  //cout << 1 << endl;
  rep(i,a.size()-1){
    b[i+1]=a[i+1]-a[i];
  }
  ll p=1000000007;
  ll dp[k+1][a.size()];
  rep(i,k+1)rep(j,a.size())dp[i][j]=0;
  dp[0][0]=1;
  //cout << 1 << endl;
  rep(i,k){
    rep(j,a.size()-1)dp[i][1+j]+=dp[i][j];
    rep(j,a.size())dp[i+1][j]=(b[j]*dp[i][a.size()-1-j])%p;
  }
  ll ans=0;
  rep(i,a.size()){
    ans=(ans+dp[k][i])%p;
  }
  cout << ans << endl;
  //rep(i,k){
  //  rep(j,a.size()-1)cout << dp[i+1][j] << " ";
  //  cout << dp[i+1][a.size()-1] << endl;
  //}
}


Measured memory_bytes: 54040
import math


def calc_minkowski_distance(data_x, data_y, types):
    # ???????´???????????¨???????map???????????¬??????????????????????????¨????????¨????????§?¶???????????????????????????§????????????????????????
    distance = list(map(lambda x, y:abs(x - y), data_x, data_y))

    results = []
    for t in types:
        if t == 'Inf':
            results.append(max(distance))
        else:
            temp = map(lambda x:math.pow(x, t), distance)
            total = sum(temp)
            results.append(math.pow(total, 1.0/t))
    return results


if __name__ == '__main__':
    # ??????????????\???
    # data_x = [1, 2, 3]
    # data_y = [2, 0, 4]
    num = int(input())
    data_x = [int(x) for x in input().split(' ')]
    data_y = [int(x) for x in input().split(' ')]

    # ???????????????
    types = [1, 2, 3, 'Inf']  # math.inf???python3.5??\?????????
    results = calc_minkowski_distance(data_x, data_y, types)

    # ???????????¨???
    for r in results:
        print('{0:.8f}'.format(r))

Measured memory_bytes: 7884
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++)
    cin>>s[i];
    int a[4]={0};
    for(int i=0;i<n;i++)
    {
        if(s[i]=="AC")
        a[0]++;
        else if(s[i]=="WA")
        a[1]++;
        else if(s[i]=="TLE")
        a[2]++;
        else
        a[3]++;
    }
    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3]<<endl;
}

Measured memory_bytes: 6740
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        bool ok=true;
        for(int j=0;j<s.size()/2;j++){
            if(s.at(j)!=s.at(s.size()-1-j)){
                ok=false;
                break;
            }
        }
        if(ok) ans++;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n, 0), s(n + 1, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
	}
	sort(a.begin(), a.end());
	vector<P> p(m);
	for (int i = 0; i < m; i++) {
		ll b, c;
		cin >> b >> c;
		p[i] = P(c, b);
	}
	sort(p.begin(), p.end(), greater<P>());
	ll cnt = 0;
	ll tmp = 0;
	for (int i = 0; i < n; i++) {
		if (p[cnt].first > a[i] && tmp < p[cnt].second) {
			a[i] = p[cnt].first;
			tmp++;
			if (tmp == p[cnt].second) {
				cnt++;
				tmp = 0;
				if (cnt == m) break;
			}
		}
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	dump(sum);
	return 0;
}

Measured memory_bytes: 3456
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()


def main():
    N,R = isRaw()
    if N < 10:
        return R + 100*(10-N)
    else:
        return R


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=2010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,K,s[N][N]; char op[3];
inline int F(int x,int y,int p,int q)
{
    return s[p][q]-s[p][y]-s[x][q]+s[x][y];
}
signed main()
{
    n=read(), K=read();
    for(ri int i=1;i<=n;i++)
    {
        int x,y;
        scanf("%lld%lld%s",&x,&y,op);
        x%=(K*2), y%=(K*2);
        if(op[0]=='B') y+=K, y%=(K*2);
        s[x+1][y+1]++;
    }
    for(ri int i=1;i<=K+K;i++)
    for(ri int j=1;j<=K+K;j++)
    s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
    
    int res=0;
    for(ri int i=1;i<=K;i++)
    for(ri int j=1;j<=K;j++)
    {
        int qwq=0;
        qwq+=F(0,0,i,j)+F(i,j,i+K,j+K)+F(i+K,j+K,K*2,K*2)+F(i+K,0,K*2,j)+F(0,j+K,i,K*2);
        res=max(res,max(qwq,n-qwq));
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 35188
X,Y = list(map(int,input().split()))
N = list(map(int,input().split()))

if(X >= Y):
    print(0)
else:
    N.sort()
    M = []
    for i in range(1,Y):
        M.append(N[i] - N[i-1])

    M.sort(reverse=True)
    O = sum(M[0:X-1])
    print(sum(M)-O)

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

#include <boost/algorithm/string/classification.hpp>  // is_any_of
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/math/tools/minima.hpp>
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::algorithm::split;
using boost::math::tools::brent_find_minima;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;
// TOP
void Main()
{
	string s;
	cin >> s;

	ll cnt;
	cnt = 0;
	ll ans;
	ans = 0;
	ll n = s.size();
	rep(i, n)
	{
		if (s.at(i) == 'W')
		{
			ans += (i - cnt);
			cnt++;
		}
	}
	cout << ans << endl;
}
// END

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


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

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

while(h != 0 && w != 0)
{
    for (x = 0; x < h; x++)
    {
        for (y = 0; y < w; y++)
        {
            cout << "#";
        }
        cout << endl;
    }
    cout << endl;
    cin >> h >> w;
}
    return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>

void PriLine(int a[],int n){
	printf("%d", a[0]);
	for(int i = 1;i < n; i++)
		printf(" %d", a[i]);
	printf("\n");
}

void swap(int &a,int &b){
	int m;
	m = a;
	a = b;
	b = m;
}

int main(){
	int i, mini, j, n, A[100];
	
	while(scanf("%d", &n) != EOF){
		for(i = 0;i < n; i++)
			scanf("%d", &A[i]);
		int num = 0;
		for(i = 0;i < n; i++){
			mini = i;
			for(j = i+1;j < n; j++)
				if(A[j] < A[mini])
					mini = j;
			if(mini != i) num++;					
			swap(A[i],A[mini]);
		} 
        PriLine(A,n);
		printf("%d\n", num);
	}
	
	return 0;
}


Measured memory_bytes: 2732
N = int(input())
As = list(map(int, input().split()))
sum_ = sum(As)
ave = float(sum_)/2
diffs = [float('inf')]*(N-1)

mysum = 0
for i in range(N-1):
    mysum += As[i]
    diffs[i] = abs(ave-mysum)

print(int(2*min(diffs)))

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

// edit by  (xcode)

using namespace std;

#define int         long long
#define ll          long long
#define double      long double
#define pb          push_back
#define in          insert
#define mp          make_pair
#define f           first
#define s           second
//#define x           first
//#define y           second
#define all(el)     el.begin(), el.end()
#define allr(el)    el.rbegin(), el.rend()
#define sz(el)      (int)el.size()
#define endl        "\n"

inline int chkmax(int &x, int y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

inline int chkmin(int &x, int y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

signed main() {
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> used(n), p;
    int st = 0;
    used[st] = 1;
    p.pb(st);
    st = a[st];
    while (!used[st]) {
        p.pb(st);
        used[st] = 1;
        st = a[st];
    }
    vector<int> cycle;
    int pos;
    for (int i = 0; i < sz(p); i++) {
        if (p[i] == st) {
            pos = i;
            break;
        }
    }
    for (int i = pos; i < sz(p); i++) {
        cycle.pb(p[i]);
    }
    if (k <= pos) {
        cout << p[k] + 1;
    } else {
        k -= pos;
        cout << cycle[k % sz(cycle)] + 1;
    }
    return 0;
}



Measured memory_bytes: 10780
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		double Kg,M;
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String[] s = sc.next().split(",");
			Kg = Double.parseDouble(s[1]);
			M = Double.parseDouble(s[2]);
			if(Kg / (M * M) >= 25){
				System.out.println(s[0]);
			}
		}

	}

}

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

int dig(ll x){
    int res=0;
    while(x!=0){
        x/=10;
        res++;
    }
    return res;
}


int main() {
    ll N; cin >> N;
    ll ans = 1e18;
    for(ll i = 1; i*i<=N; i++){
        if(N%i == 0){
            ll x = i;
            ll y = N / i;
            ll temp = max(dig(x), dig(y));
            ans = min(ans, temp);

        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char[] s = sc.next().toCharArray();
		int w = sc.nextInt();
		for (int i = 0; i < s.length; i = i + w) {
			sb.append(s[i]);
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 23252
def is_prime(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif n%2 == 0:
        return False
    for i in range(3, int(n**0.5)+1,2):
        if n % i == 0:
            return False
    return True
count=0
n=int(input())
for i in range(n):
    if is_prime(int(input())):count+=1
print(count)



Measured memory_bytes: 5676
# -*- coding: utf-8 -*-
from copy import deepcopy


def main():
    s = input()

    s_list = list(s)
    one_result = True
    two_result = True
    for i in range(len(s_list)):
        if i % 2 == 0:
            if s_list[i] == 'L':
                one_result = False
        else:
            if s_list[i] == 'R':
                two_result = False

    if one_result and two_result:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int main() {
  int n;
  cin >> n;
  vi dp(n+10, 0);
  dp[0] = 1;
  rep (i, n) {
    if (dp[i] == 0) {
      continue;
    }
    dp[i+4] = 1;
    dp[i+7] = 1;
  }
  if (dp[n] == 1) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<P> c1; //fueru
  vector<P> c2; //heru
  int op=0;
  int cl=0;
  rep(i,n){
    string s; cin >> s;
    int m = s.size();
    int a=0, b=0;
    rep(j,m){
      if(s[j]=='('){
        a++; 
      } else {
        if(a==0){ b++; }else{ a--; }
      }
    }
    if(a==0&&b==0) continue;
    if(a==0){ cl+=b; continue; }
    if(b==0){ op+=a; continue; }
    if(a>=b){ c1.emplace_back(b,a); } else { c2.emplace_back(b,b-a); }
  }
  sort(c1.begin(),c1.end());
  sort(c2.rbegin(),c2.rend());
  for(auto it:c1){
    if(op>=it.F){
      op = op-it.F+it.S;
    } else {
      cout << "No" << endl; return 0;
    }
  }
  for(auto it:c2){
    if(op>=it.F){
      op = op-it.S;
    } else {
      cout << "No" << endl; return 0;
    }
  }
  if(op==cl){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    float a,b,c;
    int ans=3;
    cin>>a>>b>>c;

    if(a==b){
        ans--;
    }
    if(a==c){
        ans--;
    }
    if(b==c){
        if(ans!=1){
            ans--;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

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

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

    vector<ll> B(N - 1), A(N, 0);

    rep(i, N - 1) {
        cin >> B[i];
    }

    if (N == 2) {
        cout << B[0] + B[0] << endl;
        return 0;
    }

    A[0] = B[0];

    ll ans = A[0];

    for (ll i = 1; i < N - 1; ++i) {
        A[i] = min(B[i], B[i - 1]);
        ans += A[i];
    }

    ans += B.back();

    cout << ans << endl;
}

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

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF (1<<30)

ll N, A, B, C, D;
bool f = false;

int main() {
	cin >> N >> A >> B >> C >> D;

	ll u=A, d=A;
	for (int i = 1; i < N; i++) {
		ll mid = (u+d)/2;
		if (mid <= B) {
			u += D;
			d += C;
		}
		else {
			u -= C;
			d -= D;
		}
	}
	if(d<=B && B<=u) f=true;

	cout << (f?"YES":"NO") << endl;
}



Measured memory_bytes: 384
#pragma warning (disable:4996)
#include <stdio.h>
#include <string.h>

int inputStr(char *str){
	scanf(" %s", str);
	if (!strcmp(str, "-")) return 0;
}
void sortStr(char *str){
	int num, h;
	char tmp[256];
	scanf("%d", &num);
	while (num--){
		scanf("%d", &h);
		strcpy(tmp, str);
		strcpy(str, tmp + h);
		strncat(str, tmp, h);
	}
}
int main(void){
	char str[256];
	while (inputStr(str)){
		sortStr(str);
		printf("%s\n", str);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef pair<int, int> ii;
typedef long long int64;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
	string str = to_string(i);
	ans += str.size() % 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sn = new Scanner(System.in);
        int A = sn.nextInt();
        int B = sn.nextInt();
        int H = sn.nextInt();
        int M = sn.nextInt();

        double HDgree = M*6;
        double MDgree = H*30;
        double Dgree = 0;
        double n = 0.5*M;

        MDgree = MDgree + n;
        
        if(HDgree > MDgree){
            Dgree = HDgree - MDgree;
        }else{
            Dgree = MDgree - HDgree;
        }
        
        Dgree = Math.abs(Dgree);

        double c = Math.pow(A, 2) + Math.pow(B, 2) - 2*A*B*Math.cos(Math.toRadians(Dgree));

        double result = Math.sqrt(c);

        System.out.println(result);
    }
}

Measured memory_bytes: 36048
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


ll mpow(ll x, ll n) { //x^n(mod M)
    ll ans = 1;
    while (n != 0) {
        if (n & 1) ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x) {
    return mpow(x, MOD - 2);
}

int n;
vector<vector<int> > g;
ll ans;

int dfs(int par, int curr)
{
    int siz=(int)g[curr].size();
    int sum=0;
    vector<int> z;
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(par==next) continue;
        int ret=dfs(curr, next);
        z.push_back(ret);
        sum+=ret;
    }
    z.push_back(n-1-sum);
    ll ans0=0;
    for(i=0; i<(int)z.size(); i++) {
        ll tmp0=mpow(2,z[i]);
        tmp0=(tmp0-1+MOD)%MOD;
        ans0=(ans0+tmp0)%MOD;
    }
    ans0=(mpow(2,n-1)-ans0-1+MOD)%MOD;
    ans=(ans+ans0)%MOD;

    sum++;
    return sum;
}

void solve()
{
    scanf("%d", &n);
    g.resize(n);
    int i;
    for (i = 0; i < n - 1; i++) {
        int a,b;
        scanf("%d%d", &a, &b); a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ans=0;
    int ret=dfs(-1,0);
    assert(ret==n);
    ans=ans*minv(mpow(2,n))%MOD;
    printf("%lld\n", ans);

	return;
}


int main(int argc, char* argv[])
{
#if 1
	solve();
#else
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 27008
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> D(N);
    for (int n = 0; n < N; ++n) cin >> D[n];
    
    if (N%2 ==1) {
        cout << 0 << endl;
        return 0;
    }
    
    sort(D.begin(), D.end());
    cout << D[N/2] - D[N/2-1] << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    V<> c(n + 1);
    for (int i = 0; i < n - 1; ++i)
    {
        c[i + 1] = c[i] + (s[i] == 'A' and s[i + 1] == 'C');
    }
    while (q--)
    {
        int l, r;
        cin >> l >> r, --l, --r;
        cout << c[r] - c[l] << '\n';
    }
}


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


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int start = max(a, c);
    int end = min(b, d);
    int time = max(end - start, 0);

    cout << time << endl;

}

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

#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...)        GET_MACRO(__VA_ARGS__, repn, rep0)(__VA_ARGS__)
#define rep0(i, b)      for(int i = 0; i < (b); ++i)
#define repn(i, a, b)   for(int i = a; i < (b); ++i)
#define trav(a, b)      for(auto& a : (b))
#define all(a)          (a).begin(),(a).end()
#define endl            '\n'
#define M               1000000007
#define tests           int ___;cin>>___;while(___--)

using namespace std;
using ll = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<int, int>;
using vpi = vector<pi>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);

    int n; cin >> n;
    cout << n/2 + (n%2) << endl;

    return 0;
}


Measured memory_bytes: 256
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;

int N;
long long K;
vector<int> A;
int MOD = 1e9 + 7;

void solve() {
	cin >> N >> K;
	A.resize(2*N);
	for (int n = 0; n < N; n++) {
		cin >> A[n];
		A[n + N] = A[n];
	}
	long long counter = 0;
	for (int i = 0; i < N; i++) {
		long long a = 0, b = 0;
		for (int j = i + 1; j < N; j++) {
			if (A[i] > A[j])a++;
		}
		for (int j = N; j < N + i; j++) {
			if (A[i] > A[j])b++;
		}
		long long temp1 = K * (K + 1) / 2;
		temp1 %= MOD;
		counter += temp1 * a;
		counter %= MOD;
		long long temp2 = K * (K - 1) / 2;
		temp2 %= MOD;
		counter += temp2*b;
		counter %= MOD;
	}
	cout << counter << endl;
}

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

void Main() {
    int N;
    cin >> N;
    vector<int> a(N);
    vector<bool> c(N);

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int light = 0;
    int ans = 0;
    while (light != 1) {
        if (c[light]) {
            ans = -1;
            break;
        }
        c[light] = true;
        light = a[light] - 1;
        ans += 1;
    }
    cout << ans << endl;
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}

Measured memory_bytes: 640
# AtCoder Grand Contest 014
# A - Cookie Exchanges 

def f(A,B,C,n):
    if A%2==1 or B%2==1 or C%2==1:
        return [1,n]
    if A==B==C:
        return [0,-1]
    tempA=A
    tempB=B
    tempC=C
    A=tempB//2+tempC//2
    B=tempA//2+tempC//2
    C=tempA//2+tempB//2
    return [2,[A,B,C,n+1]]


A,B,C=map(int,input().split())

flg = True
n=0

while flg == True:
    a=f(A,B,C,n)
    if a[0]==0:
        flg=False
        print(-1)
        exit()
    if a[0]==1:
        flg=False
        print(n)
        exit()
    if a[0]==2:
        n+=1
        A,B,C=a[1][0], a[1][1] , a[1][2]


Measured memory_bytes: 9136
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int h, w;
    while(cin >> h >> w, h){
        vector<vector<int>> v(h, vector<int>(w, 0));
        for (int i = 0; i < h; ++i) {
            string s;
            cin >> s;
            for (int j = 0; j < w; ++j) {
                v[i][j] = (s[j] == '.');
            }
            if(i){
                for (int j = 0; j < w; ++j) {
                    if(v[i][j]) v[i][j] += v[i-1][j];
                }
            }
        }

        int ans = 0;
        for (int i = 0; i < h; ++i) {
            stack<int> s;
            v[i].emplace_back(0);
            vector<int> l(w+1);
            for (int j = 0; j <= w; ++j) {
                while(!s.empty() && v[i][j] <= v[i][s.top()]){
                    int k = s.top(); s.pop();
                    ans = max(ans, (j-l[k]-1)*v[i][k]);
                }
                l[j] = s.empty() ? -1 : s.top();
                s.emplace(j);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int H, N;
    cin >> H >> N;
    int A[N];
    int sumnum = 0;
    rep(i, N) cin >> A[i], sumnum+=A[i];

    if (sumnum>=H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int t,an,bn,a[100001],b[100001],x,y,c;
int ans1=0x3f3f3f3f,ans2=0x3f3f3f3f,ans;
int main()
{
	scanf("%d%d%d",&an,&bn,&t);
	for(int i=1;i<=an;i++)scanf("%d",&a[i]),ans1=min(ans1,a[i]);
	for(int i=1;i<=bn;i++)scanf("%d",&b[i]),ans2=min(ans2,b[i]);
	ans=ans1+ans2;
	while(t--)
	{
		scanf("%d%d%d",&x,&y,&c);
		ans=min(ans,a[x]+b[y]-c);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
import numpy as np
import math
a,b,h,m=map(int,input().split())
h=h*30+(m/60)*30
m*=6
rad=0

if(h>m):rad=min(abs(h-m),abs((360-h)+m))
else:rad=min(abs(m-h),abs((360-m)+h))

c= pow(a,2)+pow(b,2)-2*a*b*np.cos(np.pi*2*(rad/360))
print(math.sqrt(c))

Measured memory_bytes: 27200
#include <stdio.h>
int main() {
  int N, i;
  scanf("%d", &N);
  double v[N];
  double tmp = 0;
  for(i = 0; i < N; ++i){
    scanf("%lf", &v[i]);
  }
  merge_sort(v, 0, N - 1, N);
  for(i = 1; i < N; ++i){
    tmp = (v[i-1] + v[i]) / 2;
    v[i] = tmp;
    v[i-1] = 0;
    merge_sort(v, 0, N - 1, N);
  }
  printf("%f\n", tmp);
}

void merge_sort (double array[], int left, int right, int N) {
  int i, j, k, mid;
  double work[N];  // 作業用配列
  if (left < right) {
    mid = (left + right)/2; // 真ん中
    merge_sort(array, left, mid, N);  // 左を整列
    merge_sort(array, mid+1, right, N);  // 右を整列
    for (i = mid; i >= left; i--) { work[i] = array[i]; } // 左半分
    for (j = mid+1; j <= right; j++) {
      work[right-(j-(mid+1))] = array[j]; // 右半分を逆順
    }
    i = left; j = right;
    for (k = left; k <= right; k++) {
      if (work[i] < work[j]) { array[k] = work[i++]; }
      else                   { array[k] = work[j--]; }
    }
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define F first
#define S second
#define LL int
#define MP make_pair
#define PB push_back
#define I insert

const LL mod=999999, N=102;
using namespace std;

LL n, m, i, j, k, l, r, t, ans;
LL a[N][N], d[N][N];
char c;
queue < pair < LL, LL > > q;
pair < LL, LL > p;

void prnt(){
	for ( LL i = 1; i <= n; ++i ){
		for ( LL j = 1; j <= m; ++j ){
			cout << d[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}

int main(){
	cin >> n >> m;
	for ( i = 1; i <= n; ++i ){
		for ( j = 1; j <= m; ++j ){
			cin >> c;
			a[i][j] = (c == '#');
			d[i][j] = mod;
		}
	}
	d[1][1] = 0;
	if ( a[1][1] ) d[1][1] = 1;
	q.push(MP(1,1));
	while ( q.size() ){
		p = q.front();
		q.pop();
		l = p.F;
		r = p.S;
		if ( l> n || r > m ) continue;
		if ( a[l+1][r] == a[l][r] ){
			if ( d[l+1][r] == mod ) q.push(MP(l+1,r));
			d[l+1][r] = min ( d[l+1][r], d[l][r] );
		}
		else {
			if ( d[l+1][r] == mod ) q.push(MP(l+1,r));
			d[l+1][r] = min ( d[l+1][r], d[l][r] + 1 );
		}
		if ( a[l][r+1] == a[l][r] ){
			if ( d[l][r+1] == mod ) q.push(MP(l,r+1));
			d[l][r+1] = min ( d[l][r+1], d[l][r] );
		}
		else {
			if ( d[l][r+1] == mod ) q.push(MP(l,r+1));
			d[l][r+1] = min ( d[l][r+1], d[l][r] + 1 );
		}
	}
//	prnt();
	cout << (d[n][m]+1) / 2 << endl;
	return 0;
}
//      IIIIIIIII      OOOOO             A          NN        N    EEEEEEEEEE
//          I         O     O           A A         N N       N    E
//          I        O       O         A   A        N  N      N    E
//          I        O       O        A     A       N   N     N    E
//          I        O       O       AAAAAAAAA      N    N    N    EEEEEEEE
//          I        O       O      A         A     N     N   N    E
//          I        O       O     A           A    N      N  N    E
//          I         O     O     A             A   N       N N    E
//      IIIIIIIII      OOOOO     A               A  N        NN    EEEEEEEEEE ___ KAPANADZE




Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define MAX 1000003

ll mod = 1e9 + 7;

vll prime(MAX,0);

void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (ll i = 2; i < MAX; i++) { 
        if (prime[i] == 0) { 
            for (ll j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 

void solve(){ 
    ll n;
    cin >> n;
    ll ans=0;
    rep(i,1,n){
        ll x = n - i;
        if(x == 1){ 
            ans += 1;
            continue;
        }
        if(x == 0) {
            continue;
        }
        map<ll,ll> m;
        while(x != 1){
            m[prime[x]]++;
            x /= prime[x];
        }
        ll temp=1;
        for(auto x:m){
            temp *= (x.ss + 1);
        }
        ans += temp;
    }
    cout << ans;

}
	

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

	ll t = 1;
	// cin >> t;
    sieve();
	rep(i,0,t){
		solve();
	}
 
}	

Measured memory_bytes: 10920
n = gets.to_s.to_i
a = gets.to_s.split

if a.include?('0')
  puts 0
  exit
end

a.map!{|e|e.to_i}
ans = 1
inf = 1_000_000_000_000_000_000
a.each do |t|
  ans *= t
  if ans > inf
    puts "-1"
    exit
  end
end

puts ans

Measured memory_bytes: 20868
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int n, a, b, c, d;
vector<pair<int, int>> red;
vector<pair<int, int>> blue;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
    //debug start
    //cout << "input check start" << endl;
    //for (auto e : red) {
    //    cout << e.first << " " << e.second << endl;
    //}
    //for (auto e : blue) {
    //    cout << e.first << " " << e.second << endl;
    //}
    //cout << "input check end" << endl;
    //debug end
    sort(red.begin(), red.begin() + n);
    sort(blue.begin(), blue.begin() + n);
    int pos = 0;
    int ans = 0;
    multiset<int> st;
    for (int i = 0; i < n; ++i) {
        while(red[pos].first < blue[i].first) st.insert(red[pos++].second);
        auto itr = st.lower_bound(blue[i].second);
        if (itr != st.begin()) {
            st.erase(--itr);
            ans++;
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    cin >> n;
    red.resize(n + 1);
    blue.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a >> b;
        red[i] = make_pair(a, b);
    }
    red[n] = make_pair(INF, INF);
    for (int i = 0; i < n; ++i) {
        cin >> c >> d;
        blue[i] = make_pair(c, d);
    }
    solve();
    return 0;
}



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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

const int mod=1e9+7;

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

	int maru=0;
	for (int i = 0; i < s.size(); ++i){
		if(s[i]=='o')maru++;
	}

	if(maru>=8||(15-s.size())+maru>=8)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

}


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

ll txor(ll x);

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

ll txor(ll x){
  ll res;
  if (x%2==0) res=x;
  else res=0;
  if ((x+1)/2%2==1) res++;
  return res;
}

Measured memory_bytes: 256
data class Card(val mark: String, val number: Int)

fun main(args: Array<String>) {
    val array1 = Array<Card>(readLine()?.toInt() ?: 0) {
        val input = readLine()
            ?.split(" ".toRegex())
            ?.toTypedArray()
            ?: arrayOf<String>()
        Card(input[0], input[1].toInt())
    }
    val array2 = array1.clone()
    array1.mergeSort()
    array2.qSort(0, array2.lastIndex)
    println(
        if (array1.contentEquals(array2)) {
            "Stable"
        } else {
            "Not stable"
        }
    )
    println(
        array2.joinToString("\n") {
            "${it.mark} ${it.number}"
        }
    )
}

fun Array<Card>.qSort(p: Int, r: Int) {
    if (p < r) {
        val mid = partition(p, r)
        qSort(p, mid - 1)
        qSort(mid + 1, r)
    }
}

fun Array<Card>.partition(p: Int, r: Int): Int {
    val x = this[r]
    var i = p - 1
    for (j in p until r) {
        if (this[j].number <= x.number) {
            i++
            swap(i, j)
        }
    }
    swap(i + 1, r)
    return i + 1
}

fun Array<Card>.mergeSort(): Int {
    return this.mergeSort(0, this.size)
}

fun Array<Card>.mergeSort(left: Int, right: Int): Int {
    var cnt = 0
    if (left + 1 < right) {
        val mid = (left + right) / 2
        cnt += this.mergeSort(left, mid)
        cnt += this.mergeSort(mid, right)
        cnt += this.merge(left, mid, right)
    }
    return cnt
}

fun Array<Card>.merge(left: Int, mid: Int, right: Int): Int {
    var cnt = 0
    val array1 = Array((mid - left) + 1) {
        Card("S", Int.MAX_VALUE)
    }
    val array2 = Array((right - mid) + 1) {
        Card("S", Int.MAX_VALUE)
    }
    for (i in 0 until array1.size - 1) {
        array1[i] = this[left + i]
    }
    for (i in 0 until array2.size - 1) {
        array2[i] = this[mid + i]
    }
    var i = 0
    var j = 0
    for (k in left until right) {
        this[k] = if (compare(array1[i], array2[j])) {
            array1[i++]
        } else {
            array2[j++]
        }
        cnt++
    }
    return cnt
}

fun compare(card1: Card, card2: Card): Boolean {
    return card1.number <= card2.number
}

fun Array<Card>.swap(i: Int, j: Int) {
    val tmp = this[i]
    this[i] = this[j]
    this[j] = tmp
}


Measured memory_bytes: 113660
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#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 FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;

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

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
ll Max(ll a, ll b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){
	int a,b;
	scanf("%d %d", &a,&b);
	PRINTD((a-1)*(b-1));
}

Measured memory_bytes: 128
#include<stdio.h>

#define N 10000

struct node{
  int p,l,r;
};
struct node T[N];

void preOrder(int);
void inOrder(int);
void postOrder(int);

int n;

void preOrder(int u){
  if(u == -1){
    return;
  }
  printf(" %d",u);
  preOrder(T[u].l);
  preOrder(T[u].r);
}

void inOrder(int u){
  if(u == -1){
    return;
  }
  inOrder(T[u].l);
  printf(" %d",u);
  inOrder(T[u].r);
}

void postOrder(int u){
  if(u == -1){
    return;
  }
  postOrder(T[u].l);
  postOrder(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,u,l,r,root;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    T[i].p=-1;
  }
  for(i = 0;i < n;i++){
    scanf("%d%d%d",&u,&l,&r);
    T[u].l = l;
    T[u].r = r;
    if(l != -1){
      T[l].p=u;
    }
    if(r != -1){
      T[r].p=u;
    }
  }
  for(i = 0;i < n;i++){
    if(T[i].p == -1){
      root = i;
    }
  }
  printf("Preorder\n");
  preOrder(root);
  printf("\n");
  printf("Inorder\n");
  inOrder(root);
  printf("\n");
  printf("Postorder\n");
  postOrder(root);
  printf("\n");
  return 0;
}

Measured memory_bytes: 620
using System;

namespace _094D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = new int[n];

            string[] str = Console.ReadLine().Split(' ');
            for (int i = 0; i < str.Length; i++)
            {
                x[i] = int.Parse(str[i]);
            }

            Array.Sort(x);

            int max = x[x.Length-1];
            int med = max / 2;

            int maxc = 0;
            for (int i = 0; i < x.Length - 1; i++)
            {
                int m = x[i];
                if (med < m)
                {
                    m = max - m;
                }
                if (med == m)
                {
                    maxc = x[i];
                    break;
                }
                if (maxc < m)
                {
                    maxc = x[i];
                }
            }


            string ret = string.Format("{0} {1}", max, maxc);
            System.Console.Write(ret);
        }

    }
}

Measured memory_bytes: 20448
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
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 PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int getLevenshteinDistance(string s1, string s2) {
    int dp[s1.size()+1][s2.size()+1];
    // dp[i+1][j+1] = Levenshtein Distance between s1.substr(0,i) and s2.substr(0,j)
    REP(i,s1.size()+1) dp[i][0] = i;
    REP(i,s2.size()+1) dp[0][i] = i;
    FOR(i,1,s1.size()+1) {
        FOR(j,1,s2.size()+1) {
            dp[i][j] = min(dp[i-1][j],dp[i][j-1]) + 1;
            dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (s1[i-1]!=s2[j-1]));
        }
    }
    return dp[s1.size()][s2.size()];
}

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    cout << getLevenshteinDistance(s1, s2) << endl;
    return 0;
}

Measured memory_bytes: 5104