akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
int main()
{
    IOS
    int n,m; cin>>n>>m;
    int sizes[m+1];
    vector<int> vec[m+1];
    for(int i=1;i<=m;i++)
    {
        int si; cin>>si;
        sizes[i] = si;
        for(int j=0;j<si;j++)
        {
            int a; cin>>a;
            vec[i].pb(a);
        }
    }
    int P[n+1];
    for(int i=1;i<=m;i++) cin>>P[i];
    int ans_on = 0;
    int poss_swi = pow(2,n);
    //cout<<poss_swi<<endl;
    for(int i=0;i<poss_swi;i++)
    {
        int on[m+1];
        for(int l=0;l<=m;l++) on[l]=0;
        //for all these switch combinations are all the bulbs lighted up
        for(int j=0;j<n;j++)
        {
            int state = i & 1<<j;
        //    cout<<state<<" ";
            if(state != 0)
            {
                int sn = j+1;
                for(int k=1;k<=m;k++)
                {
                    for(int s=0;s<sizes[k];s++)
                    {
                        if(vec[k][s] == sn)
                        {
                            on[k]++;
                        }
                    }
                } 
            }
        }
       /* cout<<endl;
        for(int y=1;y<=m;y++)
            cout<<on[y]<<" ";
        cout<<endl;*/
        int count = 0;
        for(int y=1;y<=m;y++)
        {
            if(on[y]%2 == P[y])
                count++;
        }
        int flag = 0;
        if(count == m) {
            flag++;
            ans_on++;
        }
     //   cout<<"----------"<<" "<<flag<<endl;
    }

    cout<<ans_on<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    char a[8][8][4];

    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            cin >> a[i][j][0];
        }

    }

    for (int k = 0; k < 3; k++) {
        cout << (k + 1) * 90 << endl;
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
		cout << a[7-j][i][k];
		a[i][j][k+1] = a[7-j][i][k];
            }
            cout << endl;
        }
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    ll a,b; cin >> a >> b;
    ll x = a*b;
    ll tmp;
    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
    }
    ll r = a % b;
    while(r!=0){
    a = b;
    b = r;
    r = a % b;
    }
    cout << x / b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int N,M,A[100];
    cin>>N>>M;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for (int k = 1; k<= M; k++){
        for (int i = 0; i < N-1; i++){
            if (A[i] % k > A[i+1]%k){
            swap(A[i],A[i+1]);
            }
        }
    }
    for (int i = 0; i < N; i++){
        cout << A [i] << endl;
    }
        return 0;
    }



Measured memory_bytes: 3076
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct Shop {
  ll price;
  ll quantity;

  bool operator<( const Shop& right ) const {
    return price < right.price;
  }
};

