akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(void){
  int k,s;
  cin>>k>>s;
  k ++;
  int ret = 0;
  rep(i,k)rep(j,k){
    if(i + j <= s && s - i - j < k){ 
      ret ++;
      // cout<<i<<' '<<j<<endl;
    }
  }

  cout<<ret<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int a, b; cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++) {
        int digit = i;
        int d1 = digit % 10; digit /= 10;
        int d2 = digit % 10; digit /= 10;
        int d3 = digit % 10; digit /= 10;
        int d4 = digit % 10; digit /= 10;
        int d5 = digit % 10;
        if (d1 == d5 and d2 == d4) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

int main(){
	ll n,m;
	while(scanf("%lld%lld",&n,&m),n){
		ll x[110]={};
		rep(_,0,n){
			ll d,v;
			scanf("%lld%lld",&d,&v);
			x[d]=max(x[d],v);
		}
		ll ans=0;
		rep(i,1,m+1)ans+=x[i];
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 1980
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    ll n;
    cin >> n;
    string s[n];
    for (ll i=0;i<n;i++)cin >> s[i];
    sort(s,s+n);
    vector<pair<ll,ll>> x;
    ll c=1;
    for (ll i=1;i<n;i++){
        if (s[i-1]==s[i]){
            c++;
        }else{
            x.push_back(make_pair(i-1,c));
            c=1;
        }
    }
    x.push_back(make_pair(n-1,c));
    sort(x.begin(),x.end(),pairCompareSecond);
    vector<string> p;
    p.push_back(s[x[x.size()-1].first]);
    for (ll i=1;i<x.size();i++){
        if (x[x.size()-1].second==x[x.size()-1-i].second){
            p.push_back(s[x[x.size()-1-i].first]);
        }
    }
    sort(p.begin(),p.end());
    for (ll i=0;i<p.size();i++){
        cout << p[i] << endl;
    }
    return 0;
}


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

int main()
{
	int top1 = 0, top2 = 0, top3 = 0;
	int temp;
	
	for (int i = 0; i < 10; i++) {
		cin >> temp;
		if (temp >= top1) {
			top3 = top2;
			top2 = top1;
			top1 = temp;
		} else if (temp >= top2) {
			top3 = top2;
			top2 = temp;
		} else if (temp >= top3) {
			top3 = temp;
		}
	}
	
	cout << top1 << "\n" << top2 << "\n" << top3 << "\n";
	return 0;
}

Measured memory_bytes: 1164
n=int(input())
ti=list(map(int,input().split()))
m=int(input())
pi=[0for i in range(m)]
xi=[0for i in range(m)]
for i in range(m):
  pi[i],xi[i]=map(int,input().split())

#print(pi)
#print(ti)
for i in range(m):
  time=0
  for j in range(n):
    if(j==pi[i]-1):
      time+=xi[i]
    else:
      time+=ti[j]
    #print(time)
  print(time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    
    int n;
    cin>>n;
    
    vector<long long> H(n);
    for(int i=0;i<n;i++){
        cin>>H[i];
    }
    
    long long mx=-1, cnt=0;
    for(int i=0;i<n;i++){
        if(H[i] < mx && i!=0) {
            cnt+=mx-H[i];
        }
        mx = max(H[i], mx);
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 4688
n = int(input())
cube = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]

for _ in range(n):
    b, f, r, v = map(int, input().split())
    cube[b-1][f-1][r-1] += v

for x in range(4):
    for y in range(3):
        for z in range(10):
            print(' ' + str(cube[x][y][z]), end='')
        print()
    if x < 3: 
        print('#' * 20)



Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
const int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string last;
    cin >> last;
    set<string>st;
    st.insert(last);
    f(n-1) {
        string s;
        cin >> s;
        if (s[0] != last.back() || st.count(s)) {
            cout << "No\n";
            exit(0);
        }
        last = s;
        st.insert(s);
    }
    cout << "Yes\n";
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        string s = ins();
        char pre = ' ';
        rep(i, s.size()) {
            if (s[i] == pre) {
                cout << "Bad" << endl;
                return 0;
            }
            pre = s[i];
        }
        cout << "Good" << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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


#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main() {
    int i,n,k;
    c_p_c();
    int a[4]={0};
    w(t){

    	string s;
    	cin>>s;
    	if(s=="AC"){
    		a[0]++;
    	}else if(s=="WA"){
    		a[1]++;
    	}else if(s=="TLE")
    		a[2]++;
    	else
    		a[3]++;


    }

    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3]<<endl;


    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cstdio>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
int n;
int x,last,sum=1,flag=0;
int main()
{
    scanf("%d",&n);
    scanf("%d",&last);
    for(int i=1;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(flag==1)
        {
            if(x<last)
            {
                sum++;
                flag=0;
            }
        }
        else if(flag==-1)
        {
            if(x>last)
            {
                sum++;
                flag=0;
            }
        }
        else
        {
            if(x>last)
            {
                flag=1;
            }
            else if(x<last)
            {
                flag=-1;
            }
        }
        last=x;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str):
    tot = 0
    count = 0
    for i, c in enumerate(S):
        if c in "ACGT":
            count += 1
        else:
            tot = max(tot, count)
            count = 0
    tot = max(tot, count)
    print(tot)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int main() {
    double W, H, w, h, x, y;
    while (cin >> W >> H >> w >> h >> x >> y) {
    double left = max(-W/2, x - w/2);
    double right = min(W/2, x + w/2);
    double bottom = max(-H/2, y - h/2);
    double top = min(H/2, y + h/2);

    double cx = (left + right) / 2;
    double cy = (bottom + top) / 2;
    cout << fixed << setprecision(10) << cy / cx << endl;
    }
}



Measured memory_bytes: 3280
import sys
input = sys.stdin.readline
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
N,M = map(int,input().split())
uf = UnionFind(N)
for m in range(M):
    temp = [int(i)-1 for i in input().split()]
    uf.union(temp[0],temp[1])
print(-min(uf.parents))

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N;
    cin >> N;

    cout << N * (N+1) / 2 << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
  public static void Main() {
    int total = int.Parse(Console.ReadLine());
    long[] input = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
    bool flag = false;
    
    Array.Sort(input);
    
    for (int i = 0; i < total - 1; i++) {
      if (input[i] == input[i + 1])
        flag = true;
    }
    
    if (flag)
      Console.WriteLine("NO");
    else
      Console.WriteLine("YES");
  }
}

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

char maze[20][20];
int maxNum;
int h, w;

void update(int hh, int ww, int cost, int length[20][20])
{
    // 壁にぶつかって死んだパターン
    if (hh < 0 || hh >= h || ww < 0 || ww >= w || maze[hh][ww] == '#' ) {
        return;
    }
    if (cost >= length[hh][ww]) {
        return;   
    }
    length[hh][ww] = cost;
    // 上下左右に移動
    update(hh - 1, ww, cost + 1, length);
    update(hh, ww - 1, cost + 1, length);
    update(hh + 1, ww, cost + 1, length);
    update(hh, ww + 1, cost + 1, length);
}

int main()
{
    int result = 0;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> maze[i][j];
        }
    }

    // スタートだけ選んで、あとは全部の道について距離を調べる
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int length[20][20];
            for (int ii = 0; ii < h; ii++) {
                for (int jj = 0; jj < w; jj++) {
                    length[ii][jj] = 999999;
                }
            }
            maxNum = 0;
            update(i, j, 0, length);
            for (int ii = 0; ii < h; ii++) {
                for (int jj = 0; jj < w; jj++) {
                    if (length[ii][jj] == 999999) continue;
                    result = max(result, length[ii][jj]);
                }
            }
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
/*template*/

int main()
{
  ll n,r;cin>>n>>r;
  ll ans= n<10 ? r+100*(10-n):r;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    int prev;
    cin >> prev;
    ll res = 0;
    rep(i,N-1) {
        int a; cin >> a;
        if (prev > a) res += prev - a;
        prev = (prev > a) ? prev : a;
    }
    cout << res << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
 
int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	
 
const ll mod=1e9+7;
const int INF=INT_MAX/2;

int main(){
	int n,m;
	cin>>n>>m;
	int sum=0;
	int a[1001];
	REP(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	int cnt=0;
	REP(i,n){
		//cout<<(double)n/(4*m)<<endl;
		if(a[i]>=((double)sum/(4*m))){
			cnt++;
		}
	}
	if(cnt>=m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
 

Measured memory_bytes: 256
#include<stdio.h>
int Y[]={0,1,0,-1};
int X[]={1,0,-1,0};
int main(){
  int h,w,y,x,d,ny,nx,nd,gy,gx,a=0,i,j,k,f[110][110][5]={};
  char m[110][110]={};
  char c[]={">v<^"};
  scanf("%d %d",&h,&w);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      scanf(" %c",&m[i][j]);
      if(m[i][j]=='G')m[gy=i][gx=j]='.';
      for(k=0;k<4;k++){
	if(m[i][j]==c[k])break;
      }
      if(k-4){
	m[y=i][x=j]='.';
	d=k;
	f[i][j][k]=1;
      }
    }
  }
  while(gy-y||gx-x){//printf("%d %d %d\n",y,x,d);
    nd=(d+1)%4;
    ny=y+Y[d];
    nx=x+X[d];
    if(m[ny][nx]-'.'){
      ny=y;
      nx=x;
      d=(d+3)%4;
    }
    else if(m[ny+Y[nd]][nx+X[nd]]=='.')d=nd;
    if(f[ny][nx][d])break;
    if(f[ny][nx][0]+f[ny][nx][1]+f[ny][nx][2]+f[ny][nx][3]==0)a++;
    f[y=ny][x=nx][d]=1;
  }
  printf("%d\n",gy==y&&gx==x?a+1:-1);
  return 0;
}
    

Measured memory_bytes: 852
//package atcoder.yahoo;

import java.io.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long k = s.nextLong();
        long a = s.nextLong();
        long b = s.nextLong();

        if(a > b) {
            System.out.println(k+1);
        } else {
            if(k < a - 3){
                System.out.println(k+1);
            } else {
                long a1 = k + 1;
                long totalBis = a;
                k = k - a + 1;

                while(k > 1) {
                    totalBis += b - a;
                    k -= 2;
                }
                if(k == 1) {
                    totalBis++;
                }
                System.out.println(Math.max(totalBis, a1));
            }
        }
//        System.out.println(func(k,a,b,1,0));
    }



    private static int func(int k, int a, int b, int currBis, int currY) {
        if(k == 1) {
            int ans = currBis;
            if(currY >= 1){
                ans += b;
            }else {
                ans +=1;
            }
            return ans;
        }


        if(currBis < a) {
            if(currY > 0) {
                int a1 = func(k-1, a, b, currBis + 1, currY);
                int a2 = func(k - 1, a, b, currBis + b, currY - 1);
                return Math.max(a1, a2);
            } else {
                int a1 = func(k-1, a, b, currBis + 1, currY);
                return a1;
            }
        } else {
            if(currY > 0) {
                int a1 = func(k-1, a, b, currBis + 1, currY);
                int a2 = func(k - 1, a, b, currBis + b, currY - 1);
                int a3 = func(k - 1, a, b, currBis - a, currY + 1);
                return Math.max(a1, Math.max(a2, a3));
            } else {
                int a1 = func(k-1, a, b, currBis + 1, currY);
//                int a2 = func(k - 1, a, b, currBis + b, currY - 1);
                int a3 = func(k - 1, a, b, currBis - a, currY + 1);
                return Math.max(a1, a3);
            }
        }
    }
}


Measured memory_bytes: 23252
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


int main()
{
	ll a, b, c;
	cin >> a >> b >> c;

	string res = "NO";
	if (b - a == c - b)
	{
		res = "YES";
	}

	println(res);
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

#define MOD 1000000007
#define FACT_MAX 1000000

LL fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0;
    if(k==n || k==0) return 1;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};

LL n,m;
vector<LL> a,b,v;

int main(){
  cin>>n>>m;
  LL tmp;
  REP(i,n){
    cin>>tmp;
    a.push_back(tmp);
  }
  REP(i,m){
    cin>>tmp;
    b.push_back(tmp);
  }
  Combinatrics comb;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  REP(i,a.size()-1){
    if(a[i]==a[i+1]){
      cout<<0<<endl;
      return 0;
    }
  }
  REP(i,b.size()-1){
    if(b[i]==b[i+1]){
      cout<<0<<endl;
      return 0;
    }
  }
  if(a[a.size()-1]!=n*m || b[b.size()-1]!=n*m){
    cout<<0<<endl;
    return 0;
  }

  v.push_back(0);
  
  int ia=0,ib=0;
  FOR(i,1,n*m+1){
    ia=min(ia,(int)n-1);
    ib=min(ib,(int)m-1);
    if(a[ia]==i && b[ib]==i){
      v.push_back(i);
      ia++;
      ib++;
    }else if(a[ia]==i){
      v.push_back(i);
      ia++;
    }else if(b[ib]==i){
      v.push_back(i);
      ib++;
    }
  }

  LL cum=1;
  ia=a.size()-1;
  ib=b.size()-1;
  LL target;
 
  REP(i,v.size()-1){
    target=v[v.size()-1-i];
    LL blank = (n-ia)*(m-ib)-(n*m-target);
    LL band = target-v[v.size()-2-i];
    //cerr<<blank<<" "<<band<<endl;
    if(blank<band){
      cout<<0<<endl;
      return 0;
    }
    
    if(a[ia]==b[ib])
      cum=(cum*comb.nck((int)blank-1,(int)band-1)%MOD)*fact[(int)band-1]%MOD;
    else if(a[ia]==target)
      cum=((cum*(m-ib)%MOD)*comb.nck((int)blank-1,(int)band-1)%MOD)*fact[(int)band-1]%MOD;
    else if(b[ib]==target)
      cum=((cum*(n-ia)%MOD)*comb.nck((int)blank-1,(int)band-1)%MOD)*fact[(int)band-1]%MOD;

    if(ia==0)ib--;
    else if(ib==0)ia--;
    else if(a[ia-1]<b[ib-1])ib--;
    else if(a[ia-1]>b[ib-1])ia--;
    else{
      ia--;
      ib--;
    }
  }

  cout<<cum<<endl;
  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 105;

int A[N];

int main(){
	fio; cout<<fixed<<setprecision(25);	
	int n; cin >> n;
	for(int i = 1; i <= n; ++i) cin >> A[i];

	int cost = 1000000000;
	for(int i = -100 ;i <= 100 ; ++i){
		int curr = 0;
		for(int j = 1 ;j <= n ; ++j) curr += (A[j]-i)*(A[j]-i);
		cost =min(cost , curr);
	}

	cout << cost << endl;

	return 0;
}










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

public class Main {
    int capacity = 2;
    int[] stack = new int[capacity];
    int top = 0;

    public void push(int data) {
        if(size() == capacity)
            expand();

        stack[top] = data;
        top++;
    }

    private void expand() {
        int length = size();
        int[] newStack = new int[capacity * 2];
        System.arraycopy(stack, 0 , newStack, 0, length);
        stack = newStack;
        capacity *= 2;
    }

    public int pop() {
        int data = 0;

        if(isEmpty())
        {
            System.out.println("stack is empty");
        } else {
            top--;
            data = stack[top];
            stack[top] = 0;
            shrink();
        }
        return data;
    }

    public void shrink() {
        int length = size();
        if(length <= (capacity/2)/2)
        {
            capacity = capacity / 2;
        }
        int[] newStack = new int[capacity];
        System.arraycopy(stack, 0 , newStack, 0, length);
        stack = newStack;
    }

    public int size() {
        return top;
    }

    public boolean isEmpty() {
        return top <= 0;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        Main stack1 = new Main();
        int a, b;

        for(String s : lines)
        {
            if(s.equals("+"))
            {
                a = stack1.pop();
                b = stack1.pop();
                stack1.push(a+b);
            } else if(s.equals("-"))
            {
                a = stack1.pop();
                b = stack1.pop();
                stack1.push(b-a);
            } else if(s.equals("*"))
            {
                a = stack1.pop();
                b = stack1.pop();
                stack1.push(a*b);
            } else {
                stack1.push(Integer.parseInt(s));
            }
        }
        System.out.println(stack1.pop());
    }
}



Measured memory_bytes: 24460
import java.lang.Math.*

fun main(args:Array<String>?): Unit {
    val (r, x, y, n) = readLine()!!.trim().split(' ').map(String::toInt)
    val percentage = readLine()!!.trim().split(' ').map(String::toInt)
    val angles = IntArray(n + 1){if (it == 0) 0 else percentage[it - 1]}.let{percent ->
        for (i in 1 .. n) percent[i] += percent[i - 1]
        percent.map{Angle(sin(2 * PI * it / 100), cos(2 * PI * it / 100))}
    }
    val points = angles.map{Point(it.sin * r, it.cos * r)}
    val origin = Point(0, 0)
    val newOrigin = Point(x, y)
    println(
            (0 until n).joinToString(" "){i ->
                val defaultSize = r * r * PI * percentage[i] / 100
                val line = Line(points[i], points[i + 1])
                if (percentage[i] < 50) {
                    val mid = Angle.angleABC(line.endA + line.endB, origin, newOrigin)
                    val heightDiff = origin.distanceFrom(newOrigin) * mid.cos
                    val areaDiff = heightDiff * line.length / 2
                    ((defaultSize + areaDiff) / defaultSize * 100).toInt().toString()
                }else if (percentage[i] > 50){
                    val mid = Angle.angleABC(line.endA + line.endB, origin, newOrigin)
                    val heightDiff = origin.distanceFrom(newOrigin) * mid.cos
                    val areaDiff = heightDiff * line.length / 2
                    ((defaultSize - areaDiff) / defaultSize * 100).toInt().toString()
                }else {
                    val angle = Angle.angleABC(points[i], origin, newOrigin)
                    val diff = -angle.sin * r * origin.distanceFrom(newOrigin)
                    ((defaultSize + diff) / defaultSize * 100).toInt().toString()
                }
            }
    )
}

data class Point(val x: Double, val y: Double) {
    operator fun plus(that: Point): Point = Point(this.x + that.x, this.y + that.y)
    operator fun minus(that: Point): Point = Point(this.x - that.x, this.y - that.y)
    fun distanceFrom(that: Point): Double = (this - that).let{(x, y) -> sqrt(x * x + y * y)}
    constructor(x: Int, y: Int):this(x.toDouble(), y.toDouble())
}
class Line(val endA: Point, val endB: Point) {
    val length: Double = endA.distanceFrom(endB)
}
class Vector(from: Point, to: Point) {
    val x  = to.x - from.x
    val y = to.y - from.y
    fun dot(that: Vector): Double = this.x * that.x + this.y * that.y
    fun cross(that: Vector): Double = this.x * that.y - this.y * that.x
    val length: Double = sqrt(x * x + y * y)
}

class Angle(val sin: Double, val cos: Double) {
    val tan: Double
        get() = sin / cos
    val radian: Double = if (cos >= 0) asin(sin) else 2 * PI - asin(sin)
    operator fun minus(that: Angle): Angle = Angle(sin * that.sin - cos * that.cos, cos * that.cos + sin * that.sin)
    companion object {
        fun angleABC(a: Point, b: Point, c: Point): Angle {
            val ab = Vector(a, b)
            val bc = Vector(b, c)
            return Angle(ab.cross(bc) / ab.length / bc.length, ab.dot(bc) / ab.length / bc.length)
        }
    }
}


Measured memory_bytes: 34024
# div2019B - RGB Boxes
r, g, b, n = list(map(int, input().rstrip().split()))
x = n // min(r, g, b) + 1
cnt = 0
for i in range(x):
    for j in range(x):
        if (n - (i * r + j * g)) >= 0 and (n - (i * r + j * g)) % b == 0:
            cnt += 1
print(cnt)

Measured memory_bytes: 41196
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
    return x;
    else
    return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
    if(m%2)
	r=(r*n)%p;
    n=(n*n)%p;
    m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
       return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
	z[i] = min (r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	++z[i];
    if (i + z[i] - 1 > r)
	l = i, r = i + z[i] - 1;
    }
    return z;
}//n=a+b-x;
//x=(a+b)-(n);
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/    
   int n,a,b;
   cin>>n>>a>>b;
   int mi=-1;
   if(a+b>=n)
   {
   	mi=a+b-n;
   }
   else
   {
   	mi=0;
   }
   cout<<min(a,b)<<' '<<mi<<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 < (n); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)


