akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i=a,_b=b;i<=_b;i++)
#define FORD(i,a,b) for(ll i=a,_b=b;i>=_b;i--)
#define fi first
#define se second
typedef long long ll;
const ll MAXN=100010;
const ll INF=1000000000;
const ll MOD=1000000007;
const ll MAXL=100000;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
//***********RHYMASTER************
main()
{
    #define FILE "a"
  //  freopen(FILE".inp","r",stdin);
  //  freopen(FILE".out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,k;
    cin>>n>>k;
    if(k%2==1)
    {
        ll kq=0;
        FOR(i,1,n) if(i%k==0) kq++;
        cout<<kq*kq*kq;
    }
    else
    {
        ll kq1=0,kq2=0;
        FOR(i,1,n) if(i%k==0) kq1++;
        FOR(i,1,n) if(i%(k/2)==0) kq2++;
        kq2-=kq1;
        cout<<kq1*kq1*kq1+kq2*kq2*kq2;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int n,ans=1;
    string s;
    cin >> n  >> s;

    rep(i,1,n-1){
        if(s[i]!=s[i-1])++ans;
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a + b < c + d)
    {
        cout << "Right\n";
    }
    else if(a + b == c + d)
    {
        cout << "Balanced\n";
    }
    else
    {
        cout << "Left\n";
    }
    return 0;
}

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

struct SegmentTree {
    SegmentTree(vector<int> v, int ini) {
        int sz = v.size();
        n = 1;
        while (n < sz)
            n *= 2;
        node.resize(2 * n - 1, ini);

        for (int i = 0; i < sz; i++) {
            node[i + n - 1] = v[i];
        }
        for (int i = n - 2; i >= 0; i--) {
            node[i] = node[2 * i + 1] + node[2 * i + 2];
        }
    }

    void update(int k, int val) {
        k += n - 1;
        node[k] = val;
        while (k > 0) {
            k = (k - 1) / 2;
            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0)
            r = n;

        if (r <= a || b <= l)
            return 0;
        if (a <= l && r <= b)
            return node[k];

        int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;
    }

private:
    int n;
    vector<int> node;
};

map<ll, int> compress(vector<ll> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    map<ll, int> mp;
    for (int i = 0; i < (int)v.size(); i++) {
        mp[v[i]] = i;
    }
    return mp;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }

    vector<ll> b(N + 1, 0);
    for (ll i = 0; i <= N; i++) {
        b[i] = a[i] - i * K;
    }

    auto compressed = compress(b);
    int n = compressed.size();

    SegmentTree st(vector<int>(n, 0), 0);
    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        int idx = compressed[b[i]];
        ans += st.query(0, idx + 1);
        int cur = st.query(idx, idx + 1);
        st.update(idx, cur + 1);
    }

    cout << ans << endl;
}


Measured memory_bytes: 18660
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// ある辺がどの最短経路にも使われない時
// その辺がつなぐ二点間の最短距離がその辺ではない。

int main(){
    int N,M;
    cin>>N>>M;
    
    ll G[110][110];
    rep(i,110){rep(j,110){
        if(i==j)    G[i][j]=0;
        else        G[i][j]=LINF;}}
    map<pair<int,int>,int> mp;

    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;a--;b--;
        mp[make_pair(min(a,b),max(a,b))]=c;
        G[a][b]=c;G[b][a]=c;
    }
    rep(k,N){rep(i,N){rep(j,N){
        G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
    }}}
    int ans=0;
    for(auto x:mp){
        if(G[x.first.first][x.first.second]!=x.second) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
  print(0)
else:
  X.sort()
  Y = []
  for i in range(len(X) - 1):
    Y.append(X[i + 1] - X[i])
  Y.sort()
  print(sum(Y[:M - N]))

Measured memory_bytes: 20456
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	std::string S;
	in >> S;

	if (S[0] != 'A')
	{
		out << "WA" << std::endl;
		return 0;
	}

	int cnt = 0;
	for (int i = 2; i < S.length() - 1; ++i)
	{
		if (S[i] == 'C') ++cnt;
	}
	if (cnt != 1)
	{
		out << "WA" << std::endl;
		return 0;
	}

	bool flag = true;
	rep(i, S.length())
	{
		if (S[i] != 'A'&&S[i] != 'C'&&std::isupper(S[i]))
		{
			flag = false;
			break;
		}
	}
	out << (flag ? "AC" : "WA") << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 50

using namespace std;
typedef pair<int, int> ipair;

int V[MAX_N];
int N, K;

int main(int argc, char **argv) {
    cin >> N >> K;
    for(int i = 0; i < N; ++i)
        cin >> V[i];

    int res = -INF;
    for(int i = 0; i <= K; ++i)
        for(int j = 0; j <= K - i; ++j) {
            //右からi個，左からj個
            if(i + j > N) break;
            
            int sum = 0;
            priority_queue<int> pq;
            for(int ii = 0; ii < i; ++ii) {
                sum += V[ii];
                pq.push(-V[ii]);
            }
            for(int ji = N - 1; ji >= N - j; --ji) {
                sum += V[ji];
                pq.push(-V[ji]);
            }

            for(int k = 0; k < K - (i + j); ++k) {
                if(pq.empty()) break;
                if(-pq.top() < 0)
                    sum -= -pq.top();
                else
                    break;
                pq.pop();
            }

            res = max(res, sum);
        }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int S,h=0,m=0,s=0;
  scanf("%d",&S);
  while(S>=3600){
    h+=1;
    S-=3600;
  }
  while(S>=60){
    m+=1;
    S-=60;
  }
  s=S;
  printf("%d:%d:%d\n",h,m,s);

  return 0;
}

Measured memory_bytes: 592
#include<cstdio>
#include<algorithm>
using namespace std;
int d1,n,a[100002],b[100001];
long long cnt;
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n+1;i++)scanf("%d",&a[i]);
	for(register int i=1;i<=n;i++)scanf("%d",&b[i]);
	for(register int i=1;i<=n;i++){
		d1=min(a[i],b[i]);
		cnt+=d1;
		a[i]-=d1;
		b[i]-=d1;
		cnt+=min(b[i],a[i+1]);
		a[i+1]-=min(b[i],a[i+1]);
	}
	printf("%lld",cnt);
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    ll x; cin >> x;
    ll ans = 1;
    for(ll i = 2; i*i <= x; ++i) {
        for(ll j = i*i; j <= x; j *= i) {
            ans = max(ans, j);
        }
    }

    cout << ans << endl;

    return 0;
}


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

