akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


void shuffle(int h, char *s0) {
  int length;
  length = strlen(s0);
  char temp[length-h+1],s1[length+1];
  strcpy(temp,s0+h);
  strncpy(s1, s0, h);
  s1[h]='\0';
  sprintf(s0, "%s%s", temp, s1);
}


int main() {
  int i,h;
  char s0[201];
  while(1) {
    scanf("%s", s0);
    if(strcmp(s0, "-") == 0) break;
    scanf("%d", &i);
    for(;i>0;i--){
      scanf("%d", &h);
      shuffle(h, s0);
    }
    printf("%s\n", s0);
    memset(s0, '\0', 200);
  }
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  
  int mn = a[0], mx = a[0];
  for(int i = 1; i < n; i++){
    if(mn > a[i]) mn = a[i];
    if(mx < a[i]) mx = a[i];
  }
  
  cout << mx - mn << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
struct W{double v,t;W(double _v=0,double _t=0):v(_v),t(_t){}}a[N],q[N];
inline bool operator <(W x,W y){return x.t<y.t;}
inline W operator +(W x,W y){return W(x.v+y.v,(x.t*x.v+y.t*y.v)/(x.v+y.v));}
int main()
{	int n,L,h=1,t=0; double sum1=0,sum2=0; cin>>n>>L;
	for(rint i=1;i<=n;i++) scanf("%lf%lf",&a[i].t,&a[i].v);
	for(rint i=1;i<=n;i++)
	{	for(;sum2+a[i].v>L;h++)
		{	if(sum2-q[h].v+a[i].v<L)
			{q[h].v-=sum2+a[i].v-L,sum1-=q[h].t*(sum2+a[i].v-L),sum2-=sum2+a[i].v-L;break;}
			else sum1-=q[h].v*q[h].t,sum2-=q[h].v;
		}
		q[++t]=a[i]; sum1+=a[i].v*a[i].t; sum2+=a[i].v;
		for(;t-1>=h;t--)
		if(q[t].t>q[t-1].t) break; else q[t-1]=q[t-1]+q[t];
		printf("%.10lf\n",sum1/sum2);
	}
	return 0;
}


Measured memory_bytes: 41728
#include<iostream>
#include<vector>
using namespace std;
vector<char> vec;
char tab[20][20];
int ans,pre,dx[]={0,0,1,-1},dy[]={1,-1,0,0},pl,used[20][20];
void are1(int y,int x,char c){
	pre++;
	used[y][x]=1;
	int ny,nx;
	for(int i=0;i<4;i++){
		ny=dy[i]+y;nx=dx[i]+x;
		if(ny>=0&&ny<12&&nx>=0&&nx<6){
		if(tab[ny][nx]==c&&used[ny][nx]==0)
			are1(ny,nx,c);
		}
	}
}
void are2(int y,int x,char c){
	int ny,nx;
	tab[y][x]='.';
	for(int i=0;i<4;i++){
		ny=dy[i]+y;nx=dx[i]+x;
		if(ny>=0&&ny<12&&nx>=0&&nx<6){
			if(tab[ny][nx]==c)
				are2(ny,nx,c);
			else if(tab[ny][nx]=='O')
				tab[ny][nx]='.';
		}
	}
}
void rensa(){
	for(int i=0;i<12;i++)
	for(int j=0;j<6;j++)
	used[i][j]=0;
	for(int i=0;i<12;i++)
	for(int j=0;j<6;j++){
		if(tab[i][j]!='O'&&tab[i][j]!='.'){
			pre=0;
			are1(i,j,tab[i][j]);
			if(pre>=4){
				are2(i,j,tab[i][j]);
				pl++;
			}
		}
	}
}
void liset(){
	int k;
	for(int i=0;i<6;i++){
		k=0;
		for(int j=11;j>=0;j--){
			if(tab[j][i]!='.')
			vec.push_back(tab[j][i]);
		}
		for(int j=11;(int)11-j<(int)vec.size();j--)
			tab[j][i]=vec[k++];
		for(int j=(int)11-vec.size();j>=0;j--)
			tab[j][i]='.';
		vec.clear();
	}
}
void solve(){
	do{
		pl=0;
		rensa();
		if(pl){
		liset();
		ans++;
		}
	}while(pl);
}
int main(){
	int n;
	cin>>n;
	while(n-->0){
		ans=0;
		for(int i=0;i<12;i++)
		cin>>tab[i];
		solve();
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int64 fn_even(int64 a_prev){ return a_prev / 2;     }
int64 fn_odd (int64 a_prev){ return 3 * a_prev + 1; }

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    int s; cin >> s;
    unordered_map<int64, bool> ht;
    
    int64 a_prev = s;
    int64 a_next;
    ht[ a_prev ] = true;
    
    int64 i=2ll;
    for(;;){
        a_next = (a_prev%2==0) ? fn_even(a_prev) : fn_odd(a_prev);
        if( ht.find( a_next ) != ht.end() ){ break; }
        ht[ a_next ]=true;
        
        a_prev = a_next;
        ++i;
    }
    
    cout << i << endl;
    
    return 0;
}


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

const ll INF = pow(10, 9) + 7;

int main() {
  ll n,k,q;
  cin >> n >> k >> q;
  vector<int> a(n,k-q);
  rep(i,q){
    int m;
    cin >> m;
    m--;
    a[m]++;
  }
  rep(i,n){
    if(a[i]<=0) cout << "No" << endl;
    else cout << "Yes" <<endl;
  }
}

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


int main(){
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);
    sort(A.begin(), A.end());
    vector<int> dst(N);
    rep(i, N - 1) dst.at(i) = A.at(i + 1) - A.at(i);
    dst.at(N-1) = K - A.at(N-1)+A.at(0);
    sort(dst.begin(), dst.end());
    cout << K - dst.at(N-1) << endl;

    return 0;
}


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

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

    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    string T = S;
    reverse(T.begin(), T.end());
    int cnt = 0;
    for (int i = 0; i < (int)S.size(); i++) {
        if (S[i] != T[i]) cnt++;
    }
    cout << cnt / 2 << endl;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=1e5+1e3+7;

char s[N],t[N];

int n,ans,cnt,pos[N];

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		if(s[i]!='x')
			t[++cnt]=s[i],pos[cnt]=i;
	}
	for(int i=1;i<=cnt;i++)
		if(t[i]!=t[cnt-i+1])
		{
			printf("-1");
			exit(0);
		}
	pos[0]=0;
	pos[cnt+1]=n+1;
	for(int i=1;i<=cnt/2+(cnt&1);i++)
	{
		int x=i,y=cnt-i+1;
		int l=pos[x]-pos[x-1]-1;
		int r=pos[y+1]-pos[y]-1;
		ans+=abs(l-r);
	}
	cout<<ans;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int n;
    cin >> n;
    vector<string> data(n);
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        data.at(i) = s;
    }
    sort(data.begin(),data.end());
    long cnt = 1;
    long ans = 0;
    for(int i=1;i<n;i++){
        if(data.at(i) == data.at(i-1)) cnt++;
        else{
            ans += cnt*(cnt-1)/2;
            cnt=1;
        }
    }
    ans += cnt*(cnt-1)/2;
    cout << ans << endl;
    //rep(i,n) cout << data.at(i) << endl;
}