int main(){
    int a,b,h;
    cin>>a>>b>>h;

    cout<< (a+b)*h/2 <<endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*freopen{"input.txt","r",stdin};
freopen{"output.txt","w",stdout};*/
#define mp make_pair
#define pb push_back
const int INF=1000*1000*1000;
//vector<int>
const int maxn=3e5+5;
typedef long long ll;
typedef long double ld;
priority_queue <int,vector<int>,greater<int> > q1;  //从小到大 
priority_queue <int,vector<int>,less<int> >q2;  //从大到小 
ll a[300030],b[300030],c[300030];
ll ans=-1e18;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<3*n;i++){
		cin>>a[i];
	} 
	for(int i=0;i<3*n;i++){
		q1.push(a[i]);
		b[i]=b[i-1]+a[i];
		if(q1.size()>n)
		{
			b[i]-=(q1.top());
			q1.pop();
		}
	  }
	for(int i=3*n-1;i>=0;i--){
		q2.push(a[i]);
		c[i]=c[i+1]+a[i];
		if(q2.size()>n)
		{
			c[i]-=(q2.top());
			q2.pop();
		}
	  }
	for(int i=n-1;i<2*n;i++){
		ans=max(ans,b[i]-c[i+1]);
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 8184
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 200005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';

ll abs1(ll x) {
  if (x < 0)
    return -x;
  return x;
}
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
ll n;
ll arr[N][2];
ll dp[N];
// just do initialise tr with -inf for max,and inf for min
// for min just change all max to min
ll tr[4 * N];
void update(ll indx, ll val, ll ogL, ll ogR, ll si = 1) {
  if ((indx < ogL) or (indx > ogR))
    return;

  if (ogL == ogR) {
    tr[si] = max(tr[si], val);
    return;
  }
  ll mid = (ogL + ogR) >> 1;
  update(indx, val, ogL, mid, si << 1);
  update(indx, val, mid + 1, ogR, (si << 1) | 1);

  tr[si] = max(tr[si << 1], tr[(si << 1) | 1]);
}

ll query(ll l, ll r, ll ogL, ll ogR, ll si = 1) {
  if (l > r)
    return 0;
  if ((r < ogL) or (l > ogR))
    return 0; // for min change it to inf

  if ((ogL >= l) && (ogR <= r)) {
    return tr[si];
  }

  ll mid = (ogL + ogR) >> 1;
  return max(query(l, r, ogL, mid, (si << 1)),
             query(l, r, mid + 1, ogR, (si << 1) | 1));
}

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

  memset(dp, 0, sizeof(dp));
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> arr[i][0];
  }

  for (ll i = 1; i <= n; i++)
    cin >> arr[i][1];

  memset(tr, 0, sizeof(tr));
  for (ll i = 1; i <= n; i++) {
    dp[i] = query(1, arr[i][0] - 1, 1, n) + arr[i][1];
    update(arr[i][0], dp[i], 1, n);
  }

  cout << (*max_element(dp + 1, dp + n + 1)) << en;
  return 0;
}


