akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll x=c-a;
    ll y=d-b;
    string ans;
    ll i;
    for(i=0; i<x; i++)
        ans+='R';
    for(i=0; i<y; i++)
        ans+='U';
    for(i=0; i<x; i++)
        ans+='L';
    for(i=0; i<=y; i++)
        ans+='D';
    for(i=0; i<=x; i++)
        ans+='R';
    for(i=0; i<=y; i++)
        ans+='U';
    ans+='L';
    ans+='U';
    for(i=0; i<=x; i++)
        ans+='L';
    for(i=0; i<=y; i++)
        ans+='D';
    ans+='R';
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    string t;
    cin >> t;
    rep(i,t.size()){
        if(t[i]=='?'){
            t[i]='D';
        }
    }
    cout << t << endl;
}

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

const int maxn = 100010;
int n;
vector<int> num[maxn], G[maxn];
bool used[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        if (i * (i + 1) / 2 > n) continue;
        if (i * (i + 1) / 2 == n) {
            printf("Yes\n%d\n", i + 1);
            for (int j = 1, x = 0; j <= i; j++) {
                for (int k = 1; k <= j; k++) {
                    num[j].push_back(++x);
                }
            }
            for (int j = 1; j <= i; j++) {
                for (int k = 1; k <= j; k++) {
                    G[j].push_back(num[j][k - 1]);
                }
                for (int k = j + 1; k <= i; k++) {
                    G[j].push_back(num[k][j - 1]);
                }
            }
            for (int j = 1; j <= i; j++) {
                G[i + 1].push_back(num[j].back());
            }
            for (int j = 1; j <= i + 1; j++) {
                printf("%d ", G[j].size());
                for (int k : G[j]) {
                    printf("%d ", k);
                }
                printf("\n");
            }
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	vector<int>s(N + 1, 0);
	int sum = 0;
	rep(i, N) {
		int a; cin >> a;
		s[i + 1] = a;
		sum += a;
	}
	sort(s.rbegin(), s.rend());
	int ans = 0;
	rep(i, N + 1) {
		int a = sum - s[i];
		ans = max(ans, (a % 10 ? a : 0));
	}
	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
a = [int(input()) for i in range(m)]

from collections import deque
stack_deque = deque(a)

def pl():
    try:
        return stack_deque.popleft()
    except:
        return -1

MOD = 10**9+7
#i段目への移動方法
dp = [0] * (n+1)
dp[0]=1
min_a = pl()
if min_a!=1:
    dp[1]=1
else:
    min_a = pl()
for i in range(2,n+1):
    if i == min_a:
        dp[i]=0
        min_a = pl()
    else:
        dp[i]=(dp[i-1]%MOD+dp[i-2]%MOD) % MOD
print(dp[-1])

Measured memory_bytes: 8864
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	n := nextInt()
	a := nextInt()
	if n%500 <= a {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    ll n;
    cin >> n;
    string ans = "";
    while (n) {
        n--;
        ans += 'a' + (n%26);
        n /= 26;
    }
    for (int i=(int)ans.size()-1; i>-1; i--) cout << ans[i];
    cout << "\n";
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 200005;

int v[N], dp[N];

int main(){
	fastio;
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        dp[i] = mod;
    }
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    for(int i = 1; i < n; i++){
        for(int j = 1; j <= i and j <= k; j++){
            dp[i] = min(dp[i], dp[i-j] + abs(v[i]-v[i-j]));
        }
    }
    cout << dp[n-1] << '\n';
	return 0;
}


Measured memory_bytes: 4344
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)2e5 + 7;
const long long INF = 1e18;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, k, a[N], used[N];

bool ok (int x){
  while (x){
    int cur = x % 10;
    if (used[cur]) return 0;
    x /= 10;
  }
  return 1;
}

int main (){
  scanf ("%d %d", &n, &k);
  forn (i, 1, k) scanf ("%d", a + i), used[a[i]] = 1;
  forn (i, n, 100000){
    if (ok(i)) return printf ("%d\n", i), 0;
  }
  return 0;
}

Measured memory_bytes: 256
s = input()
import sys
n = len(s)
kisuu = ["R","U","D"]
guusuu = ["L","U","D"]

for i in range(n):
    if i%2 == 0:
        if s[i] not in kisuu:
            break
    else:
        if s[i] not in guusuu:
            break
else:
    print("Yes")
    sys.exit()
print("No")

Measured memory_bytes: 9116
#include "bits/stdc++.h"
#define lp(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using l = long;
using vi = vector<int>;
using vl = vector<l>;
using vll = vector<ll>;
using vvl = vector<vector<l>>;
using vvll = vector<vector<ll>>;
using pll = pair<ll, ll>;
using un = unsigned;

int n, res = 0, ccc = 0;
string s;

int main()
{
	l n, m; cin >> n >> m;
	vl h(n, 0);
	vvl ld(n, vl());
	for (auto& htmp : h) {
		cin >> htmp;
		htmp--;
	}

	for (int i = 0; i < m; i++) {
		l a, b; cin >> a >> b;
		ld[a - 1].push_back(b - 1);
		ld[b - 1].push_back(a - 1);
	}

	int cnt = 0, tmp;
	for (int i = 0; i < n; i++) {
		tmp = ld[i].size();
		for (int j = 0; j < ld[i].size(); j++) {
			if (h[i] > h[ld[i][j]]) tmp--;
		}
		if (tmp == 0) cnt++;
	}

	cout << cnt;
}



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

using namespace std;

typedef long long ll;

const ll INF = 1e13;

template <typename T>
struct SegmentTree {
    int n;
    vector<T> data;

    //使うときは、この3つを適宜変更する
    static T INITIAL_VALUE;
    static T merge(T x, T y); 
    void updateNode(int k, T x);

    SegmentTree(int size) {
        n = 1;
        while (n < size) n *= 2;
        data.resize(2 * n - 1, INITIAL_VALUE);
    }

    T getLeaf(int k) {
        return data[k + n - 1];
    }
    
    void update(int k, ll x) {
        k += n - 1; //葉の節点
        updateNode(k, x);
        while (k > 0) {
            k = (k - 1) / 2;
            data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }
    
    //区間[a, b)に対するクエリに答える
    //k:節点番号, [l, r):節点に対応する区間
    T query(int a, int b, int k, int l, int r) {
        //[a, b)と[l, r)が交差しない場合
        if (r <= a || b <= l) return INITIAL_VALUE;
        //[a, b)が[l, r)を含む場合、節点の値
        if (a <= l && r <= b) return data[k];
        else {
            //二つの子をマージ
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return merge(vl, vr);
        }
    }
    
    //外から呼ぶ用
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }
};

//使うときは以下3つを変更
template <typename T>
T SegmentTree<T>::INITIAL_VALUE = INF;

template <typename T>
T SegmentTree<T>::merge(T x, T y) {
    return min(x, y);
}

template <typename T>
void SegmentTree<T>::updateNode(int k, T x) {
    data[k] = x;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	ll a;
	cin >> n >> q >> a;
	a--;
	vector<ll> x(q + 1);
	cin >> x[0];
	x[0]--;
	for (int i = 1; i <= q; i++) {
		cin >> x[i];
		x[i]--;
	}

	SegmentTree<ll> st1(n), st2(n);

	st1.update(a, -a);
	st2.update(a, a);

	ll add = 0;
	for (int i = 1; i <= q; i++) {
		ll tmp = INF;
		tmp = min(tmp, st1.query(0, x[i]) + x[i]);
		tmp = min(tmp, st2.query(x[i], n) - x[i]);
		tmp += add;
		add += abs(x[i] - x[i - 1]);
		ll tar = st1.getLeaf(x[i - 1]) + x[i - 1] + add;
		if (tar <= tmp) continue;
		tmp -= add;
		st1.update(x[i - 1], tmp - x[i - 1]);
		st2.update(x[i - 1], tmp + x[i - 1]);
	}

	ll ans = INF;
	for (int i = 0; i < n; i++) {
		ans = min(ans, st1.getLeaf(i) + i);
	}
	ans += add;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9984
N = int(input())
A = []
for i in range(N):
    x,l = map(int,input().split())
    A.append([x-l,x+l])
B=sorted(A,key=lambda x: x[1])
s = B[0][1]
n = 1
for i in range(1,N):
    a = B[i][0]
    b = B[i][1]
    if a >= s:
        n += 1
        s = b
print(n)

Measured memory_bytes: 22104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N; cin >> N;
    while(true){
        if(N <= 1000){
            break;
        }
        else{
            N = N - 1000;
        }
    }
    int ans = 1000 - N;
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll x=0;x<n;x++)
        cin>>a[x];
    ll s[61][2];
    memset(s,0,sizeof(s));
    ll ans=0;
    ll po[61];
    po[0]=1;
    for(int x=1;x<61;x++)
        po[x]=(po[x-1]*2)%mod;
    for(ll x=n-1;x>=0;x--)
    {
        ll g=a[x];
        for(ll y=0;y<60;y++)
        {
            if(g&(1ll<<y))
            {
             ans+=(s[y][0]*po[y])%mod;
             ans%=mod;
            }
            else
                {ans+=(s[y][1]*po[y])%mod;
                ans%=mod;}
        }
        for(ll y=0;y<60;y++)
        {   if(g&(1ll<<y))
            ++s[y][1];
            else
            ++s[y][0];
        }
    }
    cout<<ans%mod;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int xs[] = {0, 1, 0, -1}, ys[] = {1, 0, -1, 0};
int dist[1080][1080];
int main(){
    Int h, w;
    char a;
    queue<P> q;
    cin >> h >> w;
    for(int i = 1;i <= h;i++){
        for(int j = 1;j <= w;j++){
            cin >> a;
            if(a == '#')dist[i][j] = 0;
            else dist[i][j] = -1;
            if(a == '#')q.push(P(i,j));
        }
    }
    int res = 0;
    while(!q.empty()){
        auto top = q.front();q.pop();
        for(int i = 0;i < 4;i++){
            int nx = top.first + xs[i];
            int ny = top.second + ys[i];
            if(nx <= 0 || ny <= 0 || nx > h || ny > w)continue;
            if(dist[nx][ny] != -1)continue;
            dist[nx][ny] = dist[top.first][top.second] + 1;
            q.push(P(nx,ny));
            res = max(res, dist[nx][ny]);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 20788
def main():

    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i + j)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 47388
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
string a;
string b,c;
int f1,f2;//yymm,mmyy
string ans;

signed main(){
  cin >> a;
  b = a.substr(0,2);
  c = a.substr(2,2);
  if(b=="00") f2 = 1;
  if(stoi(b)>12) f2 = 1;
  if(c=="00") f1 = 1;
  if(stoi(c)>12) f1 = 1;
  if(f1==1&&f2==1) ans = "NA";
  if(f1==1&&f2==0) ans = "MMYY";
  if(f1==0&&f2==1) ans = "YYMM";
  if(f1==0&&f2==0) ans = "AMBIGUOUS";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  priority_queue<pint> que;
  rep(i,0,5){
    cin >> A;
    que.push(pint(-(10-A%10)%10,A));
  }
  rep(i,0,5){
    auto v=que.top();que.pop();
    sum+=v.second;
    if(i!=4)sum-=v.first;
  }
  Out(sum);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  mint ans = 0;
  combination c(100100);
  rep(ri, 2) {
    mint s = 0;
    for(int i = 0; i < n; ++i){
      s += c(i, k - 1) * a[i];
    }
    if(ri % 2 == 0) ans += s;
    else ans -= s;

    reverse(a.begin(), a.end());
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 2176
import math

n,k,q = map(int,input().split())
A=[0]*q
B=[0]*n
for i in range(q):
  A[i] = int(input())-1
for ii in range(q):
  B[A[ii]] +=1
for j in range(n):
  if(k+B[j]-q>0):
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 13800
#include<bits/stdc++.h>
#define int long long int
#define pi pair<int,int>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,b) for(int i=0;i<b;i++)
#define u_m unordered_map
#define mod 1e9+7
#define pii pair<pair<int,int> >
#define vpi vector<pair<int,int> >
#define vi vector<int>
#define vii vector<vector<int,int> >
#define endl "\n"
#define MAX 1e+5
using namespace std;


int32_t main()
{
	int n;
	cin>>n;

	int h[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}

	int dp[n+1];
	for(int i=1;i<=n;i++)
	{
		dp[i]=INT_MAX;
	}

	dp[1]=0;

	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<i+3;j++)
		{
			dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
		}
	}

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pcnt __builtin_popcount
const int N=(1<<16)+5,M=18,Mod=1e9+7;
int n,m,an,a[M],fac[N],inv[N],f[M][N],ans;
#define mul(x,y) (1ll*(x)*(y)%Mod)
inline void upd(int& x, int y)
{	x=(x+y>=Mod?x+y-Mod:x+y);
}
inline int po(int x, int y=Mod-2)
{
	int r=1;
	for(;y;y>>=1,x=mul(x,x)) if(y&1) r=mul(r,x);
	return r;
}
inline int C(int x, int y)
{
	if(x<y||x<0||y<0) return 0;
	return mul(fac[x],mul(inv[y],inv[x-y]));
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+m,greater<int>());
	an=(1<<n),fac[0]=inv[0]=f[0][0]=1;
	for(int i=1;i<=an;++i) fac[i]=mul(i,fac[i-1]);
	inv[an]=po(fac[an],Mod-2);
	for(int i=an-1;i;--i) inv[i]=mul(i+1,inv[i+1]);
	for(int i=1;i<=m;++i)
		for(int s=0;s<an;++s) if(f[i-1][s])
		{
			upd(f[i][s],f[i-1][s]);
			for(int j=0;j<n;++j) if(~s&(1<<j))
				upd(f[i][s|(1<<j)],mul(f[i-1][s],mul(C(an-a[i]-s,(1<<j)-1),fac[1<<j])));
		}
	for(int s=0;s<an;++s)
	{
		int t=mul(f[m][s],fac[an-1-s]);
		ans=(pcnt(s)&1)?(ans-t+Mod)%Mod:(ans+t)%Mod;
	}
	printf("%d\n",mul(ans,an));
}


Measured memory_bytes: 4352
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
	int max=-100000;
	int a;
	int b;
	cin>>a>>b;
	int c,d,e,f;
	c=a+b;
	d=a-b;
	e=a*b;
	if(max<c){
		max=c;
	}
	if(max<d)
	max=d;
	if(max<e)
	max=e;
	cout<<max;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 32

ll POW[NUM];
int table[NUM];


int main(){

	POW[0] = 1;
	for(int i = 1; i < NUM; i++){
		POW[i] = 2*POW[i-1];
	}

	ll num;
	scanf("%lld",&num);

	int index = 0;

	for(int i = NUM-1; i >= 0; i--,index++){
		if(POW[i] <= num){

			table[index] = 1;
			num -= POW[i];

		}else{

			table[index] = 0;
		}
	}

	//そのまま
	for(int i = 0; i < NUM; i++){
		printf("%d",table[i]);
	}
	printf("\n");

	//反転
	for(int i = 0; i < NUM; i++){
		printf("%d",1-table[i]);
	}
	printf("\n");

	//左シフト
	for(int i = 1; i < NUM; i++){
		printf("%d",table[i]);
	}
	printf("0\n");

	//右シフト
	printf("0");
	for(int i = 0; i < NUM-1; i++){
		printf("%d",table[i]);
	}
	printf("\n");

	return 0;
}




Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
    string S;
    cin >> S;
    int n = 0;
    int a = 0;
    int b = S.length()-1;
    REP(i, S.length()/2) {
        if(S.at(a) != S.at(b)) {
            n++;
        }
        a++;
        b--;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>

using namespace std;

namespace {
	enum BIT_FLAGS { // 最上位bit注意、int型になる。
		BIT_DIGIT_3 = 0b100,
		BIT_DIGIT_5 = 0b010,
		BIT_DIGIT_7 = 0b001,
	};
}

int DFS(long long tmpN, int N, unsigned bitFlags) // tmpNは一時的に1e10になる。
{
	if (tmpN > N) {
		return 0;
	}

	int sum = 0;
	if (bitFlags == (BIT_DIGIT_3 | BIT_DIGIT_5 | BIT_DIGIT_7)) {
		sum = 1;
	}

	sum += DFS(tmpN * 10 + 3, N, bitFlags | BIT_DIGIT_3);
	sum += DFS(tmpN * 10 + 5, N, bitFlags | BIT_DIGIT_5);
	sum += DFS(tmpN * 10 + 7, N, bitFlags | BIT_DIGIT_7);

	return sum;
}
int main()
{
	int N = 0;
	cin >> N;

	unsigned bitFlags(0b00); // 3, 5, 7 
	cout << DFS(0, N, bitFlags) << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $N, $M, $K);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$B = array_map('intval', explode(' ', trim(fgets(STDIN))));

for ($i = 1; $i < $N; $i++) {
    $A[$i] = $A[$i - 1] + $A[$i];
}
for ($i = 1; $i < $M; $i++) {
    $B[$i] = $B[$i - 1] + $B[$i];
}
array_unshift($A, 0);
array_unshift($B, 0);
$bb = $M;
$ans = [];
for ($i = 0; $i <= $N; $i++) {
    if ($A[$i] > $K) continue;
    while($A[$i] + $B[$bb] > $K && $bb > 0) {
        $bb--;
    }
    if ($bb >= 0) {
        $ans[] = $i + $bb;
    }
}
printf("%d", max($ans));


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

int main()
{
  int n,m;
  cin>>n>>m;
  if(n<2)
    n=1;
  if(m<2)
    m = 1;
  int ans = (n*(n-1))/2 + (m*(m-1))/2;
  cout<<ans;
  return 0;
}

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

#define MAX 100
#define INF 1000000
int G[MAX][MAX];
int c, n, m, s, d, a, b, f;

int dijkstra(){
    int D[MAX][11];
    bool visited[MAX][11];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= c; j++) {
            D[i][j] = INF;
            visited[i][j] = false;
        }
    }
    D[s][c] = 0;
    while (true) {
        int u, w, minv = INF;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= c; j++) {
                if (!visited[i][j] && minv > D[i][j]) {
                    minv = D[i][j];
                    u = i;
                    w = j;
                }
            }
        }
        if (minv == INF) {
            break;
        }
        visited[u][w] = true;
        for (int v = 0; v < n; v++) {
            if (G[u][v] == INF) {
                continue;
            }
            D[v][w] = min(D[v][w], D[u][w] + G[u][v]);
            if (w) {
                D[v][w-1] = min(D[v][w-1], D[u][w] + G[u][v] / 2);
            }
        }
    }
    int minv = INF;
    for (int i = 0; i <= c; i++) {
        minv = min(minv, D[d][i]);
    }
    return minv;
}

