akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
vector<int> arrN;
vector<int> arrW;
vector<vector<long long>> dp;
long long knapSackAt(int n,int w){
    if(dp[n][w]!=-1){
        return dp[n][w];
    }
    if(n==0){
        if(arrN[0]<=w){
            dp[n][w] = arrW[0];
            return dp[n][w];
        }else {
            dp[n][w] = 0;
            return dp[n][w];
        }

    }if(arrN[n]<=w){
        dp[n][w] = max(knapSackAt(n-1,w),(arrW[n]+knapSackAt(n-1,w-arrN[n])));
        return dp[n][w];
    }else{
        dp[n][w] = knapSackAt(n-1,w);
        return dp[n][w];
    }
}

long long knapBottomUp(int n,int w){
    long long maxval =0;
    for(int i =0;i<=w;i++){
        if(arrN[0]<=i){
            dp[0][i] = arrW[0];
            maxval = arrW[0];
        }else dp[0][i] = 0;
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<=w;j++){
            if(arrN[i]<=j){
                dp[i][j] = max(arrW[i]+dp[i-1][j-arrN[i]],dp[i-1][j]);
            }else dp[i][j] = dp[i-1][j];
            if(maxval<dp[i][j])maxval = dp[i][j];
            // cout << i << " "<< j << " "<<dp[i][j] << " "<< arrN[i] << " "<< arrW[i]<< "\n";
        }
    }
    return maxval;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,w;
    cin >> n >> w;
    arrN = vector<int>(n);
    arrW = vector<int>(n);
    for(int i =0;i<n;i++){
        cin >> arrN[i] >> arrW[i];
    }   
    dp = vector<vector<long long>>(n,vector<long long>(w+1,0));

    // cout << knapSackAt(n-1,w) << "\n";
    cout << knapBottomUp(n,w) << "\n";
    return 0;
}

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

using namespace std;

const int MAXN = 1E5;
int x[MAXN];

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> x[i];
    int ans = 1E9;
    for (int i = 0; i + k <= n; i++)
    {
        ans = min(ans, min(abs(x[i]), abs(x[i + k - 1])) + abs(x[i] - x[i + k - 1]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  int ans = N;
  for ( int i = 0 ; i < M ; i++){
    int A;
    cin >> A;
    ans -= A; 
  }
  if ( ans < 0) {
    cout << "-1" << endl;
  }
  else{
    cout << ans << endl;
  }
  
}

Measured memory_bytes: 3632
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

typedef ll T;
int sgn(T x){return (x>0)-(x<0);}
struct P{
    T x,y;
    P(){} P(T x,T y):x(x),y(y){}
    void read(){scanf("%lld%lld",&x,&y);}
    P operator - (const P&b) const {return P(x-b.x,y-b.y);}
    P operator + (const P&b) const {return P(x+b.x,y+b.y);}
    T operator * (const P&b) const {return x*b.x+y*b.y;}
    P operator * (const T&k) const {return P(x*k,y*k);}
    T operator ^ (const P&b) const {return x*b.y-y*b.x;}
    bool operator < (const P&b) const {return sgn(y-b.y)?y<b.y:x<b.x;}
};
typedef vector<P> polygon;
polygon convex(polygon A){
    int n=sz(A),m=0;
    polygon B;B.resize(n+1);
    sort(all(A));
    rep(i,0,n){
        while(m > 1 && sgn((B[m-1]-B[m-2])^(A[i]-B[m-2]))<0) --m;
        B[m++]=A[i];
    }
    per(i,0,n-1){
        while(m > 1 && sgn((B[m-1]-B[m-2])^(A[i]-B[m-2]))<0) --m;
        B[m++]=A[i];
    }
    B.resize(m);
    if(sz(B) > 1) B.pop_back();
    return B;
}

int main(){
    int n;scanf("%d",&n);
    polygon A;
    rep(i,0,n){
        P p;p.read();
        A.pb(p);
    }
    A = convex(A);
    printf("%d\n",sz(A));
    rep(i,0,sz(A)) printf("%lld %lld\n",A[i].x,A[i].y);
    return 0;
}

Measured memory_bytes: 6728
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> Paint;

__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  //cout << fixed << setprecision(n)
  int n;cin>>n;n%=26;
  string s;cin>>s;
  for(int i = 0; s.size() > i; i++){
    if(s[i]+n > 'Z')s[i] += n-26;
    else s[i] += n;
  }
  cout << s << endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_H = (int)(3e2 + 5);
const int MAX_W = (int)(3e2 + 5);
const int MAX_NUM = (int)(MAX_H * MAX_W);

int h, w, d;
int a[MAX_H][MAX_W];
int q;

map<int, pair<int, int>> to_index;
int cost[MAX_NUM];

int main(void) {
  // Here your code !
  scanf("%d %d %d", &h, &w, &d);

  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      scanf("%d", &(a[i][j]));
    }
  }

  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      to_index[a[i][j]] = make_pair(i, j);
    }
  }

  for (int i = 1; i <= h * w; ++i) {
    if (cost[i] > 0) continue;

    for (int j = i + d; j <= h * w; j += d) {
      auto last = to_index[j - d];
      auto cur = to_index[j];

      cost[j] += abs(cur.first - last.first) + abs(cur.second - last.second);
      cost[j] += cost[j - d];
    }
  }

  scanf("%d", &q);

  for (int i = 0; i < q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);

    printf("%d\n", cost[r] - cost[l]);
  }

  return 0;
}


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

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int maxn = 2e5+10;
                        