bool solve(int now,int sum){
    if(!sum) return true;
    else if(now == A.size() || sum < 0) return false;
    return solve( now + 1, sum - A[now]) || solve( now + 1, sum);
}

int main() {
    int num1, num2, test;
    cin >> num1;
    A.resize(num1);
    for (int i = 0; i < num1; i++) {
        cin >> A[i];
    }
    cin >> num2;
    for (int i = 0; i < num2; i++) {
        cin >> test;
        if (solve(0, test) == 1) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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


int find(const string str, const string subStr) {
    vector<int> result;

    int subStrSize = subStr.size();
    int pos = str.find(subStr);

    int cnt=0;

    while (pos != string::npos) {
        cnt++;
        pos = str.find(subStr, pos + subStrSize);
    }

    return cnt;
}

int main(){
    int n; cin>>n;
    string str; cin>>str;
    int ans = find(str, "ABC");
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<n;i++)
typedef long long ll;
using namespace std;



int main(){
	int x,a;
	cin>>x>>a;
	if(x<a){
		cout<<0;
	}
	else{
		cout<<10;
	}
	return 0;
}

Measured memory_bytes: 256
A, B, C ,D, E, F = map(int, input().split())

now = 0
ans_w = 0
ans_s = 0
for a in range(F//(100*A)+1):
    for b in range(F//(100*B)+1):
        for c in range(F//C+1):
            for d in range(F//D+1):
                w = A * a * 100 + B * b * 100
                s = C * c + D * d
                if s / E > w / 100 or s + w > F:
                    break
                elif w + s != 0:
                    if now < 100*s/(w+s):
                        now = 100*s/(w+s)
                        ans_w = w
                        ans_s = s

if ans_w == 0 and ans_s == 0:
    ans_w = 100 * A
print(ans_w + ans_s, ans_s)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 1000000000000
#define N 1000100
ll x,n,m,T,a[N],b[N],ans,i,la,lb,ra,rb; 
int main()
{
	scanf("%lld %lld %lld",&n,&m,&T);
	for (i=1;i<=n;i++) scanf("%lld",&a[i]);
	for (i=1;i<=m;i++) scanf("%lld",&b[i]);
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	for (i=1;i<=T;i++)
	{
		scanf("%lld",&x);
		ra=lower_bound(a+1,a+1+n,x)-a;
		la=ra-1;
		rb=lower_bound(b+1,b+1+m,x)-b;
		lb=rb-1;
		ans=inf;
		if (la>0&&lb>0) ans=min(ans,x-min(a[la],b[lb]));
		if (ra<=n&&rb<=m) ans=min(ans,max(a[ra],b[rb])-x);
		if (la>0&&rb<=m) 
		{
			ans=min(ans,2*(x-a[la])+b[rb]-x);
			ans=min(ans,2*(b[rb]-x)+x-a[la]);
		}
		if (ra<=n&&lb>0) 
		{
			ans=min(ans,2*(x-b[lb])+a[ra]-x);
			ans=min(ans,2*(a[ra]-x)+x-b[lb]);
		}
		printf("%lld\n",ans);
	}
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    ll pre[n];
    pre[0] = a[0];
    for(int i=1;i<n;i++){
        pre[i] = __gcd(a[i],pre[i-1]);
    }
    ll suf[n];
    suf[n-1] = a[n-1];
    for(int i=n-2;i>=0;i--){
        suf[i] = __gcd(a[i],suf[i+1]);
    }
    ll ans = 1;
    for(int i=0;i<n;i++){
        ll x,y;
        if(i-1>=0) x = pre[i-1];
        else x = 0;
        if(i+1<n) y = suf[i+1];
        else y = 0;
        ans = max(ans,__gcd(x,y));
    }
    cout<<ans<<"\n";

    return 0;

}




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

using namespace std;

typedef long long ll;
#define mp make_pair
#define F first
#define S second
#define pb push_back


const int N = 200200;
const int mod = 1e9 + 7;

#define fo(i, n) for(int i = 1; i <= n; ++i)

ll n, a[N];

inline int sign(ll x)
{	
	if(x == 0) return 0;
	if(x < 0) return -1;
	return 1;
}
ll calc()
{
	ll sum = 0, last = 0, ans = 0;
	fo(i, n)
	{
		sum += a[i];
		if(sign(sum) != sign(last) && sign(sum) != 0)
			last = sum;
		else 
		{
			if(sign(last) == -1)
				ans += abs(sum) + 1, sum = 1;
			else
				ans += abs(sum) + 1, sum = -1;
			last = sum;
		}
	}
	return ans;
}	

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	fo(i, n)
		cin >> a[i];
	ll ans = 1e18;
	ans = min(ans, calc());
	ll w = a[1];
		a[1] = -1;
		ans = min(ans, calc() + abs(w + 1));
		a[1] = 1;
		ans = min(ans, calc() + abs(w - 1));
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;
void read(int &x){int f=1;x=0;char s=getchar();while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}x*=f;}
//void write(int x){if(x<0){putchar('-');x=-x;}if(x>9)write}
int main(){
	int a,b;
	read(a);
	read(b);
	if(a*b%2==0){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;
    
    set<int> r;
    set<int> g;
    set<int> b;
    
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') r.insert(i);
        if (s[i] == 'G') g.insert(i);
        if (s[i] == 'B') b.insert(i);
    }
    
    long long sum = 0;
    for (int ri : r) {
        for (int rg : g) {
            sum += b.size();
            int d = abs(ri - rg);
            if (b.find(min(ri, rg) - d) != b.end()) 
                sum--;
            if (b.find(max(ri, rg) + d) != b.end()) 
                sum--;
            if ((d > 1) && (d % 2 == 0) && b.find((ri + rg) / 2) != b.end()) 
                sum--;
        }
    }

    cout << sum << "\n";
        
    return 0;
}

// scanf("%d %d", &a, &b)
// printf("%d %d", 123, 456);

// getline(cin, s)
// while (cin >> x) {...} - read unknown data



Measured memory_bytes: 3800
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N; cin >> N;
	vector<ll> a(N + 1), sums(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
		sums[i] = (sums[i - 1] + a[i]) % DIV;
	}

	ll ans = 0;
	for (int j = 1; j <= N; j++) {
		ans += (a[j] * sums[j - 1]) % DIV;
		ans %= DIV;
	}
	cout << ans << endl;
}


Measured memory_bytes: 6424
#include<algorithm>
#include<iostream>
using namespace std;
 
int main()
{
	int n,x,y;
	cin>>n;
	cin>>x;
	y=x;
	for(int i=1;i<n;i++)
	{
		cin>>x;
		y=__gcd(x,y);
	}
	cout<<y<<"\n";
	return 0;
}

Measured memory_bytes: 256
/*input
5 3
1 2 3 4 5
*/

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n,k;
	int l[n];
	cin >> n >> k;
	for(int i = 0; i < n; i ++) cin >> l[i];
	sort(l, l + n);
	int ans = 0;
	for(int i = n - 1; i >= n - k; i --) ans += l[i];
	cout << ans << endl;
}

Measured memory_bytes: 256
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 = sc.nextInt();
			int sum = N; 
			sum = sum % 500;		
			if(sum <= A)
				System.out.println("Yes");
			else System.out.println("No");
			}}

Measured memory_bytes: 21204
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
  int  a, b, c, d, e, X, Y;
  //  double  c;
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003]={};

  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