int main()
{
    while (true) {
        cin >> c >> n >> m >> s >> d;
        if (s == 0 && d == 0) {
            break;
        }
        s--;
        d--;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                G[i][j] = INF;
            }
        }
        for (int i = 0; i < m; i++) {
            cin >> a >> b >> f;
            a--;
            b--;
            G[a][b] = G[b][a] = f;
        }
        cout << dijkstra() << endl;
    }

    return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int check = 0;
	
	scanf("%d", &a); scanf("%d", &b); scanf("%d", &c);
	if (a == b) check++;
	if (b == c) check++;
	if (a == c) check++;
	if (check == 3) check--;
		
	
	printf("%d",3 - check);
	
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <string>
#define SIZE 200005

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

map <int,int> mp;
char str[SIZE];
bool use[SIZE];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	mp[0]=0;
	for(int i=0;i<n;i++)
	{
		int c=str[i]-'a';
		use[c]=!use[c];
		int S=0;
		for(int j=0;j<26;j++) if(use[j]) S|=1<<j;
		int mn=i+1;
		if(mp.count(S)) mn=min(mn,mp[S]+1);
		for(int j=0;j<26;j++)
		{
			if(mp.count(S^(1<<j)))
			{
				mn=min(mn,mp[S^(1<<j)]+1);
			}
		}
		if(!mp.count(S)) mp[S]=mn;
		else mp[S]=min(mp[S],mn);
		if(i==n-1) printf("%d\n",mn);
	}
	return 0;
}


