akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

typedef long long LL;

const double PI = acos(-1.0);

double a, b, x;

int main()
{
	scanf("%lf %lf %lf", &a, &b, &x);
	
	double s = a*b;
	x /= a;
	
	if(s/2 >= x)
	{
		double l=0, r=PI;
		while(r-l >= 1e-12)
		{
			double mid = (l+r)/2;
			if(tan(mid) > 2*x/b/b)
				r = mid;
			else
				l = mid;
		}
		l = l/PI*180;
		l = 90-l;
		printf("%.10f", l);
	}
	else
	{
		x = s-x;
		double l=0, r=PI;
		while(r-l >= 1e-12)
		{
			double mid = (l+r)/2;
			if(tan(mid) > 2*x/a/a)
				r = mid;
			else
				l = mid;
		}
		l = l/PI*180;
		printf("%.10f", l);
	}
	return 0;
}

Measured memory_bytes: 384
def main():
    H, N = map(int, input().split())
    AB = sorted([tuple(map(int, input().split())) for _ in range(N)])
    v = [0] * (H + 1)
    for i in range(1, H + 1):
        v[i] = min(v[max(i - a, 0)] + b for a, b in AB)
    print(v[-1])

main()


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  for (int i = 0; i < C; i += A) {
    ++ans;
    if (ans % 7 == 0)
      i += B;
  }
  cout << ans << endl;
}


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

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