int main(){
  int N;
  ll M;
  cin >> N >> M;
  vector<Shop> shops(N);
  for(int i=0;i<N;i++) {
    cin >> shops[i].price >> shops[i].quantity;
  }
  sort(shops.begin(), shops.end());

  ll money = 0;
  for(int i=0;i<N;i++) {
    if(shops[i].quantity <= M) {
      money += shops[i].quantity * shops[i].price;
      M -= shops[i].quantity;
    } else {
      money += M * shops[i].price;
      break;
    }

    if(M <= 0) {
      break;
    }
  }

  cout << money << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

int main()
{
	int n;
	string str;
	int r = 0, g = 0, b = 0;
	ll int ans;
	int tha;
	int c = 0;

	cin >> n;
	cin >> str;

	for (int i = 0; i < n; i++) {
		if (str[i] == 'R') {
			r++;
		} else if (str[i] == 'G') {
			g++;
		} else {
			b++;
		}
	}
	ans = (ll int)r * (ll int)g * (ll int)b;

	for (int fir = 0; fir < n; fir++) {
		for (int sec = fir + 1; sec < n; sec++) {
			tha = 2 * sec - fir;
			if (tha < n) {
				if (str[fir] - str[sec] && str[sec] - str[tha] && str[tha] - str[fir]) {
					ans -= 1LL;
				}
			}
		}
	}

	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3724
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    int M = N, cnt = 1;
    for(cnt=1; M>0; cnt++) M -= cnt;
    if(M < 0) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        vector< vector<int> > sets(cnt);

        int id = 1;
        for(int i=0; i<cnt; i++) {
            for(int j=i+1; j<cnt; j++) {
                sets[i].push_back(id  );
                sets[j].push_back(id++);
            }
        }

        cout << cnt << endl;
        for(int i=0; i<cnt; i++) {
            cout << sets[i].size() << " ";
            for(int j=0; j<sets[i].size(); j++) {
                cout << sets[i][j] << " \n"[j + 1 == sets[i].size()];
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(), vec.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define repc(bit, k, n) for (ll bit = (1 << k) - 1; bit < (1 << n); bit = next_combination(bit))
#define repi(itr, vec) for (auto itr = vec.begin(); itr != vec.end(); ++itr)
using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<bool> d;
  rep(i, n)
  {
    int a, b;
    cin >> a >> b;
    d.push_back(a == b);
  }
  bool flag = false;
  rep(i, n - 2)
  {
    if (d[i] && d[i + 1] && d[i + 2])
      flag = true;
  }
  if (flag)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


Measured memory_bytes: 3652
//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
using namespace std;
typedef long long ll;
#define SZ(x) ((int)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//bool cmp(pair<string,int>p1,pair<string,int>p2) {
//    return p1.ss > p2.ss;
//}
//if (s1.find(s2) != std::string::npos) {
//   std::cout << "found!" << '\n';
//}


using namespace std;

int main() {
    fio
    int3(a,b,c)
    cout << c <<" "<<  a <<" "<< b;



}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 int A,B,C,D,E;
  cin>>A>>B>>C>>D>>E;
  vector<int> x(5);
  vector<int> y(5);
  x={A,B,C,D,E};
  for(int i=0;i<5;i++){
    if(x.at(i)%10!=0)
      y.at(i)=10-x.at(i)%10;
    else
      y.at(i)=0;
  }
  sort(y.begin(),y.end());
  int sum=0;
  for(int i=0;i<4;i++)
    sum+=x.at(i)+y.at(i);
  cout<<sum+x.at(4);
}

Measured memory_bytes: 3580
#include<stdio.h>
#define MAX 2000000
#define swap(a,b) a^=b^=a^=b

int H, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest;
  l = 2*i;
  r = 2*i+1;

  if(l <= H &&A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}

int main(){
  int i;
  scanf("%d",&H);
  for(i = 1;i <= H;i++) scanf("%d",&A[i]);

  for(i = H/2;i>=1;i--) maxHeapify(i);

  for(i = 1;i <= H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3808
s=input()
l=list("AKIHABARA".split("A"))[1:-1]

for ii in range(2**4):
  p="A" if ii%2 else ""
  i=ii
  for j in range(3):
    p+=l[j]
    i//=2
    p+="A" if i%2 else ""
  if s==p:print("YES");exit()
print("NO")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[2][101];
  int b[2][101];
  cin>>n;
  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
    }
  }
  int ans=0;
  for(int k=0;k<n;k++){
    int sum=0;
    for(int i=0;i<=k;i++){
      sum+=a[0][i];
    }
    for(int j=k;j<n;j++){
      sum+=a[1][j];
    }
    ans=max(ans,sum);
  }

      
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
const int mod = 1000000007;

ll gcd(ll a, ll b){return b ? gcd(b,a%b) : a;};//最大公約数
ll lcm(ll a, ll b){return a*b/gcd(a,b);};//最小公倍数
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
//ll a[100000];
//ll dom[100001];

int main(){
  ll n,k;
  cin>>n>>k;
  ll h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  sort(h,h+n);
  ll ans=0;
  for(int i=0;i<n-k;i++){
    ans+=h[i];
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<Long> list2 = new ArrayList<>();

    int x = sc.nextInt();
    int t = sc.nextInt();

    if(x >= t){
        System.out.println(x - t);
    }else{
        System.out.println(0);
    }

   
    





}
}

Measured memory_bytes: 35764
n = int(input())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
ans = 0
prex = -1 * 10**10
data.sort()
for i in range(n):
    x, l = data[i]
    if prex <= x - l:
        prex = x + l
    else:
        ans += 1
        prex = min(prex, x+l)
print(n-ans)

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

int main() {
int n;
int max = 0;
string s,x,y;
cin >> n >> s;

for(int i = 1;i < n;i++){
int count = 0;
  x = s.substr(0,i);
  y = s.substr(i);
  set<char> st1, st2; 
  for(int j = 0;j < x.size();j++){
    st1.insert(x[j]);
  }
  for(int j = 0;j < y.size();j++){
    st2.insert(y[j]);
  }
  for(auto itr1 = st1.begin(); itr1 != st1.end(); ++ itr1){
  for(auto itr2 = st2.begin(); itr2 != st2.end(); ++ itr2){
    if(*itr1== *itr2){
        count++;
    }
  }
  }
if(count > max){
  max = count;
}
}

cout << max << endl;
return 0;
}

Measured memory_bytes: 256
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(20);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define double long double
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI=3.141592653589793;
const int L=1e18;


void solve()
{
    int x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(x/d>=k)
	{
		cout << abs(x-k*d) << nl;
		return ;
	}
	k-=x/d;
	x%=d;
	if(k%2) cout << d-x;
	else cout <<x;
}

int32_t main()
{
	FastIO;
	Fast_D;
	solve();
	return 0;
}


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

int main()
{
   string s;
   cin>>s;
   int n;
   n=s.length();
   string s1,s2,s3;
   for(int i=n-1;i>=0;i--)
   {
       s1=s1+s[i];
   }
   int z=(n-1)/2;
   z--;
   int z1=(n+3)/2;
   z1--;
   for(int i=0;i<=z;i++)
   {
       s2=s2+s[i];
   }
   string ps2;
   for(int i=s2.length()-1;i>=0;i--)
   {
       ps2=ps2+s2[i];
   }
   for(int i=z1;i<n;i++)
   {
       s3=s3+s[i];
   }
   string ps3;
   for(int i=s3.length()-1;i>=0;i--)
   {
       ps3=ps3+s3[i];
   }
  if(s==s1&&s2==ps2&&s3==ps3)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;


  return 0;
}






Measured memory_bytes: 256
/*2019/10/19 */
/*template*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){if(*(int*)a < *(int*)b)return -1;else if(*(int*)a == *(int*)b)return 0;else return 1;}
int desc(const void *a,const void *b){if(*(int*)a < *(int*)b)return 1;else if(*(int*)a == *(int*)b)return 0;else return -1;}
int llasc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return -1;else if(*(ll*)a == *(ll*)b)return 0;else return 1;}
int lldesc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return 1;else if(*(ll*)a == *(ll*)b)return 0;else return -1;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}
 
//int asc_t(const void *a,const void *b){if(((pair_t*)a)->d < ((pair_t*)b)->d)return -1;else if(((pair_t*)a)->d == ((pair_t*)b)->d)return 0;else return 1;}
//int asc_t(const void *a,const void *b){if(((pair_t*)a)->d < ((pair_t*)b)->d)return 1;else if(((pair_t*)a)->d == ((pair_t*)b)->d)return 0;else return -1;}
double to_deg(double r) {return r * 180.0 / (atan(1.0) * 4.0);}

int main(){
    int x;
    scanf("%d",&x);
    int value[]={105,101,102,103,104,105,105,105,105,105};
    int min;
    while((x%10>0||((x%100)/10)>0)&&x>=100){
        x-=value[x%10];
        //printf(">%d %d\n",x,(x%100)/10);
    }
    if(x%10==0&&((x%100)/10)==0)printf("1\n");
    else printf("0\n");
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

int ltor(string s){
	int x=s[0]-'0';
	for(int i=1;i<s.size();i+=2){
		if(s[i] == '*') x *= s[i+1]-'0';
		if(s[i] == '+') x += s[i+1]-'0';
	}
	return x;
}
int mult(string s){
	stack<int> st;
	st.push(s[0]-'0');
	for(int i=1;i<s.size();i+=2){
		if(s[i] == '*') st.top() *= s[i+1]-'0';
		if(s[i] == '+') st.push(s[i+1]-'0');
	}
	int ans = 0;
	while(!st.empty()){
		ans += st.top();
		st.pop();
	}
	return ans;
}

main(){
	ios::sync_with_stdio(false);
	string s;
	cin >> s >> n;
	int ans = (ltor(s) == n)*2 + (mult(s) == n);
	puts(ans == 3 ? "U" : ans == 2 ? "L" : ans == 1 ? "M" : "I");
	return 0;
}

Measured memory_bytes: 1216
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

#include <vector>

class union_find {
private:
	vector<int>parent;
	vector<int>rank;
	vector<int>clump;
public:
	union_find(int siz) {
		parent.resize(siz);
		rank.resize(siz);
		clump.resize(siz);
		for (int i = 0; i < siz; ++i) {
			parent[i] = i;
			rank[i] = 0;
			clump[i] = 1;
		}
	}
	void unite(int x, int y) {
		int xr = find(x);
		int yr = find(y);
		if (xr == yr)return;
		if (rank[xr] > rank[yr]) {
			parent[yr] = xr;
			clump[xr] += clump[yr];
		}
		else if (rank[yr] > rank[xr]) {
			parent[xr] = yr;
			clump[yr] += clump[xr];
		}
		else if (xr != yr) {
			parent[yr] = xr;
			clump[xr] += clump[yr];
			++rank[xr];
		}
	}
	int find(int x) {
		if (parent[x] == x) {
			return x;
		}
		else {
			return parent[x] = find(parent[x]);
		}
	}
	bool check(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return clump[find(x)];
	}
};
int N;
int u, v;
vector<int>G[123456];

int disV[123456];
void dfsV(int n, int p, int d) {
	disV[n] = d;
	for (int x : G[n]) {
		if (x == p)continue;
		dfsV(x, n, d + 1);
	}
}

int disU[123456];
void dfsU(int n, int p, int d) {
	disU[n] = d;
	for (int x : G[n]) {
		if (x == p)continue;
		dfsU(x, n, d + 1);
	}
}

int main() {
	cin >> N;
	cin >> u >> v;
	for (int i = 1; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	--u; --v;
	dfsV(v, -1, 0);
	dfsU(u, -1, 0);
	union_find uf(N);
	for (int i = 0; i < N; ++i) {
		if (disV[i] > disU[i]) {
			for (int j : G[i]) {
				if (disV[j] > disU[j]) {
					uf.unite(i, j);
				}
			}
		}
	}
	int big = 0;
	for (int i = 0; i < N; ++i) {
		if (uf.check(u, i)) {
			big = max(big, disV[i]);
		}
	}
	cout << big - 1 << endl;
	return 0;
}

Measured memory_bytes: 12032
N, M = map(int, input().split())
if N >= M:
  print(0)
  exit()

X = [int(x) for x in input().split()]

X = sorted(X)
L = [ X[i] - X[i-1] for i in range(1, M)]
L = sorted(L)
#print(X)
#print(L)
 
print(sum(L[:M-N]))

Measured memory_bytes: 13840
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

struct item{
    string name;
    int point;
    int num;
    bool operator<( const item& right ) const {
        return name == right.name ? point > right.point : name < right.name;
    }
};

int main(){
    int n;
    cin >> n;
    struct item rest[n];
    rep(i,n){
        cin >> rest[i].name >> rest[i].point;
        rest[i].num=i+1;
    }
    sort(rest,rest+n);
    rep(i,n) cout << rest[i].num << endl;
}

Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long x, y;
    scan(x, y);
    long[] tmp;
    tmp ~= x;
    while (x * 2 <= y)
    {
        x *= 2;
        tmp ~= x;
    }
    // writeln(tmp);
    writeln(tmp.length);

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3668
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> in(N);
  for (int i = 0; i < N; i++) cin >> in[i];

  sort(in.begin(), in.end());
  in.push_back(-1);

  vector<int> num;
  for (int i = 0; i < N;) {
    int j = i + 1;
    for (; j < N + 1; j++) {
      if (in[j] != in[i]) {
        num.push_back(j - i);
        i = j;
        break;
      }
    }
  }

  sort(num.begin(), num.end());

  int num_change = num.size() - K;

  if(num.size() <= K) cout << 0 << endl;
  else cout << accumulate(num.begin(), num.begin() + num_change, 0) << endl;

  return 0;
}

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

int main()
{
    long n,i;
    cin>>n;
    long arr[n];
    unordered_map<long,long> freq;
    unordered_map<long,long>::iterator it;
    
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        freq[arr[i]]++;
    }
    long long sum=0;
    
    for(it=freq.begin();it!=freq.end();it++)
    {
        sum+=(it->second-1)*it->second/2;
    }
    
    for(i=0;i<n;i++)
    {
        cout<<sum-freq[arr[i]]+1<<"\n";
    }
    
    return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF INT_MAX
#define MOD 100000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,M;
  cin>>N>>M;
  vector<int>L(M),R(M);
  for(int i=0;i<M;i++)cin>>L[i]>>R[i];
  vector<int>sum(N+2,0);
  for(int i=0;i<M;i++)sum[L[i]]++,sum[R[i]+1]--;
  for(int i=1;i<N+1;i++)sum[i]+=sum[i-1];
  int ans=0;
  for(auto it:sum)if(it==M)ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

char s[10];

int main()
{
	scanf("%s", s);
	if (strcmp(s, "ARC") == 0) {
		printf("ABC\n");
	} else {
		printf("ARC\n");
	}
	

	return 0;
}


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

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

    int cont = 0;
    for (int i=0; i<n; i++){
        double x, y, r; cin>>x>>y;
        r = sqrt(x*x*1ll + y*y*1ll);
        if(r<=d) cont++;
    }
    cout<<cont<<endl;
}

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


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

int main() {
    int A, B, C;
    std::cin >> A >> B >> C;

    const int r = A % B;
    std::set<int> s;

    int cur = r;
    s.insert(cur);
    while (true) {
        if (cur == C) {
            std::cout << "YES\n";
            return 0;
        }

        cur += r;
        cur %= B;
        if (s.count(cur) != 0) {
            std::cout << "NO\n";
            return 0;
        } else {
            s.insert(cur);
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<math.h>
using namespace std;

int main()
{

int a, b, c;
	cin >> a >> b >> c;
	if ((a != b&&a==c)||(a==b&&a!=c)||(b==c&&c!=a))
		cout << 2 << endl;
	else if (a != b&&a != c&&b != c)
		cout << 3 << endl;
	else if (a == b&&a == c)
		cout << 1 << endl;


    return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, m, Q;
int a[50],b[50],c[50],d[50];
int dp[11][11];
int dfs(vector<int> v, int now, int pre){
	if(now == n){
		int cnt = 0;
		for(int i = 0; i < Q; i++){
			if(v[b[i]]-v[a[i]] == c[i]) cnt += d[i];
		}
		return cnt;
	}
	int res = 0;
	for(int i = pre; i <= m; i++){
		vector<int> vv = v;
		vv.push_back(i);
		chmax(res, dfs(vv, now+1,i));
	}
	return res;
}
void solve(){
	cin >> n >> m >> Q;
	for(int i = 0; i < Q; i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	
	vector<int> v;
	v.push_back(1);
	cout << dfs(v,1,1) << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3608
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll r = 0, w = 0;
  for(ll i = 0; i < n; i++) r += (s[i] == 'R');
  w = n - r;
  ll mw = 0, mr = 0;
  for(ll i = 0; i < n; i++) {
    if(s[i] == 'W' and i < r) mw++;
    else if(s[i] == 'R' and i >= r) mr++;
  }
  ll xx = min(mw, mr);
  mw-=xx;
  mr-=xx;
  cout << mw + mr + xx << endl;
  return 0;
} //good night.

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

int main() {
    int N; cin>>N;
    string S;cin>>S;
    char prev=S[0];
    int ans=1;
    for (int i = 1; i < N; i++){
        if(S[i]!=prev)ans++;
        prev=S[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int k = 38, n = k * (k - 1) + 1;
int main() {
	printf("%d %d\n", n, k);
	for (int i = 0; i < k; i++) {
		for (int j = 1; j < k; j++) {
			printf("%d ", i * (k - 1) + j);
		}
		printf("%d\n", n);
	}
	for (int i = 0; i < k - 1; i++) {
		for (int j = 0; j < k - 1; j++) {
			for (int l = 0; l < k - 1; l++) {
				printf("%d ", l * (k - 1) + (j + i * l) % (k - 1) + 1);
			}
			printf("%d\n", n - k + i + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long long a, long long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long long a, long long b){
	return a / gcd(a,b) * b;
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int n, cnt = 0;
char c,d;

int main(){
	cin >> n;
	
	REP(i,n){
		cin >> c;
		
		if (c != d) cnt++;
		
		d = c;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>

#define PI 3.14159265359	

using namespace std;

int main(){
	int h, w;
	while (1){
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if(i * j == 0 || i == h - 1 || j == w - 1) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}

}

Measured memory_bytes: 3008
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;

int paper[10][10];

bool range(int x, int y)
{
	return x >= 0 && y >= 0 && x < 10 && y < 10;
}

void dropMedium(int x, int y)
{
	for (int dy = -1; dy <= 1; ++dy)
	{
		for (int dx = -1; dx <= 1; ++dx)
		{
			int xx = x+dx;
			int yy = y+dy;
			if (range(xx, yy))
				++paper[yy][xx];
		}
	}
}
void dropSmall(int x, int y, int d = 1)
{
	int dx[] = { 0, 0, 1, 0, -1 };
	int dy[] = { 0, 1, 0, -1, 0 };
	for (int i = 0; i < 5; ++i)
	{
		int xx = x+d*dx[i];
		int yy = y+d*dy[i];
		if (range(xx, yy))
			++paper[yy][xx];
	}
}
void dropLarge(int x, int y)
{
	dropSmall(x, y, 2);
	dropMedium(x, y);
	--paper[y][x];
}


int main()
{
	int x, y, s;
	while (scanf("%d,%d,%d", &x, &y, &s) != EOF)
	{
		switch (s)
		{
			case 1: dropSmall(x, y); break;
			case 2: dropMedium(x, y); break;
			case 3: dropLarge(x, y); break;
		}
	}
	int empties = 0;
	int m = 0;
	for (int y = 0; y < 10; ++y)
	{
		for (int x = 0; x < 10; ++x)
		{
			if (paper[y][x] == 0)
				++empties;
			m = max(m, paper[y][x]);
		}
	}
	printf("%d\n%d\n", empties, m);

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

struct UnionFind {
	vector<int> rank, parent, num;
	UnionFind() {};
	UnionFind(int size) :rank(size, 0), parent(size, 0), num(size, 0) {
		for (int i = 0; i < size; i++)makeset(i);
	}

	void makeset(int x) {
		parent[x] = x;
		rank[x] = x;
		num[x] = 1;
	}

	int size(int x) {
		return num[findset(x)];
	}

	bool same(int x, int y) {
		return findset(x) == findset(y);
	}

	int findset(int x) {
		if (x != parent[x]) {
			parent[x] = findset(parent[x]);
		}
		return parent[x];
	}

	void unite(int x, int y) {
		link(findset(x), findset(y));
	}

	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			parent[y] = x;
			num[x] += num[y];
		}
		else {
			parent[x] = y;
			num[y] += num[x];
			if (rank[x] == rank[y])rank[y]++;
		}
	}
};

int main() {
	cin >> N >> M;
	vector<int>a(M), b(M);
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < M; i++) {
		UnionFind uf(N + 1);
		for (int j = 0; j < M; j++) {
			if (j == i)continue;
			if (!uf.same(a[j], b[j]))
				uf.unite(a[j], b[j]);
		}
		if (uf.size(1) != N)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
void main()
{
    long i, o, t, j, l, s, z;
    rdVals(i, o, t, j, l, s, z);

    long result = o;
    if (i && j && l && (i & 1) + (j & 1) + (l & 1) >= 2)
    {
        result += 3;
        --i, --j, --l;
    }
    result += 2 * (i / 2 + j / 2 + l / 2);

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

public class Main {
	public static int[] charCount = new int[26];

	public static void main(String... args) throws IOException {
		final StringBuilder sb = new StringBuilder();
		final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			final int charactor = br.read();
			if (97 <= charactor && charactor <= 123) {
				charCount[charactor - 97]++;
			} else if (65 <= charactor && charactor <= 91) {
				charCount[charactor - 65]++;
			} else if (charactor == -1) {
				break;
			}
		}

		for (int i = 0; i < 26; i++) {
			sb.append(((char) (i + 97))).append(" : ").append(charCount[i]).append(i != 25 ? '\n' : "");
		}

		System.out.println(sb);
	}
}

Measured memory_bytes: 16868
#include<bits/stdc++.h>
using namespace std;
static const int MAX_N = 100000;

int N;
int a[MAX_N + 1];

void solve(){
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(a[a[i]] == i) ans++;
	}
	printf("%d\n", ans / 2);
}

int main(){
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", &a[i]);
	solve();
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

void solve() {
    ll a, b;
    cin >> a >> b;
    ll g = __gcd(a, b);
    auto div = prime_factor(g);
    cout << div.size() + 1 << endl;
}

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


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

int main() {
	string	S;
	cin >> S;
	if (S.at(2) == S.at(3) && S.at(4) == S.at(5))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  string s;
  string t;
  cin >> s >> t;

  string n = t.substr(0, t.size() - 1);

  if (n == s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> k;
	int a[100050];

	rep(i, n) cin >> a[i];

	f = 1000000050;
	rep(i, n-k+1){
		f = min(abs(a[i]) + abs(a[i]-a[i+k-1]), f);
		f = min(abs(a[i+k-1]) + abs(a[i]-a[i+k-1]), f);
	}

	cout << f << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define binary_count(a) __builtin_popcount(a) //计算一个数字的二进制中有多少个位是1
#define ULL unsigned long long
#define LL_INF 0x7fffffffffffffff
#define INF 0x3f3f3f3f
#define MAXN 1010
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
int A[4];
int main()
{
    cin >> A[1] >> A[2] >> A[3];
    sort(A+1, A+4);
    int ans = 0;
    if (A[1]%2 ==0 && A[2]%2 == 0 && A[3]%2==0) {
        ans = (A[3] - A[1]) /2 + (A[3] - A[2]) / 2;
    }
    else if(A[1]%2 ==1 && A[2]%2 == 1 && A[3]%2==1)
    {
        ans = (A[3] - A[1]) /2 + (A[3] - A[2]) / 2;
    }
    else if (A[1]%2 ==1 && A[2]%2 == 0 && A[3]%2==0) {
        ans = (A[3]+1 - A[1]) /2 + (A[3]- A[2]) / 2 + 1;
    }
    else if (A[1]%2 ==1 && A[2]%2 == 1 && A[3]%2==0) {
        ans = (A[3] - A[1] - 1) /2 + (A[3] - A[2] - 1) / 2 + 1;
    }
    else if (A[1]%2 ==0 && A[2]%2 == 0 && A[3]%2==1) {
         ans = (A[3] - A[1] - 1) /2 + (A[3] - A[2] - 1) / 2 + 1;
    }
    else if (A[1]%2 ==0 && A[2]%2 == 1 && A[3]%2==1) {
        ans = (A[3]+1 - A[1]) /2 + (A[3] - A[2]) / 2 + 1;
    }
    else if (A[1]%2 ==0 && A[2]%2 == 1 && A[3]%2==0) {
        ans = (A[3] - A[1]) /2 + (A[3]+1 - A[2]) / 2 + 1;
    }
    else if (A[1]%2 ==1 && A[2]%2 == 0 && A[3]%2==1) {
        ans = (A[3] - A[1]) /2 + (A[3]+1 - A[2]) / 2 + 1;
    }
    cout << ans << endl;
    return 0;
}


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

int n,m;
string obj[222];
int memo[200200];

int rec(int state){
  if(memo[state]>=0)return memo[state];

  int cnt = 0, tmp = state;
  vector<int> col(m);
  rep(i,m){ col[i] = tmp%3; tmp/=3; }

  rep(i,n){
    bool f = true;
    rep(j,m){
      if(col[j] == 1 && obj[i][j] == '1')f = false;
      if(col[j] == 2 && obj[i][j] == '0')f = false;
      if(!f)break;
    }
    if(f)cnt++;
    if(cnt>1)break;
  }
  if(cnt<=1)return memo[state] = 0;

  int res = m;
  rep(i,m){
    if(col[i]==0){
      int maxv = 0;

      for(int k=1;k<=2;k++){
	col[i] = k;
	int nstate = 0;
	for(int j=m-1;j>=0;j--)nstate = nstate*3 + col[j];
	maxv = max(maxv, rec(nstate));
      }
      res = min(res, maxv);
      col[i] = 0;
    }
  }
  return memo[state] = res+1;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  while(cin >> m >> n, m){
    rep(i,n)cin >> obj[i];

    memset(memo,-1,sizeof(memo));
    cout << rec(0) << endl;
  }
}

Measured memory_bytes: 2012
#include <stdio.h>
#include <string.h>
#define SIZE (20)

const char *d1[91] = {
	[' ']="101", ['\'']="000000", [',']="000011", ['-']="10010001",
	['.']="010001", ['?']="000001", ['A']="100101", ['B']="10011010",
	['C']="0101", ['D']="0001", ['E']="110", ['F']="01001",
	['G']="10011011", ['H']="010000", ['I']="0111", ['J']="10011000",
	['K']="0110", ['L']="00100", ['M']="10011001", ['N']="10011110",
	['O']="00101", ['P']="111", ['Q']="10011111", ['R']="1000",
	['S']="00110", ['T']="00111", ['U']="10011100", ['V']="10011101",
	['W']="000010", ['X']="10010010", ['Y']="10010011", ['Z']="10010000"
};
const char *d2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

int bin2dec(char bin_list[SIZE]) {
	return ((bin_list[0]-'0') * 16 + (bin_list[1]-'0') * 8 +
			(bin_list[2]-'0') * 4 + (bin_list[3]-'0') * 2 +
			(bin_list[4]-'0'));
}

void line_end(char bin_list[SIZE]) {
	if (strlen(bin_list) > 0) {
		strcat(bin_list, "0000");
		putchar(d2[bin2dec(bin_list)]);
	}
	putchar('\n');
	memset(bin_list, '\0', sizeof(char)*SIZE);
}

int main(void) {
	int c = 0, end = 0;
	char bin_list[SIZE] = "";

	while (1) {
		c = getchar();
		if (c == EOF) {
			if (!end)
				line_end(bin_list);
			break;
		}
		if (c == '\n') {
			line_end(bin_list);
			end = 1;
			continue;
		}
		end = 0;
		strcat(bin_list, d1[c]);
		while (strlen(bin_list) >= 5) {
			putchar(d2[bin2dec(bin_list)]);
			strcpy(bin_list, bin_list+5);
		}
	}
	return 0;
}

Measured memory_bytes: 524
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()

    ans = 0
    for a in range(1, 1000005):
        for b in range(1, 1000005):
            if a * b > 1000_000:
                break
            c = N - (a * b)
            if c > 0:
                ans += 1
    print(ans)

if __name__ == '__main__':
    solve()



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

#define MAX_N 200000
#define MAX_Q 200000

int n, q, g[MAX_N];
std::string s;
char t[MAX_N + 2], d[MAX_N + 2];

bool fallLeft(int x) {
  if(x == 0) return true;
  for(int i = 0; i < q; ++i) {
    if(t[i] == s[x - 1]) {
      if(d[i] == 'L') {
        --x;
      } else {
        ++x;
      }
      if(x == 0) return true;
      if(x == n + 1) return false;
    }
  }

  return false;
}

bool fallRight(int x) {
  if(x == n + 1) return true;
  for(int i = 0; i < q; ++i) {
    if(t[i] == s[x - 1]) {
      if(d[i] == 'L') {
        --x;
      } else {
        ++x;
      }
      if(x == n + 1) return true;
      if(x == 0) return false;
    }
  }

  return false;
}

int main() {
  std::cin >> n >> q;
  std::cin >> s;
  for(int i = 0; i < q; ++i) {
    std::cin >> t[i] >> d[i];
  }

  int l = 0, r = n + 1, m = (l + r) / 2, cnt = 0;
  while(r - l > 1) {
    if(fallRight(m)) {
      r = m;
    } else {
      l = m;
    }
    m = (l + r) / 2;
  }
  cnt += n + 1 - r;

  l = 0, r = n + 1, m = (l + r) / 2;
  while(r - l > 1) {
    if(fallLeft(m)) {
      l = m;
    } else {
      r = m;
    }
    m = (l + r) / 2;
  }
  cnt += l;

  std::cout << n - cnt << std::endl;
}


Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    int a[110];
    int b[110];
    int ans = 0;
    cin >> n;
    for(int i=0;i<n-1;i++){
        cin >> b[i];
    }
    a[0] = b[0];
    a[n-1] = b[n-1-1];
    for(int i=1;i<n-1;i++){
        a[i] = min(b[i-1],b[i]);
    }
    for(int i=0;i<n;i++){
        ans += a[i];
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256