akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}

int calc2(vector<P> A){
  const int N = (1e6) + 100;
  vector<int> cnt(N, 0);
  int n = A.size();
  for(int i=0;i<n;i++){
    int a, b; tie(a, b) = A[i];
    cnt[a]++;
    cnt[b]--;
  }

  for(int i=1;i<N;i++) cnt[i] += cnt[i-1];
  int ans = 0;
  for(int i=0;i<N;i++) Max(ans, cnt[i]);
  return ans;
}

int calc1(vector<P> A){
  int n = A.size();
  vector<int> L, R;
  for(int i=0;i<n;i++){
    int l, r; tie(l, r) = A[i];
    L.push_back(l);
    R.push_back(r);
  }
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());

  int ans = 0;
  for(int i=0;i<n;i++){
    int l, r; tie(l, r) = A[i];
    int numL = n - (lower_bound(L.begin(), L.end(), r) - L.begin());
    int numR = upper_bound(R.begin(), R.end(), l) - R.begin();
    int num = n - (numL + numR);
    Max(ans, num);
  }
  return ans;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin>>n;
  vector<P> A(n);
  cin>>A;
  int s1 = calc1(A);
  int s2 = calc2(A);
  cout<<s1<<" "<<s2<<endl;
  return 0;
}



Measured memory_bytes: 12988
#include <stdio.h>

int main(void)
{
	int n, counter;
	int a, b, c, d;
	
	while(scanf("%d", &n) != EOF){
		counter = 0;
		
		for(a = 0; a < 10; a++){
			for(b = 0; b < 10; b++){
				for(c = 0; c < 10; c++){
					for(d = 0; d < 10; d++){
						if(n == (a + b + c + d))
							counter++;
					}
				}
			}
		}
		
		printf("%d\n", counter);
	}
	
	return 0;
}

Measured memory_bytes: 596
#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>
using namespace std;
using LL = long long;

struct point
{
	LL x, y;
	point(LL xx, LL yy) :x(xx), y(yy)
	{}
};
LL W, H, N;
vector<point>xsort;//x??????????????????????????????
vector<point>ysort;//y??????????????????????????????

				   //?????????P??????s
bool cond(LL P)
{
	point now(P, 0);
	LL seive = 0;
	for (point teki : xsort)
	{
		if (teki.x <= now.x || teki.y <= now.y)
		{
			++seive;
		}
	}
	if (seive == N)
	{
		return true;
	}
	for (int k = 0; k < P; ++k)
	{
		now.x--;
		now.y++;
		auto plussleft = lower_bound(ysort.begin(), ysort.end(), point(1145148101919, now.y), [](const point&p1, const point&p2)
		{
			if (p1.y == p2.y)return p1.x < p2.x; return p1.y < p2.y;
		});
		auto plussright = lower_bound(ysort.begin(), ysort.end(), point(now.x + 2, now.y), [](const point&p1, const point&p2)
		{
			if (p1.y == p2.y)return p1.x < p2.x; return p1.y < p2.y;
		});
		int pluss = plussleft - plussright;
		int minus = lower_bound(xsort.begin(), xsort.end(), point(now.x + 1, 1145148101919), [](const point&p1, const point&p2)
		{
			if (p1.x == p2.x)return p1.y < p2.y; return p1.x < p2.x;
		})
			- lower_bound(xsort.begin(), xsort.end(), point(now.x + 1, now.y + 1), [](const point&p1, const point&p2)
		{
			if (p1.x == p2.x)return p1.y < p2.y; return p1.x < p2.x;
		});
		seive += pluss;
		seive -= minus;
		if (seive == N)
		{
			return true;
		}
	}
	return false;
}

int main(void)
{
	cin >> W >> H >> N;
	for (int i = 0; i < N; ++i)
	{
		int x, y;
		cin >> x >> y;
		xsort.push_back({ x,y });
		ysort.push_back({ x,y });
	}
	sort(xsort.begin(), xsort.end(), [](const point&p1, const point&p2)
	{
		if (p1.x == p2.x)return p1.y < p2.y; return p1.x < p2.x;
	});
	sort(ysort.begin(), ysort.end(), [](const point&p1, const point&p2)
	{
		if (p1.y == p2.y)return p1.x < p2.x; return p1.y < p2.y;
	});
	int lo = 0, hi = W + H + 1;
	if (cond(0))
	{
		cout << 0 << endl;
		return 0;
	}
	while (lo + 1 < hi)
	{
		int mid = (lo + hi) / 2;
		if (cond(mid))
		{
			hi = mid;
		}
		else
		{
			lo = mid;
		}
	}
	cout << hi << endl;
	return 0;
}

Measured memory_bytes: 6172
def bubble_sort(A, n):
	for i in range(n):
		for j in range(n-1, i, -1):
			if A[j][1] < A[j-1][1]:
				A[j], A[j-1] = A[j-1], A[j]

	print(' '.join(A))