Measured memory_bytes: 9856
s = input()
t = input()

S = sorted(list(s))
T = reversed(sorted(list(t)))
s = "".join(S)
t = "".join(T)
L = [s, t]
L2 = sorted(L)
if s == t:
    print("No")
else:
    if L == L2:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
 
int main(){
    int n,mat[200][3],point[200]={0};
 
    cin >> n;
    for(int i = 0 ; i < n ; i++)
	for(int j = 0 ; j < 3 ; j++)
	    cin >> mat[i][j];
 
    for(int i = 0 ; i < n ; i++){
	for(int j = 0 ; j < 3 ; j++){
	    int cnt = 0;
	    for(int l = 0 ; l < n ; l++){
		if(mat[i][j] != mat[l][j] && i != l) cnt++;
	    }
	    if(cnt == n-1) point[i] += mat[i][j];
	}
    }
 
    for(int i = 0 ; i < n ; i++){
	cout << point[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
num = list(map(int,input()))
l = len(num)
for i in range(2**(l-1)):
    ans = num[0]
    cur = bin(i)[2:]
    cur = '0' * (l-1-len(cur)) + cur
    s = str(num[0])
    for j in range(l-1):
        if cur[j] == '1':
            s += "-"
            s += str(num[j+1])
            ans -= num[j+1]
        else:
            s += "+"
            s += str(num[j+1])
            ans += num[j+1]
    if ans == 7:
        break
s += "=7"
print(s)

Measured memory_bytes: 3064
#include <assert.h>
main(a,b,c,p,q,r,s,i){for(;scanf("%d%d%d",&a,&b,&c),a;){
	if(!c){
		if(a==1&&b<0)printf("1 0 %d %d\n",a,b);
		else printf("%d %d 1 0\n",a,b);
		continue;
	}
	for(r=1;r*r<=a;r++)if(a%r==0)
		for(p=a/r,s=1;s<=abs(c);s++)if(c%s==0)
			for(i=0;i<2;i++,s=-s)if(q=c/s,p*s+q*r==b){
				if(p==r&&q<s)printf("%d %d %d %d\n",r,s,p,q);
				else printf("%d %d %d %d\n",p,q,r,s);
				goto next;
			}
	puts("Impossible");
next:;}exit(0);}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;


int main(){
    int n;
    cin >> n;
    vector<list<int>>  L(n);
    rep(i,n){
        int u, e;
        cin >> u>>e;
        rep(j,e){
            int v;cin>>v;--v;
            L[i].push_back(v);
        }
    }
    vector<vector<int>> M(n,vector<int>(n));
    rep(i,n){
        rep(j,n){
            list<int>::iterator it = find(L[i].begin(),L[i].end(),j);
            if(it!=L[i].end()){
                M[i][j]=1;
                L[i].erase(it);
            }
        }
    }
    rep(i,n){
        rep(j,n){
            if(j) cout << " "<<M[i][j];
            else cout << M[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(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 (b<a) { a=b; return 1; } return 0; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) (x.begin(), x.end()

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ld a, b;
    cin >> a >> b;
    cout << fixed << setprecision(20) << a/b << endl;
}

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  vector<int> news(4,0);
  for(int i=0;i<N;i++){
    int c=S.at(i);
    if(c=='N'){
      news.at(0)=1;
    }
    if(c=='E'){
      news.at(1)=1;
    }
    if(c=='W'){
      news.at(2)=1;
    }
    if(c=='S'){
      news.at(3)=1;
    }
  }
  int x=(news.at(0)^news.at(3))|(news.at(1)^news.at(2));
  if(x==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

void BubbleSort(char A[],int B[], int N){
	int flag = 1;
	char change1;
	int change2;
	int count = 0;
	while(flag){
		flag = 0;
		
		for(int j = N-1;j > 0;j--){
			if(B[j] < B[j-1]){
				change1 = A[j];
				change2 = B[j];
				A[j] = A[j-1];
				B[j] = B[j-1];
				A[j-1] = change1;
				B[j-1] = change2;
				flag = 1;
			}
		}
	}
	for(int i = 0;i < N;i++){
	printf("%c%d",A[i],B[i]);
		if(i != N-1)printf(" ");
	}
	printf("\n");
	printf("Stable\n");
}


void selectionSort(char A[],int B[], int N){
	int count = 0;
	int min;
	char change1;
	int change2;
	for(int i = 0;i <N-1;i++){
		min = i;
		for(int j = i;j < N;j++){
			if(B[j] < B[min]){
			min = j;
			}
		}
			change1 = A[i];
			change2 = B[i];
			A[i] = A[min];
			B[i] = B[min];
			A[min] = change1;
			B[min] = change2;
			
			
		
	}
	for(int i = 0;i < N;i++){
	printf("%c%d",A[i],B[i]);
		if(i != N-1)printf(" ");
	}
	printf("\n");
}


int main(void){
	int n;
	scanf("%d",&n);
	char card1[n];
	char card2[n];
	int card1int[n];
	int card2int[n];
	for(int i = 0;i < n;i++)
	{
		scanf(" %c %d",&card1[i],&card1int[i]);
		card2int[i] = card1int[i];
	}
	
	strcpy(card2,card1);
	
	BubbleSort(card1, card1int, n);
	selectionSort(card2, card2int, n);
	
	if(strcmp(card1,card2)==0){printf("Stable\n");}
	else{printf("Not stable\n");}
	
}


Measured memory_bytes: 2092
from collections import deque


class Graph:
    # クラス変数
    WHITE = 0
    GRAY = 1

    def __init__(self):
        self.color = [self.__class__.WHITE] * n
        self.out = deque([])
        self.Q = deque([])

    def bfs(self, s, w):
        self.Q.appendleft((s, w))
        self.color[s] = self.__class__.GRAY
        while self.Q:
            u, w = self.Q.popleft()

            self.out.append((u, w))

            for v, dw in G[u]:
                if self.color[v] == self.__class__.WHITE:
                    self.color[v] = self.__class__.GRAY
                    self.Q.append((v, dw+w))


n = int(input())
G = {}
for i in range(n):
    G[i] = []
for i in range(1, n):
    s, t, w = map(int, input().split())
    G[s].append((t, w))
    G[t].append((s, w))

# 最も遠い点xを求める
graph = Graph()
graph.bfs(0, 0)
x, w = max(graph.out, key=lambda x: x[1])

# xから最も遠い点yを求める
graph = Graph()
graph.bfs(x, 0)
y, w = max(graph.out, key=lambda x: x[1])

# x, yの距離が答え
print(w)



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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int a;
  long double b;
  cin >> a >> b;

  cout << int(a * b) << '\n';
  return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-4;
const int MAX=1e6+10;
const ll mod=1e9+7;
/****************************************  head  ****************************************/
int main()
{
	int n,i,t,ans,x;
	while(~scanf("%d",&n))
	{
		ans=0;
		for(i=0;i<n;i++) scanf("%d",&x),ans+=x-1;
		printf("%d\n",ans);
	}
	return 0;
}


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

int main(){
    ll n;
    cin>>n;
    vector<string>s(n);
    rep(i,n) {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s.begin(),s.end());
    ll c=0;
    ll ans=0;
    rep(i,n-1){
        if(s[i]!=s[i+1]) {
            ans=ans+(c*(c+1))/2;
            c=0;
        }else{
        c++;
        }
    }
    ans=ans+(c*(c+1))/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7296
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
bunkai = factorization(n)
ans = 0
for i in bunkai:
    a = i[1]
    b = 1
    cnt = 0
    while a > 0:
        a -= b
        b += 1
        if a >= 0:
            cnt += 1
        else:
            pass
    ans += cnt
if n == 1:
    print(0)
else:
    print(ans)

Measured memory_bytes: 9500
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>
 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
 
const int MAXN=1E5+10;
 
int n,val[MAXN],S;
int cnt[20],ans,f[1<<16];
int stk[20],top,bin[20];
 
int main()
{
    scanf("%d",&n);memset(f,0x3f,sizeof f);
    bin[0]=1;
    for(int i=1;i<=15;i++) bin[i]=bin[i-1]<<1;
    for(int i=1,u,v,w;i<n;i++)
        scanf("%d%d%d",&u,&v,&w),++u,++v,val[u]^=w,val[v]^=w;
    for(int i=1;i<=n;i++) cnt[val[i]]++;
    for(int i=1;i<=15;i++) ans+=cnt[i]>>1,S|=(cnt[i]&1)<<i;
    f[0]=0;
    for(int l=1;l<=15;l++)
        for(int s=0;s<(1<<16);s++)
            if(__builtin_popcount(s)==l&&(s&1)==0)
                {
                    top=0;
                    for(int i=1;i<16;i++) if((s>>i)&1) stk[++top]=i;
                    for(int i=1;i<=top;i++)
                        for(int j=i+1;j<=top;j++)
                            f[s]=min(f[s],f[s^bin[stk[i]]^bin[stk[j]]^bin[stk[i]^stk[j]]]+1+((s>>(stk[i]^stk[j]))&1));
                }
    printf("%d\n",f[S]+ans);
    #ifdef LOCAL
        system("pause");
    #endif
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/06/29  Problem: ABC 132 A / Link: http://abc132.contest.atcoder.jp/tasks/abc132_a  ----- */


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

	string s; cin >> s;
	map<char, int>m;
	for (auto c : s) {
		m[c]++;
	}
	LL ans = SZ(m)==2;
	for (auto it : m) {
		ans &= it.second == 2;
	}
	auto print_yesno = [](LL yes, int mode = 0) {
		if (mode == 0) {
			cout << (yes ? "yes" : "no") << endl;
		}
		else if (mode == 1) {
			cout << (yes ? "Yes" : "No") << endl;
		}
		else if (mode == 2) {
			cout << (yes ? "YES" : "NO") << endl;
		}
		else assert(0);
	};
	print_yesno(ans,1);
	return 0;
}


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

int main(){
  int N,L;
  cin>>N>>L;
  vector<string> vec(N);
  for(int i=0;i<N;i++) cin>>vec[i];
  string T="";
  sort(vec.begin(), vec.end());
  for(int i=0;i<N;i++)T+=vec[i];
  cout << T << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int X, res, ans;

int main()
{
	in >> X;
	ans = 1;
	for (int i = 2; i < X; ++i)
	{
		if (i * i > X) break;
		res = i;
		while(res * i <= X) res *= i;
		ans = std::max(ans, res);
	}
	out << ans << std::endl;
	return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<int> K(M);
    vector<vector<int>> s(M);
    rep(i,M){
        cin >> K.at(i);
        rep(j, K.at(i)) {
            int a; cin >> a;
            s.at(i).push_back(a);
        }
    }
    vector<int> p(M);
    rep(i,M) cin >> p.at(i);
    vector<int> cnt(M, 0);

    ll ans = 0;
    for(int i=0; i<(1<<N); i++){
        for(int j=0; j<N; j++){
            if(i&(1<<j)){
                for(int k=0; k<M; k++){
                    for(int l=0; l<K.at(k); l++){
                        if(s.at(k).at(l) == j+1){
                            cnt.at(k)++;
                        }
                    }
                }
            }
        }
        
        rep(k, M){
            cnt.at(k) = cnt.at(k)%2;
            if(p.at(k) != cnt.at(k)) break;
            if(k==M-1) ans++;
        }

        rep(k, M){
            cnt.at(k) = 0;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string>

using namespace std;


	long long dp[262144];
	long long need[109];
	#define beg 131072
	#define MOD 1000000007

	long long sum(int l , int r){
		
		long long sum = 0;
		
		while(l <= r){
			
			if(l%2!=0){
				sum += dp[l];
				l++;
			}
			if(r%2==0){
				sum += dp[r];
				r--;
			}
			r/=2;
			l/=2;
			
		}
		
	//	cout << l << " " << r << " " << sum << endl;
		return sum;
		
	}

int main(){

	int n; cin >> n;
	int k; cin >> k;
	
	dp[beg + k] = 1;
	for(int j = beg-1; j > 0; j--) dp[j] = dp[j*2] + dp[j*2+1];
	for(int i = 0; i < n; i++){
		cin >> need[i];
		
		//cout << i << endl;
		for(int j = 0; j <= k; j++){
			
			dp[beg + j] += sum((long long)beg + j + 1 , min(beg + j + need[i],2*(long long)beg-1));
			dp[beg + j]%=MOD;
			
		}
		
		for(int j = beg-1; j > 0; j--){
			dp[j] = dp[j*2] + dp[j*2+1];
			dp[j]%=MOD;
		}
		
	} 
	cout << dp[beg]; 
	
	
//	0 1 2 3 4
//	1
//	1 1
//	1 1 1 
//	1 1 1 1 
//	  1 1 1 1
//	1
//	1 1 
//	1 1 1 
//      1 1 1 
//	    1 1 1  
//	3       
//	2



	return 0;
}

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

int res,m=9*8*7*6*5*4*3*2;
int a[10],b[10];
bool A[10]={};

void dfs(int index,int L,int R){
  if(index==9){
    if(L>R)res++;
  }
  else {
    for(int i=0;i<9;i++){
      if(A[i])continue;
      A[i]=true;
      if(a[i] < b[index])dfs(index+1,L+a[i]+b[index],R);
      else dfs(index+1,L,R+a[i]+b[index]);
      A[i]=false;
    }
  }
}

int main()
{
  int n;

  cin>>n;
  for(int k=0;k<n;k++){
    for(int i=0;i<9;i++)cin>>a[i];
    for(int i=0;i<9;i++)cin>>b[i];
    for(int i=0;i<9;i++)A[i]=false;
    res=0;
    dfs(0,0,0);
    printf("%.5f %.5f\n",(1-res/(double)m),res/(double)m);  
  }
  return 0;
}

Measured memory_bytes: 1184
n,m = map(int,input().split())
ac,wa = 0,0
number=[0]*n

for i in range(m):
  p,s = input().split()
  p = int(p) - 1
  if number[p]!=-1:
    if s == "WA":
      number[p]+=1
    elif s == "AC":
      ac+=1
      wa+=number[p]
      number[p]=-1
print(ac,wa)

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <cmath>
#define rep(i,n) for (int i = 0; i<(n); i++)
using namespace std;
using P = pair<int,int>;
#include <vector>
#include <algorithm>

int main(){
    long double  ans = 1.0;
    long double  a,b;
    cin >> a>>b;
    ans = a*(b*1000)/1000;
    int long long num = ans;
    cout<< num;
}

Measured memory_bytes: 3708
<?php
	$a=fgets(STDIN);
	$b=fgets(STDIN);
	$c=fgets(STDIN);
	$x=fgets(STDIN);
	for($i=0;$i<=$a;$i++)for($j=0;$j<=$b;$j++)for($k=0;$k<=$c;$k++)$cnt+=$i*500+$j*100+$k*50==$x;
	echo $cnt;


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

int main() {
	string a,b,c;
	int n,ans;
	ans = 0;
	cin >> n;
	cin >> a >> b >> c;
	for (int i = 0; i <= n; i++) {
		if (!(a[i] == b[i])||!(b[i]==c[i])||!(c[i]==a[i])){
			ans++;
		}
		if (!(a[i] == b[i]) && !(b[i] == c[i]) && !(c[i] == a[i])){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(void) {
    int N,M;cin>>N>>M;
    map<int, int> mp;
    for (int i = 1; i <= M; i++) mp[i] = 0;

    for (int i = 0; i < N; i++) {
        int k;cin>>k;
        for (int j = 1; j <= k; j++) {
            int a;cin>>a;
            mp[a] += 1;
        }
    }

    int result = 0;
    for (int i = 1; i <= M; i++) {
        if (mp[i] == N) result++;
    }
    cout << result << endl;
    
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> cnt(13);
    for(int i = 0; i < n; i++){
        int d;
        cin >> d;
        cnt[d]++;
    }
    vector<int> aa;
    aa.push_back(0);
    if(cnt[0] || cnt[12] >= 2){
        cout << 0 << endl;
        return 0;
    }
    if(cnt[12] == 1)
        aa.push_back(12);
    bool flip = true;
    for(int i = 1; i < 12; i++){
        switch(cnt[i]){
            case 0:
                break;
            case 1:
                if(flip) aa.push_back(i);
                else aa.push_back(24-i);
                flip = !flip;
                break;
            case 2:
                aa.push_back(i);
                aa.push_back(24-i);
                break;
            default:
                cout << 0 << endl;
                return 0;
        }
    }
    int mn = 24;
    aa.push_back(24);
    sort(aa.begin(), aa.end());
    for(int i = 0; i+1 < aa.size(); i++){
        if(mn > aa[i+1]-aa[i]) mn = aa[i+1]-aa[i];
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 3624