akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//.define
// #define FILE_IN_OUT
#define RET(_x)    return cout << (_x) << '\n', 0;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    ll x, k, d;
    cin >> x >> k >> d;
    ll y = abs(x) / d;
    if (y >= k) {
        cout << abs(x) - k * d << endl;
        return 0;
    }
    k -= y;
    x = abs(x) - y * d;
    ll nx = abs(x - d);
    --k;
    if (k % 2 == 0) {
        RET(nx);
    }
    cout << x << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <utility>
#include <set>
#include <tuple>
#include <numeric>
#include <deque>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

bool f(std::vector<intmax_t> const& A, intmax_t K, intmax_t x) {
  size_t N = A.size();
  std::deque<intmax_t> B(N);
  for (size_t i = 0; i < N; ++i)
    B[i] = A[i] % x;

  std::sort(B.begin(), B.end());
  while (!B.empty() && B[0] == 0) B.pop_front();

  while (B.size() > 1 && K > 0) {
    intmax_t k = std::min({B.front(), x-B.back(), K});
    B.front() -= k;
    B.back() += k;
    K -= k;
    if (B.front() == 0) B.pop_front();
    if (B.back() == x) B.pop_back();
  }
  return B.empty();
}

int main() {
  size_t N;
  intmax_t K;
  scanf("%zu %jd", &N, &K);

  std::vector<intmax_t> A(N);
  for (auto& ai: A) scanf("%jd", &ai);
  intmax_t sum = std::accumulate(A.begin(), A.end(), 0_jd);

  intmax_t res = 0;
  for (intmax_t i = 1; i*i <= sum; ++i) {
    if (sum % i) continue;
    if (f(A, K, i)) res = std::max(res, i);
    if (sum / i != i && f(A, K, sum / i)) res = std::max(res, sum / i);
  }

  printf("%jd\n", res);
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元を計算する
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}

int main(){

	ll n,a,b;
	cin>>n>>a>>b;

	ll ans=0;

	const ll MOD=1000000007;

	ans=mod_pow(2, n, MOD)-1;

	ans-=ncr(n,a,MOD);
	if(ans<0){
		ans+=MOD;
	}
	ans-=ncr(n,b,MOD);
	if(ans<0){
		ans+=MOD;
	}

	
	cout<<ans%MOD<<endl;

    return 0;
}


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

using namespace std;