Measured memory_bytes: 5760
from test.support import ALWAYS_EQ
mNM = map(int, input().split())
lNM = list(mNM)

mHigh = map(int, input().split())
lHigh = list(mHigh)
lNum = [1 for i in range(lNM[0])]

for i in range(lNM[1]):
    mWay = map(int, input().split())
    lWay = list(mWay)
    if lHigh[lWay[0]-1] > lHigh[lWay[1]-1]:
        lNum[lWay[1]-1] = 0
    elif lHigh[lWay[0]-1] < lHigh[lWay[1]-1]:
        lNum[lWay[0]-1] = 0
    elif lHigh[lWay[0]-1] == lHigh[lWay[1]-1]:
        lNum[lWay[0]-1] = 0
        lNum[lWay[1]-1] = 0

print(sum(lNum))

Measured memory_bytes: 31156
#include <stdio.h>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  vector<long long int> arr[8];
  for(int i = 0; i < n; i++) {
    long long int a,b,c;
    scanf("%ld%ld%ld",&a,&b,&c);
    arr[0].push_back(a+b+c);
    arr[1].push_back(-a+b+c);
    arr[2].push_back(a-b+c);
    arr[3].push_back(-a-b+c);
    arr[4].push_back(a+b-c);
    arr[5].push_back(-a+b-c);
    arr[6].push_back(a-b-c);
    arr[7].push_back(-a-b-c);
  }
  long long int ans = 0;
  for(int i = 0; i < 8; i++) {
    sort(arr[i].begin(),arr[i].end());
    /*
    printf("%d\n",arr[i].size());
    for(int j = 0; j < arr[i].size(); j++) {
      printf("%d ",arr[i][j]);
    }
    printf("\n");
    */
    long long int _ans = 0;
    for(int j = 0; j < m; j++) {
      _ans += arr[i][n-j-1];
      //printf("%d ",arr[i][n-j-1]);
    }
    //printf("\n");
    //printf("%ld\n",_ans);
    ans = max(ans,_ans);
  }
  printf("%ld\n",ans);
}


Measured memory_bytes: 256
def main():
    S = input()
    smaller_cnt = [0]  # <
    seq_cnt = 0
    for c in S:
        if c != '<':
            seq_cnt = 0
        else:
            seq_cnt += 1
        smaller_cnt.append(seq_cnt)
    larger_cnt = [0]  # >
    for c in S[::-1]:
        if c != '>':
            seq_cnt = 0
        else:
            seq_cnt += 1
        larger_cnt.append(seq_cnt)
    larger_cnt.reverse()
    ans = 0
    for x, y in zip(smaller_cnt, larger_cnt):
        ans += max([x, y])
    print(ans)


