akhauriyash/Code-Regression huggingface dataset:
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

struct ExGCDRet{
    ll gcd, a, b;
    friend ostream& operator << (ostream& out, ExGCDRet& e) {
        return out << e.gcd << '(' << e.a << ',' << e.b << ')';
    }
};
ExGCDRet exGCD(ll xx, ll yy){
    // (a2 a1) = (a1 a0)(1 1 )
    // (b2 b1) = (b1 b0)(0 -q)
	ll a0 = 1, b0 = 0, a1 = 0, b1 = 1;
	while(yy){
        auto ret = lldiv(xx, yy);
        xx = yy;
        yy = ret.rem;
		ll a2 = a0 - ret.quot * a1;
        ll b2 = b0 - ret.quot * b1;
        printde(a0, a1, a2);
        printde(b0, b1, b2);
        a0 = a1; b0 = b1;
        a1 = a2; b1 = b2;
	}
	return {xx, a0, b0};
}

map<ll, int> factorization(ll n){
    map<ll, int> fs;
    auto sq = sqrt(n);
    for(int i = 2; i <= sq; i++){
        while(n % i == 0){
            fs[i]++;
            n /= i;
        }
    }
    if(n > 1){
        fs[n]++;
    }
    return fs;
}

ll solve(ll n){
    auto fs = factorization(2 * n);
    vector<pair<ll, int>> fs2(fs.begin(), fs.end());
    int n2 = fs2.size();
    printde(fs2);
    ll ans = n & 1 ? n - 1 : 2 * n - 1;
    for(int bits = 0; bits < (1 << n2); bits++){
        ll num1 = 1, num2 = 1;
        for(int i = 0; i < n2; i++){
            for(int j = 0; j < fs2[i].second; j++){
                (bits >> i & 1 ? num1 : num2) *= fs2[i].first;
            }
        }
        if(num1 == 1 || num2 == 1){
            continue;
        }
        auto ret = exGCD(num1, num2);
        ll k1 = abs(num1 * ret.a), k2 = abs(num2 * ret.b);
        ll cand = k1;
        ans = min(ans, cand);
        printde(num1, num2, ret);
        printde(k1, k2, cand);
    }
    return ans;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    if(n == 1){
        cout << 1 << '\n';
        return 0;
    }
    cout << solve(n) << '\n';
    // cout << min(solve(n, n), solve(n, n * 2)) << '\n';
    // for(int n = 1; n < 10000; n++){
    //     // auto ans = solve(n, n);
    //     auto ans = min(solve(n, n), solve(n, n * 2));
    //     for(ll i = 1; i < ans; i++){
    //         if(i * (i + 1) / 2 % n == 0){
    //             printde(n, ans, i);
    //             return 0;
    //         }
    //     }
    // }
}


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

void search(int,int,int);

int g[100][100],start[2],h,w,ans;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(void){
  
  int i,j;

  while(scanf("%d %d",&w,&h),w,h){
    
    memset(g,-1,sizeof(g));

    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	scanf("%d",&g[i][j]);
	if(g[i][j]==2){
	  g[i][j]=0;
	  start[0]=i,start[1]=j;
	}
      }
    }
    
    ans=100000000;
    search(start[0],start[1],0);
    if(ans==100000000)ans=-1;
    printf("%d\n",ans);
  }
  return 0;
}

void search(int x,int y,int turn){

  int i,nx,ny;

  if(g[x][y]==3){
    ans=ans<turn?ans:turn;
    return;
  }
 if(turn>=10||turn>=ans)return;
  for(i=0;i<4;i++){
    if(g[x+dx[i]][y+dy[i]]!=1){
    nx=x,ny=y;
    while(1){
      nx+=dx[i],ny+=dy[i];
      if(g[nx][ny]!=0)break;
    }
    if(g[nx][ny]==-1)continue;
    if(g[nx][ny]==1){
      g[nx][ny]=0;
      search(nx-dx[i],ny-dy[i],turn+1);
      g[nx][ny]=1;
    }
    else if(g[nx][ny]==3)search(nx,ny,turn+1);
    }
  }

}

Measured memory_bytes: 0
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> xy_t;
double cross_product(xy_t a, xy_t b) {
    return(conj(a)*b).imag(); 
}

int main() {
    int n;
    cin >> n;
    for (int task = 0; task < n; task++) {
        xy_t p[4];
        double x[4], y[4], eps = 1e-11;
        for (int i = 0; i < 4; i++) cin >> x[i] >> y[i];

        xy_t a[2];
        a[0] = xy_t(x[0], y[0]) - xy_t(x[1], y[1]);
        a[1] = xy_t(x[2], y[2]) - xy_t(x[3], y[3]);

        bool b = abs(cross_product(a[0], a[1])) / 2.0 < eps;
        cout << (b ? "YES" : "NO") << endl;
    }
}

/*
g++ -std=c++14 pr_prog/_main.cpp
 */


