akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;
template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	ll L, R;
	cin >> L >> R;

	ll ans = MAX<ll>;
	if ( R - L >= 2019 )
		ans = 0;
	else
	{
		for ( ll i = L; i < R; ++i )
		{
			for ( ll j = i + 1; j <= R; ++j )
			{
				chmin( ans, ( i * j ) % 2019 );
			}
		}
	}

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=188;

int n,m;
int a[N][N],s[N][N];
int dw[N][N][N],rt[N][N][N];
int ndw[N][N][N],nrt[N][N][N];

int chk(int x,int y,int u,int v){
    int tmp=s[u][v]-s[x-1][v]-s[u][y-1]+s[x-1][y-1];
    return !tmp || tmp==(u-x+1)*(v-y+1);
}

void mx(int &a,int b){
    a=max(a,b);
}

main(){
    #define task "agc033_d"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    fasty;

    cin>>m>>n;
    forinc(i,1,m){
        forinc(j,1,n){
            char ch; cin>>ch;
            a[i][j]=ch=='#';
            s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
        }
    }
    forinc(i,1,m){
        forinc(j,i,m) forinc(t,1,n){
            int le=t,mi,ri=n;
            while(le<=ri){
                mi=(le+ri)/2;
                if(chk(i,t,j,mi)) rt[i][j][t]=nrt[i][j][t]=mi,le=mi+1;
                else ri=mi-1;
            }
        }
        forinc(j,1,n) forinc(t,j,n){
            int le=i,mi,ri=m;
            while(le<=ri){
                mi=(le+ri)/2;
                if(chk(i,j,mi,t)) dw[i][j][t]=ndw[i][j][t]=mi,le=mi+1;
                else ri=mi-1;
            }
        }
    }
    int worst=log2(m) + log2(n) + 2;
    forinc(col,1,worst){
        if(rt[1][m][1]==n) return cout<<col-1,0;
        forinc(i,1,m) forinc(j,1,n){
            forinc(t,i,m){
                mx(nrt[i][t][j],rt[i][t][rt[i][t][j]+1]);
                mx(nrt[i][dw[t+1][j][rt[i][t][j]]][j],rt[i][t][j]);
            }
            forinc(t,j,n){
                mx(ndw[i][j][t],dw[dw[i][j][t]+1][j][t]);
                mx(ndw[i][j][rt[i][dw[i][j][t]][t+1]],dw[i][j][t]);
            }
        }
        forinc(i,1,m) forinc(j,1,n){
            forinc(t,i,m){
                rt[i][t][j]=nrt[i][t][j];
            }
            forinc(t,j,n){
                dw[i][j][t]=ndw[i][j][t];
            }
        }
        forinc(i,1,m) forinc(j,1,n){
            fordec(t,m,i) mx(rt[i][t][j],rt[i][t+1][j]);
            fordec(t,n,j) mx(dw[i][j][t],dw[i][j][t+1]);
        }
        forinc(i,1,m) forinc(j,1,n){
            fordec(t,m,i) mx(dw[i][j][rt[i][t][j]],t);
            fordec(t,n,i) mx(rt[i][dw[i][j][t]][j],t);
        }
    }
}
/**
3 3
..#
.##
..#

*/


Measured memory_bytes: 104064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for (int i = 0; i < M; i++) {cin >> a.at(i) >> b.at(i);}
  for (int i = 0; i < N; i++) {
    int O = 0;
    for (int j = 0; j < M; j++) {
      if (a.at(j) == i + 1) {O++;}
      if (b.at(j) == i + 1) {O++;}
    }
    cout << O << endl;
  }
}

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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
	if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
	if(H==T) return -1;return *H++;
}
inline int read()
{
	int x=0;char c=Get();
	while(!isdigit(c)) c=Get();
	while(isdigit(c)) x=x*10+c-'0',c=Get();
	return x;
}

const int N=100010;
struct Edge{int to,next;} e[N<<1];
int h[N],n,K,sum=0;
int fa[N],deg[N],dep[N];
int c[N],id[N];
bool done[N];

void add_edge(int u,int v)
{
	e[++sum].to=v;
	e[sum].next=h[u];
	h[u]=sum;
}

void dfs(int u)
{
	if(done[u]) return;
	for(int t=h[u];t;t=e[t].next)
	{
		dep[e[t].to]=dep[u]+1;
		dfs(e[t].to);
	}
}

