akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
int s_gcd(int x, int y) {
	if (y == 0) { return x; }
	int d = x % y;
	return s_gcd(y, d);
}
int gcd(int x, int y) {
	if (y > x) { swap(x, y); }
	return s_gcd(x, y);
}
signed main(){
	int x, y; cin >> x >> y;
	cout << x + y - gcd(x, y) + 1 << endl;
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

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

vector<pair<ll, ll>> pF;

ll mod_pow(ll a, ll b, ll p){
    if(b == 0){
        return 1;
    }
    if(b % 2){
        return  a * mod_pow(a, b - 1, p) % p;
    }
    return mod_pow(a * a % p, b / 2, p);
}


void prime_fact(ll n){
    // 素因数分解
    for(ll i = 2; i * i <= n; i ++){
        ll cnt = 0;
        while(n % i == 0){
            cnt ++;
            n /= i;
        }
        pair<ll, ll> f = {i, cnt};
        pF.push_back(f);
    }
    if(n != 1){
        pF.push_back({n, 1});
    }
}

vector<ll> f;
vector<ll> fInv;
vector<ll> inv;

ll mod(ll a, ll m){
    // a mod m
    return (m + a % m) % m;
}

void comInit(ll n, ll m){
    f.push_back(1);
    // 0の逆元は存在しないので0
    inv.push_back(0);
    inv.push_back(1);
    fInv.push_back(1);
    rep(i, n){
        // 階乗
        ll tmp = (i + 1) * f[i] % m;
        f.push_back(tmp);
    }
    for(int i = 2; i <= n; i ++){
        // 逆元.
        ll tmp = mod(- (m / i) * inv[m % i], m);
        inv.push_back(tmp);
    }
    rep(i, n){
        // 階乗の逆元
        ll tmp = fInv[i] * inv[i + 1] % m;
        fInv.push_back(tmp);
    }
}

ll com(ll n, ll k, ll m){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return (f[n] * fInv[n - k] % m) * fInv[k] % m;
}


int main(){
    ll N, M;
    ll p = 1e9 + 7;
    cin >> N >> M;
    ll iMax = 1e6;
    comInit(iMax, p);
    prime_fact(M);
    ll ans = 1;
    rep(i, pF.size()){
        ll index = pF[i].second;
        ans = ans * com(index + N - 1, N - 1, p) % p;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 30952
#include <iostream>
#include <algorithm>
#include <map>
#include <regex>
#include <string>
#include <cstdlib>
#include <math.h>
using namespace std;
int main() {
  double N;
  cin >> N;

  long long min = 9999999999999;
  for (double i = 1; i <= sqrt(N); i++) {
    if (fmod(N, i) == 0) {
      long long d = i - 1 + (N / i) - 1;
      if (min > d) {
        min = d;
      }
    }
  }

  cout << min << endl;
  return 0;
}



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

signed main() {
    ll x, y;
    cin >> x >> y;
    ll ans = 1;
    for(ll i = x; i*2 <= y;){
        i *= 2;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long X;
    
    cin >> X;
    
    long long money = 100;
    int year = 0;
    while(money < X){
        year++;
        money += money / 100;
        //if(money>=X) break;
        //cout << money << endl;
    }
    
    cout << year;
    
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<string> vstr;
typedef long long int llint;



int main(void) {
	int N,K,num;
	cin >> N >> K;
	if (N % 2 == 0)num = N / 2;
	else num = N / 2 + 1;

	if (num >= K)cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

typedef long long ll;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0);
//#define cerr if(false)cerr
#define PRINT(x) cerr<<"\n" << (#x) << " is " << (x) << endl;
//Erase duplicates in vector
#define REMOVE_DUP(x) x.erase(unique(x.begin(), x.end()), x.end());
#define UP toupper // lowercase to uppercase;
#define DOWN tolower
#define SZ(a) (int)a.size()
#define EB emplace_back
#define PB push_back
#define REP(i, a, b) for(int i=a; i<b; i++)
#define PER(i, a, b) for(int i=a; i>=b; i--)
ostream_iterator<int> output(cout, " ");
#define MOD 1e9+7
#define INF INT_MAX;
#define lim_size 200007

void solve(){
	int n, k, c;
	cin >> n >> k >> c;
	string str;
	cin >> str;
	stack<int>s;
	int cnt = 0, i = 0;
	while(i < n){
		if(str[i] == 'o'){
			cnt++;
			s.push(i);
			i+=c;
		}
		i++;
	}
	if(cnt > k){
		cout << endl;
		return;
	}
	vector<int> ans;
	//cout << cnt << endl;
	int start, end;
	s.push(n+c);
	while(!s.empty()){
		if(s.size() == 1) break;
		end = s.top(); s.pop();
		end-=c+1;
		start = s.top(); s.pop();
		//int i;
		//bool flag = false;
		for(i=end;  i>=start; i--){
			if(str[i] == 'o'){
				//flag = true;
				break;
			}
		}
		if(i == start){
			ans.push_back(i);
		}
		s.push(i);
	}
	reverse(ans.begin(), ans.end());
	for(auto x: ans) cout << x+1 << endl;
	return;		
}

int main(){
	FAST_IO;
	int t=1; //cin >> t;
	while(t--){
		solve();
	}
}			


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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
#define MOD (ll)(1ll << 51)

long long modPow(long long x, long long n) {
  if(n == 0)
    return 1;
  if(n % 2 == 0) {
    long long sqrtX = modPow(x, n / 2);
    return sqrtX * sqrtX % MOD;
  } else {
    return x * modPow(x, n - 1) % MOD;
  }
}

long long kaizyou(long long x) {
  long long res = 1;
  for(int i = 1; i <= x; i++) {
    res = (res * i) % MOD;
  }
  return res;
}

long long modCombi(long long a, long long b) {
  if(b > a / 2)
    return modCombi(a, a - b);
  return ((kaizyou(a) * modPow(kaizyou(b), MOD - 2)) % MOD) *
         modPow(kaizyou(a - b), MOD - 2) % MOD;
}

// 二項係数計算
long long COM(int n, int k) {
  if(n < k)
    return 0;
  if(n < 0 || k < 0)
    return 0;
  if(k == 0)
    return 1;
  return n * COM(n - 1, k - 1) / k;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, P;
  cin >> n >> P;
  VI a(n);
  rep(i, n) cin >> a[i];
  ll even = 0;
  ll odd = 0;
  rep(i, n) {
    if(a[i] % 2 == 0)
      even++;
    else
      odd++;
  }
  ll ans = 0;
  if(P == 0) {
    // odd 取らない
    ll tmp = modPow(2, even);
    // oddとる
    for(ll num = 0; num <= odd; num += 2) {
      ans += tmp * COM(odd, num);
    }
    cout << ans << endl;
  } else {
    if(odd == 0) {
      cout << 0 << endl;
      return 0;
    }
    // odd 一つとる
    ll tmp = modPow(2, even);
    for(ll num = 1; num <= odd; num += 2) {
      ans += tmp * COM(odd, num);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys

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

N = int(input())
X = sorted(map(int, input().split()))

ans = None
for i in range(X[0], X[-1] + 1):
    dist = sum((i - j) ** 2 for j in X)
    if ans is None or dist < ans:
        ans = dist
print(ans)


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

const long long INF = 1000000000;

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	long long ans=0;
	if(abs(a-b)%2 == 0){
		ans = abs(a-b)/2;
	}else{
		long long l = max(a-1, b-1);
		long long r = max(n-a, n-b);
		ans = min(l, r);
		long long l2 = (a+b-1)/2;
		long long r2 = (n+n-a-b+1)/2;
		ans = min(ans, l2);
		ans = min(ans, r2);
    }
	cout << ans <<endl;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000009
#define MX 1

using namespace std;

int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int x=tx-sx,y=ty-sy;
    rep(i,x)cout<<"R";
    rep(i,y)cout<<"U";
    rep(i,x)cout<<"L";
    rep(i,y+1)cout<<"D";
    rep(i,x+1)cout<<"R";
    rep(i,y+1)cout<<"U";
    cout<<"L";
    cout<<"U";
    rep(i,x+1)cout<<"L";
    rep(i,y+1)cout<<"D";
    cout<<"R";
    return 0;
}

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

using namespace std;

int main(){
    string str;
    cin >> str;
    if(8 <= count(begin(str), end(str), 'o') + 15 - str.size()){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << -1 << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,K;
    string S;
    cin >> N >> K;
    cin >> S;
    int B=1;
    REP(i,N-1){
        if(S[i]!=S[i+1]){
            B++;
        }
    }
    //cout << B << endl;
    REP(i,K){
        if(B>2){
            B-=2;
        }else{
            B--;
        }
    }
    int Ans=N-max(1ll,B);
    cout << Ans << endl;
    
  return 0;
}



Measured memory_bytes: 512
#  --*-coding:utf-8-*--


def f(X, n, d):
    if n == 0:
        print(''.join(map(lambda x:chr(x+97), X)))
        return

    for i in range(0, d):
        X[-n] = i
        f(X, n-1, d)

    X[-n] = d
    f(X, n-1, d+1)



N = int(input())
X = [0]*N

f(X, N, 0)



Measured memory_bytes: 4340
import java.util.Scanner;

/**
 * Disjoint Set of Common Divisors
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            long A = sc.nextLong();
            long B = sc.nextLong();

            long gcd = gcd(A, B);

            long ans = 0;

            for (long d = 1; d * d <= gcd; d++) {
                if (gcd % d != 0) {
                    continue;
                }

                if (isPrime(d)) {
                    ans++;
                }

                if (gcd / d != d && isPrime(gcd / d)) {
                    ans++;
                }
            }

            System.out.println(ans);
        }
    }

    static long gcd(long M, long N) {
        if (M < N) {
            return gcd(N, M);
        }
        return N > 0 ? gcd(N, M % N) : M;
    }

    static boolean isPrime(long N) {
        for (long i = 2; i * i <= N; i++) {
            if (N % i == 0) {
                return false;
            }
        }
        return true;
    }

}


Measured memory_bytes: 23892
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<complex>
using namespace std;
double x[100][5];
double y[100][5];
double abs(double a){return max(-a,a);}
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
P wolf[100][5];
namespace std{
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
double dist[100][100];
double PI=3.14159265359;
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		double p,q,r,s;
		for(int i=0;i<a;i++){
			scanf("%lf%lf%lf%lf",&p,&q,&s,&r);
			x[i][0]=p-r*sin(s*PI/180);
			x[i][1]=p-r*sin((s+144)*PI/180);
			x[i][2]=p-r*sin((s+288)*PI/180);
			x[i][3]=p-r*sin((s+72)*PI/180);
			x[i][4]=p-r*sin((s+216)*PI/180);
			y[i][0]=q+r*cos(s*PI/180);
			y[i][1]=q+r*cos((s+144)*PI/180);
			y[i][2]=q+r*cos((s+288)*PI/180);
			y[i][3]=q+r*cos((s+72)*PI/180);
			y[i][4]=q+r*cos((s+216)*PI/180);
		}
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				dist[i][j]=INF;
		for(int i=0;i<a;i++)dist[i][i]=0;
		for(int i=0;i<a;i++)
			for(int j=0;j<5;j++){
				wolf[i][j]=P(x[i][j],y[i][j]);
			//	printf("%d,%d: %f %f\n",i,j,x[i][j],y[i][j]);
			}
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				for(int k=0;k<5;k++)
					for(int l=0;l<5;l++){
					//	L wolf(P());
						dist[i][j]=min(dist[i][j],distanceSS(L(wolf[i][k],wolf[i][(k+1)%5]),L(wolf[j][l],wolf[j][(l+1)%5])));
					}
			}
		}
		for(int k=0;k<a;k++)
			for(int i=0;i<a;i++)
				for(int j=0;j<a;j++)
					dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		printf("%.8f\n",dist[b-1][c-1]);
	}
}

Measured memory_bytes: 1212
from collections import deque
def main():
    N, M = map(int, input().split())
    d = [-1 for i in range(N)]
    par = [-1 for i in range(N)]
    adj = [list() for i in range(N)]

    for i in range(M):
        A, B = map(int, input().split())
        adj[A-1].append(B-1)
        adj[B-1].append(A-1)

    dq = deque()
    dq.append(0)
    d[0] = 0

    while(len(dq) > 0):
        n = dq.popleft()
        for i in range(len(adj[n])):
            if d[adj[n][i]] != -1:
                continue
            else:
                dq.append(adj[n][i])
                d[adj[n][i]] = d[n] + 1
                par[adj[n][i]] = n

    print("Yes")
    for i in range(1, len(par)):
        print(par[i]+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 34944
import math

A, B = list(map(int,input().split()))

cnt = 0
for i in range(1,100000):
    X = math.floor(i * 0.08)
    Y = math.floor(i * 0.1)
    if A == X and B == Y:
        print(i)
        cnt += 1
        break
        
if cnt == 0:
    print(-1)

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r){
  if( l >= r ) return;
  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  rec(l, m);
  rec(m+1, r);
  post.push_back(root);
}

void solve(){
  int i;
  pos = 0;
  rec(0, pre.size());
  for( i = 0 ; i < n ; i++ ){
    if(i) cout << " ";
    cout << post[i];
  }
  cout << endl;
}

int main(){
  int i, k;

  cin >> n;

  for( i = 0 ; i < n ; i++ ){
    cin >> k;
    pre.push_back(k);
  }

  for( i = 0 ; i < n ; i++ ){
    cin >> k;
    in.push_back(k);
  }

  solve();

  return 0;
}



Measured memory_bytes: 3160
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1626&lang=jp

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	while(true){
		int b;
		bool flag = false;
		cin>>b;

		if(!b) break;
		
		for(int i = 1, j = 1, sum = 0; i; i++){
			for(; sum < b; j++){
				sum += j;
			}
			if(sum == b){
				cout<<i<<" "<<j-i<<endl;
				flag = true;
				break;
			}
			sum -= i;
			if(flag) break;
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 3232
import sys
# import numpy as np

n = int(sys.stdin.readline().rstrip())
xy = [[] for _ in range(n)]

for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    for j in range(a):
        x, y = map(int, sys.stdin.readline().split())
        xy[i].append((x-1, y))

# xy = np.array(xy)
# x, y = xy[:, :].T
# x = x.T 
# y = y.T

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        ok = True
        for i in range(n):
            if not comb >> i & 1:
                continue
            for x, y in xy[i]:
                if comb >> x & 1 ^ y:
                    ok = False
                    break
            if ok:
                cnt += 1
            else:
                break
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3064
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 5;

vector <int> g[N];
bool s[N], t[N];

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int u, v;
		cin >> u >> v;
		if (u > v)
			swap(u, v);

		if (u == 1)
			s[v] = true;
		if (v == n)
			t[u] = true;
	}

	bool ans = false;
	for (int i = 2; i <= n; ++i)
		if (s[i] and t[i])
			ans = true;

	if (ans)
		cout << "POSSIBLE\n";
	else
		cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  int mx_dist = 0;
  for(int i=0; i<n-1; i++){
    if(a.at(i+1) - a.at(i) > mx_dist){
      mx_dist = a.at(i+1) - a.at(i);
    }
    //cout << mx_dist << endl;
  }
  if(k - a.at(n-1) + a.at(0) > mx_dist){
    mx_dist = k - a.at(n-1) + a.at(0);
  } 
  cout << k - mx_dist << endl;
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ code.cpp
./a.out
*/

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

int main(){
    long long n;
    cin >> n;
    long long ans = 1;
    long long x = pow(10,9) + 7;
    for (long long i = 1; i <= n; i++){
        ans *= i;
        ans %= x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def dekoboko(n: int, v: list) -> int:
    o, e = {}, {}
    for i, vv in enumerate(v):
        if i % 2 == 0:
            if vv not in e:
                e[vv] = 1
            else:
                e[vv] += 1
        else:
            if vv not in o:
                o[vv] = 1
            else:
                o[vv] += 1

    ol = sorted(o.items(), key=lambda x: -x[1])
    el = sorted(e.items(), key=lambda x: -x[1])

    # pivot 選択
    # 頻度が最大のものを固定してそれに合わす様にしたいが、
    # 偶数番号列と奇数番号列とで同じあたいの pivot を使う
    # ことはできない。なので、頻度が最大のものがかぶる様な
    # ら、2番目に頻度が多いものを比較して、頻度の多い方は
    # 2番目のものを使う様にする。
    if ol[0][0] == el[0][0]:
        if len(ol) > 1:
            # 長さが 1 でない時は 2 番目に頻度が高いものの頻度を比べる。
            if ol[1][1] > el[1][1]:
                ol[0], ol[1] = ol[1], ol[0]
            else:
                el[0], el[1] = el[1], el[0]
        else:  # len(ol) == 1
            # 長さが 1 の時はダミーを挿入する
            el.append((0, 0))
            el[0], el[1] = el[1], el[0]

    return sum(v for _, v in ol[1:]) + sum(v for _, v in el[1:])


if __name__ == "__main__":
    n = int(input())
    v = map(int, input().split())
    ans = dekoboko(n, v)
    print(ans)


Measured memory_bytes: 21044
#include <iostream>
using namespace std;
int main(void){
    int X,Y;
    cin>>X>>Y;
    if((4*X-Y)>=0 && (4*X-Y)%2==0 && X>=(4*X-Y)/2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3644
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans,temp,curr,m;
    int tc;
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;



int main(){
	int n;
	cin>>n;
	vector <string> s,d,rs;
	pan(i,n) {
	    string dum;
	    cin>>dum;
	    s.push_back(dum);
		d.pb(dum);
	}
	//cout<<d.size();
	sort(d.begin(),d.end());
	//pan(i,n) cout<<d[i]<<endl;
	string ds=d[0];
	rs.pb(ds);
	vi arr;
	int freq=1;
	for(int i=1;i<n;i++){
		if(d[i]!=ds){
			//rs.pb(ds);
			ds=d[i];
			//cout<<ds<<endl;
			rs.pb(ds);
			arr.pb(freq);
			freq=1;
		}
		else if(ds==d[i]){
			freq++;
		}
	}
	arr.pb(freq);
	//pan(i,n) cout<<arr[i]<<endl;
	vector <string> a;
	int me=arr[0];
	pan(i,arr.size()) me=max(me,arr[i]);
	//cout<<rs.size();
	for(int i=0;i<rs.size();i++){
		if(arr[i]==me){
		    //cout<<rs[i]<<"--";
			a.pb(rs[i]);
		}
	}
	sort(a.begin(),a.end());
	pan(i,a.size()) cout<<a[i]<<endl;
}

Measured memory_bytes: 21984
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

bool is_loop(ll now, vector<vector<ll>>& graph, vector<ll>& state) {
    state[now] = 1;
    for (ll to : graph[now]) {
        if (state[to] == 1) {
            return true;
        }
        if (state[to] == 2) {
            continue;
        }
        if (is_loop(to, graph, state)) {
            return true;
        }
    }
    state[now] = 2;
    return false;
}

int main() {
    ll N, M;
    cin >> N >> M;
    string s;
    cin >> s;
    vector<vector<ll>> graph(2 * N);
    rep(i,0,M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if (s[a] == s[b]) {
            graph[2*a+0].push_back(2*b+1);
            graph[2*b+0].push_back(2*a+1);
        } else {
            graph[2*a+1].push_back(2*b+0);
            graph[2*b+1].push_back(2*a+0);
        }
    }
    vector<ll> state(2 * N);
    rep(i,0,2*N) {
        if (state[i] == 2) {
            continue;
        }
        if (is_loop(i, graph, state)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 28096
//NEERC Western Subregional 2014 - Problem D
#include<stdio.h>
#include<vector>
#include<utility>
using namespace std;
int n,len;
vector<int> e[111111];
vector<pair<int,int> > res;
int vert[111111];
void construct(){
	int minlen = (len+1)/2;
	int prev = -1;
	for(int i=len; i>=minlen; i--){
		if(e[i].empty()){
			res.clear();
			return;
		}
		int y = e[i].back();
		vert[i]=y;
		e[i].pop_back();
		if(prev!=-1)res.push_back(make_pair(prev,y));
		prev = y;
	}
	for(int i=len%2?minlen:minlen+1; i<=len; i++){
		if(e[i].empty()){
			res.clear();
			return;
		}
		int y = e[i].back();
		e[i].pop_back();
		res.push_back(make_pair(prev,y));
		prev = y;
	}
	for(int i=1; i <= minlen; i++)
		if(!e[i].empty()){
			res.clear();
			return;
		}
	for(int i=minlen+1; i<=len; i++)
		for(int j=0; j<e[i].size(); j++)
			res.push_back(make_pair(e[i][j],vert[i-1]));
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		int x;
		scanf("%d",&x);
		e[x].push_back(i);
		if(x > len)len=x;
	}
	construct();
	if(res.empty())puts("Impossible");else{
		puts("Possible");
	}
	return 0;
}

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

int main(){
	int n, count = 0;
	string s;
	cin >> n >> s;
	rep(i, n){
		if(i != 0 && s[i] == s[i-1])count++;
	}
	cout << n - count << endl;
	
	return 0;
	
}

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

int main(){
	string str, key="hijklmnopyu";
	while(1){
		str.clear();
		cin>>str;
		int ans=0;
		if(str=="#") break;
		
		bool f,s;
		f = (key.find(str[0]) != -1);
		
		for(int i=1;i<str.size();i++){
			s=(key.find(str[i])!=-1);
			if(f^s)ans++;
			f=s;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1188
a = input()
b = input()
A = "GREATER"
B = "LESS"
AB = "EQUAL"

if len(a)>len(b):
  print(A)
elif len(a)<len(b):
  print(B)
elif a == b:
  print(AB)
else:
  list=[a,b]
  list.sort()
  if list[1] == a:
    print(A)
  else:
    print(B)

Measured memory_bytes: 3060
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    A,B,C,K = map(int,input().split())

    a = K if A>=K else A
    b = (K-a) if B>=(K-a) else B
    c = K-a-b if C>=(K-a-b) else C
    print(a-c)


main()


Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

struct T {
    ll x, y, z;
};

bool comb_xy (const T& l, const T& r) {
    return l.x-l.y > r.x-r.y;
}

ll X, Y, Z;
ll n;
ll sl[100000], sr[100000];
T t[100000];

int main() {
    cin >> X >> Y >> Z;
    n = X + Y + Z;
    rep(i,n) cin >> t[i].x >> t[i].y >> t[i].z;
    sort(t, t+n, comb_xy);

    {
        priority_queue<pl, vector<pl>, greater<pl>> que;
        ll sx = 0, sz = 0;
        rep(i,n) {
            que.push(pl(t[i].x-t[i].z, i));
            sx += t[i].x;
            if (que.size() > X) {
                pl p = que.top(); que.pop();
                sx -= t[p.second].x;
                sz += t[p.second].z;
            }
            sl[i] = sx + sz;
        }
    }
    {
        priority_queue<pl, vector<pl>, greater<pl>> que;
        ll sy = 0, sz = 0;
        for (int i = n-1; i >= 0; i--) {
            que.push(pl(t[i].y-t[i].z, i));
            sy += t[i].y;
            if (que.size() > Y) {
                pl p = que.top(); que.pop();
                sy -= t[p.second].y;
                sz += t[p.second].z;
            }
            sr[i] = sy + sz;
        }
    }
    ll ans = 0;
    for (int i = X-1; i < n-Y; i++) {
        ans = max(ans, sl[i] + sr[i+1]);
    }
    cout << ans << endl;
}

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

#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))

using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;

int main(){
string order;
string save;
int m;
int h;
while(1){
cin>>order;
if(order=="-")break;
cin>>m;
REP(i,m){
    cin>>h;
    save=order.substr(0,h);
    order.erase(0,h);
    order=order+save;
}
cout<<order<<endl;
}
}


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

int main() {
    int N; cin >> N;
    bool ok = false;
    while(N > 0) {
        if(N % 10 == 7) ok = true;
        N /= 10;
    }
    cout << (ok ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 3596
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {
    def main(args: Array[String]): Unit = { 
        @tailrec
        def digit(n: Int): Unit = {
           println(n.toString.length)
           val next: String = readLine
           if(next == null) Unit else digit(next.split(" ").map(_.toInt).sum)
        }
        digit(readLine.split(" ").map(_.toInt).sum)
    }   
}

Measured memory_bytes: 43812
#include <iostream>
using namespace std;
int main() {
	int K; int S; cin >> K >> S;
	int cnt = 0;
	for (int x = 0; x <= K; x++) {
		for (int y = x; y <= K; y++) {
			for (int z = y; z <= K; z++) {
				if (x + y + z != S) continue;

				if (x != y && y != z && z != x) {
					cnt += 6; continue;
				}
				if (x == y && y == z && z == x) {
					cnt++; continue;
				}
				cnt += 3;

			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll solve(ll a,ll b){
    ll k=1;
    while(b>=k*2)k*=2;
    ll t=1;
    while(t<=b-k)t*=2;
    if(a>k)return solve(a-k,b-k);
    if(a==k)return t;
    ll ans=t+k-a;
    ans+=min(k-a,k-t);
    return ans;
}
int main(){
    ll a,b;cin>>a>>b;
    out(solve(a,b));
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define il inline
#define ri register
using namespace std;
int main(){
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	int n,d1,d2;
	scanf("%d%d%d",&n,&d1,&d2);
	int a[4]{},n1(n<<1),b1(0),b2(0);
	for(int i(d1);~i&1;++b1,i>>=1);
	for(int i(d2);~i&1;++b2,i>>=1);
	for(int i(0),j;i<n1;++i)
		for(j=0;j<n1;++j)
			++a[(b1&1?i:j-i)>>(b1>>1)&1|((b2&1?i:j-i)>>(b2>>1)&1)<<1];
	int b3(0);
	for(int i(0);i<4;++i)if(a[b3]<a[i])b3=i;
	for(int i(0),j,i1(0);i<n1;++i)
		for(j=0;j<n1;++j)
			if(((b1&1?i:j-i)>>(b1>>1)&1|((b2&1?i:j-i)>>(b2>>1)&1)<<1)==b3){
				printf("%d %d\n",i,j);
				if(++i1==n*n)return 0;
			}
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

#define lint long long
#define MAX 100'000
int main() {
	
	string S, T; cin >> S >> T;
	vector<int> St(26, -1);
	vector<int> Go(26, -1);
	for (int i = 0; i < S.size(); i++)
	{
		int a = S[i] - 'a';
		int b = T[i] - 'a';
		if ((St[a] != -1 || Go[b] != -1) && (St[a] != b || Go[b] != a)) {
			cout << "No" << endl;
			return 0;
		}

		St[a] = b;
		Go[b] = a;

	}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e5 + 5;

char s[N],t[N];
int n,m,q,a[N],b[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> (s + 1) >> (t + 1);
  n = strlen(s + 1);
  m = strlen(t + 1);
  for (int i = 1 ; i <= n ; i++) {
    a[i] = a[i - 1];
    if (s[i] == 'A')
      a[i]++;
    else
      a[i]--;
  }
  for (int i = 1 ; i <= m ; i++) {
    b[i] = b[i - 1];
    if (t[i] == 'A')
      b[i]++;
    else
      b[i]--;
  }
  cin >> q;
  while(q--) {
    int la,lb,ra,rb;
    cin >> la >> ra >> lb >> rb;
    if (((a[ra] - a[la - 1]) % 3 + 3) % 3 == ((b[rb] - b[lb - 1]) % 3 + 3) % 3)
      cout << "YES\n";
    else
      cout << "NO\n";
  }

}

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

typedef long long ll;

int main() {        
	string s1;
	string s2;
	cin >> s1 >> s2;
	int cnt = 0;
	for (int i = 0; i < (int)s1.size(); ++i) {
		if (s1[i] != s2[i]) {
			cnt++;
		}
	}
	cout << cnt;
}








Measured memory_bytes: 3852
#include<iostream>
#include<vector>
#include<string>
#include <cmath>
using namespace std;

int main()
{
	int n,res;
	int ans[7];
	cin >> n;
	for( int i = 0; i < 7; i++ )
	{
		ans[i] = pow(2,i);
	}

	for( int i = 0; i < 7; i++ )
	{
		if( n > ans[i] )
		{
			res = ans[i];
		}else if( n == ans[i] )
		{
			res = ans[i];
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 100000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (b <= a) {
        b *= 2;
        k--;
    }
    while (c <= b) {
        c *= 2;
        k--;
    }
    cout << (k >= 0 ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
const int nax=3005;
long long int dp[nax][nax];

int main(){

	int n;
	scanf("%d", &n);
	vector<int> a(n);

	for(int &x:a)
		scanf("%d", &x);
	
	
	for(int L=n-1;L>=0;--L)
	{
		for(int R=L;R<n;++R)
		{
			if(L==R)
				dp[L][R]=a[L];
			else
			dp[L][R]=max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]);
		}
	}

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

	return 0;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
#define pb push_back
#define long long long
#define pll pair < long , long >
#define vll vector < pll >
#define ml map < long , long >
#define mll map < pll , long >
#define x first
#define y second
#define vl vector < long >
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    io
    string a,b,ans;
    cin>>a>>b;
    long i,j,n=a.length(),m=b.length();
    for(i=0;i<=n-m;++i)
    {
        string cur=a;
        for(j=i;j<i+m;++j)
        if(a[j]!=b[j-i] && a[j]!='?') break;
        else cur[j]=b[j-i];
        if(j==i+m)
        {
            for(j=0;j<n;++j)
            if(cur[j]=='?') cur[j]='a';
            if(ans.size()==n)
            ans=min(ans,cur);
            else ans=cur;
        }
    }
    if(ans.size())
    cout<<ans;
    else cout<<"UNRESTORABLE";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A =list(map(int,input().split())) 

cnt=0
okFlg = True

while True:
    
    for i in range(N):
        
        if A[i]%2==0:
            A[i] = A[i]/2
        else:
            okFlg = False
            break
            
    if okFlg == True:
        cnt +=1
    else:
        break
    
print(cnt)

Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int64_t read_int() {
    int64_t ret = 0, sgn = 1;
    int ch = getchar_unlocked();
    while (isspace(ch)) { ch = getchar_unlocked(); }
    if (ch == '-') { sgn = -1; ch = getchar_unlocked(); }
    for (; isdigit(ch); ch = getchar_unlocked())
        ret = (ret * 10) + (ch - '0');
    ungetc(ch, stdin);
    return sgn * ret;
}

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()

template <typename T> inline void assign_min(T& x, const T& value) noexcept { x = min(x, value); }
template <typename T> inline void assign_max(T& x, const T& value) noexcept { x = max(x, value); }

constexpr char LF = '\n';

//-------------------------------------------------------------------------------------------------

template <class Func>
struct Fix {
    Func f;
    template <class... Args>
    decltype(auto) operator()(Args&&... args) const {
        return f(*this, forward<Args>(args)...);
    }
};
template <class Func>
Fix<std::decay_t<Func>> fix(Func&& f) {
    return {forward<Func>(f)};
}

int main() {
    int N = read_int();
    int M = read_int();
    vector<vector<int>> graph(N);
    REP(i, M) {
        int a = read_int() - 1;
        int b = read_int() - 1;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    vector<bool> visited(N);
    auto dfs = fix([&](auto&& self, int v) -> void {
        if (visited[v]) return;
        visited[v] = true;
        for(auto dst : graph[v]) {
            self(dst);
        }
    });

    int cc = 0;
    REP(i, N) {
        if (!visited[i]) {
            dfs(i);
            ++cc;
        }
    }
    cout << cc-1 << endl;
}


Measured memory_bytes: 9096
n = list(map(int, input().split()))
a = n[0]
b = n[1]

if a < b:
  min = a
else:
  min = b
  
c = []
i = 2
while i <= min:
  if a % i == 0 and b % i == 0:
    a //= i
    b //= i
    min //= i
    c += [i]
  else:
    i += 1
    

n = 1
for i in range(len(c)):
  n *= c[i]

l = n * a * b

print(l)

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

VI g[100010];
int d[100010];
int dfs(int x, int p) {
  int leaf = 0, ret= 0;
  for(int i: g[x]) {
    if(i == p) continue;
    if(g[i].size() == 1) {leaf++; continue;}
    int tmp = dfs(i, x);
    if(tmp == 0) leaf++;
    ret += tmp;
  }
  ret += max(0LL, leaf - 1);
  // cout << x << " " << ret << endl;
  return ret;
}

signed main(void)
{
  int n;
  cin >> n;
  REP(i, n-1) {
    int a, b;
    cin >> a >> b;
    g[a].PB(b);
    g[b].PB(a);
  }

  int root = -1, ma = -1;
  REP(i, n) {
    if((int)g[i].size() > ma) ma = (int)g[i].size(), root = i;
  }
  cout << max(1LL, dfs(root, -1)) << endl;

  return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

int modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) 
      return 0; 
    while (a > 1) 
    { 
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
    return x; 
} 


int main() {
	int n;
	cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];

	}
	reverse(a.begin(),a.end());
	vector<ll> d(n,mod);
	for(int i=0;i<n;i++)
	{
		int u=upper_bound(d.begin(),d.end(),a[i])-d.begin();
		d[u]=a[i];
	}
	ll ans=-1;
	for(int i=0;i<n;i++)
	{
		if(d[i]==mod)
		{
			ans=i;
			break;
		}
	}
	if(ans==-1)
		ans=n;
	cout<<ans;

	
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = (ll)1e16;

int main(void){
    int N; 
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    vector<ll> color(N, INF);
    for(int i = N-1; i >= 0; i--){
        *upper_bound(color.begin(), color.end(), A[i]) = A[i];
    }

    cout << lower_bound(color.begin(), color.end(), INF) - color.begin() << '\n';

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>

int R,C;	// (1 <= R <= 10, 1 <= C <= 10 000)
const int MAX_ROW = 10;
const int MAX_COL = 10000;
bool is_flipped[MAX_ROW + 1][MAX_COL + 1];

void flip(int row)
{
	for(int c=0;c<C;c++)
		is_flipped[row][c] = !is_flipped[row][c];
}
int solve()
{
	int min_score = R*C;
	for(int i=0;i<1<<R;i++)
	{
		for(int r=0;r<R;r++)
			if((i>>r)&1) flip(r);
		int score = 0;
		for(int c=0;c<C;c++)
		{
			int column_sum = 0;
			for(int r=0;r<R;r++)
				if(is_flipped[r][c]) column_sum++;
			score += std::min(column_sum, R-column_sum);
		}
		min_score = std::min(min_score,score);
		for(int r=0;r<R;r++)
			if((i>>r)&1) flip(r);
	}
	return R*C-min_score;
}

int main()
{
	scanf("%d %d", &R, &C);
	int input;
	while(C!=0 || R!=0)
	{
        for (int r = 0; r < R; r++)
            for (int c = 0; c < C; c++)
			{
                scanf("%d", &input);
				is_flipped[r][c] = input==1;
			}
        printf("%d\n", solve());
        scanf("%d %d", &R, &C);
    }
	return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
int n,r1,r2,id[200005],ans[100005];
vector<int> e1[100005],e2[100005],ee[200005];
set<pair<int,int> > vis;
pair<int,int> mk(int x,int y)
{
	return make_pair(min(x,y),max(x,y));
}
void dfs(int x)
{
	while(id[x]<ee[x].size())
	{
		int y=ee[x][id[x]++];
		if(vis.count(mk(x,y))) continue;
		vis.insert(mk(x,y));
		dfs(y);
//		cerr<<x<<' '<<y<<endl;
		if(1<=x&&x<=n&&y==x+n){
			ans[x]=1;
		}
		if(1<=y&&y<=n&&x==y+n){
			ans[y]=-1;
		}
	}
}
int main()
{
	int i,j;
	scanf("%d",&n);
	rep(i,n){int x;scanf("%d",&x);if(x==-1) r1=i; else e1[x].push_back(i);}
	rep(i,n){int x;scanf("%d",&x);if(x==-1) r2=i; else e2[x].push_back(i);}
	rep(i,n) if(e1[i].size()%2!=e2[i].size()%2)
	{
		puts("IMPOSSIBLE");
		return 0;
	}
	ee[n+n+1].push_back(r1);ee[r1].push_back(n+n+1);
	ee[n+n+1].push_back(r2+n);ee[r2+n].push_back(n+n+1);
	rep(i,n) if(e1[i].size()%2==0)
	{
		ee[i].push_back(i+n);
		ee[i+n].push_back(i);
	}
	rep(i,n)
	{
		for(j=0;j<e1[i].size();j++)
		{
			ee[i].push_back(e1[i][j]);
			ee[e1[i][j]].push_back(i);
		}
		for(j=0;j<e2[i].size();j++)
		{
			ee[i+n].push_back(e2[i][j]+n);
			ee[e2[i][j]+n].push_back(i+n);
		}
	}
	rep(i,n+n+1) id[i]=0;
	rep(i,n+n+1) if(ee[i].size()&1) exit(i);
	dfs(n+n+1);//cerr<<n+n+1<<endl;
	puts("POSSIBLE");
	rep(i,n) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 56312
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007

int main() {
  int n, m;
  cin >> n >> m;
  if (n == m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    REP(i, N) { cin >> A[i] >> B[i]; }

    vector<vector<long long>> dp(N + 1, vector<long long>(H + 1, iINF));
    dp[0][0] = 0;
    REP(i, N) {
        REP(j, H + 1) {
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][min(j + A[i], H)], dp[i + 1][j] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
    return 0;
}

Measured memory_bytes: 78592