def selection_sort(A, n):
	for i in range(n):
		minj = i
		for j in range(i, n):
			if A[j][1] < A[minj][1]:
				minj = j

		A[i], A[minj] = A[minj], A[i]

	print(' '.join(A))

if __name__ == '__main__':
	n = int(input())
	A = list(input().split())
	B = A[:]

	bubble_sort(A, n)
	print('Stable')

	selection_sort(B, n)
	print('Stable' if A == B else 'Not stable')

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

#define rep(i,n) for(int i=0; i<n; i++)

const int INF = 1001001001;

using namespace std;

int main() {

    int n; cin >> n;
    vector<int> h(n); rep(i,n) cin >> h[i];

    vector<int> dp(n,INF);

    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);

    for(int i=2; i<n; i++) {

        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));

    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/extc++.h>

struct bipartite_matching {
  bipartite_matching(int h = 0, int w = 0) : g(h), r(h, -1), c(w, -1), vis(h) {}

  void add(int i, int j) {
    assert(0 <= i), assert(i < int(size(r)));
    assert(0 <= j), assert(j < int(size(c)));
    g[i].push_back(j);
  }
  std::vector<std::pair<int, int>> run() {
    for (bool updated = true; ++t, std::exchange(updated, false);)
      for (int i = size(r); i--;)
        if (r[i] == -1) updated |= dfs(i);
    std::vector<std::pair<int, int>> res;
    for (int i = 0; i < int(size(r)); ++i)
      if (r[i] != -1) res.emplace_back(i, r[i]);
    return res;
  }

 private:
  int t = 0;
  std::vector<std::vector<int>> g;
  std::vector<int> r, c, vis;

  bool dfs(int i) {
    if (std::exchange(vis[i], t) == t) return false;
    for (int j : g[i])
      if (c[j] == -1) return r[i] = j, c[j] = i, true;
    for (int j : g[i])
      if (dfs(c[j])) return r[i] = j, c[j] = i, true;
    return false;
  }
};

int main() {
  using namespace std;
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (auto&& e : s) cin >> e;

  bipartite_matching bm(n * m, n * m);
  auto add = [&](int i1, int j1, int i2, int j2) -> void {
    int p1 = (i1 + j1) & 1;
    int p2 = (i2 + j2) & 1;
    assert(p1 != p2);
    if (p1) {
      swap(i1, i2);
      swap(j1, j2);
    }
    bm.add(i1 * m + j1, i2 * m + j2);
  };

  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '#') continue;
      if (i and s[i - 1][j] != '#') add(i - 1, j, i, j);
      if (j and s[i][j - 1] != '#') add(i, j - 1, i, j);
    }

  int cnt = 0;
  for (auto [v1, v2] : bm.run()) {
    ++cnt;
    int i1 = v1 / m, j1 = v1 % m;
    int i2 = v2 / m, j2 = v2 % m;
    if (i1 == i2) {
      if (j1 > j2) swap(j1, j2);
      assert(j1 + 1 == j2);
      s[i1][j1] = '>';
      s[i1][j2] = '<';
    } else {
      assert(j1 == j2);
      if (i1 > i2) swap(i1, i2);
      assert(i1 + 1 == i2);
      s[i1][j1] = 'v';
      s[i2][j1] = '^';
    }
  }

  cout << cnt << '\n';
  for (auto&& e : s) cout << e << '\n';
}


Measured memory_bytes: 4188
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 200005
#define MAXH 4
#define MAXM 100
#define INF 1LL << 60
#define ll long long
#define ull unsigned long long
#define RNG mt19937
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
const int N = 100005;
int n,m;
vector<pll> g[N];

inline ll mul(ll x, ll y){
	return x * y % MOD;
}

inline ll add(ll x, ll y){
	ll res = x + y;
	if(res >= MOD)res-=MOD;
	return res;
}

inline ll sub(ll x, ll y){
	ll res = x + MOD - y;
	if(res >= MOD)res -= MOD;
	return res;
}

inline ll sqr(ll x){
	return mul(x,x);
}

vector<pll> dij(int s){
	vector<pll> d(n, {INF,0});
	priority_queue<pair<pll,ll>, vector<pair<pll,ll>>, greater<pair<pll,ll>>> pq;
	pq.push({{0,s},-1});
	while(pq.size()){
		int cur = pq.top().F.S;
		ll dist = pq.top().F.F;
		ll pri = pq.top().S;
		pq.pop();
		if(d[cur].F == INF){
			d[cur].F = dist;
			d[cur].S = (pri == -1?1:d[pri].S);
			for(pll a:g[cur]){
				if(dist + a.S <= d[a.F].F){
					pq.push({{dist + a.S , a.F}, cur});
				}
			}
		}
		else if(dist == d[cur].F){
			d[cur].S = add(d[cur].S, d[pri].S);	
		}
	}
	return d;
}