if __name__ == '__main__':
    main()

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

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPI(i, a, b) for (int(i) = int(a); (i) < int(b); ++(i))

using namespace std;

int main()
{
    int Z;           //入力待ち
    int j, k;        //for文用
    string to = ","; //デバッグ用
    int e_count = 0; //演算回数を数える
    int count = 0;   //よくあるカウント
    //----------

    int n;
    cin >> n;
    long nums[200];
    REP(i, n)
    {
        cin >> nums[i];
    }

    //2で割れる回数を数える
    int min = INFINITY;
    REP(i, n)
    {
        while (nums[i] % 2 == 0)
        {
            nums[i] = nums[i] / 2;
            count++;
        }
        if (min > count)
            min = count;

        count = 0;
    }
    cout << min << endl;

    //-----------
    cin >> Z;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
using namespace std;
typedef long long ll;
//定義場所//
ll i, j, k, l, m, n;
ll N, M, K;
ll MOD = 1000000007;
ll ans = 0;
////////////

bool pairCompare(const pair<ll,ll> firstElof, pair<ll,ll> secondElof)
{
	return firstElof.second > secondElof.second;
}

int main()
{
	cin >> N >> M;
	vector<ll> A;
	vector<pair<ll, ll> >BC(100000);
	ll ans = 0;
	for (i = 0; i < N; i++) {
		ll a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());
	for (i = 0; i < M; i++) {
		int b, c;
		cin >> b >> c;
		BC[i] = make_pair(b, c);
	}
	sort(BC.begin(), BC.end(),pairCompare);
	//reverse(BC.begin(), BC.end());
	int depth = 0;
	int count = 0;
	for (i = 0; i < N; i++) {
		if (A[i] < BC[depth].second) {
			A[i] = BC[depth].second;
			count++;
		}
		else {
			break;
		}
		if (count >= BC[depth].first) {
			depth++;
			count = 0;
			if (depth > M - 1) {
				break;
			}
		}
	}
	for (i = 0; i < N; i++) {
		ans += A[i];
	}

	cout << ans;

}

Measured memory_bytes: 2936
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
int main(){
	while(true){
		int n,k,s,ans=0;
		cin>>n>>k>>s;
		if(n==0) break;
		rep(i,1<<n){
			int cnt=0,sum=0;
			rep(j,n) if((i>>j)&1) cnt++,sum+=j+1;
			if(sum==s&&cnt==k) ans++;
		}
		cout<<ans<<endl;
	}
}

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

const int N = 100005;

int n;
int a[N], b[N], p[N];
long long ans = 0;

bool cmp(int u,int v) {
	return a[u] + b[u] > a[v] + b[v];
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d %d", a + i, b + i);
		p[i] = i;
	}
	sort(p + 1, p + n + 1, cmp);
	for (int i = 1; i <= n; ++i) {
		if (i & 1) {
			ans += a[p[i]];
		} else {
			ans -= b[p[i]];
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define db(x) cout<<x<<" "
#define db1(x) cout<<x<<'\n'
#define db2(x,y) cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pair(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ll  long long int
#define vi vector<ll>
#define pi pair<ll,ll>
#define vpi vector<pair<ll,ll>>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define mod 1000000007
#define MAX_N 100000
using namespace std;
// int dx[4] = {1,-1,0,0};
// int dy[4] = {0,0,1,-1};



void solve(){

    ll n,k;
    cin>>n>>k;

    ll arr[n+1];
    repA(i,1,n)
    cin>>arr[i];


    ll dp[n+1];
    dp[1]=0;
    dp[2]=abs(arr[2]-arr[1]);

    repA(i,3,n){
        dp[i]=INT_MAX;
        repA(j,1,k){
        if(i-j<=0)
        break;    
        dp[i] = min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
        }
    }

    db1(dp[n]);
    
}
int main(){ 



int t=1;
//cin>>t;
while(t--){
 solve();
}
  return 0; 
}





Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  string S; cin >> S;
  ll sum = 0;
  rep(i,sz(S)){
    sum += (ll)(S[i]-'0');
  }
  if(sum%9==0)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;




int main(){
	int x,y; cin >> x >> y;
	int ans;
	if(abs(x) == abs(y)){
		if(x == y) ans = 0;
		else ans = 1;
	}
	else if(abs(x) > abs(y)){
		if(x > y){
			if(y > 0) ans = x-y+2;
			else ans = x+y+1;
		}
		else{
			if(y > 0) ans = -x-y+1;
			else ans = y-x;
		}
	}
	else{
		if(x > y){
			if(x < 0) ans = x-y+2;
			else ans = -x-y+1;
		}
		else{
			if(x < 0) ans = x+y+1;
			else ans = y-x;
		}
	}
	cout << ans << endl;
}



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

struct branch{
	int n1,n2,w;
};
bool f(branch i,branch j){
	return(i.w>j.w);
}
int main(){
	while(1){
		int m,n,i,x=0;
		char c;
		cin>>n;
		if(n==0)break;
		vector<int>T(n);
		for(i=0;i<n;i++) T[i]=i;

		cin>>m;
		vector<branch>S(m);
		for(i=0;i<m;i++) cin>>S[i].n1>>c>>S[i].n2>>c>>S[i].w;
		sort(S.begin(),S.end(),f);

		branch tmp;
		while(S.size()){
			tmp=S.back();
			S.pop_back();
			int b=T[tmp.n1],c=T[tmp.n2],a=b;
			if(b!=c){
				if(b>c)a=c,c=b;
				for(i=c;i<n;i++)
					if(T[i]==c)T[i]=a;
				x+=tmp.w/100-1;
			}
		}
		cout<<x<<endl;
	}
}

Measured memory_bytes: 1272
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<vector<int>>graph;
int dfs(int now,int cnt){
  if(graph[now].size()==0)return cnt;
  vector<int> tmp;
  for(int v:graph[now]){
     int t=dfs(v,cnt+1);
      tmp.push_back(t);
  }
  int res=0;
  sort(all(tmp),greater<int>());
  int cn=0;
  for(int u:tmp){
      chmax(res,u+cn);
      cn++;
  }
   return res;
}
int main(){
    int n;
    cin>>n;
    graph.resize(n);
    for(int i=1;i<n;i++){
        int a;
        cin>>a;
        graph[a-1].push_back(i);
    }
    cout<<dfs(0,0)<<endl;
}



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

//  c0 c1 c2 c3 c4 c5 c6
//  a0 a1 a2 a3 a4 a5 a6
const int tam = 1e5+10;
int dp[tam];
long long h[tam];


int solve( int i  ) {
    // cout << i << '\n';
    if( i <= 1 ) return abs(h[0]-h[i]);
    int &ans = dp[i];
    if( ans != -1 ) return ans;
    return ans = min( solve( i-1)+abs(h[i]-h[i-1]), solve(i-2)+abs(h[i]-h[i-2]) );
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k;
    cin >> n;
    for( int i = 0; i < n; i++  ) {
        cin >> h[i];
    } 
    // dp[0] = 0;
    // for( int i = 1; i < n; i++ ) {
    //     dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
    //     for( int j = 2; j <= k; j++)
    //     if( j <= i ) {
    //         dp[i] = min( dp[i], dp[i-j] + abs(h[i]-h[i-j]) );
    //     }
    // }
    // cout << dp[n-1] << '\n';
    memset( dp, -1, sizeof dp );
    cout << solve(n-1) << '\n';
    return 0;
}

Measured memory_bytes: 7092
package main

import (
	"fmt"
)

func main() {
	var A, B, C int
	fmt.Scanf("%d%d%d", &A, &B, &C)
	var ans int
	if C < A+B+1 {
		ans = B + C
	} else {
		ans = A + B + B + 1
	}
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 512
i = input().split()

a = int(i[0])
b = int(i[1])

once = a + b

twiceA = a + a - 1

twiceB = b + b -1

if once > twiceA and once > twiceB:
    print(once)
elif twiceA > twiceB:
    print(twiceA)
else:
    print(twiceB)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


int N;
vector<long long> A, B;

long long solve() {
    vector<long long> vmi, vma;
    for (int i = 0; i < N; ++i) vmi.push_back(A[i]), vma.push_back(B[i]);
    sort(vmi.begin(), vmi.end());
    sort(vma.begin(), vma.end());
    if (N % 2 == 0) {
        long long mi = (vmi[N/2-1] + vmi[N/2]) / 2;
        long long ma = (vma[N/2-1] + vma[N/2]) / 2;
        //COUT(mi); COUT(ma);
        return ma - mi + 1;
    }
    else {
        long long mi = vmi[N/2];
        long long ma = vma[N/2];
        //COUT(mi); COUT(ma);
        return ma - mi + 1;
    }
}

int main() {
    while (cin >> N) {
        A.resize(N); B.resize(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i] >> B[i];
            if (N % 2 == 0) A[i] *= 2, B[i] *= 2;
        }
        cout << solve() << endl;
    }
}

















Measured memory_bytes: 9776
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, q: usize,
        c: [Usize1; n],
        lr: [(Usize1, Usize1); q]
    }

    let mut queries = lr.into_iter().enumerate().map(|(i, (l, r))| (i, l, r)).collect_vec();
    queries.sort_by_key(|&(_, l, _)| l);

    let mut pairs = Vec::new();
    let mut prevs = vec![n; n];
    for (i, c) in (0..).zip(c) {
        if prevs[c] != n {
            pairs.push((prevs[c], i));
        }
        prevs[c] = i;
    }
    pairs.sort();

    let mut bit = BIT::new(n);
    let mut ans = vec![0; q];
    while let Some((i, l, r)) = queries.pop() {
        while let Some((l2, r2)) = pairs.pop() {
            if l2 < l {
                pairs.push((l2, r2));
                break;
            }
            bit.add(r2+1, 1);
        }
        ans[i] = r + 1 - l - bit.sum(r+1);
    }

    for ans in ans {
        println!("{}", ans);
    }
}

#[allow(dead_code)]
/// Binary Indexed Tree of usize
pub struct BIT {
    buf: Vec<usize>,
}
#[allow(dead_code)]
impl BIT {
    pub fn new(n: usize) -> BIT {
        BIT {
            buf: vec![0; n + 1],
        }
    }
    pub fn sum(&self, i: usize) -> usize {
        let mut i = i;
        let mut s = 0;
        while i > 0 {
            s += self.buf[i];
            i &= i - 1;
        }
        s
    }
    pub fn add(&mut self, i: usize, x: usize) {
        let mut i = i as i64;
        while i < self.buf.len() as i64 {
            self.buf[i as usize] += x;
            i += i & -i;
        }
    }
}

Measured memory_bytes: 43672
#include <bits/stdc++.h>
using namespace std;
  
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
  
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  
typedef long long int ll;
  
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;
const ll maxn=1000001;
const ll LOGMAXN=30;
ll power(ll x, ll n) {
      ll res = 1;
      for (; n > 0; n >>= 1) {
        if (n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
      }
      return res;
}

int main()
{
  
  IOS
  ll n;
  cin>>n;
  string s;
  cin>>s;
  set<string> s1,s2,s3;
  for(ll i=0;i<n;i++)
  { 
    string temp="";
    temp+=s[i];
    for(auto y:s2)
    {
      s3.in(y+temp);
    }
    for(auto x:s1)
    {
      s2.in(x+temp);
    }
    s1.in(temp);
  }
  cout<<s3.size();

}
    

  
  
	

 

Measured memory_bytes: 384
/***********************************************
 *                   _ooOoo_                   *
 *                  o8888888o                  *
 *                  88" . "88                  *
 *                  (| -_- |)                  *
 *                  O\  =  /O                  *
 *               ____/`---'\____               *
 *             .'  \\|     |//  `.             *
 *            /  \\|||  :  |||//  \            *
 *           /  _||||| -:- |||||-  \           *
 *           |   | \\\  -   * |    |           *
 *           | \_|  ''\---/''  |   |           *
 *           \  .-\__  `-`  ___/-. /           *
 *         ___`. .'  /--.--\  `. . __          *
 *      ."" '<  `.___\_<|>_/___.'  >'"".       *
 *     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     *
 *     \  \ `-.   \_ __\ /__ _/   .-` /  /     *
 *======`-.____`-.___\_____/___.-`____.-'======*
 *                   `=---='                   *
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

             佛祖保佑       永无BUG

   本程序已经经过开光处理，绝无可能再产生bug
 **********************************************/
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define ll long long
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1==p2)?EOF:*p1++)
using namespace std;
char buf[(1<<22)],*p1=buf,*p2=buf;
inline ll read(){
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
const int maxn=1e5+10;
priority_queue<int>Q;
int main(){
    #ifdef DanDan
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //DanDan
    int n,m;ll ans=0;
    scanf("%d%d",&n,&m);
    for(int x,i=0;i<n;i++){
        scanf("%d",&x);Q.push(x);
    }
    for(int i=0;i<m;i++){
        int o=Q.top();o/=2;
        Q.pop();Q.push(o);
    }
    while(!Q.empty()){
        ans+=Q.top();Q.pop();
    }
    cout<<ans<<endl;
    #ifdef DanDan
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //DanDan
    return 0;
}


// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ????━????   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━



Measured memory_bytes: 892
# -*- coding: utf-8 -*-
import math
import operator
from functools import reduce
def gcd(a,b):
    c = 0
    while a != b:
        if a&1==b&1==0:
            a, b = a>>1, b>>1
            c += 1
        elif min(a,b) == 0:
            a = max(a,b)
        else:
            a, b = max(a,b)%min(a,b), min(a,b)
    return a*2**c


def lcm(a,b):
    return (a*b)//gcd(a,b)

def solve():
    N = int(input())
    *A, = map(int, input().split())
    m = reduce(lcm, A) - 1
    s = sum([m%a for a in A])

    return str(s)

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 3804
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
    string S[3];
    REP(i,3){
        cin >> S[i];
    }
    char next='a',ans;
    REP(i,300){
        if(next=='a'){
            if(S[0].length()==0){
                ans = 'A';
                break;
            }
            next = S[0][0];
            S[0].erase(S[0].begin());
        }else if(next=='b'){
            if(S[1].length()==0){
                ans = 'B';
                break;
            }
            next = S[1][0];
            S[1].erase(S[1].begin());
        }else{
            if(S[2].length()==0){
                ans = 'C';
                break;
            }
            next = S[2][0];
            S[2].erase(S[2].begin());
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(){

    int flag = 0;
    int c[4],r[4];
    int i,sum,a,money;
    int d[4] = {10,50,100,500};
    while(1){
        scanf("%d",&money);
        if(money == 0){
            break;
        }
        if(flag == 1){
            printf("\n");
        }
        scanf("%d %d %d %d",&c[0],&c[1],&c[2],&c[3]);
        sum = 0;
        for(i = 0; i < 4 ; i++){
            sum += c[i] * d[i];
            r[i] = 0;
        }

        sum = sum - money;
        for(i = 3; i >= 0 ;i--){
           while(sum >= d[i]){
               sum -= d[i];
               r[i]++;
           }
        }

        for(i = 0; i < 4 ; i++){
            a = c[i] - r[i];
            if(a > 0){
                printf("%d %d\n",d[i],a);
            }
        }
    flag = 1;
    }
    return 0;
    
}


Measured memory_bytes: 2052
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N, X; std::cin >> N >> X;
  int d = 0;
  for (int i = 0; i < N; ++i) {
    int L; std::cin >> L;
    d += L;
    if (d > X) {
      std::cout << i + 1 << std::endl;
      return 0;
    }
  }
  std::cout << N + 1 << std::endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 N, T, L, B;
  while (cin >> N >> T >> L >> B &&N+L+T+B) {
    vector<int> ty(N+1, 0);
    REP(i, L) { int64 l; cin >> l; ty[l] = 1; }
    REP(i, B) { int64 b; cin >> b; ty[b] = 2; }
    auto dp = make_v<double>(T+1, N+1);
    fill_v<double>(dp, 0);
    dp[0][0] = 1;
    REP(t, T) {
      REP(i, N) {
        FOR(j, i+1, i+7) {
          int64 p = N-abs(N-j);
          if (ty[p] == 0) {
            dp[t+1][p] += dp[t][i] / 6;
          } else if (ty[p] == 1) {
            dp[min(T, t+2)][p] += dp[t][i] / 6;
          } else {
            dp[t+1][0] += dp[t][i] / 6;
          }
        }
      }
    }
    double res = 0;
    REP(i, T+1) {
      res += dp[i][N];
    }
    cout << fixed << setprecision(10) << res << endl;
  }
}




Measured memory_bytes: 3376
using System;
using System.Linq;

namespace ABC88_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(s);
            Array.Reverse(s);

            var dif = 0;
            for (int i = 0; i < s.Length - 1; i += 2)
            {
                dif += s[i] - s[i + 1];
            }

            if (s.Length % 2 == 1)
            {
                dif += s[s.Length - 1];
            }

            Console.WriteLine(dif);
        }
    }
}


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