int main(){
  int h,w; cin >> h >> w;
  vector<string> M;
  for(int i=0;i<h;i++){
  	string s; cin >> s;
    M.push_back(s);
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(M[i][j]=='.') M[i][j]='0';
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(M[i][j]=='#') {
      	for(int k=0;k<8;k++){
          int x=i+dx[k];
          int y=j+dy[k];
          if(0<=x&&x<h&&0<=y&&y<w){
            if(M[x][y]=='#') continue;
            M[x][y]++;
          }
        }
      }
    }
  }

  for(int i=0;i<h;i++){
    cout << M[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */
int n;

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

/* convert a string into an integer value */
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 (key % (M-1)) + 1; }

int find(char str[]){
  long long int i,key,a;
  key = getKey(str);
  for(i=0;i<n;i++){
    a = (h1(key) + (i*h2(key))) % M;
    if(strcmp(H[a],str)==0)
      return 1;
    else if(strlen(H[a]) == 0) return 0;
    //printf("%s is not match\n",H[i]);
  }
  return 0;
}

int insert(char str[]){
  long long int i,key,a;

  key = getKey(str);
  for(i=0;i<n;i++){
    a = (h1(key)+ (i*h2(key))) % M;
    if(H[a][0]=='\0'){
      strcpy(H[a],str);
      //printf("suc:insert %s\n",H[i]);
      return 1;
    }
    else if((strcmp(H[a],str)) == 0) return 0;
  }
  return 0;
}

int main(){
    int i, 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: 15460
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
 
int main(){
  int n,k,l=0;
  cin >> n >> k;
  vi p(n);
  rep(i,n) cin >> p[i];

  sort(p.begin(),p.end());
  rep(i,k) l+=p[i];
  cout << l << endl; 
 
    return 0;
}

Measured memory_bytes: 3624
def main():
    N, K = list(map(int, input().split()))
    S = input()
    ans = 0

    for i in range(N):
        if S[i] == 'L' and i != 0 and S[i] == S[i-1]:
            ans += 1
        elif S[i] == 'R' and i != N-1 and S[i] == S[i+1]:
            ans += 1

    # print(ans)
    print(min(ans + (2 * K), N - 1))


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;
ll p[40];
map<ll, int> mp;
ll a[maxn];

void init() {
    p[0] = 1;
    for (int i = 1; i <= 32; i++) {
        p[i] = p[i - 1] * 2;
    }
}


int main() {
    init();
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a, a + n);
    int ans = 0;
    ll now;
    for (int i = n - 1; i >= 0; i--) {
        if (mp[a[i]] > 0) {
            mp[a[i]]--;
            for (int j = 0; j <= 32; j++) {
                now = p[j] - a[i];
                if (mp.count(now) && mp[now] > 0) {
                    mp[now]--;
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14460
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

// dp(i) = 1 if first player wins with i stones remaining
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int N,K;
	cin >> N >> K;
	vector<int> A(N+5);
	for (int i = 0; i < N; i++) cin >> A[i];
	vector<bool> dp(K+5);	
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j < N; j++) {
			if (i >= A[j] && !dp[i-A[j]]) dp[i] = true;
		}
	}
	if (dp[K]) cout << "First";
	else cout << "Second";
    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Linear Approximation
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const long long LINF = 1LL << 62;

/* typedef */

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

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  ll asum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &as[i]);
    as[i] -= i;
  }
  sort(as, as + n);

  int nh0 = (n - 1) / 2, nh1 = n / 2;
  ll mind = LINF;
  for (int nh = nh0; nh <= nh1; nh++) {
    ll d = 0;
    int &c = as[nh];
    for (int i = 0; i < n; i++) d += abs(as[i] - c);
    if (mind > d) mind = d;
  }

  printf("%lld\n", mind);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const int N = 51;

long long a,b,n,k;

struct matrix{
    long long n;
    long long arr[N][N];
    matrix(long long n1 = 0){
        n = n1;
        memset(arr,0,sizeof(arr));
    }
};

matrix mul(matrix A,matrix B){
    matrix C(A.n);
    for(int i=0;i<C.n;i++)
        for(int j=0;j<C.n;j++)
            for(int k=0;k<C.n;k++)
                C.arr[i][k] = (C.arr[i][k] + (A.arr[i][j]*B.arr[j][k])%MOD)%MOD;
    return C;
}

matrix expo(matrix A,long long k){
    matrix I(n);
    for(int i=0;i<n;i++)
        I.arr[i][i] = 1;
    while(k>0){
        if(k&1)
            I = mul(I,A);
        A = mul(A,A);
        k/=2;
    }
    return I;
}

int main(){

    cin>>n>>k;
    matrix A(n);

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>A.arr[i][j];

    matrix res = expo(A,k);
    long long ans = 0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            ans = (ans + res.arr[i][j])%MOD;

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
    int N, Q;
    cin>>N>>Q;
    vector<int> S(N), T(N), X(N);
    for (int i=0; i<N; i++)
        cin>>S[i]>>T[i]>>X[i];
    vector<int> D(Q);
    for (int &d: D)
        cin>>d;

    vector<pair<int, int>> V;
    for (int i=0; i<N; i++)
    {
        V.push_back(make_pair(S[i]-X[i], X[i]));
        V.push_back(make_pair(T[i]-X[i], -X[i]));
    }
    sort(V.begin(), V.end());

    vector<int> ans(Q);
    int v = 0;
    int d = 0;
    multiset<int> A;
    while (v<(int)V.size() && d<(int)D.size())
    {
        while (v<(int)V.size() &&
            (d>=(int)D.size() || V[v].first<=D[d]))
        {
            int X = V[v].second;
            v++;
            if (X>0)
                A.insert(X);
            else
                A.erase(-X);
        }

        while (d<(int)D.size() &&
            (v>=(int)V.size() || D[d]<V[v].first))
        {
            if (A.empty())
                ans[d] = -1;
            else
                ans[d] = *A.begin();
            d++;
        }
    }
    for (int a: ans)
        cout<<a<<endl;
}


Measured memory_bytes: 17644
// coding on smartphone
#include<iostream>
using namespace std;

int main(){
	int n, x, ma = -1000001, mapos, mi = 1000001, mipos;
	cin >> n;
	
	for(int i =0; i < n; i++){
		cin >> x;
		if(x > ma){
			ma = x;
			mapos = i;
		}
		if(x < mi){
			mi = x;
			mipos = i;
		}
	}
	
	cout << 2*n-1 << endl;
	int pivot = (abs(ma) > abs(mi) ? mapos : mipos);
	
	pivot++;
	
	for(int i = 1; i <= n; i++) cout << pivot << " " << i << endl;
	
	if(abs(ma) > abs(mi)){
		for(int i = 1; i < n; i++)   cout << i << " " << i+1 << endl;
	}else{
		for(int i = n; i > 1; i--)	cout << i << " " << i-1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;



class Program
{
    const string az = "abcdefghijklmnopqrstuvwxyz";
    static void Main(string[] args)
    {
        int aaa = "abcdZ".CompareTo("abc");
        string a;
        a = Console.ReadLine(); //標準入力
        if (a == "zyxwvutsrqponmlkjihgfedcba")
        {
            Console.WriteLine("-1");
            return;
        }

        if(a.Length < 26)
        {
            char c = CharUnused(a);
            Console.WriteLine(a + c.ToString());
        }
        else { 
            Console.Write(test(a));
        }
    }

    static char CharUnused (string str)
    {
        for(int i=0;i < az.Length;i++ )
        {
            if (Regex.IsMatch(str,az[i].ToString()))
            {
                continue;
            }
            return az[i];
        }
        return 'z';
    }

    static bool UniquCheck(string str)
    {
        HashSet<char> hsTable = new HashSet<char>();

        char[] cs = Getchars(str);
        for(int i = 0; i < cs.Length; i++)
        {
            if (!hsTable.Add(cs[i]))
                return false;
        }
        return true;
    }

    static char[] Getchars(string str)
    {
        char[] cs = new char[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            cs[i] = str[i];
        }

        return cs;
    }
    
    static bool Uniqucheck(char[] src, char c)
    {
        for(int i = 0; i < src.Length; i++)
        {
            if (src[i] == c)
                return false;
        }
        return true;
    }

    static string test(string str)
    {
        int i = 26;
        int inc = 1;

        while (true)
        {
            string add = Convert.ToString((char)(str[i - 1] + inc));
            if (add != "{")
            {
                string str2 = str.Substring(0, i - 1) + add;
                if (UniquCheck(str2))
                {
                    return str2;
                }
            }
            if (add == "z" || add == "{")              
            {
                inc = 1;
                i--;
            }
            else {
                inc++;
            }
        }
        return null;
        
    }
}


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

using namespace std;
 
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
void fastscan(int &x)
 {
        bool neg=false;
        register int c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    } 
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int mod = 1e9+7;
const int inf = 2e18+5;
const int nax = 100010;
const int mod1 = 998244353;

signed main()
 {
  
  int n;
  cin>>n;
  vector<int> v(n,0);
  vector<int> num;
  loop(i,0,n)
   {
    int x;    
    cin>>x;
    num.pb(x);
    v[x-1]++;
   }
  int ways = 0;
  vector<int> each(n);
  loop(i,0,n)
    {
      if(v[i]>=2)
         {
         ways += v[i]*(v[i]-1)/2;
         each[i] = v[i]*(v[i]-1)/2;
       }
      else
         each[i] = 0;
    }
  loop(i,0,n)
   {
    int k = num[i],ans;
    int stk = v[k-1];
    if(stk<=2)
       ans = ways - each[k-1];
    else
       ans = ways - each[k-1] + (stk-1)*(stk-2)/2;

    
    cout<<ans<<END;
   }
  
return 0;
}

Measured memory_bytes: 7408
#include<iostream>
#include <queue>
#include <algorithm>

using namespace std;

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

int main(){
	int n;
	cin >> n;
	queue<int> q[n];
	int a;
	rep(i, n)rep(j, n-1){
		cin >> a;
		a = a - 1;
		q[i].push(a);
	}
	bool flag = true;
	int ans = 0;
	int b[n];
	rep(i, n) b[i] = 0;
	while(flag){
		flag = false;
		rep(i, n){
			if(q[i].size() != 0){
				int nxt = q[i].front();
				if(q[nxt].front() == i){
					q[i].pop();
					q[nxt].pop();
					int date = max(b[i], b[nxt]) + 1;
					b[i] = date;
					b[nxt] = date;
					flag = true;
				}
			}
		}
	}
	
	flag = true;
	rep(i, n) {
		ans = max(ans, b[i]);
		if(q[i].size() != 0){
			flag = false;
		}
	}
	if(flag){
		cout << ans << endl;
	}else{
		cout << -1 << endl;
	}
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  long long N;
  cin >> N;
  vector<int> furui(N+1);
  furui[1] = 1;
  for(int i = 2; i <= N; i++){  
    if(furui[i] == 0){  
      int n = i;
      while(n <= N){  
        furui[n] = i;
        n += i;
      }
    } 
  }
  /*
  for(int i = 2; i < N; i++){  
    cout << furui[i] << " "; 
  }
  //*/
  long long ans = 0;
  for(int i = 1; i < N; i++){  
    int n = i;
    int tmp = 1;
    map<int, int> mp;
    while(n > 1){  
      mp[furui[n]]++;
      n /= furui[n];
    }
    for(auto x: mp){  
      int kazu = x.second;
      tmp *= (kazu+1);
    }
    ans += tmp;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 7124
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    int n;
    scanf("%d", &n);
    long long int l[87];
    l[0] = 2;
    l[1] = 1;
    for (int i=2; i<=n; i++)
    {
        l[i] = l[i-2] + l[i-1];
    }
    printf("%lld\n", l[n]);
    return 0;
}


Measured memory_bytes: 128
def resolve():
    N,K =map(int,input().split())

    if K > ((N-1)*(N-2))//2:
        print(-1)
        return
    XX = [(1,i) for i in range(2,N+1)]
    xx2=[]
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            xx2.append((i,j))

    xx2 = xx2[:((N-1)*(N-2))//2-K]

    ans = XX+xx2
    print(len(ans))

    for i,j in ans:
        print(i,j)    



if __name__ == "__main__":
    resolve()

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

using namespace std;

int F[1000000][2],cnt;
int n,m,a[1000000],ss[1000000];
pair<int,int> tmp[100];
int main()
{
	memset(F,-1,sizeof F);
	F[0][0]=0; cin >> n; m=1<<n;
	for(int i=0;i<m;i++) cin >> a[i];

	for(int i=1;i<m;i++)
	{
		cnt=0; tmp[++cnt]=make_pair(a[i],i);
		for(int j=0;j<n;j++) if(i&(1<<j))
		{
			int x1=F[i^(1<<j)][0];
			int x2=F[i^(1<<j)][1];
			if(x1!=-1) tmp[++cnt]=make_pair(a[x1],x1);
			if(x2!=-1) tmp[++cnt]=make_pair(a[x2],x2);
		}
		sort(tmp+1,tmp+1+cnt);
		reverse(tmp+1,tmp+1+cnt);
		cnt=unique(tmp+1,tmp+1+cnt)-tmp-1;
		F[i][0]=tmp[1].second; F[i][1]=tmp[2].second;
		ss[i]=tmp[1].first+tmp[2].first;
	}
	for(int i=1;i<m;i++) ss[i]=max(ss[i],ss[i-1]);
	for(int i=1;i<m;i++) printf("%d\n",ss[i]); 
	return 0;
}

Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int B = 318;
const int INF = 19191919;

int a[B][B];
vector<int> s[B];

int QUERY(int l, int r, int d){
    auto F = [&](int x){
        return abs(d-x);
    };

    int ret = INF;
    int lid = l/B, rid = r/B;
    if(lid == rid){
        for(int i=l; i<=r; ++i) ret = min(ret, F(a[i/B][i%B]));
    }
    else{
        for(int i=l; i<(lid+1)*B; ++i) ret = min(ret, F(a[i/B][i%B]));
        for(int b=lid+1; b<rid; ++b){
            auto itr = lower_bound(all(s[b]),d);
            ret = min(ret, F(*itr));
            --itr;
            ret = min(ret, F(*itr));
        }
        for(int i=B*rid; i<=r; ++i) ret = min(ret, F(a[i/B][i%B]));
    }
    return ret;
}

int main(){
    int n;
    scanf(" %d", &n);
    rep(i,n){
        int v;
        scanf(" %d", &v);

        int bid = i/B;
        a[bid][i%B] = v;
        s[bid].pb(v);
    }

    rep(i,B){
        s[i].pb(-INF);
        s[i].pb(INF);
        sort(all(s[i]));
    }

    int q;
    scanf(" %d", &q);
    rep(i,q){
        int l,r,d;
        scanf(" %d %d %d", &l, &r, &d);
        printf("%d\n", QUERY(l,r,d));
    }
    return 0;
}



Measured memory_bytes: 4112
import java.util.*;
import java.math.*;
public class Main{
    public static void main(String args[]){
       Scanner cin = new Scanner(System.in);
       BigInteger a, b,d;
       while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       }
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int a[3]={};
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++) {
    a[s[i]-'a']++;
  }
  sort(a,a+3);
  if(a[2]-a[0]<=1) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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

string search(vector<char> ss) {
	for (int i(0); i < ss.size(); ++i) {
		vector<char> ssd = ss;
		for (int j = i; j < ssd.size(); ++j) {
			ssd.erase(ssd.begin() + i, ssd.begin() + j);
			string str(ssd.begin(), ssd.end());
			if (str == "keyence") {
				return "YES";
			}
			ssd = ss;
		}
	}
	return "NO";
}

int main() {
	ios::sync_with_stdio(false);
	string s; cin >> s;
	if (s == "keyence") {
		cout << "YES";
		return 0;
	}
	vector<char> ss(s.begin(), s.end());
	
	cout << search(ss);
	return 0;
}

Measured memory_bytes: 256
/*#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
int H, W;
vector<vector<int>> A(501, vector<int>(501, 0));

int main(void){
	
	scanf("%d %d", &H, &W);
	for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) scanf("%d", &A[i][j]);
	
	
	
    return 0;
}
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
ll N, X;
vector<ll> x(100010, 0);

int main(void){
	
	scanf("%lld %lld", &N, &X);
	for(int i = 0; i < N; ++i) scanf("%lld", &x[i]);
	sort(x.begin(), x.begin() + N);
	
	if(N == 1){ printf("%lld\n", abs(x[0] - X)); return 0; }
	
	int n = -1;
	for(int i = 0; i < N; ++i) if(x[i] < X) n = i; 
	if(n == -1) x.insert(x.begin(), X);
	else x.insert(x.begin() + n + 1, X);
    
	vector<ll> v;
	for(int i = 0; i < N; ++i) v.push_back(x[i + 1] - x[i]);
	
	ll ans = 0, mx = *min_element(v.begin(), v.end());
	for(ll i = mx; i >= 1; --i){
	    ans = i;
	    for(auto j : v){
	        if(j % i != 0){
	            ans = -1;
	            break;
	        }
	    }
	    if(ans != -1){
	        printf("%lld\n", ans);
	        break;
	    }
	}
	
    return 0;
}


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

const int d[4] = {0,0,-1,1};

int dfs(int& H, int& W, vector<vector<char>>& tiles, vector<vector<bool>>& visited, pair<int,int> now){
    int h = now.first;
    int w = now.second;
    int res = 0;
    if(h < 0 || h >= H || w < 0 || w >= W) return 0;
    if(tiles[h][w] == '#' || visited[h][w]) return 0;

    visited[h][w] = true;
    res++;

    for(int i=0;i<4;i++){
        int nh = h + d[i];
        int nw = w + d[i^2];
        res += dfs(H,W,tiles,visited,{nh,nw});
    }

    return res;
}

int main(){
    int H,W;
    while(cin >> W >> H, H != 0 && W != 0){
        vector<vector<char>> tiles(H,vector<char>(W));
        vector<vector<bool>> visited(H,vector<bool>(W,false));
        pair<int,int> start;

        for(int h=0;h<H;h++){
            for(int w=0;w<W;w++){
                cin >> tiles[h][w];
                if(tiles[h][w] == '@') start = {h,w};
            }
        }

        cout << dfs(H, W, tiles, visited, start) << endl;
    }
}


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

typedef long long LL;

const int N=100000,mod=998244353;
 
int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,m[3];
struct side{
  int y,next;
}e[N*6+9];
int lin[3][N+9],cs;

void Ins(int id,int x,int y){e[++cs].y=y;e[cs].next=lin[id][x];lin[id][x]=cs;}
void Ins2(int id,int x,int y){Ins(id,x,y);Ins(id,y,x);}

void into(){
  scanf("%d",&n);
  for (int i=0;i<3;++i){
	scanf("%d",&m[i]);
	for (int j=1;j<=m[i];++j){
	  int x,y;
	  scanf("%d%d",&x,&y);
	  Ins2(i,x,y);
	}
  }
}

int pw[N+9];

void Get_pw(){
  int pw18=1;
  for (int i=1;i<=18;++i) smul(pw18,10);
  pw[0]=1;
  for (int i=1;i<=n;++i) pw[i]=mul(pw[i-1],pw18);
}

int sg[3][N+9],b[N+9];
int sum[3][N+9],mx[3];

void Get_sg(int id){
  for (int i=n;i>=1;--i){
	for (int j=lin[id][i];j;j=e[j].next)
	  if (e[j].y>i) b[sg[id][e[j].y]]=1;
    for (;b[sg[id][i]];++sg[id][i]);
	sadd(sum[id][sg[id][i]],pw[i]);
	mx[id]=max(mx[id],sg[id][i]);
	for (int j=lin[id][i];j;j=e[j].next) b[sg[id][e[j].y]]=0;
  }
}

int ans;

void Get_ans(){
  for (int i=0;i<=mx[0];++i)
	for (int j=0;j<=mx[1];++j) sadd(ans,mul(mul(sum[0][i],sum[1][j]),sum[2][i^j]));
}

void work(){
  Get_pw();
  Get_sg(0);
  Get_sg(1);
  Get_sg(2);
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 11168
#pragma GCC optimize("Ofast")
/*#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                      
using namespace std;
                      
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                      
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define ghost signed
#define left left228
#define right right228
#define prev prev228
#define list list228

const int N = 105;
const int MOD = 1e9 + 7;

void add(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int summ(int a, int b) {
	add(a, b);
	return a;
}

void mul(int &a, int b) {
	a *= b;
	a %= MOD;
}

int mult(int a, int b) {
	mul(a, b);
	return a;
}

struct BIG
{
	int l, r, value;
	BIG() {}
	BIG(int _l, int _r, int _value) {
		l = _l, r = _r, value = _value;
	}
};

vector< BIG > getbigs(int x) {
	int K = (int)sqrt(x);
	vector< BIG > res;
	int i = 1;
	while (i <= x) {
		int value = x / i;
		int nw = x / value;
		while (x / nw == value) ++nw;
		int l = i;
		int r = nw - 1;
		uax(l, K + 1);
		if (l <= r)
			res.push_back(BIG(l, r, value));
		i = nw;
	}
	return res;
}

int H, n;
int dp[33500][2];
int sum[33500][2];
int K;


ghost main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> H >> n;
	vector< BIG > bigs = getbigs(H);
	K = (int)sqrt(H);
	for (int i = 1; i <= K; ++i) {
		dp[i][0] = 1;
	}
	for (auto p : bigs) dp[p.value][1] = p.r - p.l + 1;
	for (int i = 1; i <= K; ++i) {
		for (int j = 0; j < 2; ++j) {
			sum[i][j] = summ(sum[i - 1][j], dp[i][j]);
		}
	}
	for (int it = 2; it <= n; ++it) {
		for (int i = 1; i <= K; ++i) {
			dp[i][0] = dp[i][1] = 0;
		}
		for (int last = 1; last <= K; ++last) {
			int pref = min(K, H / last);
			add(dp[last][0], sum[pref][0]);
			add(dp[last][0], (sum[K][1] - sum[last - 1][1] + MOD) % MOD);
		}
		for (BIG p : bigs) {
			dp[p.value][1] = mult(sum[p.value][0], p.r - p.l + 1);
		}
		for (int i = 1; i <= K; ++i) sum[i][0] = sum[i][1] = 0;
		for (int i = 1; i <= K; ++i) {
			sum[i][0] = summ(sum[i - 1][0], dp[i][0]);
			sum[i][1] = summ(sum[i - 1][1], dp[i][1]);
		}
	}
	int res = 0;
	for (int i = 1; i <= K; ++i) {
		add(res, dp[i][0]);
		add(res, dp[i][1]);
	}
	cout << res << '\n';
	return 0;
} // kek ;





Measured memory_bytes: 2168
#include <stdio.h>
int main (void)
{
    char a;

    scanf("%s",&a);

    if(a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o')
        printf("vowel\n");
        else
            printf("consonant\n");

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

    long ans = a*b;
    if (ans %2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
n = gets.chomp.to_i
pa = gets.chomp.split.map(&:to_i)
q = gets.chomp.split.map(&:to_i)

a = nil
b = nil
index = 0
(1..n).to_a.permutation do |arr|
  if arr == pa
    a = index
  end
  if arr == q
    b = index
  end
  index += 1
end
p (a-b).abs


Measured memory_bytes: 2172
#include<iostream>
#define N 101
using namespace std;
int A[N][N];
bool visited[N];
int n;
int order=0;
int time_r[N][2];

void dfs(int A[][N],int n,int loc){
    //if(visited[loc]) return;
    for(int i=0;i<n;i++){
        if(i==loc) continue;
        if(visited[i]==false && 1==A[loc][i]){
            visited[i]=true;
            order++;
            time_r[i][0]=order;
            dfs(A,n,i);
        }
    }
    order++;
    time_r[loc][1]=order;
}

int main(){
    int k,num;
    int e;
    cin>>n;
    for(int i=0;i<n;i++){
        visited[i]=false;
        for(int j=0;j<n;j++)
            A[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>k;
        k--;
        cin>>num;
        for(int j=0;j<num;j++){
            cin>>e;
            e--;
            A[k][e]=1; //A[e][k]=1;
        }
    }


    for(int i=0;i<n;i++){
        if(visited[i]==false){
            order++;
            time_r[i][0]=order;
            visited[i]=true;
            dfs(A,n,i);
        }
    }

    for(int i=0;i<n;i++){
        cout<<i+1<<' '<<time_r[i][0]<<' '<<time_r[i][1]<<endl;
    }
    return 0;

}



Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define N 100


int main() {
        int n, a, b;
        cin >> n >> a >> b;
        cout << ( ((b-a) % 2) ? "Borys" : "Alice") << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M,Q;
    cin >> N >> M >> Q;
    vector<vector<ll>> S(N+1, vector<ll>(N+1));
    ll l,r;
    rep(i,M){
        cin >> l >> r;
        l--;r--;
        S[l+1][r+1]++;
    }
    vector<ll> p(Q), q(Q);
    rep(i,Q){
        cin >> p[i] >> q[i];
        p[i]--;q[i]--;
    }
    rep(i,N){
        rep(j,N){
            S[i+1][j+1] += S[i+1][j];
        }
    }
    rep(j,N){
        rep(i,N){
            S[i+1][j+1] += S[i][j+1];
        }
    }
    rep(i,Q){
        cout << S[q[i]+1][q[i]+1] + S[p[i]][p[i]] - S[q[i]+1][p[i]] - S[p[i]][q[i]+1] << endl;
    }
}

Measured memory_bytes: 6608
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll h,a;
	cin>>h>>a;
	ll x,y,z;
	x=h/a;
	if(h-x*a==0)
	cout<<x;
	else  
	cout<<x+1;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using ull = unsigned long long;
using namespace std;

ll M = 1000000007;

void solve()
{
	int n;
	string s;
	cin >> n >> s;
	vector<set<int>> al(26);
	rep(i, n)
	{

		al[s[i] - 'a'].insert(i);
	}
	int q;
	cin >> q;
	rep(i, q)
	{
		int type;
		cin >> type;
		if (type == 1)
		{
			int i_q;
			char c_q;
			cin >> i_q >> c_q;
			i_q--;
			al[s[i_q] - 'a'].erase(i_q);
			s[i_q] = c_q;
			al[c_q - 'a'].insert(i_q);
		}
		else
		{
			int l, r;
			cin >> l >> r;
			l--;
			r--;
			//cout << l << " " << r << endl;
			int cnt = 0;
			FOR(j, 0, 26)
			{
				int t;

				t = *al[j].lower_bound(l);
				auto m=al[j].lower_bound(l);
				//int k=distance(al[j].begin(),al[j].lower_bound(l));
				if (t <= r && m!=al[j].end())			{
					cnt++;
				}
			}
			cout << cnt << endl;
		}
	}
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 24220
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		while(true) {
			int n = sc.nextInt();
			int s = sc.nextInt();
			if (n == 0 && s == 0) return;
			int p[] = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextInt();
			}
			int ans = 0;

			for (int i = 0; i < n-1; i++) {
				for (int j = i + 1; j < n; j++) {
					if (p[i] + p[j] <= s)
						ans = Math.max(ans,  p[i] + p[j]);
				}
			}
			if (ans == 0)
				System.out.println("NONE");
			else
				System.out.println(ans);
		}
	}
}


Measured memory_bytes: 50608
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <bitset>
using namespace std;

typedef long long ll;
int main() {
    int N;
    cin>>N;
    vector<ll> v(N);
    for (int i=0; i<N; ++i) cin>>v[i];
    while (1) {
        if (v.size()==1) {
            cout<<"YES"<<endl;
            return 0;
        }
        if (v.size()==2) {
            if ((!(v[0]%2) && v[1]%2) || (v[0]%2 && !(v[1]%2))) {
                cout<<"NO"<<endl;
                return 0;
            } else {
                cout<<"YES"<<endl;
                return 0;
            }
        }
        bool ok=0;
        while (v.size()>2) {
            ll t1=v.back(); v.pop_back();
            bool even=(t1%2)==0;
            for (int i=v.size()-1; i>=0; --i) {
                if (v[i]%2 && even) continue;
                v[i]=v[i]+t1;
                ok=1;
                break;
            }
            if (ok) break;  
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int r, c, itemcnt;
	cin >> r >> c >> itemcnt;
	vector<vector<int>> item(r + 1, vector<int>(c + 1));
	for(auto rep = 0; rep < itemcnt; ++ rep){
		int x, y, c;
		cin >> x >> y >> c, -- x, -- y;
		item[x][y] = c;
	}
	vector<vector<vector<long long>>> dp(r + 1, vector<vector<long long>>(c + 1, vector<long long>(4)));
	dp[0][0][1] = item[0][0];
	for(auto i = 0; i < r; ++ i){
		for(auto j = 0; j < c; ++ j){
			for(auto k = 0; k < 3; ++ k){
				ctmax(dp[i][j + 1][k + 1], dp[i][j][k] + item[i][j + 1]);
			}
			for(auto k = 0; k <= 3; ++ k){
				ctmax(dp[i][j + 1][k], dp[i][j][k]);
				ctmax(dp[i + 1][j][0], dp[i][j][k]);
				ctmax(dp[i + 1][j][1], dp[i][j][k] + item[i + 1][j]);
			}
		}
	}
	cout << *max_element(dp[r - 1][c - 1].begin(), dp[r - 1][c - 1].end()) << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

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

int main() {
	int c[3][3];
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			cin >> c[i][j];
	bool isYes = 1;
	for (int i1 = 0; i1 < 3; i1++)
		for (int j1 = 0; j1 < 3; j1++)
			for (int i2 = 0; i2 < 3; i2++)
				for (int j2 = 0; j2 < 3; j2++)
					if (c[i2][j2] - c[i1][j2] - c[i2][j1] + c[i1][j1])
						isYes = 0;

	cout << (isYes ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	x, y := 1000, 0
	buy := true
	for i := 0; i < n; i++ {
		j := i
		for ; j < n; j++ {
			if buy {
				if j+1 < n && a[j] < a[j+1] {
					x, y = x%a[j], x/a[j]
					break
				}
			} else {
				if (j+1 < n && a[j] > a[j+1]) || (j == n-1) {
					x, y = x+y*a[j], 0
					break
				}
			}
		}
		i = j
		buy = !buy
	}

	puts(x)
}


Measured memory_bytes: 1788
#include <iostream>
 using namespace std ;
 int main()
 {
   int A, B, c, d, e;
   cin>>A;
   cin>>B;
   c =(A + B);
   d =(A - B);
   e =(A * B);
   if (c >= e&&c >= d)
   {
   cout<<c<<endl;
   }
else   if (e >= d&&e >= c)
   {
     cout<<e<<endl;
   }
  else  if (d >= e&&d >= c) 
   {
     cout<<d<<endl;
   }
   }

Measured memory_bytes: 3632
row, col, num = map(int, input().split())

tmp_l = []
board = []
for i in range(row):
  str = input()
  for j in range(col):
    if str[j] == '.':
      tmp_l.append(0)
    if str[j] == '#':
      tmp_l.append(1)
  board.append(tmp_l)
  tmp_l = []

onoff = []
bi = [32, 16, 8, 4, 2, 1]
for i in range(64):
  tmp = i
  for j in bi:
    tmp_l.insert(0, int(tmp / j))
    tmp %= j
  onoff.append(tmp_l)
  tmp_l = []

count = 0
ans = 0
for i in range(2**row):
  for j in range(2**col):
    for k in range(row):
      if onoff[i][k] == 1:
        for l in range(col):
          if onoff[j][l] == 1:
            if board[k][l] == 1:
              count += 1
    if count == num:
      ans += 1
    count = 0

print(ans)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int power(int x,int y){
    int res=1LL;
    while(y){
        if(y&1){
            res=(res*x)%MOD;
        }
        x=(x*x)%MOD;
        y=(y>>1);
    }
    return res;
}

signed main()
{
    
    speed
    string s;cin>>s;
    int n=s.size();
    int cnt[2]={0};
    for(int i=0;i<n;i+=1){
        cnt[s[i]-'A']+=1;
    }
    if(cnt[0]>=1 && cnt[1]>=1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    

    
    
    
    return 0;
}

Measured memory_bytes: 256
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
int main(){
  fast();
  int d,t,s;
  cin>>d>>t>>s;
  if(d>s*t){cout<<"No";}
  else{cout<<"Yes";}
 return 0;
  
}


Measured memory_bytes: 3636
import java.util.*;

// ARC 96-D
// https://beta.atcoder.jp/contests/arc096/tasks/arc096_b

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		long N = in.nextLong();
		long C = in.nextLong();
		
		long[] positions = new long[(int) N + 1];
		long[] values = new long[(int) N + 1];
		
		for (int i = 1; i<= N; i++) {
			positions[i] = in.nextLong();
			values[i] = in.nextLong();
		}
		
		long[] hidari = new long[(int) N + 1];
		long[] migi = new long[(int) N + 1];
		long[] hidariMax = new long[(int) N + 1];
		long[] migiMax = new long[(int) N + 1];
		
		for (int i = 1; i < N + 1; i++) {
			hidari[i] = hidari[i - 1] - (positions[i] - positions[i - 1]) + values[i];
			hidariMax[i] = Math.max(hidariMax[i - 1], hidari[i]);
		}
		for (int i = (int) N ; i > 0; i--) {
			int index = i == N ? 0 : i + 1;
			long pre = i == N ? C : positions[i + 1];
			migi[i] = migi[index] - (pre - positions[i]) + values[i];
			migiMax[i] = Math.max(migiMax[index], migi[i]);
		}
		
//		print("hidari", hidari);
//		print("hidariMax", hidariMax);
//		print("migi", migi);
//		print("migiMax", migiMax);
		
		long answer = 0;
		
		// iまで左回りで周り、i + 1まで右回りで回る
		for (int i = 1; i < N + 1; i++) {
			long newAnswer = hidariMax[i];
//			System.out.printf("%dまで左回り: %d\n", i, newAnswer);
			answer = Math.max(answer, newAnswer);
			
			// スタートへ戻る
			newAnswer -= positions[i];
			
			int index = i == N ? 0 : i + 1;
			newAnswer += migiMax[index];
//			System.out.printf("%dまで右回り: %d\n\n", i + 1, newAnswer);
			answer = Math.max(answer, newAnswer);
		}
		
		// iまで右回りで周り、i - 1まで左回りで回る
		for (int i = (int) N; i > 0; i--) {
			long newAnswer = migiMax[i];
//			System.out.printf("%dまで右回り: %d\n", i, newAnswer);
			answer = Math.max(answer, newAnswer);
			
			// スタートへ戻る
			newAnswer -= C - positions[i];
			
			newAnswer += hidariMax[i - 1];
//			System.out.printf("%dまで左回り: %d\n\n", i - 1, newAnswer);
			answer = Math.max(answer, newAnswer);
		}
		System.out.println(answer);
	}
	
	public static void print(String s, long[] arr) {
		System.out.println(s);
		for (int i = 0; i < arr.length; i++) {
			System.out.printf("%d ", arr[i]);
		}
		System.out.println();
	}
}


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

using namespace std;

int freq[100005];
int arr[100005];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", arr + i);
    }
    int mx = 0;
    vector<pair<int, int> > vp1, vp2;
    for (int i = 0; i < n; i += 2)
        ++freq[arr[i]];
    for (int i = 0; i <= 100000; i++)
        vp1.push_back({freq[i], i});

    memset(freq, 0, sizeof(freq));
    for (int i = 1; i < n; i += 2)
        mx = ++freq[arr[i]];
    for (int i = 0; i <= 100000; i++)
        vp2.push_back({freq[i], i});
    sort(vp1.rbegin(), vp1.rend());
    sort(vp2.rbegin(), vp2.rend());

    int mn = n;
    for (int i = 0; i < 10 ; i++) {
        for (int j = 0; j < 10; j++) {
            if(vp1[i].second != vp2[j].second){
                mn = min(mn, n - vp1[i].first- vp2[j].first);
            }
        }
    }
    printf("%d\n", mn);
}

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

int main () {

    int D;
    cin >> D;

    if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
    else if (D == 23) cout << "Christmas Eve Eve" << endl;
    else if (D == 24) cout << "Christmas Eve" << endl;
    else cout << "Christmas" << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vll v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  vll biton(60), bitoff(60);
  for (int k = 0; k < 60; k++) {
    for (int i = 0; i < n; i++) {
      if ((v[i] >> k) & 1) {
        bitoff[k] += 1LL << k;
      } else {
        biton[k] += 1LL << k;
      }
    }
  }
  int k = 0;
  ll m2 = m;
  while (m2) {
    k++;
    m2 >>= 1;
  }

  ll ans = 0;
  ll now = 0;
  for (int i = 0; i < 60; i++) {
    now += bitoff[i];
  }
  ans = now;
  vll maxb(61);
  for (int i = 0; i < 60; i++) {
    maxb[i + 1] = maxb[i] + max(biton[i], bitoff[i]);
  }
  now = 0;
  for (int i = 60; i >= 0; i--) {
    if ((m >> i) & 1) {
      now += biton[i];
      ans = max(ans, now - biton[i] + bitoff[i] + maxb[i]);
    } else {
      now += bitoff[i];
    }
  }
  ans = max(ans, now);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
def main():
    ans=0
    n=input()
    for i in range(len(n)):
        ans+=int(n[i])
    if(int(n)<=10):
        ans=n
    if(n=="100000" or n=="10000" or n=="1000" or n=="100"):
        ans=10
    print(ans)


if __name__=="__main__":
    main()

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)
 
 
def main():
    n, m = [int(i) for i in input().strip().split()]
    s1 = min(n, m // 2)
    s2 = (m - s1 * 2) // 4
    print(s1 + s2)
 
 
if __name__ == "__main__":
    main()

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

int main(){
  int n, ma, mb;
  cin >> n >> ma >> mb;
  int a[n], b[n], c[n];
  rep(i,n) cin >> a[i] >> b[i] >> c[i];
  vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(401, vector<int>(401, INF)));
  dp[0][0][0] = 0;
  rep(i, n){
    rep(j, 401){
      rep(k, 401) {
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
        if(dp[i][j][k] != INF) dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
      }
    }
  }
  int ans = INF;
  for(int i = 1; i <= 400; i++){
    for(int j = 1; j <= 400; j++){
      if(i*mb == j*ma){
        ans = min(ans, dp[n][i][j]);
      }
    }
  }
  if(ans == INF) cout << "-1" << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27264
n,m=map(int, input().split())
l = [[int(i) for i in input().split()] for i in range(m)]

for i in range(m):
    l[i].append(i)
l = sorted(l,key=lambda x: (x[0],x[1]))

l[0].append(1)
for i in range(1,m):
    if l[i][0]!=l[i-1][0]:
        l[i].append(1)
    else:
        l[i].append(l[i-1][3]+1)

for i in range(m):
    l[i].append(str(l[i][0]).zfill(6) + str(l[i][3]).zfill(6))

l=sorted(l,key=lambda x:(x[2]))

for i in range(m):
    print(l[i][4])


Measured memory_bytes: 40672
#include<iostream>
#include<stack>
#include<cstdlib>
using namespace std;

int main() {
	stack<int> s;
	string x;
	while (cin >> x) {
		if (x == "+") {
			int t1 = s.top();
			s.pop();
			int t2 = s.top();
			s.pop();
			s.push(t1 + t2);

			//cout << s.top() << "+ was processed" << endl;
		}
		else if (x == "-") {
			int t1 = s.top();
			s.pop();
			int t2 = s.top();
			s.pop();
			s.push(t2 - t1);

			//cout << s.top() << "- was processed" << endl;

		}
		else if (x == "*") {
			int t1 = s.top();
			s.pop();
			int t2 = s.top();
			s.pop();
			s.push(t1 * t2);

			//cout << s.top() << "* was processed" << endl;

		}
		else {
			s.push(atoi(x.c_str()));

		}

	}


	cout << s.top() << endl;

	return 0;
}

Measured memory_bytes: 1204
#include <cstdio>
#include <stack>
using namespace std;

int main() {
	int a, b;
	stack<int> st;
	char s[100]; //存储一个字符串, 数字或者是算符
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = st.top(); st.pop();
			b = st.top(); st.pop();
			st.push(a + b);
		} else if (s[0] == '-') { //减法顺序要搞对 
			a = st.top(); st.pop();
			b = st.top(); st.pop();
			st.push(b - a);
		} else if (s[0] == '*') {
			a = st.top(); st.pop();
			b = st.top(); st.pop();
			st.push(a * b);
		} else { //数值字符串, 可能一位, 也可能多位数字 
            int sum = 0;
            for (int i = 0; s[i]; i++) 
            	sum = sum * 10 + (s[i] - '0'); 
			st.push(sum); 
		}
	} 
	printf("%d\n", st.top());
	return 0;
}


Measured memory_bytes: 2724
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	if(n>m)swap(n,m);
	long long res=0;
	res+=(1ll*max(0,n-2)*max(0,m-2));
	if(n==1&&m==1){printf("%d",1);return 0;}
	if(n==1){printf("%d",m-2);return 0;}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256