akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int x;
  cin >> x;
 if(x < 600){
   cout << 8 << endl;
   return 0;
 }
 if(x < 800){
   cout << 7 << endl;
   return 0;
 }
 if(x < 1000){
   cout << 6 << endl;
   return 0;
 }
 if(x < 1200){
   cout << 5 << endl;
   return 0;
 }
 if(x < 1400){
   cout << 4 << endl;
   return 0;
 }
 if(x < 1600){
   cout << 3 << endl;
   return 0;
 }
 if(x < 1800){
   cout << 2 << endl;
   return 0;
 }
 if(x < 2000){
   cout << 1 << endl;
   return 0;
 }
  
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k;cin>>n>>m>>k;
	vector<string>a(n);
	int ans = 0, K;
	for(int i=0;i<n;i++)	cin>>a[i];
	for(int mask_i=0;mask_i<(1ll<<n);mask_i++) {
		for(int mask_j=0;mask_j<(1ll<<m);mask_j++) {
			K = 0;
			for(int i=0;i<n;i++) {
				for(int j=0;j<m;j++) {
					if((mask_i & (1ll<<i)) || (mask_j & (1ll<<j))) continue;
					if(a[i][j]=='#')	K++;
				}
			}
			if(k==K)	ans++;
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3572
import decimal

a, b, c = map(int, input().split())
a = decimal.Decimal(a)
b = decimal.Decimal(b)
c = decimal.Decimal(c)

if c - a - b > 0 and 4*a*b - (c-a-b)**2 < 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[200000];
int f[200005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    int cnt = 1, sol = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] != cnt)
            sol++;
        else
            cnt++;
    }
    if (sol == n)
        cout << -1;
    else
        cout << sol;
}


Measured memory_bytes: 1024
// author: Saman Mahdanian
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5 + 10;
const int MOD = 1e9 + 7;

void _psum (int &, int);
int _sum (int, int);
int _mul (int, int);
int _pow (int, int);
int gcd (int, int);

int n, m, k, inv[N], f[N], res[N];
vector <int> X;

int x[] = {0, 0, -1, +1};
int y[] = {-1, +1, 0, 0};
string s[N];

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

	set <char> wtf; //?
	int n;
	cin >> n;
	while (n--) {
		char v;
		cin >> v;
		wtf.insert(v);
	}
	cout << (wtf.size() == 3? "Three":"Four") << endl;
}

int gcd (int a, int b) {
	return !b? a : gcd (b, a % b);
}

// int choose (int r, int k) {
// 	return _mul (f[k], _mul(inv[r], inv[k - r]));
// }