using namespace std;

string s, a, b, ans;
int q, t, f;
char c;
bool rev;

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	cin >> s >> q;
	while (q--) {
		cin >> t;
		if (t == 1) {
			rev ^= 1;
		}
		else {
			cin >> f >> c;

			if (!rev) {
				if (f == 1)
					a += c;
				else
					b += c;
			}
			else {
				if (f == 1)
					b += c;
				else
					a += c;
			}
		}
	}

	reverse(a.begin(), a.end());

	ans = a + s + b;

	if (rev)
		reverse(ans.begin(), ans.end());

	cout << ans << endl;
}


Measured memory_bytes: 1348
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
l=[0]*35
for i in range(n):
    for j in range(35):
        if (a[i]>>j)%2==1:
            if l[j]==0:
                l[j]=1
            else:
                l[j]=0
ans=[]
for i in range(n):
    temp=0
    for j in range(35):
        if (a[i]>>j)%2==1:
            if l[j]==0:
                temp+=2**j
        else:
            if l[j]==1:
                temp+=2**j
    ans.append(temp)

for i in ans:
    print(i,end='')
    print(' ',end='')

Measured memory_bytes: 99376
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll  n,m;
    cin>>n>>m;
    priority_queue<ll >pq;
    for(ll  i=0;i<n;i++)
    {
        ll  x;
        cin>>x;
        pq.push(x);
    }
    while(m)
    {
        ll  x=pq.top();
        pq.pop();
     //   cout<<round(float(x)/2)<<endl;
        pq.push(x/2);
        m--;
    }
    ll  sum=0;
    while(!pq.empty())
    {
        sum+=pq.top();
        pq.pop();
    }
    cout<<sum<<endl;
}


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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll no_of_div(ll a)
{
  ll cnt=0,i;
  if (a==2)return 1;
  for(i=2;i*i<a;i++)
  {
if(a%i==0)cnt+=2;
  }
  if(i*i==a)cnt++;
  return cnt;
}