int a[maxn];
struct Node{
    int x,y;
}node[maxn];
int main(void){
     #ifndef ONLINE_JUDGE
     freopen("in.txt", "r", stdin);
     freopen("out.txt", "w", stdout);
     #endif
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> node[i].x >> node[i].y;
    int cnt = 1;
    for(int i = 2; i <= n-1; i++){
        if(node[i].x==node[i].y){
            if(node[i-1].x==node[i-1].y&&node[i+1].x==node[i+1].y){
                cnt += 2;
                if(cnt==3){
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }else cnt = 1;
    }
    cout<<"No"<<endl;
    return 0;
}

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

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

    vector<string> s(N);
    map<string, int> m;
    for (int i = 0; i < N; i++)
    {
        cin >> s[i];

        sort(s[i].begin(), s[i].end());
        m[s[i]]++;
    }

    long long ans = 0;
    for (auto &&i : m)
    {
        ans += (long long)i.second * (i.second - 1) / 2;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
long long a,b,cnt;
char ar1[2001][2001];
bool vist[2001][2001];
/*void dfs(int x,int y){
	for(int i=y+1;i<b;i++){
		if(ar[x][i]=='.'){
			cnt++;
		}
		else{
			break;
		}
	}
	for(int i=y-1;i>=0;i--){
		if(ar[x][i]=='.'){
			cnt++;
		}
		else{
			break;
		}
	}
}
void dfs1(int x,int y){
	for(int i=x;i<a;i++){
		if(ar[i][y]=='.'){
			cnt++;
		}
		else{
			break;
		}
	}
	for(int i=x-1;i>=0;i--){
		if(ar[i][y]=='.'){
			cnt++;
		}
		else{
			break;
		}
	}
}
void dfs2(int x,int y){
	for(int i=0;i<y;i++){
		vist[x][i]=false;
		//vist[i][x]=false;
	}
	for(int i=0;i<x;i++){
		//vist[x][i]=false;
		vist[i][y]=false;
	}
}
 */
int main(){
cin>>a>>b;
long long ma=0;
vector<int>ar[a],arr[b];
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			cin>>ar1[i][j];
			if(ar1[i][j]=='#'){
				ar[i].push_back(j);
				arr[j].push_back(i);
			}
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(ar1[i][j]=='.'){
				long long sum=0;
				int z=upper_bound(ar[i].begin(),ar[i].end(),j)-ar[i].begin();
				if(z==ar[i].size()&&z==0){
					sum+=b;
				}
				else if(z==ar[i].size()){
					sum+=b-ar[i][z-1]-1;
				}
				else if(z==0){
					sum+=ar[i][z];
				}
				else {
					sum+=abs(ar[i][z]-ar[i][z-1]-1);
				}
				z=upper_bound(arr[j].begin(),arr[j].end(),i)-arr[j].begin();
				//cout<<z<<" "<<arr[j][z]<<" "<<arr[j][z-1]<<endl;
				if(z==arr[j].size()&&z==0){
					sum+=a;
					//cout<<sum<<" "<<a<<endl;
				}
				else if(z==arr[j].size()){
					sum+=a-arr[j][z-1]-1;
					//cout<<sum<<" "<<b-arr[j][z-1]<<endl;
				}
				else if(z==0){
					sum+=arr[j][z];
					//cout<<sum<<" "<<arr[j][z]<<endl;
				}
				else {
					sum+=abs(arr[j][z]-arr[j][z-1]-1);
					//cout<<sum<<" "<<abs(arr[j][z]-arr[j][z-1])<<endl;
				}
				sum--;
				ma=max(ma,sum);
			}
		}
	}
	cout<<ma<<endl;
}

Measured memory_bytes: 40192
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define per(i,a,b) for(int i = (a);i >= (b);i--)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n,k,a[1005],sum;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	rep(i,0,n-1) cin >> a[i];
	sort(a,a+n);
	rep(i,0,k-1) sum += a[i];
	cout << sum << endl;
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3660
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define m_p make_pair
#define vpii vector<pii>
#define vvi vector<vi>
#define vs vector<string>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const ll inf=0x3f3f3f3f3f3f3f3f;
void print(vi v){
	ll n = v.size();
	for(ll i = 0; i < n; i++)
	    cout<<v[i]<<" ";
	cout<<endl;
}
ll power(ll a, ll b){
	ll res = 1;
	while(b != 0) {
		if(b & 1)
		  res *= a;
		a = a * a;
		b /= 2;
	}
	return res;
}
int main() {
    SPEED;
    ll k;
    cin>>k;
    ll rem = 0;
    ll curr = 7 % k;
    rem += curr;
    rem %= k;
    if(rem == 0) {
    	cout<<1;
    	return 0;
    }
    for(ll i = 1; i < 1e7; i++) {
    	curr = (curr * (10 % k)) % k;
    	rem += curr;
    	rem %= k;
	    if(rem == 0) {
	    	cout<<i + 1;
	    	return 0;
	    }
    }
    cout<<-1;
    return 0;
}

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

using namespace std;

/*解法
* s[i] != s[j] !=  s[k]を満たし、j-i != k-jを満たす組の数は、
* R,G,Bそれぞれの個数をr,g,bとしたときの積rgbから、1つめの条件を満たして2詰めの条件を満たさない(2*j == k+i)要素数を引けば求められる。
*/

int main(void){
    int n;
    string s;
    cin >> n >> s;
    long long R = 0, G = 0, B =0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            R++;
        }else if(s[i] == 'G'){
            G++;
        }else if(s[i] == 'B'){
            B++;
        }
    }
    long long sum = R * G * B;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int k = 2 * j - i;
            if(k >= n) continue;
            if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) sum--;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#define _A_ true