Measured memory_bytes: 3172
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);

		sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		FenwickTree ft = new FenwickTree(a);

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int t = Integer.parseInt(sa[0]);
			if (t == 0) {
				int p = Integer.parseInt(sa[1]);
				int x = Integer.parseInt(sa[2]);
				ft.add(p, x);
			} else {
				int l = Integer.parseInt(sa[1]);
				int r = Integer.parseInt(sa[2]);
				pw.println(ft.sum(l, r));
			}
		}
		pw.flush();
		br.close();
	}
}

/**
 * Fenwick Tree（Binary Indexed Tree）
 */
class FenwickTree {
	private int n;
	private long[] data;

	/**
	 * 長さnの配列（a[0]～a[n-1]）を作る。初期値は全て0。<br>
	 * O(n)
	 * 
	 * @param n 配列の長さ
	 */
	public FenwickTree(int n) {
		this.n = n;
		data = new long[n];
	}

	/**
	 * 初期データを元にFenwick Treeを構成する。<br>
	 * O(n)
	 * 
	 * @param data 初期データ
	 */
	public FenwickTree(long[] data) {
		this(data.length);
		build(data);
	}

	/**
	 * a[p] += x を行う。<br>
	 * O(log n)
	 * 
	 * @param p 加算位置（0≦p＜n）
	 * @param x 加算値
	 */
	void add(int p, long x) {
		assert 0 <= p && p < n : "p=" + p;

		p++;
		while (p <= n) {
			data[p - 1] += x;
			p += p & -p;
		}
	}

	/**
	 * a[l] + ... + a[r-1] を返す。<br>
	 * O(log n)
	 * 
	 * @param l 開始位置（含む）    （0≦l≦r≦n）
	 * @param r 終了位置（含まない）（0≦l≦r≦n）
	 */
	long sum(int l, int r) {
		assert 0 <= l && l <= r && r <= n : "l=" + l + ", r=" + r;

		return sum(r) - sum(l);
	}

	/**
	 * a[0] + ... + a[r-1] を返す。<br>
	 * O(log n)
	 * 
	 * @param r 終了位置（含まない）（0≦r≦n）
	 */
	long sum(int r) {
		assert 0 <= r && r <= n : "r=" + r;

		long s = 0;
		while (r > 0) {
			s += data[r - 1];
			r -= r & -r;
		}
		return s;
	}

	private void build(long[] dat) {
		System.arraycopy(dat, 0, data, 0, n);
		for (int i = 1; i <= n; i++) {
			int p = i + (i & -i);
			if (p <= n) {
				data[p - 1] += data[i - 1];
			}
		}
	}
}


Measured memory_bytes: 100568
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
vector<vector<ll> >d(410,vector<ll>(410,inf));
void Warshall_Floyd(ll n){
    REP(k,1,n+1){
        REP(i,1,n+1){
            REP(j,1,n+1)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }
    }
}
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    ll h,w;cin>>h>>w;
    vector<vector<char> >m(h+2,vector<char>(w+2,'#'));
    REP(i,1,h+1){
        REP(j,1,w+1){
            cin>>m[i][j];
        }
    }
    REP(i,1,h+1){
        REP(j,1,w+1){
            if(m[i][j]=='#')continue;
            d[(i-1)*w+j][(i-1)*w+j]=0;
            rep(k,4){
                ll nx=i+dx[k],ny=j+dy[k];
                if(m[nx][ny]=='.'){
                    d[(i-1)*w+j][(nx-1)*w+ny]=1;
                }
            }
        }
    }
    Warshall_Floyd(h*w);
    ll ma=0;
    REP(i,1,h*w+1){
        REP(j,1,h*w+1){
            if(d[i][j]<inf)ma=max(ma,d[i][j]);
        }
    }
    cout<<ma<<endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int N, M; cin >> N >> M; 
	int cnt[100010] = {}; 
	for(int i = 0; i < N; i++){
		int a; cin >> a; cnt[a] ++; 
	}
	int sum[100010] = {}; 
	int odd[100010] = {}; 
	for(int i = 1; i <= 100000; i++){
		sum[i % M] += cnt[i]; 
		if(cnt[i] % 2) odd[i % M] ++; 
	}
	int rem = 0; 
	rem += odd[0] % 2; 
	if(M % 2 == 0) rem += odd[M/2] % 2; 
	for(int i = 1; i < (M+1)/2; i++){
		if(sum[i] <= sum[M-i]){
			rem += max(odd[M-i] - sum[i], 0); 
			if(odd[M-i] < sum[i] && odd[M-i] % 2 != sum[i] % 2) rem ++;  
		}
		else{
			rem += max(odd[i] - sum[M-i], 0); 
			if(odd[i] < sum[M-i] && odd[i] % 2 != sum[M-i] % 2) rem ++;  
		}
	}
	cout << (N - rem) / 2 << endl; 
}

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

int main(){
  ll a,b,c,k,ans;
  cin >> a >> b >> c >> k;
  
  if(k <= a){ans = k;}
  else if(k <= a+b){ans = a;}
  else{ans = a-(k-a-b);}
  
  
  cout << ans << endl;
  
  return 0;
}


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

int gcd(int a,int b){
	if(a<b)return gcd(b,a);
	while(true){
		int r = a%b;
		a=b;
		b=r;
		if(r==0)break;
	}
	return a;
}