//char s[101][101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  int tmp=0;
  int min=1000;
  int len=0;
  int cnt=0;
  int num=0;
  double ans=1000;
  int max=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d%d", &a, &b);
//  cnt = strlen(t);
  //printf("%d\n",cnt);
  for(i=0;i<a;i++){
    scanf("%d", &c);
    for(j=0;j<c;j++){
      scanf("%d", &d);
      A[d]++;
    }
  }    
  for(i=0;i<b+1;i++){
    if(A[i]==a) e++;
  }
  printf("%d\n",e);
  
  
  //  //  if(flag==0)   printf("TLE\n");
//    if(max < cnt - max)  printf("Yes\n");
//    else  printf("No\n");
  
return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  string s;
  cin>>s;
  if(s=="ABC")cout<<"ARC"<<"\n";
  else cout<<"ABC"<<"\n";
}


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

int main(){
  int A, B, C, ans;
  
  cin >> A >> B >> C;
  
  if(C - A + B >= 0){
    ans = C - A + B;
  } else {
    ans = 0;
  }
  
  cout << ans << endl;
  
  return 0;
}

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

int main(){
  
  string  s;
  long long k;

  cin>>s>>k;

  int i;

  char ans;
  
  for(i=0;i<s.length();i++){
    if(s[i]!='1'){
      ans=s[i];
      break;
    }
  }


  if(i>=k){
    cout<<1<<endl;
  }else{
    cout<<ans<<endl;
  }
  
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;cin>>a>>b>>c>>d;
	int e,f;
	if(a>c)e=a;else e=c;
	if(b<d)f=b;else f=d;
	if(e>f)cout<<0;
	else cout<<f-e;
	return 0;
}

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