int main(){
	fast_io();
	cin >> n >> m;
	int s,t;
	cin >> s >> t;
	--s;--t;
	cu(i,0,m){
		ll x,y,w;
		cin >> x >> y >> w;
		--x;--y;
		g[x].pb({y,w});
		g[y].pb({x,w});
	}
	vector<pll> sd = dij(s);
	vector<pll> td = dij(t);
	ll ans = sqr(sd[t].S);
	ll dist = sd[t].F;
	cu(i,0,n){
		if(sd[i].F * 2 == dist && sd[i].F == td[i].F){ // meet at the vertex
			ans = sub(ans, sqr(mul(sd[i].S, td[i].S)));	
		}
		for(pll a:g[i]){
			if(sd[i].F + a.S + td[a.F].F == dist && sd[i].F * 2 < dist && td[a.F].F * 2 < dist){ // meet in the edge (not at the vertex)
				ans = sub(ans, sqr(mul(sd[i].S, td[a.F].S)));
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 22124
# 1行目の入力を数値として扱う
n = int(input())
# 2行目の入力をリストとして扱う
s = input()

ans = s[0]

#
for i in range(1, len(s)):
#    print(s[i - 1] + "," + s[i])
    if s[i - 1] == s[i]:
        continue
    ans += s[i]
        

#
print(len(ans))


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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs {cout<<"-1\n";return 0;}
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

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

  string N;
  cin >> N;
  int M = N.size();
  int j = 0;
  int o = 20;
  drep(i, M) {
    int x = N[i] - '0';
    int next_j = min(j + x, o + x + 1);
    int next_o = min(j + 10 - x, o + 9 - x);
    j = next_j;
    o = next_o;
  }
  int ans = min(j, o+1);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000000;

int n;
pair<int, int> p[200000];

int main(){
  cin >> n;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(b, a);
  }
  sort(p, p + n);
  bool flag = true;
  ll time = 0;
  rep(i, n){
    time = time + p[i].second;
    if(time > p[i].first){
      flag = false;
      break;
    }
  }
  if(flag) cout<<"Yes"<<endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll i,j,k,l,m,n,a,b,c,d,cnt=0,pos;
    cin>>n>>k;
    ll arr[n+1];
    for(i=0;i<n;i++)
        cin>>arr[i+1];

    if(k<=n)
    {
        pos=1;
        for(i=0;i<k;i++)
        {
            pos=arr[pos];

        }
        cout<<pos<<endl;

    }
    else
    {



        map <ll,ll> mp;

        pos=1;
        for(i=0;i<k;i++)
        {
            pos=arr[pos];
            mp[pos]++;
            if(mp[pos]==2)
                break;
        }


        k-=(i+1);
        ll temp=pos;
        temp=arr[pos];
        while(temp!=pos)
        {
            temp=arr[temp];
            cnt++;
        }
        cnt++;

        k=(k%cnt);
        pos=temp;

        for(i=0;i<k;i++)
        {
            pos=arr[pos];
        }

        cout<<pos<<endl;



    }




}


Measured memory_bytes: 14980
#include <iostream>
#include <map>

using namespace std;

int main() {
    long long n, p;
    cin >> n >> p;

    map<long long, long long> m;
    for (long long i = 2, j = p; i * i <= p; i++) {
        m.erase(j);

        for (; j % i == 0; j /= i) {
            m[i]++;
        }
        if (i < j) {
            m[j]++;
        }
    }

    long long res = 1;
    for (map<long long, long long>::iterator i = m.begin(); i != m.end(); i++) {
        for (int j = 0; j < i->second / n; j++) {
            res *= i->first;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  private static void execute(ContestReader reader, PrintWriter out) {
    String s = reader.next();
    String t = reader.next();
    out.println(t + s);
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22996
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int n, a, b; cin >> n >> a >> b;
	cout << min(a * n, b) << endl;
 	return 0;
}

Measured memory_bytes: 3516
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    ll N, A, B;
    cin >> N >> A >> B;
    if (A>B || (N == 1 && A != B)) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = (B*(N-1)+A) - (A*(N-1)+B) + 1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():

    N = int(input())
    H = list(map(int, input().split()))

    if N == 1:
        print('Yes')
        exit()

    for i in range(N - 2, -1, -1):
        if H[i] == H[i + 1] + 1:
            H[i] -= 1

    ans = 'Yes'
    for i in range(N - 1):
        if H[i] <= H[i + 1]:
            continue
        else:
            ans = 'No'
            break

    # print(H)
    print(ans)


if __name__ == '__main__':
    solve()


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  vector<int> x;
  for (int i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      x.emplace_back(i);
      if (sum / i != i) x.emplace_back(sum / i);
    }
  }
  sort(x.rbegin(), x.rend());
  
  for (int i = 0; i < x.size(); i++) {
    vector<int> y(n);
    for (int j = 0; j < n; j++) y.at(j) = a.at(j) % x.at(i);
    sort(y.begin(), y.end());
    int count = 0, keep = 0, now = 0;
    while (y.back() != 0) {
      count += y.at(now);
      keep = y.at(now);
      y.at(now) = 0;
      now++;
      while (keep > 0) {
        if (x.at(i) - y.back() <= keep) {
          keep -= x.at(i) - y.back();
          y.pop_back();
        }
        else {
          y.back() += keep;
          keep = 0;
        }
      }
    }
    if (count <= k) {
      cout << x.at(i) << '\n';
      return 0;
    }
  }
  
  cout << 1 << '\n';
}

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

int main() {
    string s; cin >> s;
    vector<vector<char>> a(2);
    for (int i = 0; i < s.size(); i++) a[i & 1].emplace_back(s[i]);
    bool ok = true;
    ok &= count(a[0].begin(), a[0].end(), 'L') == 0;
    ok &= count(a[1].begin(), a[1].end(), 'R') == 0;
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
#[allow(unused)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(unused)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(unused)]
fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    assert_eq!(v.len(), 2);
    (v[0], v[1])
}
fn main() {
    input!(N: usize, K: usize);
    input!(A: [usize; N]);
    for i in K..N {
        if A[i - K] < A[i] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


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

using Plan = vector<int>;

const int N = 100000;

int dp[N][3];

void solve(vector<Plan>& p) {
  for (int i = 1; i < p.size(); ++i) {
    for (int j = 0; j < 3; ++j) {
      int x = dp[i - 1][(j + 1) % 3];
      int y = dp[i - 1][(j + 2) % 3];
      dp[i][j] = p[i][j] + max(x, y);
    }
  }
}

int main() {
  int n;
  cin >> n;
  vector<Plan> p(n);
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    p[i] = {a, b, c};
  }

  dp[0][0] = p[0][0];
  dp[0][1] = p[0][1];
  dp[0][2] = p[0][2];
  solve(p);

  cout << *max_element(dp[n - 1], dp[n - 1] + 3) << endl;
}


Measured memory_bytes: 6912
"use strict"
function main(arg) {
    let [X,Y] = arg.trim().split("\n")[0].split(" ").map(Number)
    for (let i = 0; i <= X; i++) {
        let a = i * 2 + (X-i) * 4
        if (a === Y) {
            console.log('Yes')
            return
        }
    }
    console.log('No')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29640
#include <stdio.h>

#define MOD_BY 998244353

int add(int a, int b) {
	int r = a + b;
	if (r >= MOD_BY) r -= MOD_BY;
	return r;
}

char S[512];
int K;

int scount = 0;
int suretu[512];

int memo[512][512][512];

int search(int pos, int hold, int left) {
	int answer = 0;
	int i;
	if (pos < 0) return hold == 0;
	if (memo[pos][hold][left]) return ~memo[pos][hold][left];

	for (i = -hold; i <= suretu[pos] && i <= left; i++) {
		answer = add(answer, search(pos - 1, hold + i, i < 0 ? left : left - i));
	}

	return ~(memo[pos][hold][left] = ~answer);
}

int main(void) {
	int i;
	int kaunto = 0;
	int goukei = 0;
	if (scanf("%511s%d", S, &K) != 2) return 1;
	for (i = 0; S[i] != '\0'; i++) {
		if (S[i] == '0') {
			suretu[scount++] = kaunto;
			kaunto = 0;
		} else {
			kaunto++;
		}
	}
	suretu[scount++] = kaunto;
	while (scount > 0 && suretu[scount - 1] == 0) scount--;
	for (i = 0; i < scount; i++) goukei += suretu[i];
	if (goukei < K) K = goukei;
	printf("%d\n", search(scount - 1, 0, K));
	return 0;
}

/*

…0……1… → …10………

0で区切られた1の数 → 数列とみなせる
操作 → 右の数を左に移す

一発で移動させてよい → Kは数列の要素の合計でサチらせてよい
数列の要素の合計は高々|S|

同じ要素で「置いて持つ」は無駄

*/


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

int a[101]={0};

int main()
{
	int n,x;
	cin>>n;
	
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=1;
	}
	
	int s=0;
	for(int i=1;i<=100;i++)
	{
		if(a[i]==1) s++;
	}
	
	cout<<s;
	return 0;
}

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

inline int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * flag;
}

struct node {
	int a, b, v;
}e[61];
int tot, V;

void add(int x, int y, int v) {
	e[++tot].a = x;
	e[tot].b = y;
	e[tot].v = v;
}

int main() {
	int L = read();
	V = log(L) / log(2) + 1;
	for (int i = 1; i < V; ++i) {
		add(i, i + 1, 0);
		add(i, i + 1, 1 << (V - i - 1));
	}
	int u = 1 << (V - 1);
	for (int i = V - 1; i >= 1; --i) {
		if (L & (1 << (i - 1))) {
			add(1, V - i + 1, u);
			u += 1 << (i - 1);
		}
	}
	printf("%d %d\n", V, tot);
	for (int i = 1; i <= tot; ++i) {
		printf("%d %d %d\n", e[i].a, e[i].b, e[i].v);
	}
	return 0;
}

Measured memory_bytes: 3972
#include <stdio.h>
#include <stdlib.h>

int compare(const void *x, const void *y)
{
	if (*(long*)x < *(long*)y) return 1;
	if (*(long*)x > *(long*)y) return -1;
	return 0;
}

void calc(long A, long *ans, int *tmp, int *i)
{
	if (*tmp == 0) *ans = A;
	else *ans *= A;
	++*tmp;
	++*i;
}

int main(void)
{
	int N, tmp = 0, i;
	long A[100000], ans;
	scanf("%d", &N);
	for (i = 0; i < N; ++i) scanf("%ld", &A[i]);
	qsort(A, N, sizeof(long), compare);
	for (i = 0; i < N - 1 && tmp != 2; ++i) {
		if (A[i] == A[i + 1]) calc(A[i], &ans, &tmp, &i);
	}
	if (tmp == 2) printf("%ld", ans);
	else puts("0");
	return 0;
}

Measured memory_bytes: 1788
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;


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

    int i;
    for(i=0;i<3;i++){
        if(n[i]=='1'){
            n[i]='9';
        }else if(n[i]=='9'){
            n[i]='1';
        }
    }
    cout<<n<<endl;
     return 0;
}



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

using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = 0 ; i < a ; i ++)
#define vi vector<int>

#define M 1046527
#define L 14

char H[M][L];
int getChar(char ch){
	if(ch == 'A')return 1;
	else if(ch == 'C')return 2;
	else if(ch == 'G')return 3;
	else if(ch == 'T')return 4;
	else return 0;
}
long long getKey(string s){
	long long ret = 0,p = 1;
	rep(i,s.size()){
		ret += p * getChar(s[i]);
		p *= 5;
	}
	return ret;
}

int h1(int key){return key % M;};
int h2(int key){return 1 + (key % (M - 1));}

int find(string str){
	long long key, h,i=0;
	key = getKey(str);
	while(true){
		h = (h1(key) + i * h2(key)) % M;
		if(str == H[h])return 1;
		else if(H[h][0] == '\0')return 0;
		i ++;
	}
	return 0;
}

int insert(string str){
	long long key, h, i=0;
	key = getKey(str);
	while(true){
		h = (h1(key) + i * h2(key)) % M;
		if(H[h] == str)return 1;
		else if(H[h][0] == '\0'){
			rep(j,str.size())
				H[h][j] = str[j];
			return 0;
		}
		i ++;
	}
	return 0;
}

int main(void){
	int n, h;
	string str, com;

	rep(i,M)H[i][0] = '\0';

	cin>>n;
	rep(i,n){
		cin>>com>>str;
		if(com =="insert"){
			insert(str);
		}else{
			if(find(str)){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
		}
	}
}

Measured memory_bytes: 15520
package main

import "fmt"

func main() {
	var a, b, c, x, count int
	fmt.Scan(&a, &b, &c, &x)

	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				if 500*i+100*j+50*k == x {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  sort(ALL(a));
  int ans = a[a.size()-1] - a[0];
  cout << ans << endl;
}


Measured memory_bytes: 256
// Aizu Vol-2 0268: Kongo Type
// 2017.8.17

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *gets();

int frac[7] = { 78125, 156250, 312500, 625000, 1250000, 2500000, 5000000 };
char buf[20], *p;

int x2d(char c) { if (c <= '9') return c - '0'; return c - 'a' + 10; }

int main(void)
{
	int Q, i, d, f;

	gets(buf); Q = atoi(buf);
	while (Q-- > 0) {
		gets(p = buf);
		if (*p >= '8') putchar('-');
		d = x2d(*p++); if (d >= 8) d -= 8;
		for (i = 0; i < 5; i++) d = (d << 4) + x2d(*p++);
		d <<= 1;
		f = x2d(*p++);
		if (f >= 8) d |= 1;
		printf("%d", d);
		putchar('.');
		f = (f << 4) + x2d(*p);
		for (d = i = 0; i < 7; i++, f >>= 1)
			if (f & 1) d += frac[i];
		if (d == 0) putchar('0'), putchar('\n');
		else {
			sprintf(buf, "%07d", d);
			p = buf + strlen(buf) - 1;
			while (*p == '0') p--;
			*(p+1) = 0;
			puts(buf);
		}
	}
	return 0;
}

Measured memory_bytes: 556
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
   char s[4];
   set<char>st;
   for(int i=0;i<3;i++){
       cin>>s[i];
       st.insert(s[i]);
   }
   if(st.size()>1) cout<<"Yes"<<"\n";
   else cout<<"No"<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,sum=0,s,i,mx=0,mn=1000;
  int av;
  while(scanf("%d",&n)&&n!=0){
    n,s,i,sum=0,mx=0,mn=1000;   
    for(i=0;i<n;i++){
      scanf("%d",&s);
      sum+=s;
      if(mx<s)
	mx=s;
      if(mn>s)
	mn=s; 
    }
    sum=sum-(mn+mx);
    av=sum/(n-2);
    printf("%d\n",av);
  }
  
  return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>

using namespace std;

int main(void){
	string s;
	cin >> s;
	
	int ans;
	while(true){
		s.resize(s.size() - 1);
		if(equal(&s[0], &s[s.size() / 2], &s[s.size() / 2], &s[s.size()])){
			ans = s.size();
			break;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(){
   int n, y;
   cin >> n >> y;
   int a = -1;int b = -1; int c = -1;
   for(int i = 0; i <= n; i++){
       for(int j = 0; i + j <= n; j++){
           int k = n - i -j;
           if(10000*i + 5000*j + 1000*k == y){
               a = i;b = j; c = k;
           }
       }
   }
   cout << a <<" "<< b << " "<< c << endl;
}



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

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int sum = findSumOfDigits(N);
  if(N%sum==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define MAX 200

int main(int argc, const char * argv[]) {
    
    int N = 0;
    scanf("%d", &N);
    
    int list[MAX + 10];
    int sosu[MAX];
    for(int i = 0; i <= MAX; i++){
        list[i] = 0;
    }
    int count = 0;
    int index = 2;
    while(1){
        if(index >= sqrt(MAX)){
            for(int i = index; i <= MAX; i++){
                if(list[index] == 0){
                    sosu[count] = index;
                    count++;
                }
            }
            break;
        }
        if(list[index] == 0){
            sosu[count] = index;
            count++;
            for(int i = index, p = 1; i <= MAX; p++, i = index * p){
                list[i] = 1;
            }
        }
        index++;
    }
    int result = 0;
    
    if(N < 105){
        printf("0\n");
    }else{
        for(int i = 105; i <= N; i += 2){
            int num[count];
            for(int p = 0; p < count; p++){
                num[p] = 0;
            }
            int n = i;
            for(int p = 0; p < count;){
                if(n % sosu[p] == 0){
                    n /= sosu[p];
                    num[p]++;
                }else if(n == 1){
                    break;
                }else{
                    p++;
                }
            }
            int re = 1;
            for(int p = 0; p < count; p++){
                if(num[p] >= 1){
                    re *= (num[p] + 1);
                }
            }
            if(re == 8){
                result++;
            }
        }
        
        printf("%d\n", result);
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    string s, t;
    cin >> s >> t;
    int a = t.size();
    string x = t.substr(0,a-1);
    if(x == s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3608
#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,Q;
ll S[200010],T[200010],X[200010];
ll D[200010];
vector<ll> ts;
vector<ll> vs[1000010],qs[1000010];
ll res[200010];

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

  cin>>N>>Q;
  rep(i,N){
    cin>>S[i]>>T[i]>>X[i];
    ts.push_back(S[i]-X[i]);
    ts.push_back(T[i]-X[i]);
  }
  rep(i,Q){
    cin>>D[i];
    ts.push_back(D[i]);
  }
  sort(all(ts));
  uni(ts);

  rep(i,N){
    S[i]=lower_bound(all(ts),S[i]-X[i])-ts.begin();
    T[i]=lower_bound(all(ts),T[i]-X[i])-ts.begin();
    vs[S[i]].push_back(X[i]);
    vs[T[i]].push_back(-X[i]);
  }
  rep(i,Q){
    D[i]=lower_bound(all(ts),D[i])-ts.begin();
    qs[D[i]].push_back(i);
  }

  multiset<ll> st;
  rep(i,1000010){
    for(ll v : vs[i]){
      if(v>0){
        st.insert(v);
      }else{
        st.erase(st.find(-v));
      }
    }
    for(ll q : qs[i]){
      if(st.size()>0)res[q]=*st.begin();
      else res[q]=-1;
    }
  }

  rep(i,Q)cout<<res[i]<<endl;

  return 0;
}


Measured memory_bytes: 89576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] n = line.split(" ");
		int W = Integer.parseInt(n[0]);
		int H = Integer.parseInt(n[1]);
		int x = Integer.parseInt(n[2]);
		int y = Integer.parseInt(n[3]);
		int r = Integer.parseInt(n[4]);

		if (x - r < 0 || x + r > W || y - r < 0 || y + r > H) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

	}

}



Measured memory_bytes: 26196
#include<stdio.h>
int main(void)
{
	int n,a,b,A,B,i;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		A=0; B=0;
		for(i=0;i<n;i++){
			scanf("%d%d",&a,&b);
			if(a>b)   A+=a+b;
			else if(a<b) B+=a+b;
			else{
				A+=a; B+=b;
			}
		}
		printf("%d %d\n",A,B);
	}
	return 0;
}

Measured memory_bytes: 1728
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int n;
long long int ma = 999999999999999;
long long a[200010];
long long sum1[200010];
long long sum2[200010];
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum1[i] = sum1[i - 1] + a[i];
    }
    for(int i = n; i >= 1; i--){
        sum2[n + 1 - i] = sum2[n - i] + a[i]; 
    }
    for(int i = 1; i <= n - 1; i++){
        long long int res = abs(sum1[i] - sum2[n - i]);
        if(res < ma){
            ma = res;
        }
    }
    cout << ma;
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<string>

int main(){
    int k, a, b;
    std::cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            std::cout << "OK" << std::endl;
            return 0;
        }
    }

    std::cout << "NG" << std::endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi  = vector<int>;

struct UnionFind {
    vi data;
    int comp;
    UnionFind() {}
    UnionFind(int size) {
        init(size);
    }
    void init(int size) {
        data.assign(size, -1);
        comp = size;
    }
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(x != y) {
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
            comp--;
        }
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        if (data[x] < 0) {
            return x;
        } else {
            return data[x] = root(data[x]);
        }
    }
    int size(int x) {
        return -data[root(x)];
    }
    int components() {
        return comp;
    }
};

struct LCA {
    using Query = pii;
    
    vector<vector<int>> g;
    vector<int> color;
    vector<int> ancestor;
    vector<vector<pair<int, Query>>> query_set;
    UnionFind uf;
    vector<int> res;

    LCA(const vector<vector<int>> &g, vector<Query> &query) : g(g), color(sz(g)), ancestor(sz(g)), query_set(sz(g)), uf(sz(g)), res(sz(query)) {
        int qs = sz(query);
        for (int i = 0; i < qs; ++i) {
            query_set[query[i].first ].emplace_back(i, query[i]);
            query_set[query[i].second].emplace_back(i, query[i]);
        }
    }

    void visit(int v, int prev) {
        ancestor[uf.root(v)] = v;
        for (auto &w : g[v]) {
            if (w == prev) {
                continue;
            }
            visit(w, v);
            uf.unite(v, w);
            ancestor[uf.root(v)] = v;
        }
        color[v] = 1;
        for (auto &p : query_set[v]) {
            Query q = p.second;
            int w = (q.second == v ? q.first
                    : (q.first == v ? q.second : -1));
            if (w == -1 || !color[w]) {
                continue;
            }
            res[p.first] = ancestor[uf.root(w)];
        }
    }

    vi solve(int root) {
        visit(root, -1);
        return res;
    }
};

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    rep(v, 0, N) {
        int K;
        cin >> K;
        rep(k, 0, K) {
            int X;
            cin >> X;
            G[v].push_back(X);
        }
    }
    int Q;
    cin >> Q;
    vector<pii> queries;
    rep(i, 0, Q) {
        int U, V;
        cin >> U >> V;
        queries.emplace_back(U, V);
    }
    LCA lca(G, queries);
    vi res = lca.solve(0);

    for (int ans : res) {
        cout << ans << endl;
    }
}



Measured memory_bytes: 41108
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

void compose(Vi& a, Vi b) {
	each(k, a) k = b[k];
}

Vi pow(Vi x, ll e) {
	Vi t(sz(x));
	iota(all(t), 0);
	while (e) {
		if (e & 1) compose(t, x);
		e >>= 1;
		compose(x, x);
	}
	return t;
}

void run() {
	ll first;
	int n, m;
	cin >> n >> first;

	vector<ll> dists(n-1);
	ll last = first;
	rep(i, 0, n-1) {
		cin >> dists[i];
		dists[i] -= last;
		last += dists[i];
	}

	ll k;
	cin >> m >> k;

	Vi perm(n-1);
	iota(all(perm), 0);

	rep(i, 0, m) {
		int j; cin >> j;
		swap(perm[j-2], perm[j-1]);
	}

	perm = pow(perm, k);
	cout << double(first) << '\n';

	each(i, perm) {
		first += dists[i];
		cout << double(first) << '\n';
	}
}


Measured memory_bytes: 4712
package main

import "fmt"

func count(A int, B int, C int, X int) int {
	count := 0
	for a := 0; a <= A; a++ {
		for b := 0; b <= B; b++ {
			for c := 0; c <= C; c++ {
				if (a*500 + b*100 + c*50) == X {
					count++
				}
			}
		}
	}
	return count
}

func main() {
	var A, B, C, X int
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Scan(&C)
	fmt.Scan(&X)
	fmt.Println(count(A, B, C, X))
}


Measured memory_bytes: 512
x, y, z, K = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]
b = sorted(list(map(int, input().split())))[::-1]
c = sorted(list(map(int, input().split())))[::-1]


ans = []
for i in range(x):
    for j in range(y):
        if i * j > K:
            break
        for k in range(z):
            if i * j * k > K:
                break
            ans.append(a[i] + b[j] + c[k])
ans = sorted(ans)[::-1]
for i in range(K):
    print(ans[i])


Measured memory_bytes: 159876
use input::Input;

fn main() {
    let mut input = Input::default();

    let a: f64 = input.parse();
    let b: f64 = input.parse();
    let h: f64 = input.parse();
    let m: f64 = input.parse();

    let x = 30.0 * h + 0.5 * m;
    let y = 6.0 * m;
    let g = (x - y).abs();
    let g = (g / 180.0 * std::f64::consts::PI).cos();
    let c = (a * a + b * b - 2.0 * a * b * g).sqrt();

    println!("{:.12}", c);
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 3032
package main

import (
	"fmt"
	"strings"
)

func main() {
	var w string
	fmt.Scan(&w)

	a := strings.Split(w, "")

	bucket := make(map[string]int, len(a))
	for _, v := range a {
		bucket[v]++
	}

	for _, v := range bucket {
		if v%2 != 0 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int x,y;
	cin>>x>>y;
	if(x>4)x=4;
	if(y>4)y=4;
	LL ans=(8-x-y)*100000;
	if(x==1&&y==1)ans+=400000;
	cout<<ans<<endl;



}


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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int n, a[6005], dp[2005][2005], rmx[2005], mx;
int todo[100005][3], tsz;

void add_todo(int x, int y, int v) { todo[tsz][0] = x; todo[tsz][1] = y; todo[tsz ++][2] = v; }
void upd(int x, int y, int v) { rep(_, 2) { dp[x][y] = max(dp[x][y], v); rmx[x] = max(rmx[x], v); mx = max(mx, v); swap(x, y); } }
void fix() { rep(i, tsz) upd(todo[i][0], todo[i][1], todo[i][2]); tsz = 0; }

int main() {
	scanf("%d", &n);
	rep(i, n * 3) scanf("%d", &a[i]), -- a[i];
	memset(rmx, -0x3f, sizeof(rmx));
	memset(dp, -0x3f, sizeof(dp));
	mx = -0x3f3f3f3f;
	upd(a[0], a[1], 0);
	int extra = 0;
	rep(i, n - 1) {
		int x[3] = { a[i * 3 + 2], a[i * 3 + 3], a[i * 3 + 4] }; sort(x, x + 3);
		if (x[0] == x[2]) { ++ extra; continue; }
		if (x[0] == x[1]) rep(a, n) add_todo(a, x[2], dp[a][x[0]] + 1);
		if (x[1] == x[2]) rep(a, n) add_todo(a, x[0], dp[a][x[1]] + 1);
		rep(j, 3) add_todo(x[j == 0 ? 1 : 0], x[j == 2 ? 1 : 2], dp[x[j]][x[j]] + 1);
		rep(j, 3) rep(k, j) add_todo(x[j], x[k], mx);
		rep(j, n) rep(k, 3) add_todo(j, x[k], rmx[j]);
		fix();
	}
	int ans = mx;
	ans = max(ans, dp[a[n * 3 - 1]][a[n * 3 - 1]] + 1);
	printf("%d\n", ans + extra);
	return 0;
}


Measured memory_bytes: 19644
#include <stdio.h>

void dividing(int pm, int pe, int pj);

int main(void)
{
    int number;
    scanf("%d\n", &number);    
    while (number != 0) {
        int pm[number];
        int pe[number];
        int pj[number];
        for (int i = 0; i < number; ++i) {
            scanf("%d %d %d", &pm[i], &pe[i], &pj[i]);
            dividing(pm[i], pe[i], pj[i]);
        }
        scanf("%d", &number);
    }
}
void dividing(int pm, int pe, int pj)
{
    if (pm == 100 || pe == 100 || pj == 100) {
        printf("A\n");
        return;
    }
    if ((pm + pe) / 2 >= 90) {
        printf("A\n");
        return;
    }
    if ((pm + pe + pj) / 3 >= 80) {
        printf("A\n");
        return;
    }
    if ((pm + pe + pj) / 3 >= 70) {
        printf("B\n");
        return;
    }
    if (((pm + pe + pj) / 3 >= 50) && (pm >= 80 || pe >= 80)) {
        printf("B\n");
        return;
    }
    printf("C\n");
    return;
}

Measured memory_bytes: 1012