using namespace std;

int main(){
  int n,AC=0;
  int dp[1010][1010];
  char *A = new char[1500];
  char *B = new char[1500];

  scanf("%d",&n);
  while(_A_){
    if(AC == n)break;
    scanf("%s",A);
    scanf("%s",B);
    for(int i=0;i<1010;i++)for(int j=0;j<1010;j++)dp[i][j]=0;

    for(int i=0;i<strlen(A);i++){
      for(int j=0;j<strlen(B);j++){
	if(A[i] == B[j]){
	  dp[i+1][j+1]=dp[i][j]+1;
	}
	else{
	  if(dp[i+1][j] > dp[i][j+1]){
	    dp[i+1][j+1]=dp[i+1][j];
	  }
	  else {
	    dp[i+1][j+1] = dp[i][j+1];
	  }
	}
      }
    }
    printf("%d\n",dp[strlen(A)][strlen(B)]);
    AC++;
  }
  delete [] A;
  delete [] B;

  return 0;
}

Measured memory_bytes: 4908
// ３つの整数a, b, cを読み込み、
// それらが a < b < cの条件を満たすならば"Yes"を、
// 満たさないならば"No"を出力するプログラムを作成して下さい。
// 【入力】
// ３つの整数が空白で区切られて与えられます。
// 【出力】
// YesまたはNoを１行に出力して下さい。
// 【制約】
// 0 ≤ a, b, c ≤ 100
// 【例】
// 入力：1 3 8、出力：Yes
// 入力：3 8 1、出力：No
#include<iostream>
using namespace std;