int main(){
  int k;
  string s;
  
  cin >> k;
  cin >> s;
  
  if(k>=s.size()){
    cout << s << endl;
    return 0;
  }
  
  for(int i=0; i<k; i++){
    cout << s[i];
  }
  cout << "..." << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

// �\�[�g�������l�iA, B�j�ō\�����ꂽ�\����
struct Info {
	int num;
	string valS;
	int valP;

	Info(int A, string str, int P) {
		num = A;
		valS = str;
		valP = P;
	}
};

// ���l A �Ń\�[�g���邽�߂̔��r���Z�q
bool cmpS(const Info& a, const Info& b) {
	return a.valS < b.valS;
}

// ���l B �Ń\�[�g���邽�߂̔��r���Z�q
bool cmpP(const Info& a, const Info& b) {
	return a.valP > b.valP;
}

int main() {

	int N = 0;
	cin >> N;

	vector<Info> val;

	string str;
	int P;
	for (int i = 0; i < N; i++) {
		cin >> str;
		cin >> P;
		val.push_back(Info(i + 1, str, P));
	}

	// �s���Ń\�[�g
	sort(val.begin(), val.end(), cmpS);

	vector<Info> dummy;
	dummy.clear();
	string inistr = val[0].valS;

	for (int i = 0; i < N; i++) {
		if (inistr == val[i].valS) {
			dummy.push_back(val[i]);
		}
		else {
			inistr = val[i].valS;
			// �_���Ń\�[�g
			sort(dummy.begin(), dummy.end(), cmpP);

			// �������o��
			for (int j = 0; j < dummy.size(); j++) {
				cout << dummy[j].num << endl;
			}

			dummy.clear();
			dummy.push_back(val[i]);
		}
	}


	// �Ō��̕������Ɋւ����o��
	// �_���Ń\�[�g
	sort(dummy.begin(), dummy.end(), cmpP);

	// �������o��
	for (int j = 0; j < dummy.size(); j++) {
		cout << dummy[j].num << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxn 100000
#define int long long
int a[maxn];

signed main()
{
	int n, ans = 0; scanf("%lld", &n); n *= 2;
	for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
	sort(a + 1, a + 1 + n);
	for(int i = 1; i <= n; i += 2) ans += a[i];
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
  long n; cin >> n;
  vector<vector<int>> a(n, vector<int>(60, 0));
  for(int i = 0; i < n; i++){
    long long A; cin >> A;
    for(int j = 0; j < 60; j++){
      if((A >> j) & 1) a.at(i).at(j) = 1;
    }      
  }
  vector<int> out(60);
  for(int i = 0; i < 60; i++){
    int sum = 0;
    for(int j = 0; j < n; j++){
      if(a.at(j).at(i) == 1) sum++;
    }
    out.at(i) = sum;
  }
  vector<long long> out2(60);
  for(int i = 0; i < 60; i++){
    out2.at(i) = out.at(i) * (n - out.at(i));
  }
  long long res = 0;
  long long two = 1;
  for(int i = 0; i < 60; i++){
    res += ((out2.at(i) % 1000000007) * (two % 1000000007)) % 1000000007;
    two *= 2;
    two = two;
  }
  cout << res % 1000000007;
}


Measured memory_bytes: 82304
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
using namespace std;

#define N  100005
ll a[N],b[N],c[N],d[N];
ll findPermutations(ll c[], ll n,ll d[]) 
{ 
  
    // Sort the given array 
    sort(c, c + n); 
    ll cnt=1;
    // Find all possible permutations  
    do { 
    	ll w=0;
        for(int i=0;i<n;i++)
        	if(c[i]!=d[i])
        		w=1;
        if(w==0)
        	return cnt;
        cnt++;
     //   cout<<cnt;
    } while (next_permutation(c, c + n)); 
} 
  
// Driver code 
int main() 
{ 
  
    ll n;
    cin>>n;
    for(int i=0;i<n;i++)
    	cin>>a[i];
    for(int i=0;i<n;i++)
    	cin>>b[i];
    for(int i=1;i<=n;i++)
    	c[i-1]=i;
    ll x=findPermutations(c,n,a); 
    ll y=findPermutations(c,n,b);
   // cout<<y;
    cout<<abs(x-y);
  
    return 0; 
} 

Measured memory_bytes: 256
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>

using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp update_pair
#define pb push_back
#define y2 y2228
const string FILENAME = "input";


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
  	//read(FILENAME);
	int n;
	cin >> n;
			vector<pair<int, int> > st;
	if (n % 2 == 0) {
		for (int i = 1; i <= n / 2; i++) {
			st.pb(make_pair(i, n + 1 - i));
		}
	} else {
		for (int i = 1; i <= n / 2; i++) {
			st.pb(make_pair(i, n - i));
		}
		st.pb(make_pair(n, n));
	}
	set<pair<int, int> > res;
	for (int i = 0; i < sz(st); i++) {
		for (int j = i + 1; j < sz(st); j++) {
			res.insert({st[i].first, st[j].first});
			res.insert({st[i].first, st[j].second});
			res.insert({st[i].second, st[j].first});
			res.insert({st[i].second, st[j].second});
		}
	}
	cout << sz(res) << '\n';
	for (auto x: res) {
		cout << x.first << ' ' << x.second << '\n';
	}
	return 0; 	
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;
public class Main
{
	public static void main(String[] args) throws Exception{
		FastReader s = new FastReader();
		int n = s.nextInt();
		long sum = 0;
		int max = Integer.MIN_VALUE;
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
		    arr[i] = s.nextInt();
		    if(arr[i] < max){
		        sum += max-arr[i];
		    }
		    max = Math.max(max, arr[i]);
		}
		System.out.println(sum);
	}
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 55008
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, c := iScan(), iScan(), iScan()
	k := iScan()
	ans := 0
	for {
		if a < b {
			break
		} else {
			b *= 2
			ans++
		}
	}
	for {
		if b < c {
			break
		} else {
			c *= 2
			ans++
		}
	}
	if ans <= k {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main(){
    int N, M;  cin >> N >> M;
    ll mod = 1e9+7;

    vector<ll> S(N+1,0), T(M+1,0);
    for(int i=1; i<=N; i++) cin >> S[i];
    for(int i=1; i<=M; i++) cin >> T[i];

    vector<vector<ll>> dp(N+1, vector<ll>(M+1,0));
    vector<vector<ll>> sum(N+1, vector<ll>(M+1,0));
    dp[0][0] = 1;
    for(int n=0; n<=N; n++) sum[n][0] = 1;
    for(int m=0; m<=M; m++) sum[0][m] = 1;

    for(int n=1; n<=N; n++) for(int m=1; m<=M; m++){
        if(S[n] == T[m]) dp[n][m] = sum[n-1][m-1];
        sum[n][m] = sum[n-1][m];
        sum[n][m] = (sum[n][m] + sum[n][m-1])%mod;
        sum[n][m] = (sum[n][m] + dp[n][m])%mod;
        sum[n][m] = (sum[n][m] - sum[n-1][m-1])%mod;
        while(sum[n][m]<0){
            sum[n][m] += mod;
        }

    }

    ll ans = 0;
    for(int i=0; i<=N; i++) for(int j=0; j<=M; j++){
        ans = (ans + dp[i][j])%mod;
    }
    cout << ans << endl;
}



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

int main()
{
    int A, B, C;
    int val;

    cin >> A >> B >> C;

    val = __gcd(A, B);

    if(C % val == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return (0);
}


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

struct Problem {

	UL G(UL A, UL K) {
		if (A < K) return 0;
		if (A % K == 0) return A / K;
		UL t = (A % K - 1) / (A / K + 1) + 1;
		UL ans = G(A - (A / K + 1) * t, K);
		return ans;
	}

	void Solve() {
		UL N; cin >> N;
		UL ans = 0;
		rep(i, N) {
			UL A, K; cin >> A >> K;
			ans ^= G(A, K);
		}
		if (ans == 0) cout << "Aoki" << endl;
		else cout << "Takahashi" << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   ll n,ans=maxn;
   cin>>n;
   vi w(n+1);
   rep(i,n)cin>>w.at(i+1);
  
   for(ll t=1;t<=n;t++){
       ll s1=0,s2=0;
       for(int i=1;i<=t;i++){
           s1+=w.at(i);
       }
      for(int i=t+1;i<=n;i++){
          s2+=w.at(i);
      }
       ll s12=abs(s1-s2);
       ans=min(ans,s12);
       
   }
   cout<<ans<<endl;
}

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


vector<int> get_primes(int n){
  int lim = sqrt(n) + 1;
  vector<bool> is_primes(n, true);
  for(int i = 2; i <= lim; i++){
    if(!is_primes[i]) continue;

    for (int j = i*2; j <= n; j+=i) {
      is_primes[j] = false;
    }
  }

  vector<int> primes;
  for (int i = 0; i <= n; ++i) {
    if(is_primes[i])
      primes.push_back(i);
  }

  return primes;
}

//void hoge(){
//  for (int i = 2; i < primes.size(); ++i) {
//    // 終了条件
//    bool is_all_small = true;
//    for (int j = 0; j < ta.size(); ++j) {
//      if(ta[j] >= primes[i]){
//        is_all_small = false;
//        break;
//      }
//    }
//    if(is_all_small)
//      break;
//
//
//    while(true){
//      //
//      bool is_one_divided = false;
//      for (int j = 0; j < ta.size(); ++j) {
//        if(ta[j] % primes[i] == 0) {
//          ta[j] /= primes[i];
//          is_one_divided = true;
//        }
//      }
//
//      //
//      if(is_one_divided) {
//        nums.push_back(primes[i]);
//
//        cout << primes[i] << endl;
//        for (int j = 0; j < ta.size(); ++j) {
//          cout << ta[j] << " ";
//        }
//        cout << endl;
//
//      }else{
//        break;
//      }
//    }
//  }
//
//  int m = 1;
//  for(int num: nums) m *= num;
//
//}




int main() {

//  cout << ceil(0.5) << endl;
  //

//  vector<int> primes = get_primes(1001);

  int N;
  cin >> N;
  vector<int64_t> t(N), a(N);
  for (int i = 0; i < N; ++i) {
    cin >> t[i] >> a[i];
  }

  int64_t T = 1, A = 1;
  for (int i = 0; i < N; ++i) {
    int64_t t1 = ceil(T / (long double)t[i]);
    int64_t a1 = ceil(A / (long double)a[i]);
    int64_t n = max(t1, a1);
    T = n * t[i];
    A = n * a[i];
//    cout << n << endl;
  }


  cout << T + A << endl;

  return 0;
}



Measured memory_bytes: 256
N=int(input())
S=str(input())
L="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s=""
for j in S:
  if L.index(j)+N<=len(L)-1:
    s+=L[L.index(j)+N]
  else:
    s+=L[L.index(j)+N-len(L)]
print(s)

Measured memory_bytes: 41452
#include<stdio.h>

int GDC(int a, int b){
    if(a==0){
        return b;
    }else if(b==0){
        return a;
    }
    if(a<b){
        GDC(a,b%a);
    }else{
        GDC(a%b, b);
    }
}

int main(){
    long long int A, B, C, D;
    long long int sub, sumC, sumD, sumCD;
    long long int gdcCD;

    scanf("%ld %ld %ld %ld", &A, &B, &C, &D);

    gdcCD =  GDC(C,D);

    sub = B-A+1;
    sumC = B/C-(A-1)/C;
    sumD = B/D-(A-1)/D;
    sumCD = B/(C*D/gdcCD)-(A-1)/(C*D/gdcCD);;

    printf("%ld", sub-sumC-sumD+sumCD);

    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int t; cin >> t; for(int cs = 1; cs <= t; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

//input space ---> scanf("%[^\n]%*c",s);

ll n,k,ans;
vll a(200005),b(200005);

bool can(ll x) {
	ll K = k;
	fori(i,0,n-1,1) {
		K -= max(0LL,a[i]-x/b[i]);
	}
	return K >= 0;
}

int main() {
	IOS
	cin >> n >> k;
	fori(i,0,n-1,1) {
		cin >> a[i];
	}
	fori(i,0,n-1,1) {
		cin >> b[i];
	}
	sort(a.begin(),a.begin()+n);
	sort(b.begin(),b.begin()+n,greater<ll>());
	ll l = 0,r = 1LL*INF*INF;
	while(l <= r) {
		ll m = (l+r)/2;
		if(can(m)) {
			if(!can(m-1)) {
				ans = m;
				break;
			}
			r = m-1;
		} else {
			l = m+1;
		}
	}
	cout << max(0LL,ans) << endl;
}


Measured memory_bytes: 3456
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long res = 0;
            HashMap<String, Integer> hm = new HashMap<String, Integer>();
            for (int i = 0; i < n; i++) {
                String s = in.next();
                char[] ca = s.toCharArray();
                Arrays.sort(ca);
                String _s = new String(ca);
                if (hm.containsKey(_s)) {
                    hm.replace(_s, hm.get(_s) + 1);
                    res += hm.get(_s);
                } else {
                    hm.put(_s, 0);
                }
            }
            out.println(res);
        }

    }
}



Measured memory_bytes: 55696
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;


bool A[101][101];
void solve() {
	int W, H; cin >> W >> H;
	int N; cin >> N;
	REP(_, N) {
		int x, y; cin >> x >> y;
		int a; cin >> a;
		if (a == 1) { REP(i, W)REP(j, H)if (i < x)A[i][j] = true; }
		else if (a == 2) { REP(i, W)REP(j, H)if (i >= x)A[i][j] = true; }
		else if (a == 3) { REP(i, W)REP(j, H)if (j < y)A[i][j] = true; }
		else if (a == 4) { REP(i, W)REP(j, H)if (j >= y)A[i][j] = true; }
	}
	int ans = 0;
	//REP(i, W) {
	//	REP(j, H)cout << A[i][j];
	//	cout << endl;
	//}
	REP(i, W)REP(j, H)if (!A[i][j])ans++;
	print(ans);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 3584
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	vector<ll>cs(n, 0);
	rep(i, n) {
		cin >> a[i];
	}
	cs[0] = a[0];
	rep(i, n - 1) {
		cs[i + 1] = cs[i] + a[i + 1];
	}
	ll ans = LLONG_MAX;
	rep(i, n-1) {
		ans = min(ans, abs(cs[i] - (cs[n - 1] - cs[i])));
	}
	
	cout << ans;

	return 0;
}




Measured memory_bytes: 2560
px,py,n,wx,wy,survive[14],S,t[14],water[14],i;
main(){
	for(;scanf("%d%d%d",&px,&py,&n),px|py;){
		memset(survive,0,sizeof(survive));
		survive[2+py]=4<<px;
		for(;n--;){
			for(i=2;i<12;i++){
				t[i]=survive[i+2]|survive[i+2]<<1|survive[i+2]>>1|
					 survive[i-2]|survive[i-2]<<1|survive[i-2]>>1|
					 survive[i]>>2|survive[i-1]>>2|survive[i+1]>>2|
					 survive[i]<<2|survive[i-1]<<2|survive[i+1]<<2;
			}
			memcpy(survive,t,sizeof(survive));
			scanf("%d%d",&wx,&wy);
			memset(water,0,sizeof(water));
			water[2+wy-1]=water[2+wy]=water[2+wy+1]=7<<1<<wx;
			S=0;
			for(i=2;i<12;i++)
				S|=survive[i]&=water[i]&0xffc;
		}
		puts(S?"OK":"NA");
	}
	exit(0);
}

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

#define INF 1e9
using namespace std;

int main() {

    int N; cin >> N;

    vector<int> W(N);
    for (int i = 0; i < N; ++i) {
        cin >> W[i];
    }

    int ans = INF;

    for (int i = 0; i < N; ++i) {
        int S_1 = 0;
        int S_2 = 0;

        for (int j = 0; j <= i; ++j) {
            S_1 += W[j];
        }

        for (int k = i+1; k < N; ++k) {
            S_2 += W[k];
        }

        ans = min(ans, abs(S_1 - S_2));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
typedef long long ll;
typedef int64_t in;
using namespace std;


int main() {
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0; i<h; i++){
        cin >> s[i];
    }

    vector<vector<int>> lamp(h, vector<int> (w, 0));

    for(int i=0; i<h; i++){
        int point = 0;
        for(int j=0; j<w; j++){
            if(s[i][j] == '#'){
                for(int k=point; k<j; k++){
                    lamp[i][k] += j - point;
                }
                point = j+1;
            }
            if(j == w-1){
                for(int k=point; k<w; k++){
                    lamp[i][k] += w - point;
                }
            }
        }
    }

    for(int j=0; j<w; j++){
        int point = 0;
        for(int i=0; i<h; i++){
            if(s[i][j] == '#'){
                for(int k=point; k<i; k++){
                    lamp[k][j] += i - point;
                }
                point = i+1;
            }
            if(i == h-1){
                for(int k=point; k<h; k++){
                    lamp[k][j] += h - point;
                }
            }
        }
    }
    int max=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            //cout << lamp[i][j];
            if(max < lamp[i][j] - 1){
                max = lamp[i][j] - 1;
            }
        }
        //cout << endl;
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 20096
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}



int main(void){
	string s;

	cin >> s;

	int firsthalf = atoi(s.substr(0, 2).c_str());
	int secondhalf = atoi(s.substr(2, 2).c_str());

	if (firsthalf > 0 && firsthalf <= 12){
		if (secondhalf > 0 && secondhalf <= 12){
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if (secondhalf > 0 && secondhalf <= 12){
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}


Measured memory_bytes: 256
/*  In the name of ALLAH   */
#include <bits/stdc++.h>
using namespace std;

#define int          int64_t
#define FIO()        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pii          pair<int,int>
#define pb           push_back
#define pu           push
#define fi           first
#define se           second
#define endl         "\n"

const int mod = 1e9 + 7;
const int MAX_I =  9223372036854775807;
const int MIN_I = -9223372036854775807;

int32_t main() {
	FIO();
	int N,flag=0; cin>>N;
	for(int i=1;i<=9;i++)
		for(int j=1;j<=9;j++)
			if(i*j==N)
				flag=1;
	if(flag)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

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

int main() 
{
    string s;
    cin >> s;
    int sum = 0;
    int max = 0;
    for (int i=0; i<s.size(); i++)
    {
        char c = s[i];
        if (c=='A'||c=='C'||c=='G'||c=='T')
            sum++;
        else
            sum=0;
        if (sum>max)
            max = sum;
    }
    cout << max;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
if n == 1:
    print('Hello World')
else:
    a = int(input())
    b = int(input())
    print(a+b)


Measured memory_bytes: 64620
#include <cstdio>
#include <queue>
using namespace std;
int n,a[200010],max;
long long sum;
priority_queue<int>s1;
priority_queue<pair<int,pair<int,int> > >s2;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		s1.push(a[i]);
	}
	s2.push(make_pair(s1.top(),make_pair(s1.top(),s1.top())));
	s1.pop();
	for(int i=2;i<=n;++i){
		int x=s1.top();
		s1.pop();
		sum+=s2.top().first;
		pair<int,pair<int,int> >k;
		k=s2.top();
		s2.pop();
		s2.push(make_pair(x,make_pair(k.second.first,x)));
		s2.push(make_pair(x,make_pair(k.second.second,x)));
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 8084
import java.util.*;

public class Main{
    public static void main(String[] args){
      final long mod = 1000000007;
	Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long K = sc.nextLong();
    long number = 0;
    for(long i = K ; i <= N + 1 ; i++){
      long max = (N + (N - i + 1)) * i / 2;
      long min = (0 + i - 1) * i / 2;
      number += (max - (min - 1));
        number %= mod;
    }
      System.out.println(number);
        
	
	}
}

Measured memory_bytes: 35692
N = int(input())
T = [0]
X = [0]
Y = [0]
for i in range(N):
    t,x,y = map(int,input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

flag = True
for i in range(N):
    time = T[i+1]-T[i]
    dist = abs(X[i+1]-X[i])+abs(Y[i+1]-Y[i])
    if time < dist or (dist%2!=time%2):
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')


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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	bool ok=1;
	if(s.size()%2)ok=0;
	for(int i=0;i<s.size()/2;i++){
		if(s[2*i]=='h'&&s[2*i+1]=='i'){

		}else{
			ok=0;
		}
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, mini ;
    long long minc = 0;
    cin >> n;
    int arr[n];
    for(int i =0 ; i < n; ++i){
        cin >> arr[i]; 
    }
    for(int p = 0; p < n ; ++p){
        minc = 0;
        for(int k = 0; k <= p ; ++k){
            minc += arr[k];
        }
        for(int z = 0; z < (n-1-p) ; ++z){
            minc -= arr[n-1-z];
        }
        if(p==0){
            mini = abs(minc);
        } 
        if(abs(minc)<mini){
            mini = abs(minc);
        }
    }
    cout<< mini;
    return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;

	if (N == M) cout << "Yes" << endl;
	else cout << "No" << endl;
}







Measured memory_bytes: 256
#include <stdio.h>

// バブルソート
int* bubbleSort(int* u, int N){
  int i,j;
  int temp;

  for(i=0; i<N; i++){
    for(j = N-1; j>i; j--){
      if(u[j] < u[j-1]){
        temp = u[j];
        u[j] = u[j-1];
        u[j-1] = temp;
      }
    }
  }
  return u;
}

int main(){
  int N;
  long int ans1; // ans1はans2に2の(N-1)乗を掛けたもの
  double ans2; // 答え
  scanf("%d",&N); 
  int u[N];
  long int pow[N]; // pow[n]は2のn乗の値を返す。まずは0で初期化。
  pow[0] = 1;
  scanf("%d",&u[0]); 
	for (int i = 1; i < N; i++){
	  scanf("%d",&u[i]); 
    pow[i] = pow[i - 1] * 2;
	}

  bubbleSort(u, N); // 小さいもの順に並べる
  
  ans1 = u[0];
	for (int i = 1; i < N; i++){
	  ans1 += u[i] * pow[i - 1];
	}
  ans2 = (double)ans1 / pow[N - 1];
  printf("%f", ans2);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, L, Q, W, H, T, X, Y, S;

int main()
{
    string str;cin >> str;
    if (str[0] == '9' || str[1] == '9') {
        cout << "Yes" << endl;
    } else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int D = int.Parse(Console.ReadLine());
            switch (D)
            {
                case 25:
                    Console.WriteLine("Christmas");
                    break;
                case 24:
                    Console.WriteLine("Christmas Eve");
                    break;
                case 23:
                    Console.WriteLine("Christmas Eve Eve");
                    break;
                case 22:
                    Console.WriteLine("Christmas Eve Eve Eve");
                    break;
                default:
                break;
            }

        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
int main(){
    int n,m,p;
    int i;
    int mem[105];
    int sum=0,result;
    while (1) {
        scanf("%d %d %d",&n,&m,&p);
        if(n==0&&m==0&&p==0){
            break;
        }
        sum=0;
        for (i=0; i<n; i++) {
            scanf("%d",&mem[i]);
            sum+=mem[i];
        }
        if(mem[m-1]==0){
            result=0;
        }else{
            result=(sum*(100-p))/mem[m-1];
        }
        printf("%d\n",result);
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
int n,ta,ao,ans;
vector <int>g[100010];
int dis[100010];
void bfs(int x,int p,int d)
{
    if(d>=dis[x])
    {
        ans=max(ans,dis[x]);
        return ;
    }
    for(int i=0; i<g[x].size(); i++)
    {
        int &y=g[x][i];
        if(y!=p)
        {
            bfs(y,x,d+1);
        }
    }
    if(g[x].size()==1) //是叶子结点，就特判一下之前做法中提到的情况
    {
        ans=max(ans,dis[x]-1);
    }
}
int main()
{
    cin>>n>>ta>>ao;
    for(int i=1; i<n; i++)
    {
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    memset(dis,-1,sizeof(dis));
    dis[ao]=0;
    queue<int>q;
    q.push(ao);
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for(int i=0; i<g[x].size(); i++)
        {
            int &y=g[x][i];
            if(dis[y]==-1)
            {
                dis[y]=dis[x]+1;
                q.push(y);
            }
        }
    }
    bfs(ta,-1,0);
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll a[200010];

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

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

  ll res=0;
  vector<ll> b(n+1,-INF);
  rep(i,n){
    ll idx=lower_bound(all(b),a[i])-b.begin()-1;
    if(b[idx]==-INF){
      res++;
    }
    b[idx]=a[i];
  }
  cout<<res<<endl;

  return 0;
}


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

using namespace std;
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define debug(a) cerr << #a << ": " << (a) << '\n';
#define debug_two(a, b) cerr << #a << ": " << (a) << ", " << #b << ": " << (b) << '\n';

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

const int INF = 1000000000 + 7;
const ll LL_INF  = 1ll * INF * INF;
const int MAX_N = 100000 + 7;

template <typename T>
inline void addmod(T& a, const ll& b, const int& MOD = INF) {
	a = (a + b) % MOD; if (a < 0) a += MOD;
}

vii edges;

void addEdge(int u, int v) {
	edges.push_back({ u, v });
}

void solve() {
	string s;
	cin >> s;
	int n = sz(s);
	if (s[n - 1] == '1' || s[0] == '0') {
		cout << -1;
		return;
	}
	for (int i = 0; i <= n - 2; ++i) {
		if (s[i] != s[n - 2 - i]) {
			cout << -1;
			return;
		}
	}
	int last = 0;
	rep(i, 0, n - 1) {
		addEdge(last, i + 1);
		if (s[i] == '1')
			last = i + 1;
	}
	
	for (auto& p : edges) {
		cout << p.first + 1 << ' ' << p.second + 1 << '\n';
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
	const bool multiple_test = false;
	int test = 1;
	if (multiple_test)
		cin >> test;
	
	for(int i = 0; i < test; ++i) {
		//printf("Case #%d: ", i + 1);
		solve();
	}
#ifdef _LOCAL_
	cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


Measured memory_bytes: 2372
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	if(n>=10){
		cout<<k<<endl;
	}else {
		int ans=0;
		ans=100*(10-n);
		ans+=k;
		cout<<ans<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,d,p,X,Y;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&p);
	X=a*p;
	if(p<=c){
		Y=b;
	}else{
		Y=b+(p-c)*d;
	}if(X<Y){
		printf("%d\n",X);
	}else if(X>Y){
		printf("%d\n",Y);
	}else{
		printf("%d\n",X);
	}
	return 0;
}

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


int main() {
    int n; cin >> n;
    vector<ll> c(5);//counter。m,a,r,c,hの順。
    rep(i,n){
        string t;
        cin >> t;
        if(t.at(0)=='M') c[0]++;
        else if(t.at(0)=='A') c[1]++;
        else if(t.at(0)=='R') c[2]++;
        else if(t.at(0)=='C') c[3]++;
        else if(t.at(0)=='H') c[4]++;   
    }
    ll ans=0;
    rep(i,3){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                ans+=c[i]*c[j]*c[k];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
inp = sys.stdin.buffer.readline


def resolve():
    MOD = 10 ** 9 + 7

    # 0: white, 1: black
    def dfs(v, parent):
        vistied[v] = True
        dp[v][0] = 1
        dp[v][1] = 1
        for to in G[v]:
            if to == parent or vistied[to]:
                continue
            dfs(to, v)
            # 親が白の時は子は白黒どっちでも良い
            # 親が黒の時は子は白のみ
            dp[v][0] *= (dp[to][0] + dp[to][1]) % MOD
            dp[v][1] *= dp[to][0] % MOD

    N = int(inp())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        x, y = map(lambda x: int(x) - 1, inp().split())
        G[x].append(y)
        G[y].append(x)
    dp = [[0] * 2 for _ in range(N)]
    vistied = [False] * N

    dfs(0, -1)
    ans = dp[0][0] + dp[0][1]
    print(ans % MOD)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 142988