int main()
{
	//freopen("B.in","r",stdin);
	n=read();K=read();
	for(int i=1;i<=n;i++) fa[i]=read();
	for(int i=2;i<=n;i++)
	{
		add_edge(fa[i],i);
		deg[fa[i]]++;
	}
	dfs(1);
	for(int i=1;i<=n;i++) c[dep[i]]++;
	for(int i=1;i<=n;i++) c[i]+=c[i-1];
	for(int i=1;i<=n;i++) id[c[dep[i]]--]=i;
	reverse(id+1,id+1+n);
	int ans=(fa[1]!=1);
	for(int i=1;i<=n;i++)
	{
		int x=id[i];
		if(deg[x]==0&&dep[x]>K)
		{
			int u=x;
			for(int j=1;j<K;j++) u=fa[u];
			ans++;dep[u]=1;dfs(u);
			deg[fa[u]]--;
			done[u]=1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    int64_t n, k;
    cin >> n >> k;

    int64_t answer;

    if (k % 2) {
        answer = (n / k) * (n / k) * (n / k);
    } else {
        answer = (n / k) * (n / k) * (n / k);
        int64_t temp;
        if (n % k >= k / 2) {
            temp = n / k + 1;
        } else {
            temp = n / k;
        }
        answer += temp * temp * temp;
    }
    cout << answer << endl;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(vr) vr.begin(),vr.end()

typedef long long ll;
namespace myrand
{
    mt19937 mt(chrono::system_clock::now().time_since_epoch() / chrono::microseconds(1));
    ll Int(ll l,ll r) { return uniform_int_distribution<ll> (l,r)(mt); }
}
using namespace myrand;
auto ss=chrono::system_clock::now();
double remain_time()
{
    auto en=chrono::system_clock::now();
    return (chrono::duration_cast<chrono::nanoseconds>(en-ss).count()*1e-9);
}
ll a,b,k;
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   cin >> a >> b >> k;
   cout << max(ll(0),a-k);
   if (a<=k) cout << " " << max(ll(0),b-abs(a-k)); else cout << " " << b;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXD=105;
const int MAXA=1005;
const int MAXB=10005;
const int MAXC=1000005;
const int Maxx=0x7fffffff/2;
const int Minn=-0x7fffffff/2;
const int Maxn=0x3f3f3f3f;
const int Minm=-0x3f3f3f3f;
inline void read(int &oi){
	char ch;int f=1,res=0;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	ch=='-'?f=-1:res=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')res=(res<<1)+(res<<3)+ch-'0';
	oi=res*f;
}
int maxxx(int x,int y){return x>y?x:y;}
int minnn(int x,int y){return x<y?x:y;}
int k;ll ans;
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int th_gcd(int a,int b,int c){return gcd(a,gcd(b,c));}
int main(){
	read(k);
	for(int a=1;a<=k;a++){
		for(int b=a;b<=k;b++){
			for(int c=b;c<=k;c++){
				int x=0;
				if(a==b&&b==c)x=1;
				else if(a==b||b==c||a==c)x=3;
				else x=6;
				ans+=th_gcd(a,b,c)*x;
			}
		}
	}
	printf("%lld",ans);
	puts("");
	return 0;
}

Measured memory_bytes: 3744
N = int(input())
A = tuple(map(int, input().split()))
qut = 0
odd = 0
for a in A:
  if a % 2 !=0:
    odd += 1
  elif a % 4 == 0:
    qut += 1
if odd <= qut or (N == odd + qut and odd <= qut + 1):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 19980
#include <iostream>
using namespace std;
int a[55], N, sum;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
        cin>>a[i];
    for(int i=1;i<N;i++)
        for(int j=i+1;j<=N;j++)
            sum+=a[i]*a[j];
    cout<<sum;
    return 0;
}

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

using namespace std;

const long long mod = 1000000007;
    
int main()
{
    long n;
    cin >> n;
    vector<long long> x(n+1);
    for(size_t i=1; i<x.size(); i++)
        cin >> x[i];

    auto solver = [&](){
        long long sum=0;
        long long t=0;
        for(long i=n-1; i>0; i--){
            t = (t + x[i+1]) % mod;
            sum += (t * x[i]) % mod;
            sum %= mod;
        }
        return sum;
    };
    
    cout << solver() << endl;

    return 0;
}


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

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

    bool flag = false;
    for(int i = 1; i <= 9; ++i)
    {
        for(int j = 1; j <= 9; ++j)
        {
            if(i * j == n)
            {
                flag = true;
                break;
            }
        }
        if(flag)
        {
            break;
        }
    }
    if(flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;

long long L, R;

int main(){
	long long ans = 2018;
	cin >> L >> R;
	for(long long i = L; i <= min(R, L+2019); ++i){
		for(long long j = i+1; j <= min(R, L+2019); ++j){
			ans = min(ans, (i%2019)*(j%2019)%2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> a(n+1), b(n);
    REP(i, n+1) cin >> a[i];
    REP(i, n) cin >> b[i];

    ll ans = 0;
    REP(i, n) {
        ll bt = min(a[i], b[i]);
        a[i] -= bt;
        b[i] -= bt;
        ans += bt;
        if (b[i] > 0) {
            ll bt2 = min(a[i+1], b[i]);
            a[i+1] -= bt2;
            ans += bt2;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
    if((a+b)%2==0){
        cout << (a+b)/2 << "\n";
    }else{
        cout << (a+b)/2+1 << "\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;

ll MOD=1000000007;



int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]
    ;}
    vector<vector<ll>> B(N, vector<ll>(61, 0));
    for(ll i=0;i<N;i++){
     for(ll j=1;j<61;j++){
         if(A[i]&(1LL<<j-1))B[i][j]++
     ;}
    ;}
    ll ans=0;
    ll sum=0;
    ll memo=0;
    for(ll i=1;i<61;i++){
        sum=0;memo=0;
        if(B[0][i]){memo++;}
        for(ll j=1;j<N;j++){
            if(B[j][i]){sum+=j-memo;memo++;}
            else{sum+=memo;}
            sum%=MOD;memo%=MOD;
        ;}
        
        for(int j=0;j<i-1;j++){
            sum=(sum*2)%MOD
        ;}
        ans+=sum;
        ans%=MOD;
    ;}
    cout<<ans%MOD<<endl;

return 0;
}  



Measured memory_bytes: 154880
#include<bits/stdc++.h>
using namespace std;
using li = long int;
#define pb push_back

li A, B, GCD, d, i, j;
vector<int> p_factor;

li gcd(li a, li b){
    li x = max(a, b), y = min(a, b);
    if(x % y == 0) return y;
    return gcd(y, x % y);
}

int main(){
    cin >> A >> B;

    p_factor.pb(1);  //確定約数
    GCD = gcd(A, B);
    li d = GCD;
    for(i = 2; i * i <= GCD; i++){
        if(d == 1) break;
        j = 0;
        while(d % i == 0){ d /= i; ++j; }
        if(j > 0) p_factor.pb(i);
    }
  	if(d > 1) p_factor.pb(d);

    cout << (int)(p_factor.size()) << endl;
    return 0;

}

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

#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;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)

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

int main(void) {
    int n, m;
    map<string, int> mp;
    string s;
    cin >> n;
    while(n--){
        cin >> s;
        if(mp.find(s)==mp.end()){
            mp.insert(map<string, int>::value_type(s, 1));
        }else{
            mp[s] += 1;
        }
    }

    cin >> m;
    while(m--){
        cin >> s;
        if(mp.find(s)!=mp.end()){
            mp[s] -= 1;
        }
    }
    int mx = 0;
    for(auto i: mp){
        if(mx<i.second){
            mx = i.second;
        }
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mods 1000000007
#define fint register int
#define int long long
using namespace std;
int s,ans;
int a[200003];
signed main()
{
	int n;
    cin>>n;
    for(int i=1;i<=n;i++) 
	cin>>a[i];
    sort(a+1,a+1+n);
    for(fint i=2;i<=n;i++)
    s=(s+a[i-1])%mods,ans=(ans+s*a[i])%mods;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5180
import java.util.Scanner;
public class Main {
	
	public static void main(String arg[]){
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		int[] input = new int[n];
		
		for(int i=0; i < n; i++){
			input[i] = in.nextInt();
		}	
		
		System.out.print(input[0]);
		for(int i=1; i < input.length; i++){
			System.out.print(" " + input[i]);
		}
		System.out.println();
		
		for(int i=1; i < input.length; i++){
			int key = input[i];
			int j = i-1;
			while(j >=0 && input[j] > key){
				input[j+1] = input[j];
				j--;
			}
			input[j+1] = key;
			System.out.print(input[0]);
			for(int k=1; k < input.length; k++){
				System.out.print(" " + input[k]);
			}
			System.out.println();
		}
	}
}

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

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

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

#define INF 1e16
#define mod 1000000007

ll fac[200010],finv[200010];

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll N,X,Y;
ll c[200010],w[200010];
ll cnt[200010];
vector<P> ps[200010];

int main(){
  fac[0]=1;
  rep(i,200000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,200001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>N>>X>>Y;
  rep(i,N){
    cin>>c[i]>>w[i];
    c[i]--;
  }
  rep(i,N){
    ps[c[i]].push_back(P(w[i],i));
  }
  rep(i,N){
    if(ps[i].size()==0)continue;
    sort(all(ps[i]));
    ll mn=ps[i][0].fi;
    repl(j,1,ps[i].size()){
      if(ps[i][j].fi<=X-mn)w[ps[i][j].se]=mn;
    }
  }
  ll mnidx=0;
  rep(i,N){
    if(w[mnidx]>w[i])mnidx=i;
  }
  ll mn2=INF;
  rep(i,N){
    if(c[i]==c[mnidx])continue;
    minch(mn2,w[i]);
  }
  if(w[mnidx]+mn2>Y){
    cout<<1<<endl;
    return 0;
  }

  ll sum=0;
  rep(i,N){
    if(c[i]==c[mnidx]){
      if(w[i]<=Y-mn2){
        cnt[c[i]]++;
        sum++;
      }
    }else{
      if(w[i]<=Y-w[mnidx]){
        cnt[c[i]]++;
        sum++;
      }
    }
  }
  ll res=fac[sum];
  rep(i,N)(res*=finv[cnt[i]])%=mod;
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 18944
n = input()

data = {
    'S':[0 for x in range(13)],
    'H':[0 for x in range(13)],
    'C':[0 for x in range(13)],
    'D':[0 for x in range(13)]
}

for i in range(n):
    s,num = raw_input().split()
    data[s][int(num)-1] = 1

for a in['S','H','C','D']:
    for b in range(13):
        if data[a][b] == 0:
            print('{0} {1}'.format(a,b+1))

Measured memory_bytes: 6248
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>
#include<stack>
#include<vector>

using namespace std;

int X[100009];
int costs[100009];

int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		cin >> X[i];
	}

	sort(begin(X), begin(X) + M);

	for (int i = 0; i < M - 1; i++)
	{
		costs[i] = X[i + 1] - X[i];
	}

	sort(begin(costs), begin(costs) + M - 1);

	int r = 0;
	for (int i = 0; i < M - N; i++)
	{
		r += costs[i];
	}

	cout << r << endl;

	return 0;
}


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

long long n,a[100];

int main(){
   cin>>n;
   a[0]=2;
   a[1]=1;
   for(int i=2;i<=n;i++) {
    a[i]+=(a[i-1]+a[i-2]);
   }
   cout<<a[n];


    return 0;
}


Measured memory_bytes: 3596
s = input()
n = len(s)
r = l = 0
point = -1

flag = 0
ans = [0] * n


for i in range(n):
    if (s[i] == 'R' and s[i + 1] == 'L'):
        r += 1
        point = i
        ans[point] += (r+1) // 2
        ans[point + 1] += (r) // 2
        r = l = 0
    elif s[i] == 'L' and (i == n-1 or s[i + 1] == 'R'):
        l += 1
        ans[point+1] += (l+1) // 2
        ans[point] += (l ) // 2
        l = r = 0
    elif s[i] == 'R':
        r += 1
        l = 0
    elif s[i] == 'L':
        l += 1
        r = 0

print(' '.join(map(str, ans)))


Measured memory_bytes: 84900
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1; i<=sqrt(n-1); i++)
    {
        if((n-1)%i==0)
        {
            if((n-1)/i!=i)
            ans++;
            ans++;
        }
    }
    ans--;
    for(ll i=1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll temp=n;
            if(n/i!=i)
            {
                while(i!=1)
                {
                    if(temp%i==0)
                    temp/=i;
                    else break;
                }
                if(temp==1||temp%i==1)
                ans++;
                temp=n;
                while(1)
                {
                    if(temp%(n/i)==0)
                    temp/=(n/i);
                    else break;
                }
                if(temp==1||temp%i==1)
                ans++;
            }
            else
            {
                while(i!=1)
                {
                    if(temp%i==0)
                    temp/=i;
                    else break;
                }
                if(temp==1)
                ans++;
            }
        }
    }
    cout<<ans;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}


Measured memory_bytes: 3616
#include<stdio.h>
#define MAX 100
#define LARGE 10000
int prim(void);

int n, G[MAX][MAX];
 int main(){
     
    int i, j, u;
     
    scanf("%d", &n);
     
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
             scanf("%d", &u);
            if(u == -1) G[i][j] = LARGE;
            else G[i][j] = u;
        }
    }
 
    printf("%d\n", prim());
     
    return 0;
     
}
int prim(){
     
    int u, m, d[MAX], p[MAX], c[MAX], i, v, sum = 0;
     
    for(i = 0; i < n; i++){
        d[i] = LARGE;
        p[i] = -1;
        c[i] = 0;
    }
     
    d[0] = 0;
     
    while(1){
        m = LARGE;
        u = -1;
        for(i = 0; i < n; i++){
            if(m > d[i] && c[i] != 2){
                u = i;
                m = d[i];
            }
        }
        if(u == -1) break;
        c[u] = 2;
        for(v = 0; v < n; v++){
            if(c[v] != 2 && G[u][v] != LARGE){
                if(d[v] > G[u][v]){
                    d[v] = G[u][v];
                    p[v] = u;
                    c[v] = 1;
                }
            }
        }
    }
    for(i = 0; i < n; i++){
        if(p[i] != -1){
            sum += G[i][p[i]];
        }
    }
    return sum;
}

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

int main()
{
	int K, N;

	cin >> K >> N;

	for (int i = N - K + 1; i < N + K; i++)
	{
		if (i == N + K - 1)
		{
			cout << i;
			break;
		}
		cout << i << ' ';
	}
	cout << endl;

	return 0;
}

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

vector<int> edges[100001], from[100001];
int indeg[100001];

int dist[100001], par[100001];
bitset<100001> visited;

int main(){
    int N, M;
    cin >> N >> M;
    for(int i=0; i<N-1+M; i++){
        int a, b;
        cin >> a >> b;
        indeg[b]++;
        edges[a].push_back(b);
        from[b].push_back(a);
    }

    int root = -1;
    for(int i=1; i<=N; i++) if(indeg[i] == 0) root = i;
    par[root] = 0;
    dist[root] = 0;

    queue<int> que;
    que.push(root);
    while(que.size()){
        int i = que.front(); que.pop();
        for(int j : from[i]){
            if(dist[j] + 1 > dist[i]){
                par[i] = j;
                dist[i] = dist[j] + 1;
            }
        }
        for(int j : edges[i]){
            indeg[j]--;
            if(indeg[j] == 0) que.push(j);
        }    
    }
    for(int i=1; i<=N; i++) cout << par[i] << endl;
    return 0;
}

Measured memory_bytes: 12928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		output(A, N);
		insertionSort(A, N);
		sc.close();
	}

	public static void insertionSort(int[] A, int N) {
		for (int i = 1; i < N; i++) {
			int v = A[i];
			int j = i - 1;
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;
			output(A, N);
		}
	}

	public static void output(int[] A, int N) {
		for (int i = 0; i < N; i++) {
			if (i > 0) {
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.printf("\n");
	}
}



Measured memory_bytes: 34028
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
const int N = 2e5 + 10;
struct node
{
    long long all_v;
    int edges, ans_edges, max_edge;
    int fa;
}f[N];
struct edge{
    int x, y, v;
}a[N];
int n, m;
bool cmp(const edge &a, const edge &b)
{
    return a.v < b.v;
}
int getfa(int x)
{
    if (f[x].fa == x) return x;
    return f[x].fa = getfa(f[x].fa);
}
int main()
{
    scanf("%d %d", &n ,&m);
    for (int i = 1 ; i <= n; i ++)
        scanf("%lld", &f[i].all_v), f[i].fa = i;
    for (int i = 1 ; i <= m; i ++)
        scanf("%d %d %d", &a[i].x ,&a[i].y, &a[i].v);
    sort(a + 1, a + m + 1, cmp);
    for (int i = 1; i <= m ; i ++)
    {
        int fax = getfa(a[i].x);
        int fay = getfa(a[i].y);
        if (fax == fay)
        {
            f[fax].edges ++;
            f[fax].max_edge = a[i].v;
            if (f[fax].all_v >= a[i].v)
                f[fax].ans_edges = f[fax].edges;
        } else{
            f[fax].fa = fay;
            f[fay].ans_edges += f[fax].ans_edges;
            f[fay].all_v += f[fax].all_v;
            f[fay].max_edge = a[i].v;
            f[fay].edges += 1 + f[fax].edges;
            if (f[fay].all_v >= a[i].v)
                f[fay].ans_edges = f[fay].edges;
        }
    }
    printf("%d\n", m - f[getfa(1)].ans_edges);
    return 0;
}

Measured memory_bytes: 5888
S = input()
size = len(S)
ans = 0
d = [0]*2019
pre = ''
ln = 0
v = 1
  
for i in range(1,size+1):
  md = (ln +(int(S[-1*i])*v))%2019
  d[md] += 1
  ln = md
  v *= 10
  v %= 2019

d[0] += 1
for i in range(2019):
  ans += d[i]*(d[i]-1)/2 #1~(n-1)までの和

print(int(ans))

Measured memory_bytes: 9220
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  vector<pair<int, int> > L, R;
  rep(i, n) {
    string s;
    cin >> s;
    int sz = s.size();
    int oc = 0, cc = 0, cur = 0;
    rep(j, sz) {
      if(s[j] == '(') cur--;
      else cur++, chmax(cc, cur);
    }
    cur = 0;
    rep(j, sz) {
      if(s[sz-j-1] == ')') cur--;
      else cur++, chmax(oc, cur);
    }
    if(oc >= cc) L.emplace_back(make_pair(cc, oc));
    else R.emplace_back(make_pair(oc, cc));
  }
  sort(ALL(L));
  sort(ALL(R));
  reverse(ALL(R));
  int cur = 0;
  bool ok = true;
  for(const auto& a : L) {
    cur -= a.first;
    if(cur < 0) ok = false;
    cur += a.second;
  }
  for(const auto& a : R) {
    cur -= a.second;
    if(cur < 0) ok = false;
    cur += a.first;
  }
  if(ok && cur == 0) cout << "Yes\n";
  else cout << "No\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 11248
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b,c; cin>>a>>b>>c;
	int e=a*10+b+c;
	int d=a+10*b+c;
	int s=10*c+a+b;
		cout<<max({e,d,s})<<endl;
	
	return 0;
}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main(){
   int A ,B , C ;
   cin >> A >> B >> C ; 
   if ( A - B  > C ) cout << 0 << endl;
   else cout <<  C -( A - B ) << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int main(){
  int n,m;cin >> n >> m;
  vector<int> s(n),t(m);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  for(int j=0;j<m;j++){
    cin >> t[j];
  }
  vector<vector<ll>> dp(n+1,vector<ll>(m+1));
  dp[0][0]=1;
  for(int i=0;i<=n;i++){
    dp[i][0]=1;
  }
  for(int i=0;i<=m;i++){
    dp[0][i]=1;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(s[i]==t[j]){
        dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%mod;
      }
      else{
        dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]+mod)%mod;
      }
    }
  }
  cout << dp[n][m] << endl;
}

Measured memory_bytes: 31616
fun main(args: Array<String>) {
    var n = readLine()!!.toLong()

    var s = Math.floor(Math.sqrt(n.toDouble())).toLong()
    var r = 0L
    var res = mutableListOf<Pair<Long,Long>>()
    for (i in 2..s) {
        if (n%i == 0L) {
            r = 0L
            while(n%i == 0L) {
                r++
                n = n/i
            }
            res.add(i to r)
        }
    }
    if (n > s) res.add(n to 1)

    var ans = 0
    res.forEach {
        var r = it.second
        var cnt = 1
        while (r >= cnt) {
            r -= cnt
            ans++
            cnt++
        }
    }
    println(ans)
}


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

void solve(long long N, std::vector<long long> d)
{
    set<int> A;
    long long index = 0;
    for (int i = 0; i < N; i++)
    {
        index = d[i];
        A.insert(index);
    }

    //sort(A.begin(), A.end());
    cout << A.size() << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> d(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &d[i]);
    }
    solve(N, std::move(d));
    return 0;
}


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

int main() {
	// your code goes here
	long a,b,c,k;
	while(cin >> a >>b){
		k=0;
		c=a+b;
	
		while(c){
			c/=10;
			k++;
		}
	
		cout<<k<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
struct uni{
  int d[100005];
  void init(){ memset(d,-1,sizeof(d));}    
  int find(int a){ return ( d[a]<0?a:(d[a]=find(d[a])) ); }
  void merge(int a,int b){
    a = find(a); b = find(b);
    if( a == b ) return;
    if( d[a] > d[b] ) swap( a, b );
    d[a] += d[b]; d[b] = a;
  }
  int size(int a){ return -d[find(a)]; }    
};
int N,M;
vector<int> L[100005];
uni U;
int main(){
  cin >> N >> M;
  for(int i=0;i<N;i++){
    int k; cin >> k;
    for(int j=0;j<k;j++){
      int l; cin >> l; --l;
      L[l].push_back( i );
    }
  }
  U.init();
  for(int i=0;i<M;i++){
    for( int j=1;j<(int)L[i].size();j++)
      U.merge( L[i][j-1], L[i][j] );
  }
  if( U.size(0) == N ) cout << "YES" << endl;
  else cout << "NO" << endl;
}



Measured memory_bytes: 4992
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int sum = 0;
        for (int i = 0; i < str.length(); i++) {
            sum += Integer.parseInt(String.valueOf(str.charAt(i)));
        }
        
        if (Integer.parseInt(str) % sum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include<vector>
using namespace std;
int cnt=1;
void depth(vector< vector<int> > &vv,vector<int> &f,vector<int> &c,int num){
	
	f[num]=cnt;
	cnt++;
	
	for(int i=0; i<vv[num].size(); i++){
		if(vv[num][i]!=0 && f[i]==0){
			depth(vv,f,c,i);
		}
	}

	c[num]=cnt;
	cnt++;

}
int main(){
	int n;
	cin>>n;
	vector< vector<int> > v(n,vector<int> (n,0));
	vector<int> ft(n,0);
	vector<int> ct(n,0);
	int u[n];
	for(int i=0; i<n; i++){
		int k;
		cin>>u[i]>>k;
		for(int j=0; j<k; j++){
			int x;
			cin>>x;
			v[i][x-1]=1;
		}
	}
	for(int i=0; i<n; i++){
		if(ft[i]==0){
			depth(v,ft,ct,i);
		}
		cout<<u[i]<<" "<<ft[i]<<" "<<ct[i]<<endl;
	}
  return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>

#if 0
int mikisinn = 0;

void guririba(int sumipe) {
	if (sumipe > mikisinn) mikisinn = sumipe;
}

int main(void) {
	int A, B, C;
	if (scanf("%d%d%d", &A, &B, &C) != 3) return 1;
	guririba(A * 10 + B + C);
	...
	return 0;
}
#else
int main(void) {
	int A, B, C;
	int mikisinn;
	if (scanf("%d%d%d", &A, &B, &C) != 3) return 1;
	mikisinn = A;
	if (mikisinn < B) mikisinn = B;
	if (mikisinn < C) mikisinn = C;
	printf("%d\n", A + B + C - mikisinn + (mikisinn * 10));
	return 0;
}
#endif


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

int gcd(int n, int m) { return m ? gcd(m, n % m) : n; }

void solve(long long N, std::vector<long long> A) {
  LL ans = A[0];
  for (int i = 0; i < A.size(); i++) {
    ans = gcd(ans, A[i]);
  }
  cout << ans << endl;
}

int main() {
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;

int main() {
  int x,y;
  cin >> x >> y;
  int ret = 0;
  switch (x) {
    case 1:
      ret += 300000;
      break;
      case 2:
        ret += 200000;
        break;
      case 3: 
        ret += 100000;
        break;
      default:;
      }
      switch (y)
      {
      case 1:
        ret += 300000;
        break;
      case 2:
        ret += 200000;
        break;
      case 3: 
        ret += 100000;
        break;
      default:;
      }
      if (x == 1 && y == 1)
        ret += 400000;
      std::cout << ret << std::endl;
      return 0;
} 

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

int main() {
  int N;
  int a[110];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; i++) {
    if ( i % 2 == 0) {
      Alice += a[i];
    }
    else {
      Bob += a[i];
    }
  }
  cout << Alice - Bob <<endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);

    int N, X;
    int d = -1;
    cin >> N >> X;
    for(int i=0; i<N; i++){
        int xi;
        cin >> xi;
        if (d==-1)
            d = abs(X-xi);
        else
            d = __gcd(d, abs(X-xi));
    }
    cout << d;
    return 0;
}

Measured memory_bytes: 256
import sys
if sys.version_info[0]>=3: raw_input=input

n=int(raw_input())
for i in range(0,n):
	a=map(int,raw_input().split())
	a[0]-=1;a[1]-=1
	print(196471-a[0]*195-a[0]/3*5-a[1]*20+(a[1]/2 if a[0]%3!=2 else 0)-a[2])

Measured memory_bytes: 4216
import sys
import math

from typing import List


def max_heapify(max_heap: List[int], ix: int) -> None:
    l_ix = ix * 2
    r_ix = ix * 2 + 1

    # 左の子、自分、右の子の中で値が最大のノードを選ぶ。
    if l_ix < len(max_heap) and max_heap[l_ix] > max_heap[ix]:
        largest_ix = l_ix
    else:
        largest_ix = ix
    if r_ix < len(max_heap) and max_heap[r_ix] > max_heap[largest_ix]:
        largest_ix = r_ix

    if largest_ix != ix:
        max_heap[ix], max_heap[largest_ix] = max_heap[largest_ix], max_heap[ix]
        max_heapify(max_heap, largest_ix)


def build_max_heap(max_heap: List[int]) -> None:
    half = math.floor(len(max_heap) / 2)
    for i in reversed(range(1, half + 1)):
        max_heapify(max_heap, i)


_n = int(input())
max_heap = [int(i) for i in input().split()]
max_heap.insert(0, sys.maxsize)
# print(max_heap)
build_max_heap(max_heap)
for val in max_heap[1:]:
    print(f' {val}', end='')
print()


Measured memory_bytes: 61804
use io::*;


fn main() {

    let con = read_string();
    let mut sc = Scanner::new(&con);

    let n: u32 = sc.next();
    let a: u32 = sc.next();
    let b: u32 = sc.next();

    let ans = (1..n+1)
        .filter(|x|{
            let sum = x.to_string()
                .chars()
                .map(|c|(c as u8 - b'0') as u32)
                .sum::<u32>();
            a <= sum && sum <= b
        })
        .sum::<u32>();
/*
    let mut ans = 0;
    for i in 1..n+1 {
        let mut x = i;
        let mut sum = 0;
        while x > 0 {
            sum += x % 10;
            x /= 10;
        }
        if sum >= a && sum <= b {
            ans += i;
        }
    }
*/
    println!("{}", ans);

}

pub mod io {

    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}

Measured memory_bytes: 4352
n,k = map(int,input().split())
MOD = 10**9+7
# g[i]:gcd(A1,A2,,,An)=iとなる数列の個数
g = [0 for _ in range(k)]
for i in range(k,0,-1):
  g[i-1] = pow(k//i,n,MOD)
  #ここまででg[x]=gcdがxの倍数となる数列の個数となっているので、
  #ここからgcdが2x,3x,,,となる数列の個数を引いていく。
  for j in range(2,k+1):
    if i*j > k:
      break
    g[i-1] -= g[i*j-1]
    g[i-1] %= MOD
#print(g)
ans = 0
for i in range(k):
  ans += (i+1)*g[i]
  ans %= MOD
print(ans)


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
#ifdef LOCAL
#define debug(x) cout<<#x<<" = "<<(x)<<endl
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
#else
#define debug(x) 0
template<class T>void pv(T a,T b){}
#endif

int nextInt() { int x; scanf("%d", &x); return x;}

vector<pair<int,int>> solve(const int K, const int X, const int Y) {
  vector<pair<int,int>> ans;
  int cx = 0, cy = 0;
  while ((X - cx) + (Y - cy) > 2 * K) {
    int dx = (X - cx);
    int dy = (Y - cy);
    int my = min(dy, K);
    int mx = min(dx, K - my);
    cx += mx;
    cy += my;
    ans.push_back({cx, cy});
  }
  while ((X - cx) != 0 || (Y - cy) != 0) {
    int dx = (X - cx);
    int dy = (Y - cy);
    if (dx + dy == K) {
      cx = X;
      cy = Y;
      ans.push_back({cx, cy});
    } else if ((dx + dy) % 2 == 0) {
      int R = (2*K - dx - dy) / 2;
      int b = K - R;
      int c = dx - K + R;
      int d = K - c;
      cy -= R;
      cx += b;
      ans.push_back({cx, cy});
      cx += c;
      cy += d;
      ans.push_back({cx, cy});
    } else if ((dx + dy) >= K) {
      int my = min(dy, K);
      int mx = min(dx, K - my);
      cx += mx;
      cy += my;
      ans.push_back({cx, cy});
    } else {
      cx -= K;
      ans.push_back({cx, cy});
    }
  }
  return ans;
}

int main2() {
  int K = nextInt();
  int X = nextInt();
  int Y = nextInt();
  if (K % 2 == 0 && (X+Y) % 2 != 0) {
    cout << -1 << endl;
    return 0;
  }

  int sx = X >= 0 ? 1 : -1;
  int sy = Y >= 0 ? 1 : -1;
  X = abs(X);
  Y = abs(Y);
  bool rev = false;
  if (X < Y) {
    swap(X, Y);
    rev = true;
  }
  vector<pair<int,int>> ans = solve(K, X, Y);
  cout << ans.size() << endl;
  REP(i, ans.size()) {
    if (rev) {
      swap(ans[i].first, ans[i].second);
    }
    cout << sx * ans[i].first << " " << sy * ans[i].second << endl;
  }
  return 0;
}

int main() {
#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
long long a,b,x,y,t;
int main(){
	cin>>a>>b>>x>>y;
	t=__gcd(x,y),t=x*y/t;
	cout<<b-a+1-(b/x-(a-1)/x+b/y-(a-1)/y-b/t+(a-1)/t);
}

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

int n;
vector<int> a;

bool solve(int i,int sum){
    bool res=false;
    if(i==n)return sum==0;
    res=solve(i+1,sum)|solve(i+1,sum-a[i]);
    return res;
}

int main(void){
    cin>>n;
    a.resize(n,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int m;
        cin>>m;
        if(solve(0,m))cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3108
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] input = new int[n];

		for (int i = 0; i < n; i++) {
			input[i] = sc.nextInt();
		}
		
		int timesOfReplacement = bubbleSort(input);
		
		System.out.println(format(input));
		System.out.println(timesOfReplacement);
	}

	static int bubbleSort(int[] a) {
		boolean flag = true;
		int timesOfReplacement = 0;

		while (flag) {
			flag = false;
			for (int j = a.length - 1; 1 <= j; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					flag = true;
					timesOfReplacement++;
				}
			}
		}
		return timesOfReplacement;
	}

	static String format(int[] a) {
		return IntStream.of(a).mapToObj(n -> String.valueOf(n)).collect(Collectors.joining(" "));
	}
}

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



public class Main{
	public static void main(String[] args){

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		double x1, x2, y1, y2;
		double d;
		String str;
		String[] array_str;

		try{
			str=reader.readLine();
			array_str=str.split(" ");
			x1=Double.parseDouble(array_str[0]);
			y1=Double.parseDouble(array_str[1]);
			x2=Double.parseDouble(array_str[2]);
			y2=Double.parseDouble(array_str[3]);

			d=Math.sqrt(((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));

            System.out.printf("%.8f", d);

		}catch(IOException e){
			System.out.print(e);
		}
	}

}

Measured memory_bytes: 24780
#include <stdio.h>

void swap(int *a, int *b);

int main(void)
{
	int a, b;
	
	while (scanf("%d %d", &a, &b)){
		if (a == 0 && b == 0) break;
		
		if (a > b) swap(&a, &b);
		
		printf("%d %d\n", a, b);
	}
	
	return (0);
}

void swap(int *a, int *b)
{
	int tmp;
	
	tmp = *a;
	*a = *b;
	*b = tmp;
}

Measured memory_bytes: 600