Measured memory_bytes: 11264
#define _GLIBCXX_DEBUG
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>

using namespace std;

int main(){

    int N, count = 0;
    cin >> N;

    if (N <= 9){
        cout << N << endl;
    }else if (N <= 99){
        cout << 9 << endl;
    }else if (N <= 999){
        cout << (N-99)+9 << endl;
    }else if (N <= 9999){
        cout << 909 << endl;
    }else if (N <= 99999){
        cout << (N-9999)+909 << endl;
    }else if (N <= 100000){
        cout << 90909 << endl;
    }

    return 0;
}


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

int main(void){
	int hour=0, minute=0;
	int S;
	
	cin >> S;
	
	while(S >= 3600){
		S -= 3600;
		hour += 1;
	}
	
	while(S >= 60){
		S -= 60;
		minute += 1;
	}
	
	
	cout << hour << ":" << minute << ":" << S << "\n";
	
	return 0;
}


Measured memory_bytes: 3112
#include <stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);
	if ((n / 100)*100 + (n/100)*10 + (n/100) >= n) {
		printf("%d", (n /100)*100 + (n/100)*10 + (n/100));
	} else {
		n+=100;
		printf("%d", (n / 100)*100 + (n/100)*10 + (n/100));
	}
	
	return 0;
}


Measured memory_bytes: 128
class Combination:
    def __init__(self, mod, max_n):
        self.MOD = mod
        self.MAX_N = max_n

        self.f = self.factorial(self.MAX_N)
        self.f_inv = [self.inv(x) for x in self.f]

    def inv(self,x):
        return pow(x, self.MOD-2, self.MOD)
    
    def factorial(self, n):
        res = [1]
        for i in range(1,n+1):
            res.append(res[-1] * i % self.MOD)
        return res
    
    def comb(self, n, r):
        return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD


X, Y = map(int,input().split())
k, l = (2*Y-X)//3, (2*X-Y)//3

if (X + Y) % 3 != 0 or k < 0 or l < 0:
    print(0)
    exit()

CB = Combination(10**9+7, k+l)
print(CB.comb(k+l,k))

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

int main() {
    queue<pair<string, int> > Q;
    int n;
    int q;
    string name;
    int time;
    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        cin >> name >> time;
        Q.push(make_pair(name, time));
    }
    pair<string, int> one_task;
    int elaps = 0;
    int a;
    while(!Q.empty()) {
        one_task = Q.front();
        Q.pop();
        a = min(one_task.second, q);
        one_task.second -= a;
        elaps += a;
        if(one_task.second > 0) {
            Q.push(one_task);
        } else {
            cout << one_task.first << " " << elaps << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    ll n;
    cin >> n;
    vector<pll> a(n);
    REP(i,n) cin >> a[i].SE >> a[i].FI;

    sort(a.begin(), a.end());
    ll now = 0;
    bool flag = true;
    REP(i, n)
    {
        now += a[i].SE;
        if (now > a[i].FI) flag = false;
    }
    if (!flag){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string S; int J, O, I, M1, M2;
int main(){
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'J') {
			J++;
			O = 0;
			I = 0;
		}
		if (S[i] == 'O') {
			I = 0;
			O++;
			if (i < S.size() - 1) {
				if (S[i + 1] == 'J') {
					J = 0;
					O = 0;
				}
			}
		}
		if (S[i] == 'I') {
			I++;
			if (J >= O && O <= I) {
				M2 = min(J, O);
				M2 = min(O, I);
				M1 = max(M1, M2);
			}
			if (i < S.size() - 1) {
				if (S[i + 1] != 'I') {
					J = 0;
					O = 0;
					I = 0;
				}
			}
		}
	}
	cout << M1 << endl;
	return 0;
}

Measured memory_bytes: 2048
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n, x = read_ints()
    d = read_int_list()
    ans = abs(x - d[0])
    
    for i in range(1, n):
        ans = GCD(ans, abs(x - d[i]))
    print(ans)    

if __name__ == '__main__':
    Main()

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tsii = tuple<string, int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    cout << std::fixed;
    cout << std::setprecision(7);
    int n;
    cin>>n;
    vector<double> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    double bunbo = 0;
    for (int i = 0; i < n; i++)
    {
        bunbo += 1.0/a[i];
    }
    cout<<1.0/bunbo<<endl;

    return 0;
}

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

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    bool ok=false;
    for(int i=0; i<=n; ++i){
        for(int j=0; j<=m; ++j){
            if(i*j+(n-i)*(m-j)==k)ok=true;
        }
    }
    cout<<(ok?"Yes":"No")<<endl;
    return 0;
}

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

