akhauriyash/Code-Regression huggingface dataset:
var stdin = require("fs").readFileSync("/dev/stdin", "utf8");
stdin = stdin.trim().split("\n").reverse();
function input(){return stdin.pop()}
var stdout = [];



var x = input().split(" ").map(n=>parseInt(n));
var a = x[0]
var b = x[1]
if (b % a){
    stdout.push(b - a)
}else{
    stdout.push(b + a)
}



stdout = stdout.join(" ");
console.log(stdout);

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

int main() {
  int N;
  cin >> N;
  
  int a[200];
  int cnt = 0;
  bool flag = true;
  int i;
  
  for(i = 0;i<N;i++){
	cin >> a[i];
  }
  
  while(flag){
  	for(i = 0;i<N;i++){
  		if(a[i]%2 == 0){
    		a[i] = a[i]/2;
   	 	}else{
    		flag = false;
          	break;
        }
    }
    if(flag){
      	cnt++;
      }
  }
  
  cout << cnt;
  
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  int64_t result = 0;
  for (int64_t divison = 1; divison * divison <= N; ++divison) {
    const int64_t m_1 = divison - 1;
    if (m_1 > 0 && (N / m_1) == (N % m_1)) {
      result += m_1;
    }
    const int64_t m_2 = N / divison - 1;
    if (m_2 > 0 && (N / m_2) == (N % m_2)) {
      result += m_2;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
S = input()
mod = 10 ** 9 + 7

dp = [[0] * 4 for i in range(len(S) + 1)]
dp[len(S)][3] = 1
for i in range(len(S) - 1, -1, -1):
    dp[i][3] += dp[i + 1][3] * 3 if S[i] == '?' else dp[i + 1][3]
    dp[i][3] %= mod

    for j in range(2, -1, -1):
        dp[i][j] += dp[i + 1][j] * 3 if S[i] == '?' else dp[i + 1][j]
        dp[i][j] += dp[i + 1][j + 1] if S[i] == 'ABC' [j] or S[i] == '?' else 0
        dp[i][j] %= mod

print(dp[0][0])


Measured memory_bytes: 27588
#力技
N = int(input())
n = len(str(N)) # 桁数
if n == 1:
    print(N)
elif n == 2:
    print(9)
elif n == 3:
    print(N-90)
elif n == 4:
    print(909)
elif n == 5:
    print(N-9090)
elif n == 6:
    print(90909)
else:
    None

Measured memory_bytes: 2940
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<int> a(n+1), b(n);
    for(int i=0; i<=n; i++) cin>>a[i];
    for(int i=0; i<n; i++) cin>>b[i];

    ll ans = 0;
    for(int i=0; i<n; i++){
        if(a[i] <= b[i]){
            ans += a[i];
            b[i] -= a[i];
            a[i] = 0;
        }
        else{
            ans += b[i];
            a[i] -= b[i];
            b[i] = 0;
        }

        if(a[i+1] <= b[i]){
            ans += a[i+1];
            b[i] -= a[i+1];
            a[i+1] = 0;
        }
        else{
            ans += b[i];
            a[i+1] -= b[i];
            b[i] = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
M(int*a){return*1[&a]-*a;};*s="%d %d %d %d %d\n";main(a,b,c,d,e){for(;~scanf(s,&a,&b,&c,&d,&e);printf(s,a,b,c,d,e))qsort(&a,5,4,M);}

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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String input = br.readLine();
		
		int rate = Integer.parseInt(input);
		int goal = Integer.parseInt(br.readLine());
		
		System.out.println(rate + (goal - rate) * 2);

	}

}


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

int main() {
	int a, b, c,x;
	cin >> a >> b >> c;
	if (a >= 1 && a <= 10000 && b >= 1 && b <= 10000 && c >= 1 && c <= 10000) {
		if (a > b) {
			x = b;
			b = a;
			a = x;
		}
		if (b > c) {
			x = c;
			c = b;
			b = x;
		}
		if (a > b) {
			x = b;
			b = a;
			a = x;
		}
		cout << a << " " << b << " " << c << endl;
	}
	else {
		cout << "error" << endl;
	}
}


Measured memory_bytes: 3096
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion

ll solver(string s)
{
	int l = s.size();
	ll dp[40][2][10];
	rep(i, 40)rep(j, 2)rep(k, 10)dp[i][j][k] = 0;
	for (int i = 1; i <= s[0] - '0'; ++i)
	{
		if (i < s[0] - '0')dp[1][1][i] = 1;
		else if (i == s[0] - '0')dp[1][0][i] = 1;
	}
	for (int i = 1; i < l; ++i)
	{
		int d = s[i] - '0';
		for (int j = 0; j < 2; ++j)
		{
			for (int k = 0; k <= 9; ++k)
			{
				for (int m = 0; m <= (j ? 9 : d); ++m)
				{
					if (abs(m - k) > 1)continue;
					dp[i + 1][j || (d > m)][m] += dp[i][j][k];
				}
			}
		}
	}
	ll res = 0;
	rep(i, 10)res += dp[l][0][i] + dp[l][1][i];
	return res;
}

int main()
{
	int k; cin >> k;
	ll dp[40][10];
	rep(i, 40)rep(j, 10)dp[i][j] = 0;
	for (int i = 1; i < 10; ++i)dp[1][i] = 1;
	for (int i = 1; i < 35; ++i)rep(j, 10)rep(k, 10)
	{
		if (abs(j - k) > 1)continue;
		dp[i + 1][j] += dp[i][k];
	}
	vector<ll> cnt(40);
	rep(i, 40)rep(j, 10)cnt[i] += dp[i][j];
	rep(i, 35)cnt[i + 1] += cnt[i];
	ll ok = 1e18, ng = 0;
	while (abs(ok - ng) > 1)
	{
		ll mid = abs(ok + ng) / 2;
		int d = to_string(mid).size() - 1;
		if (solver(to_string(mid)) + cnt[d] >= k)ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))

    total = 0
    for i in a:
        total ^= i
    
    ans = ""
    for i in a:
        ans += "{} ".format(total ^ i)
    print(ans)

if __name__ == "__main__":
    main()


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

typedef long double ld;
typedef long long lint;

#define PI 3.141592653589793238l

const int MAXN = 3010;

int T[MAXN];
ld X[MAXN], Y[MAXN];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, L;

	cin >> N >> L;
	for(int i = 0; i < N; i++) cin >> T[i];

	ld ansx = 0, ansy = 0;
	lint cnt = 0;
	for(int i = 0; i < N; i++) for(int j = i + 1; j < N; j++) {
		int k = (j - i - 1) - (N - j + i - 1);
		ansx += k * cos(PI * (T[i] + T[j]) / L);
		ansy += k * sin(PI * (T[i] + T[j]) / L);
		cnt += k;
	}
	cout << fixed;
	cout.precision(50);
	cout << ansx / cnt << " " << ansy / cnt << "\n";
	return 0;
}


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

int main() {
  int N , M , C , B[100], A[100][100];
  cin >> N >> M >> C;
  
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int value = C;
    for (int j = 0; j < M; j++) {
      value += (A[i][j]*B[j]);
    }
    if (value > 0) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


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

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

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

    if(N*A>=B){
        printf("%d\n",B);
    }else{
        printf("%d\n",N*A);
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int l = sc.nextInt();
      	int r = sc.nextInt();
		int d = sc.nextInt();
      	int kaisuu = 0;
      
        for(int count = l; count <= r; count++){
        	if(count % d == 0){
            	kaisuu+=1;
            }        
        }

			System.out.println(kaisuu);
		
	}
}

Measured memory_bytes: 35620
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define ll long long
#define fir first
#define sz(a) int((a).size())

int n;
int a[200005];

signed main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	ll cnt=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i>0)
		{
			if(a[i]<a[i-1])
			{
				cnt+=a[i-1]-a[i];
				a[i]=a[i-1];
			}
   			    
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 4400
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
#define Mx 1e10
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    	ll n,mn=0,mx=0,x,i,t=0,j=0,k=1e10;
    	set<ll>s;
    	cin>>n;
    	ll a[n],c[n],g[n];
    	f(i,n)
    	{
    	    cin>>a[i];
    	}
        sort(a,a+n);
        mn=a[0],mx=a[n-1];
        t=(mx+mn)/2;
        for(i=-100;i<=100;i++)
        {
            t=0;
            for(j=0;j<n;j++)
            {
                x=abs(i-a[j]);
                t+=x*x;
            }
            k=min(t,k);
        }
        cout<<k<<endl;
}







Measured memory_bytes: 3584
"""
B - Cakes and Donuts
ABC 洋菓子店では, 
1 個 4 ドルのケーキと 
1 個 7 ドルのドーナツが売られている.
このとき, 合計金額が N ドルとなる買い方はあるか, 判定せよ. 
ただし, 同じ商品を二個以上買っても良く,
 買わない商品があっても良いものとする. 
"""

N = int(input())

for a in range(0, N + 1, 4):
    if ((N - a) % 7) == 0:
        print("Yes")
        break
else:
    print("No")



Measured memory_bytes: 3060
n = int(input())
A = list(map(int, input().split()))
color = [0]*8
v = 0
for a in A:
    if a <400:
        color[0] += 1
    elif a <800:
        color[1] += 1
    elif a <1200:
        color[2] += 1
    elif a <1600:
        color[3] += 1
    elif a <2000:
        color[4] += 1
    elif a <2400:
        color[5] += 1
    elif a <2800:
        color[6] += 1
    elif a <3200:
        color[7] += 1
    else:
        v += 1
s = 0
for c in color:
    if c:
        s += 1
if s == 0:
    m = 1 # vのみの時がある!
else:
    m = s
print(m,  s+v) 

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//ll num[50];
//ll num2[50];
//ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;


int main(void)
{
    double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a;
        sum+=a;
    }
    cout<<(n>=sum?n-sum:-1);
    return 0;
}





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

