akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    ll a;
    const ll MOD=1e9+7;
    modint(ll a_=0){
        a=((a_%MOD)+MOD)%MOD;
    }
    modint inv()const{
        ll n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y(a+x.a);
        return y;
    }
    modint operator-(const modint& x){
        modint y(a-x.a);
        return y;
    }
    modint operator*(const modint& x){
        modint y(a*x.a);
        return y;
    }
    modint operator/(const modint& x){
        return *this * x.inv();
    }
    modint& operator+=(const modint& x){
        *this=*this+x;
        return *this;
    }
    modint& operator-=(const modint& x){
        *this=*this-x;
        return *this;
    }
    modint& operator*=(const modint& x){
        *this=*this*x;
        return *this;
    }
    modint& operator/=(const modint& x){
        *this=*this/x;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    ll a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(ll a,ll b){
    modint n(1),A(a);
    while(b){
        if(b&1) n*=A;
        A*=A;
        b>>=1;
    }
    return n;
}

vector<vector<vector<modint>>> dp;
vector<vector<vector<bool>>> vis;
modint rec(int i,int j,int k){
    //cout<<i<<" "<<j<<" "<<k<<endl;
    if(j<0||j>i||k<0) return 0;
    if(i==0){
        if(j==0&&k==0) return 1;
        else return 0;
    }
    if(vis[i][j][k]) return dp[i][j][k];
    vis[i][j][k]=1;
    return dp[i][j][k]=rec(i-1,j-1,k-2*j)+rec(i-1,j,k-2*j)*(2*j+1)+rec(i-1,j+1,k-2*j)*(j+1)*(j+1);
}

class FPermutationOddness {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k;
        in>>n>>k;
        dp.resize(n+1,vector<vector<modint>>(n+1,vector<modint>(k+1)));
        vis.resize(n+1,vector<vector<bool>>(n+1,vector<bool>(k+1)));
        out<<rec(n,0,k)<<endl;
    }
};