int main(){
  int n,a;
  vector <int> v;
  while(cin >> n,n){
    for(int i = 0;i < n;i++){
      cin >> a;
      v.push_back(a);
    }
    sort(v.begin(),v.end());
    int sum = 0;
    for(int i = 1;i < n-1;i++){
      sum += v[i];
    }
    sum = sum / (n-2);
    cout << sum  << endl;
    for(int i = 0;i < n;i++){
      v.pop_back();
    }
  }

}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    int n, key;
    cin >> n;
    string c;
    list<int> l;
    REP(i, n){
        cin >> c;
        if (c == "deleteFirst"){
            l.pop_front();
        }
        else if (c == "deleteLast"){
            l.pop_back();
        }
        else if (c == "insert"){
            cin >> key;
            l.push_front(key);
        }
        else {
            cin >> key;
            auto itr = l.begin();
            while (itr != l.end()){
                if (*itr == key){
                    l.erase(itr);
                    break;
                }
                else {
                    itr++;
                }
            }
        }
    }
    auto itr = l.begin();
    auto itrl = l.end();
    itrl--;
    while (itr != itrl){
        cout << *itr << " ";
        itr++;
    }
    cout << *itr << endl;
}


Measured memory_bytes: 34360
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X, M = map(int, readline().split())

    n = 1
    P = 1
    while n < N:
        n *= 2
        P += 1

    pos = [[0] * M for _ in range(P)]
    value = [[0] * M for _ in range(P)]

    for r in range(M):
        pos[0][r] = r * r % M
        value[0][r] = r

    for p in range(P - 1):
        for r in range(M):
            pos[p + 1][r] = pos[p][pos[p][r]]
            value[p + 1][r] = value[p][r] + value[p][pos[p][r]]

    ans = 0
    cur = X % M
    for p in range(P):
        if N & (1 << p):
            ans += value[p][cur]
            cur = pos[p][cur]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 119340