int main()
{
	int N,X;
	cin>>N>>X;
	vector<int> x(N);
	for(int i=0; i<N; i++){
		int buf;
		cin>>buf;
		x[i]=abs(buf-X);
	}
	int D=x.front();
	for(int i=0;i<N;i++){
		D=gcd(D,x[i]);
	}
	cout<<D<<endl;
	return 0;
}


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

using namespace std;

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

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

    int sum1, sum2;
    int ans = 100001; //INF

    for(int i = 0; i < N-1; i++){
        sum1 = 0;
        sum2 = 0;
        for(int j = 0; j <= i; j++){
            sum1 += W[j];
        }
        for(int k = i+1; k < N; k++){
            sum2 += W[k];
        }
        ans = min(ans, abs(sum1 - sum2));
    }

    cout << ans << endl;
}


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

int main() {
	int x, S00yen, Syen;
	cin >> x;

	S00yen = x / 500;
	x -= 500 * S00yen;
	Syen = x / 5;

	cout << 1000 * S00yen + 5 * Syen << endl;
}

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

const int MOD = 1000000007;
typedef pair<long long, long long> Pairs;

long long n;
map<Pairs, int> dp;

inline void Add(int &x, int a) {
    x += a; while (x >= MOD) x -= MOD;
}
inline int Calc(long long u, long long v) {
	u=0;
    if (v < 0) return 0;
    if (!v) return 1;
    if (dp.count(Pairs(u, v))) return dp[Pairs(u, v)];
    int res = 0;
    Add(res, Calc(u >> 1, v >> 1));
    Add(res, Calc((u - 1) >> 1, (v - 1) >> 1));
    if (v >= 2) Add(res, Calc(u >> 1, (v - 2) >> 1));
    return dp[Pairs(u, v)] = res;
}

int main(void) {
    //freopen("1.in", "r", stdin);
    cin >> n;
    cout << Calc(n, n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	sort(a.begin(),a.end());
	cout<<a[n/2]-a[n/2-1]<<endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define endl "\n"

#define aim_cpo do{ios::sync_with_stdio(false);\
cin.tie(nullptr);cout.precision(10);cout<<fixed;}while(0)

#define LOCAL_INPUT do{FILE *stream1;\
stream1=freopen("/Users/aim_cpo/CLionProjects/competitive/in.txt","r",stdin);\
if(stream1==nullptr)return 0;}while(0)

#define LOCAL_OUTPUT do{FILE *stream2;\
stream2 = freopen("out.txt", "w", stdout);\
if (stream2 == nullptr) return 0;}while(0)

#ifdef LOCAL_DEFINE
#define show(x) cerr << #x << " = " << x << endl
#else
#define show(x)
#endif

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

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

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

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
const ll MOD = (ll)1e9 + 7;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//LLの数値をつかう時は最後にLをつける癖をつけよう
//
//  ┏┓┏┓　┓　┏┓
//  ┏┛┃┃　┃　┗┫
//  ┗┛┗┛　┻　┗┛
//
//   謹┃賀┃新┃年┃
//   ━┛━┛━┛━┛
//WWWWWWWWWWWWWWWWWWWWWW

int n, k;
ll a[100001];
ll b[100001];
ll c[100001];
ll dp[101][100001];

int main() {
    aim_cpo; // インタラクティブのときは消すように.
#ifdef LOCAL_DEFINE
    LOCAL_INPUT; // インタラクティブのときは消すように.
//    LOCAL_OUTPUT; // ファイルに出力したいときのみ
    show(MOD);
#endif
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= k; j++) {
            if (j + a[i] <= k) dp[i + 1][j + a[i]] = max(dp[i + 1][j + a[i]], dp[i][j] + b[i]);
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= k; i++) {
        chmax(ans, dp[n][i]);
    }
    cout << ans << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s." << endl;
#endif
    return 0;
}

Measured memory_bytes: 79360
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N, M;
	cin >> N >> M;
	VLL A(N);
	LL S = 0;
	for (LL n = 0; n < N; n++) {
		cin >> A[n];
		S += A[n];
	}
	LL ans = N;
	LD cr = (LD)S / (4 * M);
	for (LL n = 0; n < N; n++) {
		if (A[n] < cr)ans--;
	}
	if (ans >= M)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int Search(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)
    i++;
    return i!=n;
}
int main(){
  int i,n,A[10000+1],q,key,total=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(Search(A,n,key)) total++;
  }
  printf("%d\n",total);
  
  return 0;
}

Measured memory_bytes: 640
N,K = list(map(int,input().split()))
ans = 0
for i in range(K,N+2):
    if i == 1:
        ans += N + 1
    elif i == 2:
        ans += 2*N - 1
    else:
        ans += N*i - i*(i-1) + 1
print(ans % (10**9 + 7))