void _psum (int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

int _sum (int a, int b) {
	return a + b - (a + b >= MOD? MOD : 0);
}

int _mul (int a, int b) {
	return 1LL * a * b % MOD;
}

int _pow (int a, int b) {
	if (!b) 
		return 1;
	int res = _pow (a, b >> 1);
	res = _mul (res, res);
	if (b & 1)
		res = _mul (res, a);
	return res;
}

// SamMHD :: Jun27-2019 :: Another Day with Shayan...

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main(int argc, char const *argv[]) {
  string S;
  int N, Q;
  cin >> N >> Q;
  cin >> S;
  int count[N];
  count[0] = 0;
  vector<int> num(0);
  for(int i=1;i<N;i++){
    int add = 0;
    if(S[i] == 'C' && S[i-1] == 'A') add = 1;
    count[i] = count[i-1] + add;
  }
  for(int i=0;i<Q;i++){
    int l, r;
    cin >> l >> r;
    std::cout << count[r-1] - count[l-1] << '\n';
  }
  return 0;
}

Measured memory_bytes: 1472
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
const int INF = (int)2e9 + 1;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, temp, temp2;
  cin >> N;

  vector<int> seq;
  vector<int> slime;

  int n2 = 1 << N;
  for (int i = 0; i < n2; i++) {
    cin >> temp;
    seq.push_back(temp);
  }
  sort(seq.begin(), seq.end());
  slime.push_back(seq.back());
  seq.back() = -INF;
  int cnt;

  for (int i = 0; i < N; i++) {
    vector<int> pre = slime;
    sort(pre.begin(), pre.end());
    cnt = n2 - 1;
    while (pre.size() > 0 && cnt >= 0) {
      if (seq[cnt] == -INF) {
        cnt--;
        continue;
      }
      if (seq[cnt] < pre.back()) {
        slime.push_back(seq[cnt]);
        pre.pop_back();
        seq[cnt] = -INF;
      }
      cnt--;
    }
    if (pre.size() > 0) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

constexpr int B=900;
struct Q {
    int L, R, id;
    bool operator<(const Q &o) const {
        return pii{L/B, R}<pii{o.L/B, o.R};
    }
};

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n, nq;
    cin >> n >> nq;
    map<int, vi> f;
    rep(i, 0, n) {
        int a;
        cin >> a;
        f[a].push_back(i);
    }
    vi x(n);
    int k=0;
    trav(p, f) {
        trav(i, p.second) x[i]=k;
        k++;
    }
    vi cnt(k);
    vector<Q> q(nq);
    rep(i, 0, nq) {
        cin >> q[i].L >> q[i].R;
        q[i].L--, q[i].R--;
        q[i].id=i;
    }
    sort(all(q));
    int L=0, R=-1, dc=0;
    vi qans(nq);
    auto add=[&](int i) { if (++cnt[i]==1) dc++; };
    auto rem=[&](int i) { if (--cnt[i]==0) dc--; };
    trav(cq, q) {
        while (L<cq.L) rem(x[L++]);
        while (L>cq.L) add(x[--L]);
        while (R<cq.R) add(x[++R]);
        while (R>cq.R) rem(x[R--]);
        qans[cq.id]=dc;
    }
    trav(i, qans) cout << i << '\n';
    return 0;
}

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

int main(){

  while(1){
    int x, y;
    cin>>x>>y;
    if(x == 0 && y == 0) break;
    
    if(x > y) swap(x, y);
    cout<<x<<" "<<y<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3096
s = input()
#s = "123"
n = s[-1:]

if n == "2":
    print("hon")
if n == "4":
    print("hon")
if n == "5":
    print("hon")
if n == "7":
    print("hon")
if n == "9":
    print("hon")
if n == "0":
    print("pon")
if n == "1":
    print("pon")
if n == "6":
    print("pon")
if n == "8":
    print("pon")
if n == "3":
    print("bon")


Measured memory_bytes: 9128
#include<stdio.h>

int m[]={0,31,29,31,30,31,30,31,31,30,31,30,31},s,a,b,i;

int main(){
	scanf("%d%d",&a,&b);
	while(a!=0 && b!=0){
		s=0;
		for(i=1;i<a;i++)s+=m[i];
		s+=b;
		if(s%7==0)printf("Wednesday\n");
		if(s%7==1)printf("Thursday\n");
		if(s%7==2)printf("Friday\n");
		if(s%7==3)printf("Saturday\n");
		if(s%7==4)printf("Sunday\n");
		if(s%7==5)printf("Monday\n");
		if(s%7==6)printf("Tuesday\n");
		scanf("%d%d",&a,&b);
	}
	
	return 0;
}

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

int main(){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    
    long long max[5];
    max[0] = a * c;
    max[1] = a * d;
    max[2] = b * c;
    max[3] = b * d;
    sort(max,max + 4);
    cout << max[3] << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long int
#define test_case long long int t,i;cin>>t;for(i=0;i<t;i++)

using namespace std;
int main()
{
    ll a, b, x, p, q, cnt=0;
    cin >> a >> b >> x;

    if(a%x==0)
        p = (a/x) - 1 ;
    else
        p=(a/x);

    q = b/x;

    cout << q-p << endl;;


    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

int main(){
	using namespace std;
	string day;
	int i;
	cin >> day;
	if (day == "SUN") {
		i = 7;
	}
	else if (day == "MON") {
		i = 6;
	}
	else if (day == "TUE") {
		i = 5;
	}
	else if (day == "WED") {
		i = 4;
	}
	else if (day == "THU") {
		i = 3;
	}
	else if (day == "FRI") {
		i = 2;
	}
	else {
		i = 1;
	}
		cout << i << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n; long double x[30], y[30], z[30];
long double norm(long double ax, long double ay, long double az) {
	long double maxn = 0;
	for (int i = 0; i < n; i++) {
		maxn = max(maxn, (ax - x[i])*(ax - x[i]) + (ay - y[i])*(ay - y[i]) + (az - z[i])*(az - z[i]));
	}
	return maxn;
}
long double solve(int depth, long double L1, long double L2) {
	long double L = -114.514l, R = 100.0l, c1, c2, maxn = 1e9;
	for (int i = 0; i < 70; i++) {
		c1 = (L + L + R) / 3.0l;
		c2 = (L + R + R) / 3.0l;
		long double I1, I2;
		if (depth == 0) { I1 = solve(depth + 1, c1, L2); I2 = solve(depth + 1, c2, L2); }
		if (depth == 1) { I1 = solve(depth + 1, L1, c1); I2 = solve(depth + 1, L1, c2); }
		if (depth == 2) { I1 = norm(L1, L2, c1); I2 = norm(L1, L2, c2); }
		if (I1 < I2)R = c2; else L = c1;
		maxn = min(maxn, min(I1, I2));
	}
	return maxn;
}
int main() {
	while (true) {
		cin >> n; if (n == 0)break; for (int i = 0; i < n; i++)cin >> x[i] >> y[i] >> z[i];
		printf("%.12Lf\n", sqrtl(solve(0, 0, 0)));
	}
	return 0;
}

Measured memory_bytes: 3136
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	ans := 0
	for i := 0; i < n; i++ {
		l, r := readInt(), readInt()
		ans += r - l + 1
	}
	fmt.Println(ans)
}


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

#define rep(a,b) for(ll ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'
#define lg 1000000000

int main()
{
  int i, j, min = INT_MAX, c;	
  string s, ss;
  cin>>s>>ss;

  for(i = 0; i<=s.length()-ss.length(); i++)
  {
  	for(j = 0; j<ss.length(); j++)
  	{
  	  if(s[i+j] != ss[j]) c++;	
  	}
  	if(c<min) min = c;
  	c = 0;
  }
  cout<<min<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int N=4e4+5;

int main(){
ios::sync_with_stdio(0);
ll a,b,n;
cin>>a>>b>>n;
if(b-1<=n)
    cout<<a*(b-1)/b<<endl;
else
    cout<<a*n/b<<endl;


return 0;
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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;
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N;
intvec A;
ll money=1000, stock=0, mx=1000;

void input() {
	cin>>N;
	init(A,N);
}

void solve() {
	for(int i=0; i<N-1; i++) {
		if(A[i]<A[i+1] && stock==0) {
			stock=money/A[i];
			money%=A[i];
		}
		else if(A[i]>A[i+1] && stock>0) {
			money+=A[i]*stock;
			chmax(mx,money);
			stock=0;
		}
	}
	chmax(mx,money+A[N-1]*stock);
	cout<<mx<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
  
#define M 1000000
#define NIL -1
#define L 14
  
char H[M][L];
  
int getChar(char ch){
  if(ch == 'A')return 1;
  else if(ch == 'C')return 2;
  else if(ch == 'G')return 3;
  else if(ch == 'T')return 4;
  else return 0;
}
  
long long getKey(char str[]){
  long long sum=0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
  
int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M-1));}
  
int find(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}
  
int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}
  
int main(){
  int i,n,h;
  char str[L],com[9];
  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
  
    if(com[0]=='i'){
      insert(str);
    }else{
      if(find(str)){
        printf("yes\n");
      }else{
        printf("no\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 14280
#include <iostream>
using namespace std;
int main(){
  int H,N;
  cin >> H >> N;
  int A[N];
  for(int i = 0;i < N;i++)
    cin >> A[i];
  for(int i = 0;i < N;i++){
      H -= A[i];
  }
  if(H <= 0)
  cout << "Yes" << endl;
  else{
      cout << "No" << endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin>>c;
  if(c=='A')cout<<'T'<<endl;
  else if(c=='T')cout<<'A'<<endl;
  else if(c=='C')cout<<'G'<<endl;
  else if(c=='G')cout<<'C'<<endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
t = s[::-1]
i = 0
k = len(s)
while i <= k-5:
  if k-i >= 7:
    if t[i] != 'r':
      if t[i:i+5] == 'maerd':
        i += 5
      elif t[i:i+5] == 'esare':
        i += 5
      else:
        i = k+1
    else:
      if t[i:i+6] == 'resare':
        i += 6
      elif t[i:i+7] == 'remaerd':
        i += 7
      else:
        i = k+1
  elif k-i == 6:
    if t[i:i+6] == 'resare':
      i = k
    else:
      i = k+1
  else:
    if t[i:i+5] == 'esare':
      i = k
    elif t[i:i+5] == 'maerd':
      i = k
    else:
      i = k+1
if i == k:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Max=1e5+10;
const int MOD=1e9+7;
int a[Max];
int pos[Max];
ll inv[Max];
ll fac[Max];
int sp;
int ss;
void init() {
    fac[0]=1;
    fac[1]=1;
    inv[0]=1;
    inv[1]=1;
    for(ll i=2; i<=Max; i++) {
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
    }
    for(ll i=1; i<=Max; i++)
        inv[i]=inv[i]*inv[i-1]%MOD;
}
ll C(ll n, ll m) {
    if(m>n)
        return 0;
    return ((fac[n]*inv[m]%MOD)*inv[n-m])%MOD;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    init();
    for(int i=1;i<=n+1;i++){
        cin>>a[i];
        if(pos[a[i]]){
            ss=a[i];
            sp=i;
        }else{
            pos[a[i]]=i;
        }
    }
    for(int i=0;i<=n;i++){
        ll res=0;
        res+=C(n+1,i+1);
        res%=MOD;
        res=(res+MOD-C(n-sp+pos[a[sp]],i))%MOD;
        cout<<res<<endl;
    }
    return 0;
}


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

template <class T>
void print(vector<T>& v){
    for(T x:v) cout<<x<<" ";
    cout<<endl;
}

void sol(){
    int a,b;
    cin>>a>>b;
    if (a>b) cout<<"safe"<<endl;
    else cout<<"unsafe"<<endl;
}

int main() {
    // int t;
    // cin>>t;
    // for (int i=0; i<t; ++i){
        sol();
    // }
    return 0;
}

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

const int INF = 1001001001;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<int> ans(n);
    rep(sv,n) {
        vector<int> dist(n, INF);
        queue<int> q;
        auto push = [&](int v, int d) {
            if (dist[v] != INF) return;
            dist[v] = d;
            q.push(v);
        };
        push(sv, 0);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            int d = dist[v];
            if (v-1 >= 0) push(v-1, d+1);
            if (v+1 < n) push(v+1, d+1);
            if (v == x) push(y, d+1);
            if (v == y) push(x, d+1);
        }
        rep(i,n) ans[dist[i]]++;
    }
    rep(i,n) ans[i] /= 2;
    for (int i = 1; i <= n-1; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    vector<int> distances(n);
    for(int i=0; i<n; i++) {
        distances[i] = abs(x - a[i]);
    }
    int max_divisor = distances[0];
    for(int i=1; i<n; i++) {
        max_divisor = gcd(max_divisor, distances[i]);
    }
    cout << max_divisor << endl;

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int s=0,t=N;
  
  while(t>0){
    s+=t%10;
    t/=10;
  }
  
  if(N%s==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
/*
problem's name:
statue:
writer:Patrick_y
*/
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <cctype>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=20050208;
/*------------main part------------*/



vector<int>a,b;
vector<vector<int> >remain;
int main()
{
	int n,k,q;
	cin>>n>>k>>q;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
		b.push_back(x);
	}
	int ans=1e9;
	sort(b.begin(),b.end());
	for(int i=0;i<n-k+1;i++)
	{
		int x=b[i];
		vector<int> rest;
		rest.clear();
		remain.clear();
		int y=0;
		for(int j=0;j<n;j++)
		{
			if(a[j]>=x)
			{
				rest.push_back(a[j]); 
			}
			else
			{
				if(rest.size()!=0)
				{
					remain.push_back(rest);
					rest.clear();
				}
			}
		}
		if(rest.size()!=0)
		{
			remain.push_back(rest);
			rest.clear();
		}
		for(int j=0;j<remain.size();j++)
		{
			sort(remain[j].begin(),remain[j].end());
		}
		vector<int> tmp;
		for(int j=0;j<remain.size();j++)
		{
			if(remain[j].size()>=k)
			{
				for(int l=0;l<remain[j].size()-k+1;l++)
				{
					tmp.push_back(remain[j][l]);
				}
			}
		}
		sort(tmp.begin(),tmp.end());
		if(tmp.size()>=q)
		{
			if(tmp[q-1]-tmp[0]<ans)
			{
				ans=tmp[q-1]-tmp[0];
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cassert>
#include <unordered_set>
#include <set>
#include <bitset>
#include <memory.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;
 
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
 
const int MOD = (int) 1e9 + 7;
const int MAGIC = 400;

long long binPow(long long a, long long b) {
    if (b == 0)
        return 1;

    long long ans = binPow(a, b / 2);
    ans = ans * ans % MOD;

    if (b % 2)
        ans = ans * a % MOD;

    return ans;
}

int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m, k;
    cin >> n >> m >> k;

    vector<string> a(n);
    vector<vector<int> > q(n);
    int last_x = -1;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        for (int j = 0; j < m; ++j) {
            if (a[i][j] == '#') {
                q[i].push_back(j);
                last_x = i;
            }
        }
    }

    vector<vector<int> > ans(n, vector<int>(m, -1));
    int cur_last_x = -1;
    int color = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < q[i].size(); ++j) {
            for (int x = cur_last_x + 1; x < (i == last_x ? n : i + 1); ++x)
                for (int y = (j == 0 ? 0 : q[i][j]); y < (j + 1 == q[i].size() ? m : q[i][j + 1]); ++y)
                    ans[x][y] = color;
            // cout << (j + 1 == q[i].size() ? m : q[i][j + 1]) << "\n";
            ++color;

            // break;
        }

        // break;

        if (q[i].size())
            cur_last_x = i;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j)
            cout << ans[i][j] << " ";
        cout << "\n";
    }
}


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<long long> f(m + 1, 0);
    while (n--) {
        int cw, cv;
        cin >> cw >> cv;
        for(int j = m; j >= cw; j--) 
            f[j] = max(f[j], f[j - cw] + cv);
    }
    cout << *max_element(f.begin(), f.end());
}


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

int bigpenis(int n){
  int sum=0;
  while (n>0){
    sum+=n%10;
  n/=10;}
return sum;}
int main(){int N,A,B;
cin>>N>>A>>B;
  int y=0;
  for(int i=1; i<=N; ++i ){
    int o=bigpenis(i);
    if (A<=o && o<=B){
      y+=i;
    }}
    cout<<y<<endl;}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

string s;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> s;

  ll res = 0;
  int c = 0;
  for (int i = (int)s.size()-1; i >= 0;) {
    if (s[i] == 'A') {
      res += c;
      i--;
    } else if (i-1 >= 0 && s[i-1] == 'B' && s[i] == 'C') {
      c++;
      i -= 2;
    } else {
      c = 0;
      i--;
    }
  }

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	int k,t;
	cin>>k>>t;
	vi a(t);
	rep(i,t)cin>>a[i];
	sort(all(a));
	if(a.back()>(k+1)/2){
		int m=k-a.back();
		cout<<k-m*2-1<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
//const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,-1,0,1,-1,1,-1,1};

class Graph{
	private:
	int n;
	vvi g,rg;
	vi scc,used;
	stack<int> stc;
	void Order(int v){
		used[v]=1;
		for(auto u:g[v]) if(!used[u]) Order(u);
		stc.push(v);
	}
	void DFS(int v,int t){
		used[v]=1;
		for(auto u:rg[v]) if(!used[u]) DFS(u,t);
		scc[v]=t;
	}
	public:
	int SCC(){
		scc=used=vi(n);
		rg=vvi(n);
		for(int i=0;i<n;i++){
			if(!used[i]) Order(i);
			for(auto v:g[i]) rg[v].push_back(i);
		}
		int t=0;
		used=vi(n);
		while(!stc.empty()){
			int v=stc.top();
			stc.pop();
			if(!used[v]) DFS(v,t++);
		}
		return t;
	}
	Graph(int v){
		n=v;
		g=vvi(v);
	}
	void add_edge(int s,int t){
		g[s].push_back(t);
	}
};

const int N=16;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int h,w;
		cin>>h>>w;
		Graph g(26);
		vs a(h);
		vi mx(26,inf),MX(26,-inf),my(26,inf),MY(26,-inf);
		for(int i=0;i<h;i++){
			cin>>a[i];
			for(int j=0;j<w;j++) if(isalpha(a[i][j])){
				int I=a[i][j]-'A';
				mx[I]=min(mx[I],i);
				MX[I]=max(MX[I],i);
				my[I]=min(my[I],j);
				MY[I]=max(MY[I],j);
			}
		}
		bool B=1;
		for(int k=0;k<26;k++) if(mx[k]<inf){
			for(int i=mx[k];i<=MX[k];i++) for(int j=my[k];j<=MY[k];j++){
				if(a[i][j]=='.') B=0;
				if(a[i][j]-'A'!=k){
					g.add_edge(k,a[i][j]-'A');
				}
			}
		}
		cout<<(B&&g.SCC()==26?"SAFE":"SUSPICIOUS")<<endl;
	}
}


Measured memory_bytes: 3216
#include <stdio.h>

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


Measured memory_bytes: 2688
#include <stdio.h>

int main(void)
{
int w,h,x,y,r;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
if(x>=r && y>=r && w>=x+r && h>=y+r){
  printf("Yes\n");
}else{
  printf("No\n");
}
return 0; 
}

Measured memory_bytes: 2680
#include<cstdio>
#include<algorithm>
int main(){
    int n,x[100],y[100],h[100],maxh,basei=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d%d%d",&x[i],&y[i],&h[i]);
    while(h[basei]==0)basei++;
    for(int cx=0;cx<=100;cx++){
        for(int cy=0;cy<=100;cy++){
            bool isvalid=true;
            maxh=h[basei]+std::abs(x[basei]-cx)+std::abs(y[basei]-cy);
            for(int i=0;i<n;i++){
                if(h[i]!=std::max(maxh-std::abs(x[i]-cx)-std::abs(y[i]-cy),0)){
                    isvalid=false;
                    break;
                }
            }
            if(isvalid){
                printf("%d %d %d",cx,cy,maxh);
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main(){
  ll N, ans=0;
  cin>>N;
  rep1(i, N){
    if(i%3!=0 && i%5!=0) ans+=i;
  }
  out(ans);
}


Measured memory_bytes: 3592
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) {if(y < x) x = y;}
template<typename T, typename U> inline void mxze(T &x, U y) {if(x < y) x = y;}

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
template<typename T>
void _scan( vector<T> &v ){
	for(int i=0; i<(int)v.size(); i++) _scan(v[i]);
}
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h)
	{ cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++;
	cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<" = "; for(auto _i:x) cerr<<_i<<", ";cerr<<"\n";}}
#define debuga(x, sz) {{cerr<<#x<<" = ";for(int _i=0;_i<sz;_i++)cerr<<x[_i]<<", ";cerr<<"\n";}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

ll MOD = 1e9+7;

inline ll Msum(ll x){return x;}
template<typename... Rest>
inline ll Msum(ll x, Rest... rest){ return (x + Msum(rest...)) % MOD; }

inline ll Mprod(ll x){return x;}
template<typename... Rest>
inline ll Mprod(ll x, Rest... rest){ return x * Mprod(rest...) % MOD; }

inline ll Mnorm(ll x){ return (x%MOD + MOD) %MOD; }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

const int MAXN = 1e2+2;

int R, C;
char g[MAXN][MAXN];

int d[MAXN][MAXN];

int dr[] = {1, 0},
	dc[] = {0, 1};
bool valid(int r, int c){
	return r<R && c<C;
}

int main(){
	scan(R, C);
	for(int r=0; r<R; r++) scan(g[r]);

	ms(d, -1);
	deque<pair<int, int>> q;
	d[0][0] = g[0][0] == '#';
	q.push_back({0, 0});
	while(!q.empty()){
		ii pp = q.front(); q.pop_front();
		int r=pp.fst, c=pp.snd;
		for(int m=0; m<2; m++){
			int nr = r+dr[m],
				nc = c+dc[m];
			if(!valid(nr, nc)) continue;
			int co=0;
			if(g[r][c] == '.' && g[nr][nc] == '#') co=1;
			int nd = d[r][c] + co;
			if(d[nr][nc] == -1 || nd < d[nr][nc]){
				d[nr][nc] = nd;
				if(co==0) q.push_front({nr, nc});
				else q.push_back({nr, nc});
			}
		}
	}
	printf("%d\n", d[R-1][C-1]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

int LINE(int N){
    int a = 1;
    while(N>0){
        a *= N;
      	a %= mod;
        N --;
    }
    return a;
}
signed main(){
    int N,M; cin>>N>>M;
    int ans = 0;
    if(abs(N-M)==1){
        ans = LINE(N)*LINE(M);
    }
    if(abs(N-M)==0){
        ans = LINE(N)*LINE(M)*2;
    }
  ans %= mod;
    Out(ans);
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	string str;
	cin >> str;
	int n = str.length();
	int ret = n;
	FOR(i, 1, n) if (str[i] != str[i - 1]) ret = min(ret, max(i, n - i));
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int n,t[100];

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>t[i];
    t[n]=1e9;
    cout<<t[0];
    for(int i=1;i<n;i++){
      if(t[i-1]+1==t[i]&&t[i]+1==t[i+1])continue;
      else if(t[i-1]+1==t[i])cout<<"-"<<t[i];
      else cout<<" "<<t[i];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)


x,y = inm()
sum = 0
sum += (300000 if x==1 else 200000 if x==2 else 100000 if x==3 else 0)
sum += (300000 if y==1 else 200000 if y==2 else 100000 if y==3 else 0)
if x==1 and y==1:
    sum += 400000
print(sum)


Measured memory_bytes: 38384
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

const int N = 2e5 + 10;
typedef long long LL;
int n, sim; LL ans;
char s[N];
int v[N], p[N];
int tr[N];

void ins(int x, int v) {
	for(; x <= n; x += x&(-x)) tr[x] += v;
}

int ask(int x) {
	int ret = 0;
	for(; x; x -= x&(-x)) ret += tr[x];
	return ret;
}

int main() {
	int i, l, r, finish = 0;
	scanf("%s", s+1); n = strlen(s+1);
	rep(i, 0, 25) {
		for(l = 1, r = n; l <= r; ++l, --r) {
			for(; l <= r && s[l]-'a' != i; ++l);
			for(; l <= r && s[r]-'a' != i; --r);
			
			if(s[l]-'a' != i || s[r]-'a' != i) break;
			
			if(l == r) {
				if(sim) {puts("-1"); return 0;}
				sim = l;
				break;
			}
			v[l] = 1; p[l] = r;
			v[r] = -1;
		}
	}
//	printf("%d\n", sim);
//	rep(i, 1, n) printf("%d ", v[i]); puts("");
//	rep(i, 1, n) printf("%d ", p[i]); puts("");
	rep(i, 1, n) {
		if(i == sim) {
			ans += finish / 2;
			++finish;
		}
		if(v[i] == 1) {
			ans += ask(p[i]) + finish;
			ins(p[i], 1);
		}
		if(v[i] == -1) {
			ins(i, -1);
			finish += 2;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
template<typename M>
bool rMax(M &a, M b) {
    return b > a ? a = b, true : false;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n, w;
    cin>>n>>w;
    vector<long long> dp(w+1, 0);
    vector<long long> nextDP(w+1);
    for(int i = 0; i< n; i++){
        long long a, b;
        cin>>a>>b;
        for(int j = 0; j<=w; j++){
            nextDP[j] = dp[j];
            if(j - a < 0) continue;
            rMax(nextDP[j], dp[j-a] + b);
        }
        dp = nextDP;
    }
    cout<<*max_element(dp.begin(), dp.end())<<"\n";
}


Measured memory_bytes: 4784
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<map>
#include<vector>
#include<ctime>
#include<stack>
#define mp make_pair
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long

using namespace std;

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

int main()
{
	int T;
	scanf("%d",&T);
	while (T--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if (a>b) swap(a,b);
		int ans=0;
		if (a==b)
			ans=2*a-2;
		else
		{
			int tmp=sqrt((ll)a*b);
			ans=(tmp-1)*2-1;
			if ((ll)tmp*tmp<(ll)a*b) ans++;
			if ((ll)tmp*(tmp+1)<(ll)a*b) ans++;
		}
		printf("%d\n",ans);	
	} 
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(1e6) + 5;
vector < pii > g[N];
int ans = 0;
int dfs(int node,int prev)
{
    int cnt = 0;
    for (auto it : g[node])
        if (it.fi != prev)
        {
            int v = dfs(it.fi,node);
            int xr = it.se;
            for (int k = 0;k < 16;++k)
                if ((v >> k) & 1)
                {
                    if ((cnt >> k) & 1)
                        ++ans;
                    cnt ^= 1 << k;
                    xr ^= k;
                }
            if (xr)
            {
                if ((cnt >> xr) & 1)
                    ++ans;
                cnt ^= 1 << xr;
            }
        }
    if (cnt & 1)
        cnt ^= 1;
    return cnt;
}
int dp[N];
int f(int mask)
{
    if (dp[mask] != -1)
        return dp[mask];
    int &ans = dp[mask];
    ans = 1e9;
    for (int i = 0;i < 16;++i)
        for (int j = 0;j < 16;++j)
            if (((mask >> i) & 1) && ((mask >> j) & 1))
            {
                int e = i ^ j;
                smin(ans,f(mask ^ (1 << i) ^ (1 << j) ^ (1 << e)) + 1 + ((mask >> e) & 1));
            }
    for (int i = 0;i < 16;++i)
        if ((mask >> i) & 1)
            smin(ans,f(mask ^ (1 << i)) + 1);
    return ans;
}
int main(void)
{
    int n;
    cin>>n;
    for (int i = 1;i < n;++i)
    {
        int a,b,c;
        cin>>a>>b>>c;
        ++a;++b;
        g[a].pb(mp(b,c));
        g[b].pb(mp(a,c));
    }
    const int MM = 16;
    const int M = 1 << MM;
    memset(dp,-1,sizeof(dp));
    dp[0] = 0;
    int cnt = dfs(1,0);
    ans += f(cnt);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 38144
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n;
string ans;
int main(){
fcin;
    cin >> n;
    ll p = 1;
    while(n){
        if( (n/p) % 26 == 0){
            ans = 'z' + ans;
            n-=p;
        }
        else{
        char x = ('a' + (n/p)%26 - 1);
        ans = x + ans;
        }
        p*=26;
        if(p>n) break;
    }
    cout << ans << '\n';

}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>

void mod(int &p,int q){
	p=(p+q)%100000;
}

int w,h;

int map[105][105][4];

int main(void){
while(1){

scanf("%d%d", &w, &h);
if(w==0)return 0;
memset(map,0,sizeof(map));

for(int i=1;i<=w;i++)map[i][1][0]=1;
for(int i=1;i<=h;i++)map[1][i][1]=1;

for(int x=2;x<=w;x++){
	for(int y=2;y<=h;y++){
		map[x][y][0] = map[x-1][y][0];
		map[x][y][1] = map[x][y-1][1];
		map[x][y][2] = map[x][y-1][0];
		map[x][y][3] = map[x-1][y][1];
		mod(map[x][y][0], map[x-1][y][3]);
		mod(map[x][y][1], map[x][y-1][2]);
	}
}

mod(map[w][h][0] ,map[w][h][1] + map[w][h][2] + map[w][h][3]);

printf("%d\n", map[w][h][0]);

}
}

Measured memory_bytes: 1208
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  rep(i, N - K) {
    if (A[i] < A[i + K])
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}

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

int check(vector<string> s, vector<string> c, int i, int j){
    int size_c = c.size();
    int flag = 0;
    for(int t = 0; t < size_c; t++){
        for(int k = 0; k < size_c; k++){
            if(s[i + t][j + k] != c[t][k]){
                flag = 1;
                break;
            }
        }
    }

    return flag;
}

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

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

    vector<string> c(m);
    for(int i = 0; i < m; i++){
        cin >> c[i];
    }

    int flag = 1;
    for(int i = 0; i <= n - m; i++){
        for(int j = 0; j <= n - m; j++){
            flag = 1;
            if(s[i][j] == c[0][0]){
                flag = check(s, c, i, j);
            }

            if(flag == 0){
                break;
            }
        }

        if(flag == 0){
            break;
        }
    }

    if(flag == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3616