const int maxn=2e5+10;
int a[maxn];
int b[maxn];

int n;

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",&a[i]);
    for(int i=0;i<n;++i) scanf("%d",&b[i]);
    int ans=0;
    for(int v=(1<<28);v;v>>=1){
        int tp=0;
        for(int i=0;i<n;++i){
            a[i]&=((v<<1)-1);
            b[i]&=((v<<1)-1);
        }
        sort(a,a+n);
        sort(b,b+n);
        for(int i=n-1;i>=0;--i){//枚举a
            int v1=lower_bound(b,b+n,v-a[i])-b;
            int v2=lower_bound(b,b+n,2*v-a[i])-b;
            int v3=lower_bound(b,b+n,3*v-a[i])-b;
//            while(j<n && a[i]+b[j]<v) j++;
//            while(k<n && a[i]+b[k]<2*v) k++;
//            while(l<n && a[i]+b[l]<3*v) l++;
            tp+=v2-v1+n-v3;
            tp&=1;
        }
        if(tp) ans|=v;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };


int dist[110][110];


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

	rep(i, 0, 110)rep(j, 0, 110) {
		dist[i][j] = INF;
		if (i == j)dist[i][j] = 0;
	}

	vector<vector<int>>edges;
	
	rep(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		dist[a][b] = c;
		dist[b][a] = c;
		edges.pb({a,b,c});
 	}

	rep(k, 0, n)rep(i, 0, n)rep(j, 0, n)dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);


	int cnt = 0;
	fore(e, edges) {
		if (dist[e[0]][e[1]] != e[2])cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <set>

using namespace std;

int main()
{
    int64_t h, w;
    int n;
    set<pair<int, int>> points;
    cin >> h >> w >> n;

    uint64_t result[10];
    for (int i = 0; i <= 9; i++)
    {
        result[i] = i == 0 ? (h - 2) * (w - 2) : 0;
    }
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;

        for (int i = -2; i <= 0; i++)
        {
            for (int j = -2; j <= 0; j++)
            {
                int x = a + i, y = b + j;
                if (x < 1 || x > h - 2 || y < 1 || y > w - 2)
                {
                    continue;
                }

                int num = 0;
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (points.find(make_pair(x + i, y + j)) != points.end())
                        {
                            num++;
                        }
                    }
                }
                result[num]--;
                result[num + 1]++;
            }
        }

        points.insert(make_pair(a, b));
    }

    for (int i = 0; i <= 9; i++)
    {
        cout << result[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4992
#include <utility>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>

using namespace std;
#define REP(i, n)  for(int i=0;i<(int)(n);++i)
#define FOR(i, b, n)  for(int i=b;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define PB(c) push_back(c)
#define SS size()
#define ST first
#define ND second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

vector<pii> m;
vvi cache;

int D;
int MX;

void fillIt(int off) {
    vi& line = cache[off];
    int x = off;
    int sum = 0;
    while(true) {
        line.PB(sum);
        int nx = x + D;
        if (nx>=MX) break;
        sum += abs(m[nx].ST-m[x].ST) + abs(m[nx].ND - m[x].ND);
        x = nx;
    }
//    for(int c : line) cout << c << " ";
//    cout << "----------\n";
}

int main() {
    ios::sync_with_stdio(0);

    int h, w; cin >> h >> w;
    cin >> D;
    MX = w * h;

    m = vector<pii>(h * w + 10);
    REP(r,h) REP(c,w) {
            int a; cin >> a; a--;
            m[a].ST = r;
            m[a].ND = c;
        }

    //fill cache
    cache = vvi(D,vi());
    REP(rem,D) fillIt(rem);
    cout << endl;
    int q; cin >> q;
    REP(i,q) {
        int L, R; cin >> L >> R; L--, R--;
        if (R==L) {cout << 0 << endl; continue; }
        int off = L % D;
        vi& line = cache[off];
        ll ans = line[R/D] - line[L/D];
        cout << ans << endl;
    }
}

Measured memory_bytes: 6144
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<queue>
#include<vector>
#include<cmath>
#include<ctime>
#include<locale>
using namespace std;
int main()
{
    long a,b,c,i,d,e,f;
    cin>>a>>b>>c;
    if((a==b&&b==c)&&(!(a%2==1||b%2==1||c%2==1)))cout<<-1;
    else
    {
        for(i=0;;i++)
        {
            if(a%2==1||b%2==1||c%2==1)break;
            d=(b+c)/2;
            e=(a+c)/2;
            f=(a+b)/2;
            a=d;
            b=e;
            c=f;
        }
        cout<<i;
    }
	return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 1005;
const int MAX_S = 10005;
int N;
struct Block {
  Block(int w = 0, int s = 0, int v = 0) : w(w), s(s), v(v) {}
  int w,s,v;
  void input()
  {
    cin >> w >> s >> v;
  }
  bool operator < (const Block &b) const {
    return s+w < b.s+b.w;
  }
};
Block blockList[MAX_N];

int dp[MAX_N][MAX_S];

signed main()
{
  cin >> N;
  REP(n,N) {
    blockList[n].input();
  }

  sort(blockList, blockList+N);

  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;

  int ans = 0;
  REP(n,N) {
    REP(w,MAX_S) {
      if(dp[n][w] < 0) continue;
      dp[n+1][w] = max(dp[n+1][w], dp[n][w]);
      if(w <= blockList[n].s) {
        ans = max(ans, dp[n][w] + blockList[n].v);
        if(w + blockList[n].w < MAX_S) {
          dp[n+1][w + blockList[n].w] = dp[n][w] + blockList[n].v;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 78848
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    if(A*N<=B){
        cout << N*A << endl;
    }
    else cout << B << endl;

    return 0;
}

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


# number_to_prime[i]: i の最小の素因数, iが素数ならば0
number_to_prime = [0] * (10**6 + 1)

# preprocess
for i in range(2, 10**6+1):
    if not number_to_prime[i]:
        j = 1
        while j*i <= 10**6:
            number_to_prime[j*i] = i
            j += 1

def is_pair_copr(A):
    import numpy as np
    U = 1 << 20
    div_p = np.arange(U)
    for p in range(2, U):
        if div_p[p] != p:
            continue
        div_p[p::p] = p
    used = np.zeros(U, np.bool_)
 
    for x in A:
        while x > 1:
            p = div_p[x]
            while x % p == 0:
                x //= p
            if used[p]:
                return False
            used[p] = True
    return True

def is_pairwise():
    used_primes = set()
    pairwise_flag = 1
    for a in A:
        curr_primes = set()
        while a > 1:
            prime = number_to_prime[a]
            curr_primes.add(prime)
            a //= prime
        if used_primes & curr_primes:
            pairwise_flag = 0
            break
        else:
            used_primes = used_primes | curr_primes
    return pairwise_flag

def is_setwise(*A):
    import math
    from functools import reduce

    return reduce(math.gcd, A) == 1

if is_pair_copr(A):
    print("pairwise coprime")
elif is_setwise(*A):
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 127544
// 単一始点最短経路 ( ダイクストラ法 : 優先度付きキュー )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

static const int MAX_N = 10000;
static const int INFTY = (1 <<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

class q_element
{
    public:
        // 各頂点のNo.と経路の値
        int vertex_num;
        int vertex_val;

        // コンストラクタ
        q_element(int a, int b)
        {
            vertex_num = a;
            vertex_val = b;
        };
};

// ">" のオーバーロード [ receive_val ] を基準に大小比較を行う
bool operator> (const q_element &q_element_1, const q_element &q_element_2)
{
    return q_element_1.vertex_val > q_element_2.vertex_val;
};

// q_elementクラスのオブジェクトを昇順にするためのキューの定義
std::priority_queue< q_element,
                     std::vector<q_element>,
                     std::greater<q_element> > pqEle;

// 隣接リストを作成する ( 頂点と重みの情報を格納する )
vector<q_element> v_Link[MAX_N + 1];

int n;

// ダイクストラ法を実施するメソッド( 優先度付きキュー )
int Dijkstra_priority_queue(int start_v);

int main(void)
{

    cin >> n;

    int k, c, u, v;
    q_element q_entity(0, 0);

    for(int i = 0; i < n; i++)
    {
        cin >> u >> k;

        for(int j = 0; j < k; j++)
        {
            cin >> v >> c;

            // 隣接リストの作成 ( 頂点と重みを設定する )
            q_entity.vertex_num = v;
            q_entity.vertex_val = c;

            v_Link[u].push_back(q_entity);
        }
    }

    // 優先度付きキューを用いたダイクストラ法
    Dijkstra_priority_queue(0);

    return 0;

}

// 優先度付きキューを用いたダイクストラ法を実施するメソッド
// start_v : スタートする頂点のNo.
int Dijkstra_priority_queue(int start_v)
{
    int u, v, minv;
    int d[MAX_N], p[MAX_N], color[MAX_N];

    for(int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    // 初期値の設定 ( 頂点 : 0 を開始点とする)
    d[start_v] = 0;
    color[start_v] = GRAY;
    // キューに要素を入れる
    pqEle.push( q_element(0, 0) );

    while( !pqEle.empty() )
    {

        // 最小の値を持つ頂点を取り出す ( キューの先頭 )
        u = pqEle.top().vertex_num;
        minv = pqEle.top().vertex_val;
        pqEle.pop();

        // 訪問完了
        color[u] = BLACK;

        for(int v_num = 0; v_num < v_Link[u].size(); v_num++)
        {
            // 隣接リストから接続している要素を取得する
            v = v_Link[u][v_num].vertex_num;

            if( color[v] != BLACK )
            {
                // u → v の経路の中で, vのコストが最小のものが見つかれば更新する
                if( d[v] > d[u] + v_Link[u][v_num].vertex_val )
                {
                    // コストの記録
                    d[v] = d[u] + v_Link[u][v_num].vertex_val;
                    // 頂点 v の親を記録する
                    p[v] = u;
                    // 訪問状態の記録
                    color[v] = GRAY;

                    // キューに要素を入れる
                    pqEle.push( q_element(v, d[v]) );
                }
            }
        }
    }

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }

    return 0;
}



Measured memory_bytes: 7728
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;

int main(){

        char abc[3] = {};
        string S;
        cin >> S;
        rep(i,3) abc[S[i]-'a']++;
        string ans = "Yes";
        rep(i,3) if(abc[i]==0) ans="No";
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define print(x) cout << (x) << '\n'
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define all(v) (v).begin(), (v).end
#define fi first
#define se second

string solve(int n){
  if (n == 0) return "0";
  string ans = "";
  while (n != 0){
    if (n % 2 == 0){
      ans += "0"; 
    }
    else {
      ans += "1"; --n;
    }
    n /= -2;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}

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

  int n; cin >> n;
  string s = solve(n);
  print(s);

  return 0;
}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K=MI()
    have = set()
    for i in range(K):
        _ = I()
        for x in LI():
            have.add(x)
    print(N-len(have))
if __name__ == '__main__':
    main()

Measured memory_bytes: 78268
N,W=map(int,input().split())

dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
    w,v=map(int,input().split())
    for j in range(W+1):
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])
        if j+w<=W:
            dp[i+1][j+w]=dp[i][j]+v

out=0
for i in range(W+1):
    out=max(out,dp[N][i])
print(out)

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

typedef pair<int, int> pr;

#define N 100005

#define inf 0x3f3f3f3f

int n;

vector<pr> to[N];

array<int, N> dis;

signed main(void)
{
	cin >> n;
	
	for (int i = 1; i < n; ++i)
	{
		int x, y, w;
		cin >> x >> y >> w;
		
		to[x].push_back(make_pair(y, w));
		to[y].push_back(make_pair(x, w));
	}
	
	memset(begin(dis), inf, sizeof(dis));
	
	queue<int> que; que.push(0); dis[0] = 0;
	
	while (!que.empty())
	{
		int u = que.front(); que.pop();
		
		for (auto e : to[u])
		{
			int v = e.first;
			int w = e.second;
			
			if (dis[v] > dis[u] + w)
				dis[v] = dis[u] + w, que.push(v);
		}
	}
	
	int newStart = 0;
	
	for (int i = 1; i < n; ++i)
		if (dis[i] > dis[newStart])
			newStart = i;
			
	memset(begin(dis), inf, sizeof(dis));
			
	que.push(newStart); dis[newStart] = 0;
	
	while (!que.empty())
	{
		int u = que.front(); que.pop();
		
		for (auto e : to[u])
		{
			int v = e.first;
			int w = e.second;
			
			if (dis[v] > dis[u] + w)
				dis[v] = dis[u] + w, que.push(v);
		}	
	}
	
	int maxi = 0;
	
	for (int i = 0; i < n; ++i)
		maxi = max(maxi, dis[i]);
		
	cout << maxi << endl;
}

Measured memory_bytes: 9776
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  for(int i=1;i<n;i++){
    if(a[i]==a[i-1])
      c++;
  }
  cout<<n-(c+1)/2*2;
}

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

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

    if(A==B && A!=C || A==C && B!=A || B==C && A!=B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define maxn 10000005
#define inf 2000000000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
const double PI = acos(-1);
using namespace std;

string s,t,ls; int n,m;
int hs[maxn]; int fmul[maxn];
int base = 31;
int Hash (int l, int r){
	//cout<<l<<' '<<r<<'\n';
	int val = hs[r]-hs[l-1]*fmul[r-l+1];
	val%=mod; val=(val+mod)%mod;
	return val;
}
bool ok (int x){
	string lt; int i,j;
	if (m*x > ls.size()) return false;
	for (i=1;i<=x;i++){
		lt+=t;
	}
	int hlt=0;
	for (i=0;i<lt.size();i++){
		hlt=hlt*base+lt[i]-96; hlt%=mod;
	}
	for (i=0;i<=ls.size()-lt.size();i++){
		int val = Hash(i,i+lt.size()-1);
		if (val==hlt) return true;
	}
	return false;
}
int binsTnum(int lo,int hi){
	int daps=0;
	while (lo<=hi){
		int mid=(lo+hi)/2;
		if (ok(mid)){
			daps=max(daps,mid);
			lo=mid+1;
		}
		else hi=mid-1;
	}
	return daps;
}

main(){
	ios::sync_with_stdio(false); cin.tie(0); srand(time(NULL));
	//freopen("inp.txt","r",stdin); //freopen("out.txt","w",stdout);
	//freopen(".inp","r",stdin); freopen(".out","w",stdout);
	cin>>s>>t; n=s.size(); m=t.size();
	int i,j,k;
	ls = s+s+s;
	while (ls.size()<=t.size()) ls+=s;
	fmul[0]=1; for(i=1;i<maxn;i++) fmul[i]=(fmul[i-1]*base)%mod;
	
	hs[0]=ls[0]-96;
	for (i=1;i<ls.size();i++){
		hs[i]=hs[i-1]*base+ls[i]-96;
		hs[i]%=mod;
	}
	int ans1= binsTnum(1,ls.size());
	ls=ls+ls+ls;
	hs[0]=ls[0]-96;
	for (i=1;i<ls.size();i++){
		hs[i]=hs[i-1]*base+ls[i]-96;
		hs[i]%=mod;
	}
	int ans2=binsTnum(1,ls.size());
	//cout<<ans1<<' '<<ans2<<'\n';
	if (ans1==ans2){
		cout<<ans1; return 0;
	}
	else{
		cout<<-1; return 0;
	}
	
	
}

Measured memory_bytes: 134552
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } 
ll ans[2000];
int main(){
  int n;
  string s;
  cin >> n >> s;
  int ca = 0;
  int cb = 0;
  rep0(i,n){
      if(s[i] == 'R')ca++;
      else cb++;
  }
  cout << (ca > cb ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
from fractions import gcd

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

lgcd, rgcd = [], []
for i in range(n):
    if i == 0:
        lgcd.append(a[0])
        rgcd.append(a[n-1])
        continue

    lgcd.append(gcd(lgcd[i-1], a[i]))
    rgcd.append(gcd(rgcd[i-1], a[-1-i]))

maxgcd = 1
for i in range(n):
    if i == 0:
        tempgcd = rgcd[n-2]
    elif i == n-1:
        tempgcd = lgcd[n-2]
    else:
        tempgcd = gcd(lgcd[i-1], rgcd[n-2-i])
    maxgcd = max(maxgcd, tempgcd)
print(maxgcd)


Measured memory_bytes: 16160
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;



int main(){
    int D;
    
    cin >> D;
    
    if (D==22) cout << "Christmas Eve Eve Eve" << endl;
    if (D==23) cout << "Christmas Eve Eve" << endl;
    if (D==24) cout << "Christmas Eve" << endl;
    if (D==25) cout << "Christmas" << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<cstdlib>

using namespace std;

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


int main(){
    int n, x, y;
    cin >> n >> x >> y;
    int d;
    int num[n];
    rep(i, n) num[i] = 0;
    for (int i = 1; i < n; i++){
        for (int j = i + 1; j <= n; j++){
            d = min(abs(j - i), min(abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j)));
            // cout << d << endl;
            num[d]++;
        }
    }
    rep(i, n - 1){
        cout << num[i+1] << endl; 
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
using namespace std;
int x[32768],y[32768];
long long w[8][32768];
int tp[32768];
struct node{
	int wz;
	long long w;
	bool operator<(node b) const
	{
		return w<b.w;
	}
};
priority_queue<node> q[8][8];
int s=0;
void change(int wz)
{
	node u;
	u.wz=wz;
	if(wz<s)
	{
		for(int i=0;i<5;i++)
		{
			if(i==tp[wz])
			{
				continue;
			}
			u.w=w[i][wz]-w[tp[wz]][wz];
			q[tp[wz]][i].push(u);
		}
	}
	else
	{
		for(int i=1;i<=5;i++)
		{
			if(i==tp[wz])
			{
				continue;
			}
			u.w=w[i][wz]-w[tp[wz]][wz];
			q[i][tp[wz]].push(u);
		}
	}
}
queue<int> qq;
long long d[8];
bool vis[8];
int pre[8],preid[8];
void spfa()
{
	for(int i=0;i<=5;i++)
	{
		d[i]=-1000000000000000LL;
	}
	d[0]=0;
	vis[0]=true;
	qq.push(0);
	while(!qq.empty())
	{
		int u=qq.front();
		qq.pop();
		vis[u]=false;
		for(int i=0;i<=5;i++)
		{
			if(q[u][i].empty())
			{
				continue;
			}
			node __=q[u][i].top();
			if(d[u]+__.w>d[i])
			{
				d[i]=d[u]+__.w;
				pre[i]=u;
				preid[i]=__.wz;
				if(!vis[i])
				{
					vis[i]=true;
					qq.push(i);
				}
			}
		}
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	n<<=1;
	while(n--)
	{
		int xx,yy,cc;
		scanf("%d%d%d",&xx,&yy,&cc);
		while(cc--)
		{
			x[s]=xx;
			y[s]=yy;
			s++;
		}
	}
	s>>=1;
	for(int i=s;i<s+s;i++)
	{
		x[i]=-x[i];
		y[i]=-y[i];
	}
	for(int i=0;i<s+s;i++)
	{
		w[1][i]=x[i]+y[i];
		w[2][i]=x[i]-y[i];
		w[3][i]=y[i]-x[i];
		w[4][i]=-x[i]-y[i];
		if(i>=s)
		{
			tp[i]=5;
		}
	}
	for(int i=0;i<s+s;i++)
	{
		change(i);
	}
	long long ans=0;
	while(1)
	{
		for(int i=0;i<=5;i++)
		{
			for(int j=0;j<=5;j++)
			{
				while(!q[i][j].empty())
				{
					node u=q[i][j].top();
					if((u.wz<s&&tp[u.wz]==i)||(u.wz>=s&&tp[u.wz]==j))
					{
						break;
					}
					q[i][j].pop();
				}
			}
		}
		spfa();
		if(d[5]<0)
		{
			break;
		}
		ans+=d[5];
		for(int i=5;i!=0;i=pre[i])
		{
			if(preid[i]>=s)
			{
				tp[preid[i]]=pre[i];
			}
			else
			{
				tp[preid[i]]=i;
			}
			change(preid[i]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4980
#include <iostream>
#include <vector>
#include <stack>
#include <utility>
using namespace std;
typedef long long ll;
int N;
pair<ll, ll> nums[10000];
pair<ll, ll> ans;

int main(void) {
    // insert code here...
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> nums[i].first;
        cin >> nums[i].second;
    }
    
    ans.first = nums[0].first;
    ans.second = nums[0].second;
    
    for(int i = 1; i < N; i++){
        ll a, b;
        if(ans.first % nums[i].first == 0){
            a = ans.first / nums[i].first;
        }else{
            a = ans.first / nums[i].first + 1;
        }
        
        if(ans.second % nums[i].second == 0){
            b = ans.second / nums[i].second;
        }else{
            b = ans.second / nums[i].second + 1;
        }
        
//        ans.first = nums[i].first * a;
//        ans.second = nums[i].second * b;
        
        if(a < b){
            ans.first = nums[i].first * b;
            ans.second = nums[i].second * b;
        }else{
            ans.first = nums[i].first * a;
            ans.second = nums[i].second * a;
        }
        
    }
    
    cout << ans.first + ans.second << endl;
    
    return 0;
}


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

bool isGood(vector<set<long long> > &G, vector<long long> &path){
    bool isValid = true;
    for(int i =0; i< path.size()-1; i++) {
        if(!G[path[i]].count(path[i+1])) isValid = false;
    }
    return isValid;
}

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b){
    vector<set<long long> > G(N);
    vector<long long> path(N);
    for(int i=0; i< M; i++){
        G[a[i]-1].insert(b[i]-1);
        G[b[i]-1].insert(a[i]-1);
    }
    for(int i=0; i< N; i++){
        path[i] = i;
    }
    long long count = 0;
    do{
        if(isGood(G, path)) count ++;
    } while (next_permutation(path.begin()+1, path.end()));
    cout << count << endl;

}

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


Measured memory_bytes: 256
def shurui(s):
	m=set(s)
	ans=[]
	for i in m:
		ans.append(s.count(i))
	return sorted(ans)

def resolve():
	s=input()
	t=input()
	if shurui(s)==shurui(t):
		print('Yes')
	else:
		print('No')
resolve()

Measured memory_bytes: 62172
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define ALL(X) X.begin(), X.end()
#define SZ(A) int((A).size())
#define RALL(X) X.rbegin(), X.rend()
#define FOR(B) for (size_t i = 0; i < B; i++)
#define FOR2(B) for (size_t j = 0; j < B; j++)
#define FORE(B) for (size_t i = 1; i <= B-1; i++)
#define FORC(A, B) for (size_t i = A; i < B; i++)
#define PRINT(X) cout << X << endl
#define PRINTALL(E, X) { FOR(X) {cout << E[i] << endl; } }
#define PRINTSIDE(E, X) { FOR(X) {cout << E[i] << " ";} }
#define READALLI(V, N) FOR(N) {int x; cin >> x; V.push_back(x); }
#define READALL(V, N) FOR(N) {LL x; cin >> x; V.push_back(x); }
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXN 100000
#define SQRSIZE  317
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<LL>VL;
typedef vector<PII> VPII;
typedef map<int, int> MII;
typedef map<char, int>MCI;
typedef map<string, int> MSI;
typedef set<int> SI;
const int INF = (1 << 30);

VL allDivisors(LL n){
	VL result;
	for(LL q = 1; q <= n; q++){
		if(n % q == 0)
			result.push_back(q);
	}
	return result;
}

int main () {
	int n = 0;
	LL pos = 0;
	cin >> n >> pos;
	VL distances;
	FOR(n){
		LL x = 0, distance = 0;
		cin >> x;
		distance = abs(x - pos);
		distances.push_back(distance);
	}
	sort(distances.begin(), distances.end());
	if(distances.size() == 1){
		cout << distances[0] << endl;
	}else{
		VL divisors = allDivisors(distances[0]);
		LL answer = 0;
		bool notTheOne = false;
		LL possible = 0;
		for(int z = 0; z < divisors.size(); z++){
			for(int q = 0; q < distances.size(); q++){
				if(distances[q] % divisors[z] != 0){
					q = distances.size();
					notTheOne = true;
				}
				possible = divisors[z];
			}
			if(!notTheOne){
				answer = possible;
			}
			notTheOne = 0;
		}
		cout << answer << endl;
	}
	return 0;
}

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

const int MAX = 310000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

// 二項係数計算
long long COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  COMinit(); //前処理
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  ll ans=0;
  for(int i=b;i<w;i++){
    ans+=COM(h-a-1+i,i)*COM(a+w-i-2,w-i-1);
    ans%=MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7552
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    string s;
    cin >> s;

    int n = (int)s.size();
    int ans = 0;
    rep(i, n >> 1){
        ans += s[i] != s[n + ~i];
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    string s, t, ans; cin >> s >> t;
    for(int i = 0; i < n; i++) {
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<malloc.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, a[2000200], b[2000200], c[10100];

void countingsort(int k){
    for(int i = 0; i < N; i++){
        c[a[i]]++;
    }
    for(int i = 1; i <= k; i++){
        c[i] += c[i - 1];
    }
    for(int i = N - 1; i >= 0; i--){
        b[c[a[i]]] = a[i];
        c[a[i]]--;
    }
}

signed main(){
    cin >> N;
    int k = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        k = max(k, a[i]);
    }
    countingsort(k);
    for(int i = 0; i < N; i++){
        cout << b[i + 1] << ((i == N - 1) ? "\n" : " ");
    }

    return 0;
}

/*

*/


Measured memory_bytes: 34384
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int main() {
    int N;
    cin >> N;
    map<string, int> m;
    rep(i, 0, N) {
        string a;
        cin >> a;
        m[a]++;
    }
    vector<string> v;
    int mm = 0;
    for(auto t : m) {
        if(mm < t.second) {
            mm = t.second;
        }
    }
    for(auto t : m) {
        if(mm == t.second) {
            v.push_back(t.first);
        }
    }
    sort(v.begin(), v.end());

    rep(i, 0, v.size()) { cout << v[i] << endl; }
}


Measured memory_bytes: 26868
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 2e5 + 7;

struct segm_tree
{
    int t[4 * N];
    int ind[4 * N];

    void build(int v, int l, int r, const vector <int> &a)
    {
        if (r - l == 1)
        {
            t[v] = a[l];
            ind[v] = l;
        }
        else
        {
            int m = (l + r) / 2;
            build(v * 2 + 1, l, m, a);
            build(v * 2 + 2, m, r, a);
            if (t[v * 2 + 1] < t[v * 2 + 2])
            {
                t[v] = t[v * 2 + 1];
                ind[v] = ind[v * 2 + 1];
            }
            else
            {
                t[v] = t[v * 2 + 2];
                ind[v] = ind[v * 2 + 2];
            }
        }
    }

    pair <int, int> get(int v, int l, int r, int tl, int tr)
    {
        if (tl >= r || tr <= l)
        {
            return {1e9, -1};
        }
        if (tl >= l && tr <= r)
        {
            return {t[v], ind[v]};
        }
        else
        {
            int tm = (tl + tr) / 2;
            return min(get(v * 2 + 1, l, r, tl, tm), get(v * 2 + 2, l, r, tm, tr));
        }
    }
    
    segm_tree()
    {
    }
};

segm_tree t[2];
int n;
int arr[N];
vector <int> ans;

set <pair <pair <int, int>, pair <int, int> > > e;

pair <int, int> find_splits(int l, int r)
{
    int p = l % 2;
    int op = p ^ 1;
    auto a = t[p].get(0, l, r + 1, 0, n);
    int ind = a.second;
    auto b = t[op].get(0, ind + 1, r + 1, 0, n);
    int jnd = b.second;
    return {ind, jnd};
}

void add_segment(int l, int r)
{
    if (l > r)
    {
        return;
    }
    auto a = find_splits(l, r);
    int x = a.first, y = a.second;
    e.insert({{arr[x], arr[y]}, {l, r}});
}

void upd()
{
    auto it = e.begin();
    int l = it->second.first, r = it->second.second;
    auto g = find_splits(l, r);
    add_segment(l, g.first - 1);
    add_segment(g.first + 1, g.second - 1);
    add_segment(g.second + 1, r);
    ans.push_back(it->first.first);
    ans.push_back(it->first.second);
    e.erase(it);
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    scanf("%d", &n);
    vector <int> p0(n, 1e9), p1(n, 1e9);
    int x = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &x);
        if (i % 2 == 0)
        {
            p0[i] = x;
        }
        else
        {
            p1[i] = x;
        }
        arr[i] = x;
    }
    t[0].build(0, 0, n, p0);
    t[1].build(0, 0, n, p1);
    add_segment(0, n - 1);
    while (!e.empty())
    {
        upd();
    }
    for (int c : ans)
    {
        printf("%d ", c);
    }
    puts("");
}


Measured memory_bytes: 18676