//vl a(1001);

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}





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

ll n;cin>>n;
ll x=1;
while(x<=n)x<<=1;
x>>=1;

cout<<x<<"\n";

  return 0;


}

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

typedef long long ll;

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

    int dist[n+1];
    dist[1] = 0;

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

    ll ans = 0;
    int now = 1, next;

    for(int i = 0; i < m; i++){
        cin >> next;
        if(next < 0){
            ans += dist[now] - dist[now+next];
        }else{
            ans += dist[now+next] - dist[now];
        }
        now += next;
    }

    cout << ans % 100000 << endl;

    return 0;
}


Measured memory_bytes: 3496
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>
#include<cstdio>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
using namespace std;
typedef long long ll;
typedef long long int lli;
// static const int MOD = 10000007;
static const int NMAX = 100;



int N, M;
int E[NMAX][NMAX];
vector<pair<int, int>> B;
bool visited[NMAX];
int parent[NMAX], timer, prenum[NMAX];



auto compares = [](int l, int r) {
  return l > r;
};

// priority_queue<
// int,
// std::vector<int>,
// greater<int>()
// > B[NMAX];




void dfs(int current, int prev) {
  prenum[current] = timer;
  timer++;

  visited[current] = true;
  int next;
  rep(i, N) {
    if (E[current][i] != 1) continue;
    if ( !visited[i] ) {
      next = i;
      parent[next] = current;
      dfs( next, current );
    }
  }
}