const int N = 100009;
const int M = N << 1;
const int H = 20;

int n,m,U[N],V[N],fa[N][H],anc[N],dep[N];
int head[N],nxt[M],to[M],delta[N];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

int find(int x) {
	return x == anc[x]? x: anc[x] = find(anc[x]);
}

void DFS(int w, int f) {
	fa[w][0] = f;
	dep[w] = dep[f] + 1;
	for (int i=head[w];i;i=nxt[i]) {
		if (to[i] != f) {
			DFS(to[i], w);
		}
	}
}

inline int LCA(int x, int y) {
	if (dep[x] < dep[y]) swap(x, y);
	for (int i=H-1;~i;i--) if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
	if (x == y) return x;
	for (int i=H-1;~i;i--) if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
	return fa[x][0];
}

int solve(int w, int f) {
	int ret = delta[w];
	for (int i=head[w];i;i=nxt[i]) {
		if (to[i] != f) {
			ret += solve(to[i], w);
		}		
	}
	if (ret & 1) {
		puts("NO");
		exit(0);
	} else {
		return ret;
	}
}

inline void AddEdge(int u, int v) {
	static int E = 1;
	to[++E] = v; nxt[E] = head[u]; head[u] = E;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

int main() {
	n = read(); m = read();
	for (int i=1;i<=n;i++) {
		anc[i] = i;
	}
	for (int i=1;i<=m;i++) {
		U[i] = read(); 
		V[i] = read();
		if (find(U[i]) != find(V[i])) {
			anc[anc[U[i]]] = anc[V[i]];
			AddEdge(U[i], V[i]);
		}
	}
	for (int i=1;i<=n;i++) {
		if (find(i) == i) {
			DFS(i, i);
		}
	}
	for (int j=1;j<H;j++) {
		for (int i=1;i<=n;i++) {
			fa[i][j] = fa[fa[i][j-1]][j-1];
		}
	}
	for (int i=1;i<=m;i++) {
		delta[U[i]]++;
		delta[V[i]]++;
		delta[LCA(U[i], V[i])] -= 2;
	}
	for (int i=1;i<=n;i++) {
		if (find(i) == i) {
			solve(i, i);
		}
	}
	puts("YES");
	return 0;
}



Measured memory_bytes: 11776
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define N (1000000000+7)
typedef pair<int,int> P;
typedef long long ll;
int d[1010][1010];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int h,w;
char board[1010][1010];
bool check(int i, int j) {
	return (i >= 0) && (i <= h) && (j >= 0) && (j <= w) && (board[i][j] == '.');
}


int main(void){
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)sum^=a[i];
    if(sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include<string>
using namespace std;
int main()
{
	//unsigned long long int a, b, c, d, e, ans = 0,n,x[19],c[19],v[19];
	int a, b, c, d, e, f = 0, ans = 0, n;
	// 整数の入力

	unsigned long long x, y;
	// 文字列の入力
//	string s;
	cin >> x>>y;
	if (x%y==0||x==y)
	{
		cout << -1 << endl;

	}
	else
	{
		for (a = 1; a*x < 1000000000000000000; a++)
		{
			if ((a*x)%y != 0)
			{
				cout << a*x << endl;
				break;
			}
		}
		
	}
	// 出力
	return 0;
}

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

using P = pair<int, int>;

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

    vector<P> xy(m);
    for (int i = 0; i < m; i++) {
        cin >> xy[i].first >> xy[i].second;
        xy[i].first--; xy[i].second--;
    }
    sort(xy.begin(), xy.end());

    vector<P> segment(n);
    for (int i = 0; i < n; i++) {
        segment[i] = make_pair(i, i);
    }
    for (int i = 0; i < m; i++) {
        int y = xy[i].second;
        segment[y].first = min(segment[y].first, segment[y+1].first);
        segment[y+1].first = min(segment[y].first, segment[y+1].first);

        segment[y].second = max(segment[y].second, segment[y+1].second);
        segment[y+1].second = max(segment[y].second, segment[y+1].second);

        /*
        cout << "y: " << y << " [" << segment[y].first << ", " << segment[y].second << "]" << endl;
        cout << "y+1: " << y+1 << " [" << segment[y+1].first << ", " << segment[y+1].second << "]" << endl;
        */
    }

    for (int i = 0; i < n; i++) {
        cout << (i == 0 ? "" : " ") << (segment[i].second - segment[i].first + 1);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

vector<vector<ll>> d(300,vector<ll>(300,IINF));
vector<vector<ll>> e(300,vector<ll>(300,IINF));
ll N,M,L;
void WarshallFloyd(){
    rep(k,N){
        rep(i,N){
            rep(j,N){
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

void AarshallFloyd(){
    rep(k,N){
        rep(i,N){
            rep(j,N){
                chmin(e[i][j],e[i][k]+e[k][j]);
            }
        }
    }
}

int main(){
    cin >> N >> M >> L;
    rep(i,M){
        ll a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    rep(i,N){
        d[i][i]=0;
    }
    WarshallFloyd();
    rep(i,N){
        rep(j,N){
            if (d[i][j]<=L){
                e[i][j]=1;
            }
        }
        e[i][i]=0;
    }
    AarshallFloyd();
    ll Q;
    cin >> Q;
    rep(i,Q){
        ll s,t;
        cin >> s >> t;
        s--,t--;
        if (e[s][t]==IINF){
            e[s][t]=0;
        }
        cout << e[s][t]-1 << endl;
    }
}

Measured memory_bytes: 1920
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = LIST()

l = sorted(L)
if l[-1] < sum(l[:-1]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3896
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int n, m;
int a[100000];
int b[100000], c[100000];
priority_queue<P, vector<P>, greater<P>> que;	//(val, num)

signed main() {
	int i;
	
	cin >> n >> m;
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i] >> c[i];
	
	rep(i, n) que.push(P(a[i], 1));
	rep(i, m) {
		int cnt = 0;
		
		while (!que.empty()) {
			if (cnt >= b[i]) break;
			P now = que.top();
			if (now.first >= c[i]) break;
			que.pop();
			int mai = now.second;
			if (cnt + mai <= b[i]) {
				cnt += mai;
			}
			else {
				que.push(P(c[i], b[i] - cnt));
				que.push(P(now.first, mai - (b[i] - cnt)));
				break;
			}
		}
		que.push(P(c[i], cnt));
	}
	
	int ans = 0;
	while (!que.empty()) {
		P now = que.top(); que.pop();
		ans += now.first * now.second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
#define mod ll(1e9+7)
ll mul(ll a,ll b){ return a*b%mod; }

ll solve(vector<ll> &v,int n){
    ll sum = 0;
    rep(i,n-1) sum += mul(v[i+1]-v[i],mul(i+1,n-i-1));
    return sum % mod;
}

int main(void){
    int n,m;
    cin>>n>>m;
    vector<ll> x(n),y(m);
    rep(i,n) cin>>x[i];
    rep(i,m) cin>>y[i];
    cout<<mul(solve(x,n),solve(y,m))<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main() {
	long long int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector<long long int> nn(n+1, 0);
		for (int i = 1; i <= n; i++) {
			cin >> nn[i];
		}
		
		for (long long int i = 1; i <= n; i++) {
			nn[i] += nn[i - 1];
		}
		set<long long int> stn;
		map<long long int, long long int> mpn;
		for (long long int i = 0; i <= n; i++) {
			for (long long int j = i + 1; j <= n; j++) {
				stn.insert(nn[j] - nn[i]);
				mpn[nn[j] - nn[i]]++;
			}
		}
		nn.clear();
		//cout << ' ' << stn.size() << endl;
		vector<long long int> mm(m+1, 0);
		for (long long int i = 1; i <= m; i++) {
			cin >> mm[i];
		}
		for (long long int i = 1; i <= m; i++) {
			mm[i] += mm[i - 1];
		}
		vector<long long int> vm;
		map<long long int, long long int> mpm;
		for (long long int i = 0; i <= m; i++) {
			for (long long int j = i + 1; j <= m; j++) {
				vm.push_back(mm[j] - mm[i]);
				mpm[mm[j] - mm[i]]++;
			}
		}
		sort(vm.begin(), vm.end());
		mm.clear();
		long long int ans = 0;
		for (set<long long int>::iterator ite = stn.begin(); ite != stn.end(); ite++) {
			vector<long long int>::iterator ite2 = lower_bound(vm.begin(), vm.end(), *(ite));
			//cout << *(ite) << ' ' << *(ite2) << endl;
			if (ite2 != vm.end() && *(ite) == *(ite2)) {
				ans += mpn[*(ite)] * mpm[*(ite2)];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 55928
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    char a;
    cin >> a;
    int a_;
    a_ = int(a);
    if (a_ >= 97)
        cout << 'a';
    else
        cout << 'A';
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int a,b;
	cin>>a>>b;
	if(b>=a){
		cout<<"unsafe";
	}else cout<<"safe";
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t h,w,x,y,z,v,d,ans;
  cin>>h>>w;
  if(h%3==0||w%3==0) cout<<0<<endl;
  else{
    x=h/3*w;
    v=h-h/3;
    if(v%2==0||w%2==0){
      y=v*w/2;
      z=y;
    }
    else{
      y=max(v,w)/2*min(v,w);
      z=v*w-y;
    }
    ans=max(x,max(y,z))-min(x,min(y,z));
    
    x=(h/3+1)*w;
    v=h-h/3-1;
    if(v%2==0||w%2==0){
      y=v*w/2;
      z=y;
    }
    else{
      y=max(v,w)/2*min(v,w);
      z=v*w-y;
    }
    d=max(x,max(y,z))-min(x,min(y,z));
    ans=min(ans,d);
    
    x=h*(w/3);
    v=w-w/3;
    if(h%2==0||v%2==0){
      y=h*v/2;
      z=y;
    }
    else{
      y=max(h,v)/2*min(h,v);
      z=h*v-y;
    }
    d=max(x,max(y,z))-min(x,min(y,z));
    ans=min(ans,d);
    
    x=h*(w/3+1);
    v=w-w/3-1;
    if(h%2==0||v%2==0){
      y=h*v/2;
      z=y;
    }
    else{
      y=max(h,v)/2*min(h,v);
      z=h*v-y;
    }
    d=max(x,max(y,z))-min(x,min(y,z));
    ans=min(ans,d);
    
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3636
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


N, X = map(int, input().split())
x = list(map(int, input().split()))
x = sorted(x)
x = list(map(lambda arg: abs(arg - X), x))

g = x[0]
for xx in x:
    g = gcd(g, xx)
print(g)


Measured memory_bytes: 14252
#include<stdio.h>
int main(void)
{
	int n,a,b,i,x,x1,d,c;
	scanf("%d %d %d",&n,&a,&b);
	c=0;
	for(i=a;i<=n;i++){
		x=i;
        x1=0;
        while(x>0)
        {
            d=x%10;
            x1=x1+d;
            x=x/10;
        }
        if(x1>=a&&x1<=b)
            c+=i;
	}	
	printf("%d\n",c);
	return 0;
}

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

using namespace std;

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

#define int ll

main(){
	int s,w;
	cin >> s >> w;

	if(s>w){
		cout << "safe" << endl;
	}else{
		cout << "unsafe" << endl;
	}

	return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <algorithm>
#include <deque>

using namespace std;
class CharCount {
public:
	CharCount(int count, char c) :count(count), c(c) {};
	int count;
	char c;
};
int main() {
	char s[100001];
	scanf("%s", s);

	char last = 0;
	int point = 0;
	deque<CharCount> que;
	while (s[point] != 0) {
		if (s[point] == last)
			que.back().count++;
		else {
			que.emplace_back(1, s[point]);
			last = s[point];
		}
		point++;
	}

	bool kaibun = true;
	long long req = 0;

	while (2 <= que.size()) {
		if (que.front().c == que.back().c) {
			int rem = min(que.front().count, que.back().count);
			que.front().count -= rem;
			que.back().count -= rem;
			if (que.front().count == 0)
				que.pop_front();
			if (que.back().count == 0)
				que.pop_back();
		} else {
			if (que.front().c == 'x') {
				req += que.front().count;
				que.pop_front();
			} else if (que.back().c == 'x') {
				req += que.back().count;
				que.pop_back();
			} else {
				kaibun = false;
				break;
			}
		}
	}

	printf("%lld\n", kaibun ? req : -1);
}

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

int main() {
    int N;
    cin >> N;
    vector<int> B(N - 1);
    rep(i, N - 1) cin >> B[i];
    int ans = B[0];
    B.push_back(100'000);
    rep(i, N - 1) {
        ans += min(B[i], B[i + 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * ARC097_C.cpp
 *
 *  Created on: May 14, 2018
 *      Author: 13743
 */

#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
using namespace std;
typedef long long llong;

#define PB push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define REP(i, n) FOR(i,0,n)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

int code[25000];
bool used[25000];

int powI(int x, int n) {
	int ans = 1;
	while(n--) {
		ans *= x;
	}
	return ans;
}

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

	char str[5010];
	int K;
	cin >> str;
	cin >> K;

	int sLen = strlen(str);
	REP(i, sLen) {
		REP(j, 5) {
			REP(k, j+1) {
				if(i+k < sLen) {
					code[5*i+j] += (str[i+k]-'a'+1)*powI(50, 4-k);
				}
			}
		}
	}
	int minI = -1;
	while(K--) {
		int minS = 1<<30;
		REP(i, 5*sLen) {
			if(!used[i] && code[i]<minS) {
				minS = code[i];
				minI = i;
			}
		}
		REP(i, 5*sLen) {
			if(code[i] == minS) {
				used[i] = true;
			}
		}
	}
	int s = minI / 5;
	int t = minI % 5;
	REP(i, t+1) {
		cout << str[s+i];
	}
	cout << endl;
}





Measured memory_bytes: 384
#pragma warning(disable:4996)

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

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}

#pragma endregion

int _same(char a, char b, char c);
int _same(char a, char b, char c) {
	if (a == b && b == c) return 0;
	if ((a == b && b != c) || (a == c && a != b) ||
		(b == c && a != c)) return 1;
	return 2;
}

static char n[1000000001];

int main(void) {
	int N,tmp=0,i,len;
	
	i_cin(N);

	_itoa(n,N);
	len=strlen(n);

	for (i = 0; i < len;i++) {
		tmp += (n[i] - '0');
	}

	s_cout((N%tmp)?"No":"Yes");

	return 0;
}

	/*int A, B, C, X;
	int a, b, r, tmp, cnt = 0;

	i_cin4(A, B, C, X);

	r = (X % 100) / 50;
	if (r && !C) {i_cout(0); return 0;}

	tmp= X / 500;
	a = (tmp > A) ? A : tmp;
	tmp = X / 100;
	b =  (tmp > B) ? B : tmp;
	if (a && b) cnt = a * b / 2;
	else cnt = _max(a, b);
	cnt++;
	i_cout(cnt);*/





Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    string s ;
    cin >> s ;

    int ans = 1e7  ;
    int n  = s.size() ;

    for(int i = 0 ; i < s.size() - 1 ; i++)
    {
        if(s[i] != s[i+1] )
            ans =
            min( ans ,  max(i+1 , n - i - 1)) ;
    }

    cout << min(n,ans) << endl ;


}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  rep(i,N) cin >> x[i];
  int d[100010]={0};
  rep(i,N) d[i]=abs(X-x[i]);
  int ans=d[0];
  rep(i,N-1) ans=__gcd(ans,d[i+1]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using  namespace std;
#define endl '\n' 
#define ll long long
#define AC ios::sync_with_stdio(false);cin.tie(0);
const ll N=2e5;
ll dp[N][2];
ll arr[N];

int main()
{
    AC
    ll n;
    cin >> n;
    for (int i= 1; i<=n; i++) cin>> arr[i];
    dp[2][0]=arr[1];dp[2][1]=arr[2];
    for (int i= 3; i<=n; i++)
    {
        if (i&1)
        {
            dp[i][1]=max({dp[i-2][1],dp[i-2][0],dp[i-3][1],dp[i-3][0]})+ arr[i];
            dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        }
        else 
        {
            dp[i][1]=max(dp[i-2][1],dp[i-2][0])+ arr[i];
            dp[i][0]=arr[i-1]+dp[i-2][0];
        }
    }
    cout<<max(dp[n][0],dp[n][1])<<'\n';
}

Measured memory_bytes: 8304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a;
  cin >> a;
  vector<int> arr(a);
  rep(i,a){
    cin >> arr[i];
  }
  int sum = 0;
  rep(i,a){
  if(arr[arr[i]-1] == i+1) sum++;
  }
  cout << (sum/2) << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<stack>
#include<queue>
#include<stdlib.h>
#include<string.h>
#include<vector>
#define LL long long
#define  long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const double INF=1e9+7;
LL Find[100005];
LL find(int x) {return Find[x]==x?x:Find[x]=find(Find[x]);}

int main()
{

     int n,m,a,b;
     scanf("%d%d%d%d",&n,&m,&a,&b);
     printf("%d\n",(n-a)*(m-b));
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var w = ReadInts();
            var ans = new List<int>();
            var sum = w.Sum();
            var tmp = 0;
            for (int i = 0; i < n; i++)
            {
                tmp += w[i];
                var s1 = tmp;
                var s2 = sum-tmp;
                ans.Add(Math.Abs(s1 - s2));
            }
            WriteLine(ans.Min());
        }
        

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
#include <unordered_set>

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979323846

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;
//==============================================
template<typename T>
void merge(vector<T> &A, int left, int mid, int right) {
	auto n1 = mid - left;
	auto n2 = right - mid;
	vector<T> L(n1);
	vector<T> R(n2);

	copy(A.begin() + left, A.begin() + mid, L.begin());
	copy(A.begin() + mid, A.begin() + right, R.begin());

	L.push_back(make_pair(INF + 5, 'Z'));
	R.push_back(make_pair(INF + 5, 'Z'));

	for (int i = 0, j = 0, k = left; k<right; k++) {
		if (L[i].first <= R[j].first) {
			A[k] = L[i];
			i++;
		} else {
			A[k] = R[j];
			j++;
		}
	}
}

template<typename T>
void mergeSort(vector<T> &A, int left, int right) {
	if (left + 1 < right) {
		auto mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);

		merge(A, left, mid, right);
	}
}

template<typename T>
int partition(vector<T> &B, int p, int r) {
	int x = B[r].first;
	int i = p - 1;

	REP2(j, p, r) {
		if (B[j].first <= x) {
			i++;
			swap(B[i], B[j]);
		}
	}

	swap(B[i + 1], B[r]);
	return i + 1;
}

template<typename T>
void quickSort(vector<T> &B, int p, int r) {
	if (p < r) {
		int q = partition(B, p, r);
		quickSort(B, p, q - 1);
		quickSort(B, q + 1 , r);
	}
}

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

	int n;
	cin >> n;

	vector<pair<int, char>>A(n);
	vector<pair<int, char>>B(n);
	REP(i, n) {
		char c; int n;
		cin >> c >> n;
		A[i].second = c;
		A[i].first  = n;

		B[i].second = c;
		B[i].first  = n;
	}

	mergeSort(A, 0, n);
	quickSort(B, 0, n - 1);

	if (A == B) {
		cout << "Stable" << "\n";
	} else {
		cout << "Not stable" << "\n";
	}

	REP(i, n) {
		if (i) cout << "\n";
		cout << B[i].second << " " << B[i].first;
	}
	cout << "\n";

	return 0;
}

Measured memory_bytes: 5872
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define out(a) cout<<a<<" "
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int main() {
    int n,k;
    int as[100005];
    cin >> n >> k;
    rep(i,n) cin >> as[i];
    int cnt=0;
    rep(i,n){
        if (as[i]>=k) cnt++;
    }
    cout << cnt << endl;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

class BIT {
   public:
    explicit BIT(int64_t nn) : n(pow(2, ceil(log2(nn)))), b(n + 1) {}

    // [0, i)の和
    int64_t sum(int64_t i) const {
        int64_t s = 0;

        while (i > 0) {
            s += b[i];
            i -= (i & -i);
        }

        return s;
    }

    void add(int64_t i, int64_t a) {
        // 1-indexedに直す
        ++i;

        while (i <= n) {
            b[i] += a;
            i += (i & -i);
        }
    }

   private:
    int64_t n;
    vector<int64_t> b;
};

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    vector<int64_t> r = a;
    sort(r.begin(), r.end());

    auto ans = *partition_point(r.begin(), r.end(), [&](int64_t m) {
        vector<int64_t> b(n + 1);
        map<int64_t, int64_t> idxs;
        idxs[b[0]] = 0;
        for (auto i : irange(1L, n + 1)) {
            b[i] = b[i - 1] - 1;
            if (a[i - 1] <= m) {
                b[i] += 2;
            }
            idxs[b[i]] = 0;
        }

        int64_t idx = 0;
        for (auto&& kv : idxs) {
            kv.second = idx++;
        }

        BIT bit(n + 1);
        bit.add(idxs[b[0]], 1);
        int64_t k = 0;
        for (auto i : irange(1L, n + 1)) {
            k += bit.sum(idxs[b[i]]);
            bit.add(idxs[b[i]], 1);
        }

        return k <= n * (n + 1) / 2 / 2;
    });

    cout << ans << endl;
}

Measured memory_bytes: 11972
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>
#define C(_Str) cout << _Str << endl

using namespace std;

typedef long long int lli;

int main()
{
	int Num;
	while (cin >> Num) {
		int S = 0;
		for (int i = 0; i < 600; i += Num) S += i*i*Num;
		C(S);
	}
	return 0;
}

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

int main() {
    long long h;
    cin >> h;
    bool app = false;
    long long mini = 1;
    long long maxi = 2;
    long long ans = 0;
    while (!app) {
        if (h < maxi && mini <= h) {
            app = true;
        }
        else {
            maxi *= 2;
            mini *= 2;
        }
    }
    maxi /= 2;
    while (maxi % 2 == 0) {
        ans += maxi;
        maxi /= 2;
    }
    ans += 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool so(int x,int y){
    
    
    bool a[x+1][y+1];
    for(int i=0;i<=y;i++)
    a[0][i]=false;
    for(int i=0;i<=y;i++)
    if(i==2 || i==4)
    a[1][i]=true;
    else
    a[1][i]=false;
    for(int i=2;i<=x;i++){
        for(int j=0;j<=y;j++){
            a[i][j]=false;
            if(j>=2)
            a[i][j]=(a[i][j]||a[i-1][j-2]);
            if(j>=4)
            a[i][j]=(a[i][j]||a[i-1][j-4]);
        }
    }
    
    return a[x][y];
}
int main(){
    int x,y;
    cin>>x>>y;
    if(so(x,y))
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3600