int main( void) {
  int a, b, c;

  cin >> a >> b >> c;

  if ( a < b && b < c ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 3072
#include<stdio.h>
int main(){
double a,b,c,d,e,f,x,y;
while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
 y=(c*d-f*a)/(b*d-e*a);
 x=(c-b*y)/a;
 printf("%.3f %.3f\n",x,y);
 }
return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  for(int i = 0; i < k; i++) {
    int d = max(a,b);
    d = max(d,c);
    if(a == d) {
      a = a * 2;
      continue;
    }
    if(b == d) {
      b = b * 2;
      continue;
    }
    if(c == d) {
      c = c * 2;
      continue;
    }
  }
  cout << a+b+c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 1000

int main(){

	int N;
	scanf("%d",&N);

	vector<int> V;
	int tmp;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	V.erase(unique(V.begin(),V.end()),V.end());

	printf("%d",V[0]);
	for(int i = 1; i < V.size(); i++){
		printf(" %d",V[i]);
	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define ll long long

ll sum(ll n)
{
    if(n == 1)
        return 1;
    else
        return (pow(n, n) + sum(n-1));
}
void printFun(int test)
{
    if(test < 1)
        return;
    else
    {
        cout << test << " ";
        printFun(test - 1);
        cout << test << " ";
        return;
    }
}
int baseToDecimal(string x, int base)
{
    int res = 0, coef = 1, len = x.length();
    for(int i = len-1; i >= 0; i--)
    {
        res += (x[i] - '0')*coef;
        coef *= base;
    }
    return res;
}
int baseToDecimalAlternate(string x, int base)
{
    int res = 0;
    int len = x.length();
    for(int i = 0; i < len; i++)
    {
        res = (res*base) + (x[i] - '0');
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    string s;
    set<string>st;
    for(int i = 0; i < n; i++)
    {
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;

    //cout << baseToDecimalAlternate(x, base) << endl;
    //cout << baseToDecimal(x, base) << endl;
    return 0;
}


Measured memory_bytes: 19212
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m,Q;

ll tim[maxn],A[maxn],Ans[maxn];

void Work(){
	tim[n]=1;
	RREP(i,n,1){
		ll k=A[i];
		int t;
		while(t=upper_bound(A+1,A+i,k)-A-1){
			tim[t]+=tim[i]*(k/A[t]);
			k%=A[t];
		}
		Ans[k]+=tim[i];
	}
	RREP(i,m,1)Ans[i]+=Ans[i+1];
	REP(i,1,m)printf("%lld\n",Ans[i]);
}

void Init(){
	read(m,Q);
	A[++n]=m;
	REP(i,1,Q){
		ll x;read(x);
		while(n&&A[n]>=x)n--;
		A[++n]=x;
	}
}

int main(){
	Init();
	Work();
	return 0;
}


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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=2e5 +10, M=(ll)1e9+1 ;
const int mod =998244353 ,sz=5, MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";

void precom(){

}

vector<ll> par(N),size(N);

void initial(){
	for(ll i=0;i<N;i++){
		par[i]=i;
		size[i]=1;
	}
}

ll root(ll x){
	while(par[x]!=x){
		x=par[x];
		par[x]=par[par[x]];
	}

	return x;	
}

void merge(ll x,ll y){
	ll r_x=root(x),r_y=root(y);
	
	if(r_x==r_y)
		return;
	if(size[r_x]<size[r_y])
		swap(r_x,r_y);

	size[r_x]+=size[r_y];
	par[r_y]=r_x;

}
void work(){
	ll n,k,l;
	cin >> n >> k >> l;

	initial();
 
 	while(k--){
		ll u,v;
		cin >> u >> v;
		--u,--v;
		merge(u,v);
	}

	vector<ll> road=vector<ll>(par.begin(),par.begin()+n);
	for(ll i=0;i<n;i++)
		road[i]=root(road[i]);


	initial();
	while(l--){
		ll u,v;
		cin >> u >> v;
		--u,--v;
		merge(u,v);
	}

	vector<ll> rail=vector<ll>(par.begin(),par.begin()+n);

	for(ll i=0;i<n;i++)
		rail[i]=root(rail[i]);

	map<pair<ll,ll>,ll > m;
	for(ll i=0;i<n;i++){
		m[{road[i],rail[i]}]++;
	}

	for(ll i=0;i<n;i++){
		cout << m[{road[i],rail[i]}] << " ";
	}
	return;
}

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

	// precomp();
	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	}
return 0;
}
	

Measured memory_bytes: 18176
n = int(input())
s = list(input())

ans_list = [s[0]]
now_color = s[0]
for i in range(1, n):
    if now_color != s[i]:
        ans_list.append(s[i])
        now_color = s[i]
    # print("s[{}]:{} now_color:{} ans_list:{}".format(i, s[i], now_color, ans_list))

print(len(ans_list))


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

int main() {
	string s;
	cin >> s;
	int ans = s.length() - 2; // 文字列の長さ あ、必ず2文字は削除しなきゃなので消しておくよ
	for (int i = 0, j = ans / 2;j < ans;i ++, j ++) {
		if (s[i] != s[j]) { // 偶文字列ではなかった
			ans -= 2; // 偶文字列は長さが偶数なので、2文字ずつ消していくよ
			i = 0;
			j = ans / 2;
		}
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

ある長さの文字列の時に偶文字列になっているかを、大きい方から判断していくだけ
オーダーもO(|S|^2)なのでセーフ
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


vector<ll> dijkstra(int n,int s, vector<vector<Pi>> &G){
    vector<ll> dist(n,LINF);
    vector<bool> visited(n,false);
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
    dist[s] = 0;
    visited[s] = true;
    q.push(make_pair(0,s));
    while(!q.empty()){
        auto p = q.top();
        ll p1 = p.first;
        int p2 = p.second;
        q.pop();
        if(p1 > dist[p2]) continue;
        visited[p2] = true;
        for(auto v : G[p2]){
            if(visited[v.first]) continue;
            if(dist[v.first] > dist[p2]+v.second){
                dist[v.first] = dist[p2]+v.second;
                q.push(make_pair(dist[v.first],v.first));
            }
        }
    }
    return dist;
}

int main(){
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<Pi>> G1(n),G2(n);
    rep(i,m){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G1[u].emplace_back(v,a);
        G1[v].emplace_back(u,a);
        G2[u].emplace_back(v,b);
        G2[v].emplace_back(u,b);
    }
    vector<ll> dist1 = dijkstra(n,s,G1);
    vector<ll> dist2 = dijkstra(n,t,G2);

    vector<ll> ans(n);
    ans[n-1] = dist1[n-1]+dist2[n-1];
    for(int i = n-1; i >= 1; i--){
        ans[i-1] = min(ans[i],dist1[i-1]+dist2[i-1]);
    }
    rep(i,n){
        ans[i] = 1000000000000000-ans[i];
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 16120
#include <iostream>
#include <numeric>

using namespace std;

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

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

    if(M - N <= 0) {
        cout << 0 << endl;
        return 0;
    }

    int sum = accumulate(dist, dist+M-N, 0);
    cout << sum << endl;
}


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

const int N = 100005;
const long long inf = 1e18;

struct SegmentTree {
	long long t[N << 2];
	SegmentTree() { for (int i = 0; i < (N << 2); ++i) t[i] = inf; }

	#define mid ((l + r) >> 1)
	void upd(int v, int l, int r, int pos, long long val) {
		if (l > r || pos < l || pos > r) return;
		if (l == r) { t[v] = val; return; }
		upd(v << 1, l, mid, pos, val); upd(v << 1 | 1, mid + 1, r, pos, val);
		t[v] = min(t[v << 1], t[v << 1 | 1]);
	}
	long long get(int v, int l, int r, int L, int R) {
		if (l > r || R < l || L > r) return inf;
		if (L <= l && r <= R) return t[v];
		return min(get(v << 1, l, mid, L, R), get(v << 1 | 1, mid + 1, r, L, R));
	}
} L, R;

int n;
long long T, E;
long long x[N];
long long f[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> E >> T;
	for (int i = 1; i <= n; ++i) cin >> x[i];
	
	int ptr = 0;
	for (int i = 1; i <= n; ++i) {
		L.upd(1, 1, n, i, f[i - 1] - x[i - 1] - x[i] * 2);
		R.upd(1, 1, n, i, f[i - 1] - x[i - 1]);
		while(ptr < i && (x[i] - x[ptr + 1]) * 2 > T) ++ptr;
		f[i] = L.get(1, 1, n, 1, ptr) + 3LL * x[i];
		f[i] = min(f[i], R.get(1, 1, n, ptr + 1, i) + T + x[i]);
	}

	long long ans = f[n] + E - x[n];

	cout << ans << endl;
}

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

using namespace std;

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	while(1){
		int n,k;
		cin >> n >> k;
		if(n==0&&k==0) return 0;
		V<int> a(n+1,0);
		for(int i = 0; i < k; ++i) {
			int b; cin >> b;
			a[b]++;
		}
		int idx = 1;
		V<P<int,int>> v;
		while(idx<=n){
			int l = idx,r = idx;
			if(!a[idx]){
				idx++;
				continue;
			}
			while(a[idx]){
				r = idx;
				idx++;
			}
			v.push_back({l,r});
		}
		int ans = 0;
		for(int i = 0; i < v.size(); ++i) chmax(ans,v[i].second - v[i].first + 1);
		for(int i = 1; i < v.size(); ++i) if(a[0]&&v[i-1].second+2==v[i].first) chmax(ans,v[i].second - v[i-1].first + 1);
		cout << ans << endl;
	}

	return 0;
}



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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

map<multiset<int>, int> cnt;

int n;

ll ans;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;

    multiset<int> key;

    for (auto &e: s) {
      key.insert(e);
    }

    cnt[key] += 1;
  }

  for (auto &e: cnt) {
    ll value = (ll)(e.second);

    ans += (value - 1) * (value) / 2LL;
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 56448
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;

const ll MX = 1e18;
const long double PI = acos(-1);

int main()
{
    int l, r, d; cin >> l >> r >> d;
    int count = 0;
    for(int i=1; i < 101; ++i)
    {
        int j = d*i;
        if(l <= j && j <= r)
            ++count;
    }
    pri(count);
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
using namespace std;
    
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
    
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
    
class fact {
public:
    int fmod = 1e9+7;
    vector<int> fac, inv;
    fact (int n, int Mod = 1e9+7) {
        fmod = Mod;
        fac = vector<int>(n,0);
        inv = vector<int>(n,0);
        fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
        for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
    }
    ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
    ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
    
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}
int poorpow(int b, int a) {
    int tmp = 1;
    REP (i,a) {
        tmp *= b;
    }
    return tmp;
}


bool solve() {
    string s; cin >> s;
    string w = "2018";
    REP (i,4) s[i] = w[i];
    cout << s << endl;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();    
}


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

using namespace std;

#define int long long
#define forr(i,n) for(int i = 0;i < (int)n; i++)
#define forn(i,n) for(int i = (int)(n-1); ~i ;i--)
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define pb push_back
#define mpa make_pair
#define endl "\n"
#define ar array

const int INF = (int)1e9+10;
const int mxN = (int)200005;
const int MOD = (int)1e9 + 7;

int n,m,k;
int a[mxN],b[mxN];

void solve(){
	cin >> n >> m >> k;
	forr(i,n){
		cin >> a[i+1];
		a[i+1]+=a[i];
	}	
	forr(i,m){
		cin >> b[i+1];
		b[i+1]+=b[i];
	}
	int i = 0,j = m,ans=0;
	for(;i<=n;i++){
		if(a[i] > k) break;
		while(a[i]+b[j] > k) --j;
		ans = max(i+j,ans);
	}
	cout<<ans<<endl;
}


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 6736
#include<iostream>
#include<cstring>
using namespace std;
int c;
char a[100];
int main()
{
    cin>>a;
    for(int i=0;i<=int(strlen(a));i++)
    {
        if(a[i]==67)
        c=1;
        if(a[i]==70&&c==1)
        {cout<<"Yes";return 0;}
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,i+6):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Measured memory_bytes: 4340
#include <iostream>
#include <string>
using namespace std;
bool Istraveled[100][100];
char data[100][100];

void solve(int h,int w) {
	Istraveled[h][w]=true;
	char x=data[h][w];
	if(x=='.') {
		cout<<w<<" "<<h<<endl;
	}
	else if(x=='^') {
		if(Istraveled[h-1][w]==true) {
			cout<<"LOOP"<<endl;
		}
		else {
			solve(h-1,w);
		}
	}
	else if(x=='v') {
		if(Istraveled[h+1][w]==true) {
			cout<<"LOOP"<<endl;
		}
		else {
			solve(h+1,w);
		}
	}
	else if(x=='>') {
		if(Istraveled[h][w+1]==true) {
			cout<<"LOOP"<<endl;
		}
		else {
			solve(h,w+1);
		}
	}
	else if(x=='<') {
		if(Istraveled[h][w-1]==true) {
			cout<<"LOOP"<<endl;
		}
		else {
			solve(h,w-1);
		}
	}
}

int main(void) {
	int h,w;
	string in;
	while(cin>>h>>w,h) {
		for(int i=0;i<h;i++) {
			cin>>in;
			for(int j=0;j<w;j++) {
				data[i][j]=in[j];
				Istraveled[i][j]=false;
			}
		}
		solve(0,0);
	}
	return 0;
}

Measured memory_bytes: 1224
from sys import exit, stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
one = 0
four = 0
for a in A:
    if a % 4 == 0:
        four += 1
    elif a % 2 == 1:
        one += 1

ans = 'No'
if one + four == N:
    if four + 1 >= one:
        ans = 'Yes'
else:
    if four >= one:
        ans = 'Yes'
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 900000000000000004
signed main(void){
    int a,b,c;cin>>a>>b>>c;
    if(a+b+c>=22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}
        


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    a, b, c, d = [int(x) for x in input().split()]
    cd = c * d // gcd(c, d)
    x = ((b // c) - (a + c - 1) // c + 1)
    y = ((b // d) - (a + d - 1) // d + 1)
    z = ((b // cd) - (a + cd - 1) // cd + 1)
    print(b-a+1-(x+y-z))



        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""


Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int n; cin>>n;
    vector<ll> a(3), dp(3), new_dp(3);
    for(int i = 0 ; i < 3; i++)
      cin>>a[i];
    for(int i = 0 ; i < 3; i++)
      dp[i] = a[i];
    for(int i = 1; i < n; i++){
      for(int j = 0; j < 3; j++)
        cin>>a[j];
        
      for(int j = 0; j <3; j++){
        for(int k = 0; k <3 ; k++){
          if(j==k) continue;
          new_dp[k] = max(new_dp[k], dp[j]+a[k]);
        }
      }
      dp = new_dp;
      //new_dp = vector<ll> (3,0);
      new_dp.assign(3,0);
    }
    cout<<*max_element(dp.begin(),dp.end())<<endl;
    return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;


int main(){
    int N; cin >> N;
    vector<char> c(N);
    for(auto &x : c) cin >> x;
    int cnt=0;
    for(int i=0; i<N; i++){
        if(c[i] == 'R') cnt++;
    }
    int ans=0;
    for(int i=0; i<cnt; i++){
        if(c[i] == 'W') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int X;
  cin >> X;
  int answer = (2199 - X) / 200;
  cout << answer << endl;
  return 0;
}


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

using namespace std;

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

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

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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

int gcd(int a, int b){if (b == 0) return a; return gcd(b, a % b);}
int n,x;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>x;

    vl v(n);
    REP(i,n) cin>>v[i];
    sort(ALL(v));

    int mx = v[n-1];
    //int mn = v[0];
    int ans = abs(mx-x);
    REP(i,n){
        ans = gcd(ans,abs(v[i]-x));
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int H,W,N;
int a[201][201];
int A[201][201];
 
inline int calc(int h,int w,int H,int W){
  return A[H][W]-A[H][w]-A[h][W]+A[h][w];
}
 
bool solve(int h,int w,int H,int W,int N,int M){
  if(calc(h,w,H,W)<M*N)return false;
  if(N==1)return true;
  for(int i=h+1;i<H;i++){
    if(calc(h,w,i,W)<M)continue;
    if(solve(i,w,H,W,N-1,M))return true;
    break;
  }
  for(int j=w+1;j<W;j++){
    if(calc(h,w,H,j)<M)continue;
    if(solve(h,j,H,W,N-1,M))return true;
    break;
  }
  for(int i=H-1;i>h;i--){
    if(calc(i,w,H,W)<M)continue;
    if(solve(h,w,i,W,N-1,M))return true;
    break;
  }
  for(int j=W-1;j>w;j--){
    if(calc(h,j,H,W)<M)continue;
    if(solve(h,w,H,j,N-1,M))return true;
    break;
  }
  return false;
}
 
bool check(int nv,int sv,int M){
  int ev=0,wv=0;
  while(calc(0,0,wv,nv)<M){
    wv++;
    if(wv>=H)return false;
  }
  while(calc(0,nv,ev,W)<M){
    ev++;
    if(ev>=H)return false;
  }
  if(sv<nv)ev=max(ev,wv);
  if(sv>nv)wv=max(ev,wv);
  if(calc(wv,0,H,sv)<M)return false;
  if(calc(ev,sv,H,W)<M)return false;
  return true;
}
 
bool check(int M){
  if(N==4)
    for(int nv=1;nv<W;nv++)
      for(int sv=1;sv<W;sv++)
        if(check(nv,sv,M))return true;
  return solve(0,0,H,W,N,M);
}
 
int compute(){
  int L=0,R=200000001,M;
  while(R-L>1){
    M=(L+R)/2;
    if(check(M))L=M;
    else R=M;
  }
  return L;
}
 
int main(){
  scanf("%d %d %d",&H,&W,&N);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      scanf("%d",&a[i][j]);
      A[i+1][j+1]=a[i][j]+A[i+1][j]+A[i][j+1]-A[i][j];
    }
  }
  int ans=compute();
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 3540
s = input()

words = [w for w in s]

cnt = 0
for r in range(len(words) - 1):
    if words[r+1] == words[r]:
        if words[r+1] == '0':
            words[r+1] = '1'
        else:
            words[r+1] = '0'
        cnt += 1

print(cnt)

Measured memory_bytes: 9764
#include <stdio.h>

int main(void)
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
   
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
   
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
   
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}


Measured memory_bytes: 2108
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp

h,w = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows,cols = h,w

OK = "."
NG = "#"

ss = np.array([[c=="#" for c in input()] for _ in range(h)])
@njit((b1[:, :],i8,i8,i8,i8), cache=True)
def main(ss,ch,cw,dh,dw):
    inf = 1<<30
    start = ch*w+cw
    goal = dh*w+dw
    n = h*w
    seen = np.full(n, inf, np.int64)
    seen[start] = 0
    q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
    # dx = [0,1,0,-1]
    # dy = [1,0,-1,0]
#     dx = []
#     dy = []
#     vvs = []
#     for i in range(-2,3):
#         for j in range(-2,3):
#             if not (i==j==0):
#                 dx.append(i)
#                 dy.append(j)
#                 if abs(i)+abs(j)>1:
#                     vvs.append(1)
#                 else:
#                     vvs.append(0)
    while q:
#         print(seen)
        pnum,pu = hpp(q)
        ux,uy = divmod(pu,w)
        # print(pnum,divmod(pu,w))
        if pu==goal:
            break
        for xx in range(-2, 3):
            for yy in range(-2, 3):
                if xx==yy==0:
                    continue
                if abs(xx)+abs(yy)<=1:
                    vv = 0
                else:
                    vv = 1
#         for xx,yy,vv in zip(dx,dy,vvs):
    #         x = ux+xx
    #         y = uy+yy
                x,y = ux+xx, uy+yy
                u = x*w + y
                num = pnum+vv
                if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
                    continue
        #         print(x,y)
                if seen[u]>num:
                    seen[u] = num
                    hp(q,(num, u))
                
    val = seen[goal]
    if val==inf:
        return -1
    else:
        return val
print(main(ss,ch,cw,dh,dw))

Measured memory_bytes: 124168
#include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;

void printv(vvi v){
	for(int i = 0; i < v.size(); i++){
		for(int j = 0; j < v.size(); j++){
			cout << v[i][j] << " ";
		}cout << endl;
	}
		return ;
		}


signed main() {
	
	cin1(n);

	vi cake(n,0);
	rep(i,0,n) {
		cin1(cake[i]);	
	}

	vvi dp(n,vi(n,0));
	rep(i,0,n) {
		dp[i][i] = cake[i];
	}

	for (int i = 0; i < n; i++) { //??????
		for (int l = 0; l < n; l++) {
			int r = (l + i) % n;
			if ((n - i) % 2 == 0) { //????????????
				if (cake[l] > cake[r]) {
					dp[l][r] = dp[(l+1)%n][r];
				}else {
					dp[l][r] = dp[l][(r-1+n)%n];
				}
			}else { //????????????
				dp[l][r] = max(dp[(l+1)%n][r] + cake[l],dp[l][(r-1+n)%n] + cake[r]);
			}
		}
	}

	int ans = 0;
	rep(i,0,n) {
		ans = max(ans,dp[i][(i+n-1)%n]);
	}
	cout(ans);

	return 0;
}

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

#define ll long long int
#define db double
#define fl float
#define endl '\n'

#define mod (ll)(1000000007)
#define mod1 (ll)998242353
#define mod2 (ll)998244353
#define PI 3.1415926535897932384626433832795

#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pob pop_back

#define Sort(v) sort(v.begin(),v.end())
#define Sortd(v) sort(v.begin(),v.end(),greater<>())

#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;--i)
#define rf1(i,n) for(int i=n-1;i>=1;--i)
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repn(i,a,b) for(int i=a;i<=b;++i)

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;

//nC2
ll C2(ll n){
    ll ans= max(((n*(n-1))/2),(ll)0);
    return ans;
}
//square
ll sq(ll n){
    return n*n;
}

//GCD
ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    if(b==0){
        return a;
    }    
    else{
        return gcd(b,a%b);
    }
}

//sort pair by second values
bool sortsec(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.second < b.second); 
}


//Binary Exponentiation
ll BinExp(ll a, ll b, ll m){
    a%=m;
    ll res =1;
    while(b>0){
        if(b&1){
            res = (res * a)%m;
        }
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin>>n;
    ll a[n];
    f(i,n)cin>>a[i];
    ll ss[n]={0};
    ss[n-1]=a[n-1];
    rf(i,n-1){
        ss[i]=(ss[i+1]+a[i])%mod;
    }
    ll ans=0;
    f(i,n-1){
        ans=((a[i]*ss[i+1])%mod+ans)%mod;
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define scl(n) scanf("%lld", &n)
#define pcl(n) printf("%lld\n", n)
#define pcl1(n) printf("%lld ", n)
#define nln printf("\n")
#define dev(x) cout << #x << " " << x << " ";
#define PTT pair<ll, ll>

map<ll, ll> mp, mp1;
map<ll, ll>::iterator itr;

int main()
{
    ll t, n, x, y;
    scl(t);
    ll d;
    scl(d);
    d *= d;
    ll cnt = 0;
    while (t--)
    {
        scl(x);
        scl(y);
        n = (x * x) + (y * y);
        if (n <= d)
        {
            cnt++;
        }
    }
    pcl(cnt);
    return 0;
}

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

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
     // cout << ex << endl;

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    cin >> N;
    const auto &res = prime_factorize(N);
    long long ans = 0;
    for (auto p : res) {
        for (int i = 1; i < N+1; ++i){
          p.second -= i;
          //cout << p.second << endl;
          if(p.second < 0) break; 
          ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612