def max(a,b); a > b ? a : b; end
  
N = gets.to_i
A = gets.split.map(&:to_i)
ans = -Float::INFINITY

dp = Array.new(6){ Array.new(N + 1, -Float::INFINITY) }
dp[0][0] = 0

(1 .. N).each do |i|
  a = A[i - 1]
  i_max = (i + 1) / 2
  i_min = N / 2 - (N - i) / 2
  (i_min .. i_max).each do |t|
    dp[i_max - t][i] = (max(i - 4, 0) .. max(i - 2, 0)).map{|j| dp[(j + 1) / 2 - (t - 1)][j] + a }.max 
    ans = max(ans, dp[i_max - t][i]) if t == N / 2
  end
end
puts ans


Measured memory_bytes: 43224
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>

using namespace std;


int main() {
    int n, m; cin >> n >> m;
    vector<pair<int, int>> pairs;
    for(int i = 0; i < m; i++) {
        int f, s; cin >> f >> s;
        pairs.emplace_back(f, s);
    }
    sort(
        pairs.begin(), pairs.end(),
        [] (pair<int, int> p, pair<int, int> q) {
            return p.second != q.second? p.second < q.second : p.first < q.first;
        }
    );
    int ans = 0;
    int prev_end = -1;
    for(auto p : pairs) {
        if(prev_end <= p.first) {
            ans++;
            prev_end = p.second;
        }
    }
    cout << ans << endl;
}
//
// Islands War
// https://atcoder.jp/contests/abc103/tasks/abc103_d
// 

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int x,n,resu;
  int result1=0;
  int result2=0;
  cin>>x>>n;
  vector<int> l;
  map<int,int> m;
  rep(i,n){
    int j;cin>>j;
    l.pb(j);
    m[j]++;
  }
  for(int i=0;i<100;i++){
    if(m[x+i]==0){
      result1=x+i;
      break;
    }
  }
  for(int i=0;i<100;i++){
    if(m[x-i]==0){
      result2=x-i;
      break;
    }
  }
  if(abs(x-result1)>abs(x-result2)){
    resu=result2;
  }
  else if(abs(x-result1)<abs(x-result2)){
    resu=result1;
  }
  else{
    resu=min(result1,result2);
  }
  cout<<resu<<endl;


}

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

int main() {
  string str; 
  getline(cin,str);
  for ( int i = 0; i < str.size(); i++ ) {
    if ( str[i] >= 'a' && str[i] <= 'z' ) str[i] -= 32;
  }
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 1172