int main() {
    FPermutationOddness solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 104064
/*
    In the name of Allah

    MohammadErfan Gooneh

*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
    ll a , b , c , d ;
    cin >> a >> b >> c >> d ;
    if(abs(a-c) <= d || (abs(a-b)<=d && abs(b-c) <=d))cout <<"Yes" ; 
    else cout << "No" ; 




















return 0 ;
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int n = (int)s.size();
    vector<vector<int>> positions(26);
    s += s;
    for (int i = 0; i < s.size(); i++) {
        positions[s[i] - 'a'].push_back(i + 1);
    }

    long long res = 0, temp = 0;
    for (int i = 0; i < t.size(); i++) {
        int c = t[i] - 'a';
        if (positions[c].empty()) {
            cout << -1 << endl;
            return 0;
        }

        int pos = *upper_bound(positions[c].begin(), positions[c].end(), temp);
        temp = pos;
        if (temp >= n) {
            res += n;
            temp -= n;
        }
    }

    res += temp;
    cout << res << endl;

    return 0;
}

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

diff = [0] * (N)
diffsum = 0
for i in range(N):
    diff[i] = A[i] - B[i]
    diffsum += diff[i]
if diffsum < 0:
    print("-1")
    exit()
diff.sort()
count = 0
sumn = 0
for i in range(N):
    if diff[i] < 0:
        count += 1
        sumn -= diff[i]
    else:
        break
for j in range(N)[::-1]:
    if sumn > 0:
        count += 1
        sumn -= diff[j]
print(count)

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

ll dp[101][100001] = {0};

int main() {
    int n, capacity;
    cin >> n >> capacity;
    vector<int> w(n+1);
    vector<int> v(n+1);
    for (int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= capacity; j++) {
            if (j < w[i]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
        }
    }
    cout << dp[n][capacity] << endl;
    return 0;
}

Measured memory_bytes: 78336
n = int(input())
#n, k = map(int, input().split())
al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]


def color(rate):
    c = rate//400
    return min(8, c)


dic = {i: 0 for i in range(9)}

for a in al:
    dic[color(a)] = dic[color(a)]+1

count = 0
for i in range(8):
    if dic[i] != 0:
        count += 1

mn = count
mx = count
if dic[8] != 0:
    if count>=1:
        mx = mn+dic[8]
    else:
        mn=1
        mx=dic[8]

print(mn, mx)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
 
const long long MOD = 1e9 + 7;
const long long MAX = 1e6 + 10;
long long fact[MAX + 1] = {0};
 
void fact_init(){
    for(long long i = 1;i <= MAX;i++){
        fact[i] = (fact[i - 1] * i % MOD) % MOD;
    }
}
 
long long repeat_fact(long long N,long long P){
    if(P == 0) return 1;
    if(P % 2 == 0){
        long long t = repeat_fact(N,P/2);
        return (t%MOD * t % MOD ) % MOD;
    }else return (N%MOD * repeat_fact(N,P-1)) %MOD;
}
 
void solve(long long X, long long Y){
    long long a = (X + Y) / 3;
    long long x = X - a;
    long long y = Y - a;
    if(x >= 0 and y >= 0){
        long long fact1 = fact[x + y];
        long long fact2 = repeat_fact(fact[x],MOD - 2);
        long long fact3 = repeat_fact(fact[y],MOD - 2);
        long long ans = ((fact1 * fact2) % MOD * fact3) % MOD;
        cout << ans << endl;
        return;
    }else{
        cout << 0 << endl;
    }
}
 
// Generated by 1.1.6 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(){
    fact[0] = 1;
    fact_init();
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    if((X + Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    solve(X, Y);
    return 0;
}

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

int main() {
    int64_t N, A, B;
    cin >> N >> A >> B;
    int64_t c = N / (A + B);
    int64_t ans = c * A;
    N %= (A + B);
    ans += min(A, N);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

ll dp[100005][13];
void solve(){
  string s;
  cin>>s;
  int n=s.size();
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  rep(i,n){
    rep(j,13){
      if(s[i]=='?'){
        rep(k,10){
          dp[i+1][(j*10+k)%13]+=dp[i][j];
          dp[i+1][(j*10+k)%13]%=mod;
        }
      }
      else {
        int m=s[i]-'0';
        dp[i+1][(j*10+m)%13]+=dp[i][j];
        dp[i+1][(j*10+m)%13]%=mod;
      }
    }
  }
  cout<<dp[n][5]<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 10704
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int Z = sc.nextInt();
    int i =0;
    while ((Y + Z) * i +Z <= X) i++;
    System.out.println(i-1);
  }
}

Measured memory_bytes: 22868
n, m = map(int, input().split())
mod = 10**9+7
nums = 5*(10**5) 
 
g1, g2, inverse = [1, 1] , [1, 1], [0, 1]
 
for num in range(2, nums + 1):
    g1.append((g1[-1] * num) % mod)
    inverse.append((-inverse[mod % num] * (mod//num)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)
    
def nPr(n, r):
    return g1[n] * g2[n-r] % mod
 
def nCr(n, r):
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
ans = 0
for r in range(n+1):
    tmp = nCr(n, r)*nPr(m, r)*(nPr(m-r, n-r)**2)%mod
    ans = (ans+(-1)**r*tmp)%mod
print(ans)

Measured memory_bytes: 68672
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let a = get!(String);
    let mut map = BTreeMap::new();
    let n = a.len();
    for e in a.chars() {
        *map.entry(e).or_insert(0) += 1;
    }

    let mut sum = 0;
    for (_, v) in map {
        sum += v*(v-1)/2;
    }
    println!("{}", n*(n-1)/2+1-sum);
}


Measured memory_bytes: 8572
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int a;
	cin>>a;
	int b;
	cin>>b;
	int c;
	cin>>c;
	int d;
	cin>>d;
	int P;
	cin>>P;
	cout<<min(a*P,b+(P<c?0:d*(P-c)))<<endl;	
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

int main() {
  string S;
  cin >> S;
   
  if (S.size() != 6) {
    cout << "No" << endl;
  }
  else if (S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D): s.append(list(map(int,input().split())))
t = []
late = [-1] * 26
for i in range(D):
    maximum = 0
    maxs = 0
    for j in range(26):
        if maximum < s[i][j] + c[j] * (i - late[j]):
            maxs = j
            maximum = s[i][j] + c[j] * (i - late[j])
    late[maxs] = i
    print(maxs + 1)

    t.append(s[i].index(min(s[i])) + 1)


Measured memory_bytes: 68572
require 'pp'
N,K = readline.chomp.split.map(&:to_i)
ai = readline.chomp.split.map(&:to_i)
if K == 0
  puts ai.inject(:+)
  exit
end

nbit = Math.log2(K).floor+1
bits = Array.new(nbit)
nhalf = N.to_f / 2
nbit.times do |b|
  mask = 2**b
  n1 = ai.map {|a| a&mask }.count {|x| x > 0 }
  if n1 > nhalf
    bits[b] = 0
  elsif n1 < nhalf
    bits[b] = 1
  elsif n1 == N/2
    bits[b] = 0
  end
end

def to_x(bs)
  x = 0
  bs.each_with_index do |b,i|
    x += 2**i*b
  end
  x
end

x = to_x(bits)
if x > K
  nbit.times do |b|
    b1 = (nbit-b-1)
    mask = 2**b1
    if K&mask==0 and x&mask > 0
      x = x^mask
    end
    break if x <= K
  end
end
# pp x
puts ai.map {|a| a ^ x }.inject(:+)



Measured memory_bytes: 26928
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e6;
int unip[max_n],unir[max_n];
void init(int n){
  for(int i=0 ; i<n ; i++){
    unip[i] = i;
    unir[i] = 0;
  }
}
int find(int x){
  if(unip[x] == x){
    return x;
  }else{
    return unip[x] = find(unip[x]);
  }
}
void unite(int x, int y){
  x = find(x);  y = find(y);
  if(unip[x] == unip[y]){
    return;
  }
  if(unir[x] < unir[y]){
    unip[x] = y;
  }else{
    unip[y] = x;
    if(unir[x] == unir[y]){
      unir[x]++;
    }
  }
}
bool same(int x, int y){
  return find(x) == find(y);
}
int main(){
  int n,m;
  cin >> n >> m;
  int p[n];
  init(n);
  for(int i=0 ; i<n ; i++){
    cin >> p[i];
    --p[i];
  }
  int x[m], y[m];
  for(int i=0 ; i<m ; i++){
    cin >> x[i] >> y[i];
    --x[i]; --y[i];
    unite(x[i], y[i]);
  }
  int count = 0;
  for(int i=0 ; i<n ; i++){
    if(same(p[i],i)){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 5888
#include<cstdio>
#include<algorithm>
using namespace std;
long long f(long long a)
{
	return a < 0 ? -a : a;
}
int main()
{
	int n, b;
	scanf("%d", &n);
	long long a[n], m = 1e16;
	scanf("%d", &b);
	a[0] = b;
	for(int i = 1; i < n; i++)
	{
		scanf("%d", &b);
		a[i] = b + a[i - 1];
	}
	for(int i = 0; i < n - 1; i++)
	{
		m = min(m, f(a[n - 1] - 2 * a[i]));
	}
	printf("%lld", m);
	return 0;
}

Measured memory_bytes: 1664
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
#pragma endregion

void solve() {
    int n;
    cin >> n;
    int cnt = -1;
    int cur = 2;
    while (cur * (cur-1) <= n * 2) {
        if (cur * (cur-1) == n * 2) {
            cnt = cur;
            break;
        } else {
            cur++;
        }
    }
    if (cnt == -1) {
        cout << "No" << "\n";
        return;
    }
    cout << "Yes" << "\n";
    cout << cnt << "\n";
    int len = cnt - 1;
    vector<vector<int>> res(cnt, vector<int>(len));
    cur = 1;
    for (int i=0; i<len; i++) {
        for (int j=0; j<len-i; j++) {
            res.at(i).at(j+i) = res.at(j+i+1).at(i) = cur + j;
        }
        cur += len - i;
    }
    for (int i=0; i<cnt; i++) {
        cout << len << " ";
        for (int j=0; j<len; j++) {
            cout << res.at(i).at(j);
            if (j == len-1) cout << "\n";
            else cout << " ";
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;

const long long MAX = 10000; // SET
vllvll Mat(MAX, vll(0));
vll dist(MAX);

template<class T>
void bfs(T start)
{
    fill(dist.begin(), dist.end(), inf);
    dist[start] = 0;

    queue<T> q;
    q.push(start);

    while (! q.empty()) {
        auto now = q.front(); q.pop();
        for (auto adj : Mat[now]) {
            if (dist[adj] == inf) {
                dist[adj] = dist[now] + 1;
                q.push(adj);
            }
        }
    }
}

int main()
{
    // INIT Mat
    ll n;
    cin >> n;
    ll u, k, v;
    rep(i, 0, n) {
        cin >> u >> k;
        --u;
        rep(j, 0, k) {
            cin >> v;
            --v;
            Mat[u].push_back(v);
        }
    }

    ll start = 0;

    bfs(start);
    rep(i, 0, n) {
        if (dist[i] > big) 
            cout << i+1 << ' ' << -1 << endl;
        else
            cout << i+1 << ' ' << dist[i] << endl;
    }
}



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

if sum(A) < sum(B):
    print(-1)
elif all([a >= b for (a,b) in zip(A,B)]):
    print(0)
else:
    D = sorted([a-b for (a,b) in zip(A,B)])
    Negative = [d for d in D if d < 0]
    negative_sum = sum(Negative)
    positive_sum = 0
    count = 0
    for d in reversed(D):
        count += 1
        positive_sum += d
        if positive_sum > - negative_sum:
            break
    print(count + len(Negative))


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int h[100005];
bool mark[100005];
V<int>adj[100005];

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,m,n,x,y,ans=0,cnt;
    cin >> n >> m;
    for(i=1;i<=n;i++)cin >> h[i];
    while(m--)
    {
        cin >> x >> y;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    for(i=1;i<=n;i++)
    {
        if(!mark[i])
        {
            mark[i]=1;
            cnt=0;
            for(int z : adj[i])
            {
                if(h[z] < h[i])++cnt,mark[z]=1;
                else if(h[z] >= h[i])break;
            }
            if(cnt == adj[i].SZ)++ans;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 9228
import Data.List
import Control.Monad
f a b c i = case i of 'a' -> if null a then "A" else f (tail a) b c (head a)
                      'b' -> if null b then "B" else f a (tail b) c (head b)
                      'c' -> if null c then "C" else f a b (tail c) (head c)
main=do
 [a,b,c]<-replicateM 3 getLine
 putStrLn$f a b c 'a'

Measured memory_bytes: 508
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>
 
#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;
 
char mar[2] = {'+','-'};
 
int main()
{
	int tmp;cin >> tmp;
	int a,b,c,d;
	
	d = tmp % 10;tmp /= 10;
	c = tmp % 10;tmp /= 10;
	b = tmp % 10;tmp /= 10;
	a = tmp;
	
	REP(i,2)REP(j,2)REP(k,2)
	{
		int aa = a;
		if(i == 0)
		{
			aa += b;
		}
		else
		{
			aa -= b;
		}
		if(j == 0)aa += c;
		else aa -= c;
		if(k == 0)aa += d;
		else aa -= d;
		
		if(aa == 7)
		{
			cout << a << mar[i] << b << mar[j] << c << mar[k] << d << "=7" << endl;
			return 0;
			
		}
	}
	
	
	return 0;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e3 + 5;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
struct Edge {
	int to;
	Edge *nxt;
	Edge(int to, Edge *nxt) : to(to), nxt(nxt) {}
} *head[N];
void add(int x, int y) {head[x] = new Edge(y, head[x]);}
int n, m, ans, fa[N], fav[N], deg[N], dep[N];
void dfs(int x) {
	dep[x] = dep[fa[x]] + 1;
	for(Edge *i = head[x]; i; i = i->nxt) {
		if(i->to == fa[x]) continue;
		fa[i->to] = x;
		dfs(i->to);
	}
}
void col(int x, int y) {
	if(dep[x] < dep[y]) swap(x, y);
	while(dep[x] > dep[y]) fav[x] ++, x = fa[x];
	while(x != y) fav[x] ++, fav[y] ++, x = fa[x], y = fa[y];
}
struct node {
	int x, y;
	node(int x = 0, int y = 0) : x(x), y(y) {}
};
bool operator == (node a, node b) {return a.x == b.x && a.y == b.y;}
vector <node> solve(vector <node> v) {
	if(v.size() == 0) return v;
	int x, u; for(x = 1; x <= n; ++ x) if(deg[x] == 1) break;
	if(x > n) return v;
	for(Edge *i = head[x]; i; i = i->nxt) {
		if(deg[i->to]) {u = i->to; break;}
	}
	deg[x] --; deg[u] --;
	vector <node> lx, nv;
	vector <int> id;
	int pos[N];
	memset(pos, -1, sizeof(pos));
	for(int i = 0; i < v.size(); ++ i) {
		if(v[i].x == x || v[i].y == x) lx.push_back(v[i]), id.push_back(i);
		else nv.push_back(v[i]), pos[i] = nv.size() - 1;
	}
	if(lx.size() == 0) return solve(v);
	for(int i = 0; i + 1 < lx.size(); i += 2) {
		if(lx[i].y == x) swap(lx[i].x, lx[i].y);
		if(lx[i + 1].y == x) swap(lx[i + 1].x, lx[i + 1].y);
		if(lx[i] == lx[i + 1]) {
			if(v[id[i]] == v[id[i + 1]]) swap(v[id[i]].x, v[id[i]].y);
			continue;
		}
		nv.push_back(node(lx[i].y, lx[i + 1].y));
		pos[id[i]] = pos[id[i + 1]] = nv.size() - 1;
	}
	if(lx.size() & 1) {
		if(lx[lx.size() - 1].y == x) swap(lx[lx.size() - 1].x, lx[lx.size() - 1].y);
		if(lx[lx.size() - 1].y != u) {
			nv.push_back(node(u, lx[lx.size() - 1].y));
			pos[id[lx.size() - 1]] = nv.size() - 1;
		}
	}
	nv = solve(nv);
	for(int i = 0; i < v.size(); ++ i) {
		if(pos[i] != -1 && !(v[i].x == nv[pos[i]].x || v[i].y == nv[pos[i]].y)) swap(v[i].x, v[i].y);
	}
	return v;
}
vector <node> v;
int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); m = read();
	for(int i = 1, x, y; i < n; ++ i) deg[x = read()] ++, deg[y = read()] ++, add(x, y), add(y, x);
	dfs(1);
	for(int i = 1, x, y; i <= m; ++ i) x = read(), y = read(), v.push_back(node(x, y)), col(x, y);
	v = solve(v);
	ans = 0;
	for(int i = 2; i <= n; ++ i) ans += min(2, fav[i]);
	printf("%d\n", ans);
	for(int i = 0; i < v.size(); ++ i) printf("%d %d\n", v[i].x, v[i].y);
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 56192
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    if((N/100) == 7 || ((N%100)/10) == 7 || (N%10) == 7) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
  
  string S;
  cin >> S;
  
  char a1, a2, a3, a4;
  a1 = S.at(0);
  a2 = S.at(1);
  a3 = S.at(2);
  a4 = S.at(3);
  
  if(a1 == a2 && a3 == a4 && a2 != a3) cout << "Yes" << endl;
  else if(a1 == a3 && a2 == a4 && a2 != a3) cout << "Yes" << endl;
  else if(a1 == a4 && a2 == a3 && a2 != a4) cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 200100;
int n, m, x, y, has[N], sz[N], ans;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	for(int i = 1; i <= n; i++) 
		sz[i] = 1;
	
	has[1] = 1;
	
	for(int i = 1; i <= m; i++) {
		cin >> x >> y;
		sz[x]--;
		sz[y]++;
		if(has[x]) has[y] = 1;
		if(sz[x] == 0) has[x] = 0;
	}
	for(int i= 1; i <= n; i++) 
		ans += has[i];
	cout << ans << '\n';
	// dbg_v(has, n + 1);
}	

	

Measured memory_bytes: 1024
A, B = map(int, input().split(' '))
S = input()

numbers = {str(n) for n in range(10)}


def resolve(s):
    for i in range(A):
        if s[i] not in numbers:
            print('No')
            return

    if s[A] != '-':
        print('No')
        return

    s = s[A + 1:]
    for i in range(B):
        if s[i] not in numbers:
            print('No')
            return

    print('Yes')


resolve(S)


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

using pii = pair<int,int> ;
using pll = pair<long,long> ;
using umpii = unordered_map<int,int> ;
using mpii = map<int,int> ;

#define f first
#define s second

int32_t main(){
	int n ;
	cin >> n ;
	int a[n+1] ; bool ans[n+1] = {0} ;
	for(int i = 1 ; i <= n ; i++) cin >> a[i] ;
	for(int i = n ; i >= 1 ; i--){
		int sum = 0 ;
		for(int j = 2*i ; j <= n ; j += i){
			sum += ans[j] ;
		}
		if(sum%2 != a[i]) ans[i] = 1 ;
	}
	vector<int> v ;
	for(int i = 1 ; i <= n ; i++) if(ans[i]) v.push_back(i) ;
	cout << v.size() << endl ;
	for(auto i : v) cout << i <<" " ;
	return 0 ;
}



Measured memory_bytes: 2552
n = int(input())
s = input()
firstcond = s.count('R') * s.count('G') * s.count('B')
minus = 0

for k in range(3, n + 1):
    for j in range(2, k):
        i = 2 * j - k
        if 1 <= i < j:
            if (s[i - 1] != s[j - 1]) and (s[j - 1] != s[k - 1]) and (s[k - 1] != s[i - 1]):
                minus += 1

print(firstcond - minus)


Measured memory_bytes: 73336
// ~maqsat~

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
	fre("");
	ACCELERATE;

	int n;
	cin >> n;
	int a[N];
	for(int i = 0; i < n; i++) cin >> a[i];
	
	sort(a, a + n);
	int ans = 0;
	for(int i = 0; i < n; i++) {
	    for(int j = i + 1; j < n; j++) {
	        for(int k = j + 1; k < n; k++) {
	            if(a[i] < a[j] + a[k] && a[j] < a[k] + a[i] && a[k] < a[i] + a[j]) ans++;
	            else break;
	        }
	    }
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

h, a = ril()
print((h + a - 1) // a)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
const ll SIZE = 1e5 + 10;


#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

vector<pair<ll, ll>> vec;

int main() {
    fastInp;

    ll n;
    cin >> n;

    for (ll i = 0; i < n; i++) {
        ll num;
        cin >> num;
        vec.push_back(make_pair(num, i));
    }
    
    sort(vec.begin(), vec.end());

    ll ans = 0;
    for (int i = 0; i < vec.size(); i++) {
        if ((vec[i].second % 2) != (i % 2)) ans++;
    }
    cout << ans / 2;
    return 0;
}

Measured memory_bytes: 2420
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
char nextChar(){char f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
typedef int (*__compar_fn_t) (const void *, const void *);
extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar)__attribute__ ((__nonnull__ (1, 2, 5))) ;
extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int compare_char(const void *a, const void *b){return *(char*)a - *(char*)b;}
int compare_short(const void *a, const void *b){return *(short*)a - *(short*)b;}
int compare_long(const void *a, const void *b){if(*(long long int*)a - *(long long int*)b < 0){return -1;}else if(*(long long int*)a - *(long long int*)b > 0){return 1;}else{return 0;}}
short n, i;
char l[200];
int ans;
int main(){
 n = nextShort()*2;
 for(i=0; i<n; i++){
  l[i] = nextChar();
 }
 qsort(l, n, sizeof(char), compare_char);
 for(i=0; i<n; i+=2){
  ans += l[i];
 }
 printInt(ans);
 println();
}


Measured memory_bytes: 128
n = int(input())
s = list(input())
x = [0]*(n+1)
for i in range(1,n+1):
    if s[i-1]=='I':
        x[i] = x[i-1] + 1
    if s[i-1]=='D':
        x[i] = x[i-1] -1
print(max(x))

Measured memory_bytes: 38404
N = int(input())
X = list(map(int,input().split(" ")))

x = sorted(X)
s = x[N//2-1]
l = x[N//2]
if s == l:
    for i in range(N):
        print(s)
    exit()

for i in range(N):
    if X[i] <= s:
        print(l)
    else:
        print(s)


Measured memory_bytes: 25556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll num[54],n,k,cnt[54];
ll dfs(ll x,ll y){
	if (y>=num[x]-1) return cnt[x];
	if (x==0) return 1;
	ll res=0;
	ll go=min(y-1,num[x-1]);
	if (y>1) res+=dfs(x-1,go);
	if (y>num[x]/2) res++;
	go=min(y-num[x]/2-1,num[x-1]);
	if (y>num[x]/2+1) res+=dfs(x-1,go);
	return res;
}
int main(){
	num[0]=1;
	cnt[0]=1;
	for (ll i=1;i<=50;i++){
		num[i]=num[i-1]*2+3;
		cnt[i]=cnt[i-1]*2+1;
	}
	cin>>n>>k;
	cout<<dfs(n,k);
}

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

using namespace std;

int main() {
	while(true){
	int n; cin >> n;
	if (n == 0) break;
	int ls[1024];
	for (int i = 0; i < n; ++i) {
		cin >> ls[i];
	}
	sort(ls, ls+n);
	long res = 0;
	for (int i = 1; i < n-1; ++i) {
		res += ls[i];
	}
	cout << long(res/(n-2)) << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
N = int(input())
S = [input()]

dic = True

for i in range(N-1):
    ss = input()
    if ss in S:
        dic = False
        break
    elif S[i][-1] != ss[0]:
        dic = False
        break
    else:
        S.append(ss)

if dic:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int n, x;
    cin>>n>>x;
    int ans=-1;
    rep(i,n){
        int input;
        cin>>input;
        if(ans==-1){
            ans = abs(input - x);
        }
        else{
            ans = __gcd(ans, abs(input - x));
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a, b,c;
    cin >> a >>b >> c;
    if(b+c<=a)
        cout << 0;
    else
        cout << c-(a-b);

    return 0;
}


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

int main(void) {
  int l[10];
  int v1, v2;
  double length;
  double distance;
  
  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2) != EOF) {
    length = 0;
    for(int i = 0; i < 10; ++i) {
      length += l[i];
    }
    
    distance = v1 * length / (v1 + v2);
    if(distance == 0) {
      cout << 1 << endl;
    } else {
      length = 0;
      for(int i = 0; i < 10; ++i) {
        length += l[i];
        if(length >= distance) {
          cout << i + 1 << endl;
          break;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define sqr(a) ((a)*(a))

using namespace std;
typedef long long ll;
const int N = 11, D = 11;

ll x[N][D];
int main(){
    ll n, d;
    cin >> n >> d;

    for (int i = 0; i < n; ++ i)
    for (int j = 0; j < d; ++ j)
        cin >> x[i][j];

    int ans = 0;
    for (int i = 0; i < n; ++ i)
    for (int j = i+1; j < n; ++ j){
        ll sums = 0;
        for (int k = 0; k < d; ++ k)
            sums += sqr(x[i][k]-x[j][k]);
        ll rt = sqrtl(sums);
        ans += sqr(rt) == sums;
    }

    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  int l[n];
  rep(i, n) { cin >> l[i]; }

  int ans = 0;
  rep(i, n) {
    rep(j, i) {
      rep(k, j) {
        if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j] &&
            l[i] != l[j] && l[j] != l[k] && l[k] != l[i])
          ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2

    if n != 1:
        a.append(n)

    return a


N = int(input())
sosu = prime_factorize(N)
history = set()
count = 0
while len(sosu) > 0:
    num = sosu.pop(0)
    cursor = num
    while True:
        if num not in history:
            history.add(num)
            break
        if (len(sosu) <= 0):
            break
        if (cursor != sosu[0]):
            break
        num *= sosu.pop(0)

print(len(history))


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

using namespace std;

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

	for (int i = 0; i < N; i++) {
		if (i == 0) {
			A[0] = B[0];
			continue;
		} else if (i == N - 1) {
			A[i] = B[i - 1];
			continue;
		}

		A[i] = min(B[i - 1], B[i]);
	}

	cout << accumulate(A.begin(), A.end(), 0) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
 
signed main(){
	int n;
	int x = 0;
	char a;
	int dem=0;
	for(int i = 10; i >= 1; i--){
		cout << "? " << (int)pow(10, i) - 1 << "\n";
		fflush(stdout);
		cin >> a;
		if(a == 'N'){
			dem = i + 1;
			break;
		}
	}
	if(dem == 0){
		for(int i = 10; i >= 0; i--){
			cout << "? " << (int)pow(10, i) << "\n";
			fflush(stdout);
			cin >> a;
			if(a == 'Y' && i == 10){
				cout << "! 1\n";
				exit(0);
			}
			if(a == 'Y'){
				dem = i + 1;
				break;
			}
		}
	}
	for(int i = 1; i < dem; i++){
		int l = 0, r = 9;
		x = x * 10;
		while(l != r){
			int mid = (l + r + 1) / 2;
			cout << "? " << x + mid << "\n";
			fflush(stdout);
			cin >> a;
			if(a == 'Y'){
				l = mid;
			}
			else{
				r = mid - 1;
			}
		}
		x += l;
	}
	x = x * 10;
	if(x == 0) x = 1;
	for(int i = 0; i <= 9; i++){
		cout << "? " << (x + i) * 10 << "\n";
		fflush(stdout);
		cin >> a;
		if(a == 'Y'){
			x = x + i;
			break;
		}
	}
	cout << "! " << x << "\n";
	fflush(stdout);}

Measured memory_bytes: 596
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mt_t=[0]*n
mt_a=[0]*n
last=0
for i in range(len(t)):
    if last < t[i]:
        mt_t[i] = -t[i]
        last=t[i]
    else:
        mt_t[i] = last
last=0
for i in reversed(range(len(t))):
    if last < a[i]:
        mt_a[i] = -a[i]
        last=a[i]
    else:
        mt_a[i] = last
mts = [0]*n
for i in range(len(t)):
    if mt_t[i] < 0 and mt_a[i] < 0:
        if mt_t[i] != mt_a[i]:
            print(0)
            exit()
    elif mt_t[i] < 0 or mt_a[i] < 0:
        kaku =abs(min(mt_t[i],mt_a[i]))
        kouho=max(mt_t[i],mt_a[i])
        if kouho < kaku:
            print(0)
            exit()
    mts[i] = min(mt_t[i],mt_a[i])

ans=1
for num in mts:
    if num > 0:
        ans*=num
        ans%=(10**9+7)
print(ans)

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

using namespace std;

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

    int a , b;
    cin >> a >> b;

    if (a >= 13)
        cout << b;
    else if (a >= 6 && a <= 12)
        cout << b / 2;
    else
        cout << 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  for(int i=1;i<=100000;i++){
    if((a*i)%b==c){
      cout<<"YES"<<endl;
      return(0);
    }
  }
  cout<<"NO"<<endl;
  return(0);
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    string S = "2019/04/30";
    if(s.compare(S) <= 0){
        cout << "Heisei" << '\n';
    }else{
        cout << "TBD" << '\n';
    }
    // cout << s.compare(S)<< '\n';
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C,D;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C>>D;
	cout<<min(A,B)+min(C,D)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256