Measured memory_bytes: 63328
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n;
    cin >> n;
    int res = n;
    int k = 0;
    while(res > 0){
        k += res % 10;
        res /= 10;
    }
    if(n % k == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# 2019/08/09

n=int(input())
a=list(map(int,input().split()))

sec=0
quad=0
rem=0
for i in range(n):
    if a[i]%4==0:
        quad+=1
    elif a[i]%2==0:
        sec+=1
    else:
        rem+=1

if sec>0:rem+=1
if rem-quad<=1:
    print('Yes')
else:print('No')

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


void solve() {
  char S[4], T[4];
  scanf("%s", &S);
  scanf("%s", &T);
  int ans = 0;
  for (size_t i = 0; i < 3; i++) {
    if (S[i] == T[i]) {
      ans++;
    }
  }


  cout << ans << "\n";
}

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


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

int main() {
	int n;
	cin >> n;
	vector<int> arr(n);
	rep(i,n) cin >> arr[i];
	
	bool flag = true;
	int ans = 0;
	while(flag){
		flag = false;
		for(int i = n - 1; i >= 1; --i){
			if(arr[i] < arr[i - 1]){
				swap(arr[i],arr[i - 1]);
				flag = true;
				ans++;
			}
		}
	}
	
	rep(i,n){
		if(i != n - 1) cout << arr[i] << ' ';
		else cout << arr[i] << endl;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3104
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0;r=10**10
while r-l>1:
  x=(l+r)//2
  ct=0
  for i in range(n):
    ct+=(a[i]-1)//x
  if ct<=k:
    r=x
  else:
    l=x
print(r)

Measured memory_bytes: 104340
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1')
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define mod %
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll a , b , c;
    cin >> a >> b >> c ;
    vl v ;
    v.pb(a) ; v.pb(b) ; v.pb(c) ;
    sort(all(v));
    unordered_map<ll , ll> mpp;
    mpp[v[0]]++;
    mpp[v[1]]++;
    mpp[v[2]]++;
    if(mpp[5] == 2 and mpp[7]== 1) {
        cout << "YES\n" ;
        ro ;
    }
    else cout << "NO\n" ;
    ro ;
}































Measured memory_bytes: 256
/*|In The Name of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int h;
int v[N];
int w[N];
long long dp[N][101];

int main(){
    scanf("%d%d" , &n , &h);
    for(int i = 1; i <= n; i++){
        scanf("%d%d" , &w[i] , &v[i]);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= h; j++){
            if(j >= w[i]){
                dp[j][i] = dp[j - w[i]][i - 1] + v[i];
            }
            dp[j][i] = max(dp[j][i] , dp[j][i - 1]);
        }
    }
    printf("%lld\n" , dp[h][n]);
    return 0;
}


Measured memory_bytes: 79104
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);


		Map<Long,Integer> factMap = factorization(stdIn.nextLong());
		stdIn.close();

		if(factMap.isEmpty()) { //1のとき
			System.out.println(0);
			return;
		}

		int cnt = 0;
		for (Entry<Long, Integer> e : factMap.entrySet()) {
			cnt += countMin(e.getValue());
		}

		System.out.println(cnt);

	}

	private static Map<Long, Integer> factorization(long n) {
		Map<Long, Integer> factMap = new LinkedHashMap<Long, Integer>();

		while (n != 1) {
			if (n % 2 == 0) {
				factMap.putIfAbsent(2L, 0);
				factMap.replace(2L, factMap.get(2L) + 1);
				n /= 2;
				continue;
			}

			long d = 3;
			while (true) {

				if(d * d == n) {
					factMap.putIfAbsent(d, 0);
					factMap.replace(d, factMap.get(d) + 2);
					n = 1;
					break;
				}

				if (d * d >= n) {
					factMap.put(n, 1);
					n = 1;
					break;
				}

				if(n % d == 0) {
					factMap.putIfAbsent(d, 0);
					factMap.replace(d, factMap.get(d) + 1);
					n /= d;
					continue;
				}

				d += 2;
			}

		}

		return factMap;
	}

	private static int countMin(int pow) {
		return (int) Math.floor((Math.sqrt(2*pow + 0.25) - 0.5));

	}
}

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

int GetMax(vector<int> source){
    int max = source.at(0);
    for(int i=1; i<source.size(); i++)
    {
        if(source.at(i) > max) max = source.at(i);
    }
    return max;
}

int main()
{
    int nvacation;
    vector<vector<int>> DP;
    vector<vector<int>> Act;

    cin >> nvacation;

    DP.resize(nvacation);
    Act.resize(nvacation);

    for(int i=0; i<nvacation; i++)
    {
        DP.at(i).resize(3);
        Act.at(i).resize(3);
        cin >> Act.at(i).at(0) >> Act.at(i).at(1) >> Act.at(i).at(2);
    }

    DP.at(0).at(0) = Act.at(0).at(0);
    DP.at(0).at(1) = Act.at(0).at(1);
    DP.at(0).at(2) = Act.at(0).at(2);

    for(int inode=1; inode<nvacation; inode++)
    {
        int dp01, dp02;// Transition from Act0
        int dp10, dp12;// Transition from Act1
        int dp20, dp21;// Transition from Act2

        dp01 = DP.at(inode-1).at(0) + Act.at(inode).at(1);
        dp02 = DP.at(inode-1).at(0) + Act.at(inode).at(2);
        dp10 = DP.at(inode-1).at(1) + Act.at(inode).at(0);
        dp12 = DP.at(inode-1).at(1) + Act.at(inode).at(2);
        dp20 = DP.at(inode-1).at(2) + Act.at(inode).at(0);
        dp21 = DP.at(inode-1).at(2) + Act.at(inode).at(1);

        DP.at(inode).at(0) = max(dp10, dp20);
        DP.at(inode).at(1) = max(dp01, dp21);
        DP.at(inode).at(2) = max(dp02, dp12);
    }

    cout << GetMax(DP.at(nvacation-1)) << endl;
    
    return 0;
}

Measured memory_bytes: 11136
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  } else {
    cout << n - k << endl;
    return 0;
  }

  return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s; cin >> s;
    std::string::size_type C = s.find('C');
    std::string::size_type F = s.rfind('F');

    if (C != std::string::npos && F != std::string::npos) {
        if (C < F) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    } else cout << "No" << '\n';
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  s.push_back(s[0]);
  s.push_back(s[1]);
  bool f = false;
  vector<int> ans(n + 2); // 0 sheep, 1 wolf
  
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      ans[0] = i, ans[1] = j;
      for (int i = 2; i <= n+1; i++) {
        if (ans[i-1] == 0) {
          // previous sheep
          ans[i] = s[i-1] == 'o' ? ans[i-2] : !ans[i-2];
        } else {
          // previous wolf
          ans[i] = s[i-1] == 'x' ? ans[i-2] : !ans[i-2];
        }
      }
      if (ans[0] == ans[n] && ans[1] == ans[n+1]) {
        f = true;
        break;
      }
    }
    if (f) break;
  }
  
  if (f) {
    for (int i = 0; i < n; i++) cout << (ans[i] == 0 ? 'S' : 'W');
  } else {
    cout << -1;
  }
  cout << endl;
  return 0;
}


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

int main() {
    int n,m;
    cin>>n;
    string s[101],t[101];
    int i,j;
    for(i=0;i<n;++i) cin>>s[i];
    cin>>m;
    for(i=0;i<m;++i) cin>>t[i];
    
    int num[101]={0};
    for(i=0;i<n;++i){
        for(j=0;j<n;++j){
            if(s[i]==s[j]){
                ++num[i];
            }
            
        }
        for(j=0;j<m;++j){
            if(s[i]==t[j]){
                --num[i];
            }
        }
            
        
    }
    sort(num,num+101,greater<int>());
    cout<<num[0]<<endl;
    
    
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N, K;
  vector<llong> A;

  cin >> N >> K;
  A.resize(N);
  vector<int> many(51, 0);
  for (auto &in: A) {
    cin >> in;
    for (int i = 0; i <= 50; i++) {
      many[i] += (in>>i)&1;
    }
  }

  llong res = 0;
  for (int i = 50; i >= 0; i--) {
    llong cand = 1ll<<i;
    if (res + cand > K) {
      continue;
    }
    if (many[i] < N - many[i]) {
      res += cand;
    }
  }

  llong ans = 0;
  for (auto a: A) {
    ans += res^a;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3988
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
//#include<iostream>
//#include<assert.h>
using namespace std;

#define maxn 30011
int n,a[maxn];
int gcd(int a,int b) {while (b^=a^=b^=a%=b); return a;}
int main()
{
	scanf("%d",&n);
	if (n<=15000)
	{
		int sum=0;
		for (int i=1;i<=n-2;i++) a[i]=i<<1,sum+=a[i],printf("%d ",a[i]);

		for (int i=3;i<=8000;i+=2)
			for (int j=i+2;j<=8000;j+=2)
				if (gcd(i,sum+j)!=1 && gcd(j,sum+i)!=1) {printf("%d %d\n",i,j); return 0;}
	}
	else
	{
		int x=15000,y=n-15000,ans=0,sum=225015000;
		for (int i=x;i;i--)
		{
			if (y&1) {y++; sum-=i*2; continue;}
			else if (sum%3==0) {ans=i; break;}
			y++; sum-=i*2;
		}
		for (int i=1;i<=ans;i++) printf("%d ",i*2);
		int now=3;
		for (int i=1;i<=n-ans;i++) printf("%d ",now),now+=6;
	}
	return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
now = 0
loop = []
flag = [0 for _ in range(n)]
for _ in range(n):
    loop.append(now+1)
    if flag[now]:
        break
    else:
        flag[now] = 1
        now = a[now]-1
tloop = loop[loop.index(loop[-1]):len(loop)-1]
floop = loop[:loop.index(loop[-1])]
if k < len(floop):
    print(floop[k])
else:
    k -= len(floop)
    print(tloop[k%len(tloop)])

Measured memory_bytes: 32372
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;	cin>>n;
	string a,b;	cin>>a>>b;
	for(int i=0;i<a.size();i++){
		bool flag=true;
		for(int j=0;i+j<a.size();j++){
			if(a[i+j]!=b[j]){
				flag=false;
				break;
			}
		}
		if(flag){
			cout<<i+n<<endl;
			return 0;
		}
	}
	cout<<2*n<<endl;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
adjacent = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adjacent[a].append(b)
    adjacent[b].append(a)


def dfs(visited, v):
    if visited == (1 << N) - 1:
        return 1

    ans = 0
    for u in adjacent[v]:
        if visited >> u & 1 == 1:
            continue
        visited += 1 << u
        ans += dfs(visited, u)
        visited -= 1 << u
    return ans


print(dfs(1, 0))


Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {

    let n: usize = read();
    let m = read();
    let mut wa_count = vec![0; n + 1];
    let mut ans_state = vec![false; n + 1];
    let mut ans_result = 0;
    let mut wa_result = 0;

    for _ in 0..m {
        let p: usize = read();
        let s: String = read();
        let s: &str = &s;

        match (ans_state[p], s){
            (false, "AC") => {
                ans_state[p] = true;
                wa_result += wa_count[p];
                ans_result += 1;    
            }
            (false, "WA") => wa_count[p] += 1,
            _ => (),
        }

    }

    println!("{} {}", ans_result, wa_result);


}


Measured memory_bytes: 4352
n = int(input())
S = []
for i in range(n):
    S.append(input())

ans = ''

for alpha in range(ord('a'), ord('z')+1):
    Chr = chr(alpha)
    Count = []
    for i in range(n):
        Count.append(S[i].count(Chr))
    ans += Chr * min(Count)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int maxf(int x){
    if (x>30) return (1<<30);
    return (1<<x)-1;
}

int bs(int n){
    int l = 1, r = n;
    while (l<r-1){
        int mid = l + (r-l)/2;
        int mins = mid, maxs = maxf(mid);
        if ((mins<=n) && (n<=maxs)){
            r=mid;
        }
        else if (n<mins){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    if ((l<=n) && (n<=maxf(l))){
        return l;
    }
    return r;
}

int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll b = 100, x, y = 0;
    cin>>x;

    while (b<x){
        b = (ll)((double)b*((double)1.01));
        y++;
    }
    cout<<y<<"\n";
    return 0;
}


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

void Main(){
    int n;
    cin >> n;
    float ans = 0.0f;
    if(n % 2 == 1){
        ans = (static_cast<float>(n / 2 + 1) / static_cast<float>(n)) ;
    }else{
        ans = 1.0f / 2.0f;
    }
    
    cout << ans << endl;
}
    
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
 
int main()
{
 
    double a, b, C;
    cin >> a >> b >> C;
 
    double S, L, h;
    double rad = C * M_PI / 180;
 
    S = a * b * sin(rad) / 2;
    L = sqrt(a*a + b*b - 2 * a*b*cos(rad)) + a + b;
    h = 2 * S / a;
 
    printf("%.4f\n", S);
    printf("%.4f\n", L);
    printf("%.4f\n", h);
 
 
 
    return 0;
}

Measured memory_bytes: 3448
k = int(input())
ok = 10**18
ng = 0
while ok-ng>1:
    mid = (ok+ng)//2
    s = list(map(int, list(str(mid))))
    n = len(s)
    dp = [[[0]*2 for i in range(10)] for j in range(n)]
    for i in range(1, s[0]):
        dp[0][i][0] = 1

    dp[0][s[0]][1] = 1
    for i in range(n-1):
        for d in range(1, 10):
            dp[i+1][d][0]+=1
        for d in range(10):
            if d+1 < 10:
                dp[i+1][d+1][0] += dp[i][d][0]
            if d-1 >= 0:
                dp[i+1][d-1][0] += dp[i][d][0]
            dp[i+1][d][0] += dp[i][d][0]
        if s[i]>0:
            if s[i+1] == s[i]-1:
                dp[i+1][s[i]-1][1]+=dp[i][s[i]][1]
            elif s[i+1]>s[i]-1:
                dp[i+1][s[i]-1][0]+=dp[i][s[i]][1]
        if s[i]<9:
            if s[i+1] == s[i]+1:
                dp[i+1][s[i]+1][1]+=dp[i][s[i]][1]
            elif s[i+1]>s[i]+1:
                dp[i+1][s[i]+1][0]+=dp[i][s[i]][1]
        if s[i+1] == s[i]:
            dp[i+1][s[i]][1]+=dp[i][s[i]][1]
        elif s[i+1]>s[i]:
            dp[i+1][s[i]][0]+=dp[i][s[i]][1]
    res = 0
    for d in range(10):
        res+=dp[n-1][d][0]+dp[n-1][d][1]
    if res>=k:
        ok = mid
    else:
        ng = mid

print(ok)






Measured memory_bytes: 41584
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var index=-1;
while(true){
   var n=arr[++index]-0;
   if(n==0)break;
   var stone=[];
   while(n--)stone.push(arr[++index]-0);
   var ary=[];
   var flag=false;
   stone.forEach(function(v,i){
      flag=!flag;
      if(flag)ary.push(v);
      else {
         if(ary[ary.length-1]==v)ary.push(v);
         else{
            ary.push(v);
            i--;
            while(true){
               if(i<0 || ary[i]==v)break;
               else {
                  ary[i]=v;
                  i--;
               }
            }
         }
      }
   });
   var cnt=0;
   ary.forEach(function(v){
      if(v==0)cnt++;
   });
   console.log(cnt);
}

Measured memory_bytes: 19420
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int k,x;
    cin>>k>>x;
    repi(i,x-k+1,x+k){
        cout<<i<<" ";
    }
}

Measured memory_bytes: 3636
n, x = map(int, input().split())
def get_len(lv):
  m = 1
  for i in range(lv):
    m = m * 2 + 3
  return m  
def count_p(lv, p):
  if p <= lv:return 0
  elif lv == 0:return 1
  m = get_len(lv)
  if p > (m-1)/2:
    return (m-1)/2 + 1 - count_p(lv, m-p)
  else:
    return count_p(lv-1,p-1)
print(int(count_p(n, x)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define regi register int
inline void py()
{
    cout<<"YES"<<endl;
    return ;
}
inline void pn()
{
    cout<<"NO"<<endl;
    return ;
}
bool got[10];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    for (regi i=1;i<=4;i++)
    {
        int n;
        cin>>n;
        got[n]=true;
    }
    if (got[1]&&got[9]&&got[7]&&got[4]) py();
        else pn();
    return 0;
}

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



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

using namespace std;
int a,b ,c;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
using namespace std;

#define MAX_N (100000)
vector<int> g[MAX_N];
int root,n;
int par[17][MAX_N];//log_2(MAX_N)
int depth[MAX_N];
void dfs(int v,int p,int dep){
    par[0][v]=p;
    depth[v]=dep;
    for(int i=0;i<g[v].size();++i){
        if(g[v][i]!=p){
            dfs(g[v][i],v,dep+1);
    }
  }
}
void lca_init(int n){
    dfs(root,-1,0);
    for(int k=0;k+1<17;++k){
        for(int i=0;i<n;++i){
            if(par[k][i]<0) par[k+1][i]=-1;
            else par[k+1][i]=par[k][par[k][i]];
        }
    }
}
int lca(int a,int b){
    if(depth[a]>depth[b]) swap(a,b);
    for(int k=0;k<17;++k){
        if((depth[b]-depth[a]) >> k & 1){
            b=par[k][b];
        }
    }
    if(a==b) return a;
    for(int k=16;k>=0;--k){
        if(par[k][a] !=par[k][b]){
            a=par[k][a];
            b=par[k][b];
        }
    }
    return par[0][a];
}

int main(){
    cin>>n;
    root=0;
    int k,c,q,u,v;
    rep(i,n){
        cin>>k;
        while(k--){
            cin>>c;
            g[i].pb(c);
        }
    }
    lca_init(n);
    cin>>q;
    rep(i,q){
        cin>>u>>v;
        cout<<lca(u,v)<<endl;
    }
    return 0;
}

Measured memory_bytes: 20252
#include <iostream>


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

  int n;
  static int a[3001], b[3001];
  std::cin >> n;
  a[1] = a[2] = 1;
  for (int i = 2; i < n; ++i)
    for (int j = i + 1; j > 0; --j)
      a[j] = (a[j] + a[j - 1]) % n;
  for (int i = 1; i <= n; ++i)
    if (i % 2 == 1)
      a[i] = -a[i];

  for (int i = 0; i < n; ++i) {
    int x;
    std::cin >> x;
    if (x == 1) {
      ++b[n];
      for (int j = 1, t = 1; j <= n; ++j, t = (t * i) % n)
        b[j] = ((b[j] + t * a[j]) % n + n) % n;
    }
  }

  for (int i = n; i > 0; --i)
    std::cout << b[i] << (i == 1 ? '\n' : ' ');

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

const int MAX_N=1252521;
// const int MAX_SQRT_B=1e9;

int prime[MAX_N];
bool is_prime[MAX_N+1];


// エラトステネスの篩
// is_prime[i]=true⇔iが素数
int sieve(int n){
  int res=0;
  REP(i, n+1){
    is_prime[i]=true;
  }
  is_prime[0]=is_prime[1]=false;
  FOR(i, 2, n+1){
    if(is_prime[i]){
      prime[res++]=i;
      for(int j=2*i; j<=n; j+=i){
        is_prime[j]=false;
      }
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int x;
  cin>>x;
  sieve(MAX_N);
  FOR(i, x, MAX_N){
    if(is_prime[i]){
      cout<<i<<'\n';
      return 0;
    }
  }
  return 0;
}


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

using namespace std;

int parent[200005] = {};
int sz[200005] = {};
int n;

void init() {
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        sz[i] = 1;
    }
}

int root(int u) {
    if (u == parent[u]) return u;
    return root(parent[u]);
}

void join(int u, int v) {
    int ru = root(u);
    int rv = root(v);

    if (ru == rv)   return;

    if (sz[rv] > sz[ru]) {
        parent[ru] = rv;
        sz[rv] += sz[ru];
    } else {
        parent[rv] = ru;
        sz[ru] += sz[rv];
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    init();
    int m ;
    cin >> m;

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        join(u,v);
    }

    vector<int> arr;

    for (int i = 0; i < n; i++) {
        if (parent[i] == i) {
            arr.push_back(sz[i]);
        }
    }

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

    int group = 0;

    int del = 0;

    for (int i = 0; i < arr.size(); i++) {
        arr[i] -= del;
        group += arr[i];
        del += arr[i];
    }

    cout << group << endl;
}

Measured memory_bytes: 5680
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m, n) for(int i = m-1; i < n; i++)
#define INF 2000000000
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
//vector<intなど> 変数名(要素数,初期値)
using namespace std;
typedef long long ll;
//gcd,lcmセット
ll gcd(ll a, ll b){
   if (a%b == 0) return b;
   else return gcd(b, a%b);
}
ll lcm(ll a, ll b){	
   return a*b/gcd(a, b);
}
bool isPrime(ll x){
    int i;
    if(x < 2)return false;
    else if(x == 2) return true;
    if(x%2 == 0) return false;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return false;
    return true;
}
//dfsではvector<vector<int>> g(n);で◎
int main(){
    int n;
    cin>>n;
    int x[n];
    REP(i,n) cin>>x[i];
    int a=INF;
    REP(i,100){
      	int cp=i+1;
      	//cout<<"cp:"<<cp<<endl;
        int tmp=0;
        REP(j,n) tmp+=(x[j]-cp)*(x[j]-cp);
          //cout<<"tmp:"<<tmp<<endl;}
      	//cout<<"tmp_f:"<<tmp<<endl;
        a=min(tmp,a);
    }
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 int main()
 {
     int A,B,ans;
     char op;
     scanf("%d %c %d",&A,&op,&B);
     if(op=='+')
        ans=A+B;
     else
        ans=A-B;
     printf("%d\n",ans);
     return 0;
 }


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int ans = 0;
    rep(i, n) {
        int t;
        cin >> t;
        if(a <= t && t < b) {
            continue;
        }
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int A,B,K; cin >> A >> B >> K;
    FOR(i,A,A+min(B-A+1,K)) cout << i << endl;
    FOR(i,max(A+K,B-K+1), B+1) cout << i << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
signed main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a;
	int cnt = 9;
	while (1) {
		a.push_back(cnt);
		cnt *= 9;
		if (cnt > 100000)break;
	}
cnt = 6;
	while (1) {
		a.push_back(cnt);
		cnt *= 6;
		if (cnt > 100000)break;
	}
	a.push_back(1);
	int dp[100004];
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		dp[i] = 999999;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < a.size(); j++) {
			int now = a[j];
			if (i - a[j] >= 0) {
				dp[i] = min(dp[i], dp[i - a[j]] + 1);
			}
		}
	}
	cout << dp[n];
}

Measured memory_bytes: 640
def Eratosthenes(n):
    prime_list = [True for _ in range(n + 1)]
    prime_list[0] = False
    prime_list[1] = False
    for j in range(4, n + 1, 2):
        prime_list[j] = False
    prime_list[2] = True
    for i in range(3, int(n ** 0.5) + 1, 2):
        if prime_list[i]:
            for j in range(i * 2, n + 1, i):
                prime_list[j] = False
    return prime_list


def prime_2017(prime_list):
    prime_2017_list = [True for _ in range(len(prime_list))]
    for i in range(len(prime_list)):
        if i <= 2:
            prime_2017_list[i] = False
        elif prime_list[i]:
            if not prime_list[(i + 1) // 2]:
                prime_2017_list[i] = False
        else:
            prime_2017_list[i] = False
    return prime_2017_list

q = int(input())
num_list = []
num_max = 0
for _ in range(q):
    l, r = map(int, input().split())
    num_list.append([l, r])
    num_max = max(r, num_max)
prime_list = Eratosthenes(num_max)
prime_2017_list = prime_2017(prime_list)
prime_num = [0 for _ in range(num_max + 1)]
for i in range(num_max):
    prime_num[i + 1] = prime_num[i] + prime_2017_list[i + 1]

for l, r in num_list:
    print(prime_num[r] - prime_num[l - 1])

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

using namespace std;
int a[4], me[4];
int main()
{
	int n, i, num, cnt = 0;
	cin >> n;
	a[1] = a[2] = a[3] = -1;
	for(i=1;i<=n;i++)
	{
		cin >> num;
		if(num == a[1]) me[1]++;
		else if(num == a[2]) me[2]++;
		else if(num == a[3]) me[3]++;
		else if(num != a[1] && num != a[2] && num != a[3])
		{
			a[++cnt] = num;
			me[cnt]  = 1;
		}
		if(cnt > 3)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	if(cnt == 3 && (a[1] ^ a[2]) == a[3] && (a[2] ^ a[3]) == a[1] &&  me[2] == me[1] && me[3] == me[1])
		cout << "Yes" << endl;
	else if(cnt == 1 && a[1] == 0)
		cout << "Yes" << endl;
	else if(cnt == 2 && ((a[1] == 0 && me[2] == 2*me[1]) || (a[2] == 0 && me[1] == 2*me[2])))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256