int tree_build(int root) {
  rep(i,N) {
    visited[i] = false;
  }
  timer = 1;

  dfs(root, -1);
  rep(i,N) {
    if(visited[i] == false) return 1;
  }
  return 0;
}

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

  rep(i,M) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    E[a][b] = E[b][a] = 1;
    B.push_back(make_pair(a, b));
  }

  int cnt = 0;
  for(auto p : B) {
    E[p.first][p.second] = E[p.second][p.first] = 0;
    cnt += tree_build(0);
    E[p.first][p.second] = E[p.second][p.first] = 1;
  }
  cout << cnt << endl;

}


Measured memory_bytes: 256
#include <iostream>
#define MAXN 1005
#define MOD 1000000007
using namespace std;

long long h, w, grid[MAXN][MAXN], dp[MAXN][MAXN];

int main() {
	cin >> h >> w;
	for (int i=0; i<h; i++) {
		char c;
		for (int j=0; j<w; j++) {
			cin >> c;
			if (c == '.') grid[i][j] = 1;
			else grid[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	for (int i=0; i<h; i++) {
		for (int j=0; j<w; j++) {
			if (!grid[i][j] || (i == 0 && j == 0)) continue;
			if (i == 0) {
				dp[i][j] = dp[i][j - 1];
				dp[i][j] %= MOD;
			}
			else if (j == 0) {
				dp[i][j] = dp[i - 1][j];
				dp[i][j] %= MOD;
			}
			else {
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
				dp[i][j] %= MOD;
			}
		}
	}
	// for (int i=0; i<h; i++) {
	// 	for (int j=0; j<w; j++) {
	// 		cout << dp[i][j] << ' ';
	// 	}
	// 	cout << "\n";
	// }
	cout << dp[h - 1][w - 1];
}

Measured memory_bytes: 16000
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
s = input()
t = input()
same = 0
for i in range(n):
    #print(s[n-i-1:], t[:i+1])
    if s[n-i-1:] == t[:i+1]:
        same = i+1
print(len(s) + len(t) - same)


Measured memory_bytes: 10384
#include <iostream>

int abs(int a)
{
  return (a > 0) ? a : -a;
}

int main()
{
	
  int n;
  std::cin >> n;
  
  int a[n], dp[n];
  for ( int i = 0; i < n; i++ )
    std::cin >> a[i];

  dp[0] = 0;
  
  for ( int i = 1; i < n; i++ )
  {
    dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
    if (i > 1)
      dp[i] = std::min(dp[i], dp[i - 2] + abs(a[i - 2] - a[i]));
  }
  std::cout << dp[n - 1] << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define N 500000
#define INFTY 1000000001
void merge(int *,int,int,int,int);
void mergeSort(int *,int,int,int);

int S[N],cnt=0;
int main(){
  int n,S[N],i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
  mergeSort(S,n,0,n);
  
  
  for(i=0;i<n;i++){
    if(i<n-1) printf("%d ",S[i]);
    else printf("%d\n",S[i]);
  }
  printf("%d\n",cnt);
 
  return 0;
  
}
int L[N/2+1],R[N/2+1];
void merge(int *S,int n,int l,int m,int r){
  int n1,n2,k,i,j=0;
   
  
  n1=m-l;
  n2=r-m;
  for(i=0;i<=n1-1;i++)L[i]=S[l+i];
  for(i=0;i<=n2-1;i++) R[i]=S[m+i];
  L[n1]=R[n2]=INFTY;
  i=0;
  for(k=l;k<=r-1;k++){
    cnt++;
    if(L[i]<=R[j]){
       
      S[k]=L[i];
    i++;
  }
  else{
     
    S[k]=R[j];
   j++;
  }
}

}
void mergeSort(int *S,int n,int l,int r){
  int m;
  if(l+1<r){
  m=(l+r)/2;
  mergeSort(S,n,l,m);
  mergeSort(S,n,m,r);
  merge(S,n,l,m,r);
  }
  
}



Measured memory_bytes: 5648
#include<iostream>
#include<cmath>
using namespace std;
int r;
long long x;
int main(){
    cin>> x;
    r = sqrt(x * 1.0);
    if(r * 1LL * r == x){
        cout<<"0 0 0 "<< r <<" "<< r <<" 0";
    }
    else{
        r++;
        cout<<"0 0 1 "<< r <<" "<< r <<" "<< r * 1LL * r - x;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define li long long 
using namespace std ; 
int main(){
	int n; 
	cin >> n; 
	int p = 0; 
	for (int i; i < n; ++i){
		int x; 
		cin >> x; 
		if ( x % 2 == 0 ){
			if ( x % 3 != 0 && x % 5 != 0)  p = 1;
		}
	}
	cout << ( (p == 1) ? "DENIED":"APPROVED" ) << endl;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (a,b) = readLine()!!.split(" ").map { it.toInt() }
    println(if(a < b) p(a,b) else p(b,a))
}

fun p(a: Int, b: Int): String {
    return if (b == 1) a.toString()
    else a.toString() + p(a, b-1)
}


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

#define ff               first
#define ss               second
#define mp               make_pair
#define pb               push_back
#define pii              pair<int,int>
#define vi               vector<int> 
#define mii              map<int,int>
#define setbits(x)       __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod              1000000007
#define inf              1e18
#define endl             "\n"

void h_code()
{
 #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
 #endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void l_code()
{
 #ifndef ONLINE_JUDGE
     cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
 #endif
}
const int N=100005;

int main() {
   // h_code();
    int t=1;
    
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        string str1="",str2="";
        int A=a;
        int B=b;
        while(B--)
        {
            str1+=to_string(a);
        }
        while(A--)
        {
            str2+=to_string(b);
        }
        if(str1.compare(str2)<0)
        {
            cout<<str1;
        }
        else
        {
            cout<<str2;
        }
        
         
    }
 //   l_code();
}

Measured memory_bytes: 256
import itertools
N = int(input())
A = ["3", "5", "7"]
L = []
for i in range(1, 10):
  for l in itertools.product(A, repeat=i):
    L.append(l)
c = 0
for l in L:
  if int("".join(l))<=N and l.count("3")>=1 and \
  l.count("5")>=1 and l.count("7")>=1:
    c += 1
print(c)

Measured memory_bytes: 12448
#include<bits/stdc++.h>
using namespace std;
bool sma(string a, string b) {
  int L = (int)a.size();
  for (int i = 0; i < L; i ++) {
    if ((int)a[i] > (int)b[i]) return true;
    if ((int)a[i] < (int)b[i]) return false;
  }
  return true;
}
int main () {
  int N, L;
  cin >> N >> L;
  vector<string>S(N);
  for (int i = 0; i < N; i ++) cin >> S[i];
  for (int i = 0; i < N; i ++) {
    for (int j = 0; j < N - 1; j ++) {
      if (sma(S[j], S[j + 1])) {
        swap(S[j], S[j + 1]);
      }
    }
  }
  for (int i = 0; i < N; i ++) cout << S[i];
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    if (a <= b && b <= c)
      cout << a << " " << b << " " << c << endl;
      
    else if (a <= c && c <= b) 
      cout << a << " " << c << " " << b << endl;
      
       else if (b <= a && a <= c) 
      cout << b << " " << a << " " << c << endl;
      
       else if (b <= c && c <= a) 
      cout << b << " " << c << " " << a << endl;
      
       else if (c <= b && b <= a) 
      cout << c << " " << b << " " << a << endl;
      
       else if (c <= a && a <= b) 
      cout << c << " " << a << " " << b << endl;
      
   
} 


Measured memory_bytes: 3080
#include <iostream>
#include <vector>

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

	if (n[4] - n[0] <= k)
	{
		std::cout << "Yay!" << std::endl;
	}
	else
	{
		std::cout << ":(" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi a(n);
    int l;
    cin>>l;
    int sum=0;
    int min=1<<30;
    int mini=-1;
    rep(i,0,n){
        a[i]=(l+i);;
        sum+=a[i];
        if(min>abs(a[i])){
        min=abs(a[i]);
        mini=i;
        }
    }
    cout<<sum-a[mini]<<endl;
    return 0;
}




Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input;
        int d, t, totalAngle = 90;
        double x = 0, y = 0;
        while (true) {
            input = br.readLine().split(",");
            d = Integer.parseInt(input[0]);
            t = Integer.parseInt(input[1]);
            if (d == 0 && t == 0) {
                break;
            }

            x += d * Math.cos(totalAngle * Math.PI / 180);
            y += d * Math.sin(totalAngle * Math.PI / 180);

            totalAngle -= t;
        }

        System.out.println(((int) x) + "\n" + ((int) y));
    }
}

Measured memory_bytes: 24132