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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#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()
{
    ll n,mincnt=0;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        if(a[i]<0) mincnt++;
    }
    ll absmin=__LONG_LONG_MAX__;
    ll ans=0;
    for (int i = 0; i < n; i++)
    {
        ans+=abs(a[i]);
        absmin=min(absmin,abs(a[i]));
    }
    if(mincnt%2>0)
    {
        ans-=2*absmin;
    }
    cout<<ans<<endl;
    return 0;
}

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



int main(void){
	double a, b, c, d, e, f;
	double x, y;


	while (cin >> a >> b >> c >> d >> e >> f){

		 y = (c*d - a*f) / (b*d - a*e);
		 x = (c - b*y) / a;
	
		 printf("%.3lf ", x);
		 printf("%.3lf\n", y);

	
	}


	
	
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef int64_t 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 int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

double calc_expected_value(int p) {
  ll sum = 0;
  for (int i = 1; i <= p; i++) sum += i;
  return (double)sum / (double)p;
}

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

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

  map<int, double> ev;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  for (auto& v : p) {
    if (ev.count(v) > 0) continue;
    ev[v] = calc_expected_value(v);
  }

  vector<double> e(n);
  rep(i, n) e[i] = ev[p[i]];

  double ans = 0;
  double tmp = 0;
  for (int i = 0; i < k; i++) tmp += e[i];
  ans = tmp;
  int st = 0, ed = k - 1;
  for (ed = k; ed < n; ed++) {
    tmp += e[ed];
    tmp -= e[st];
    st++;
    chmax(ans, tmp);
  }

  printf("%.7f\n", ans);

  return 0;
}


Measured memory_bytes: 2816
/*
    Ujjawal Pabreja
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
using ll = long long;
using ld = long double;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define gcd(a,b)        __gcd(a,b)
#define nl              "\n"
#define debug(x)        cout << #x << " : " << x << nl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5;

// ====== int_1024t begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== int_1024t ends ======

// ====== pbds begins ======
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, 
//         tree_order_statistics_node_update> 
//         pbds; 
// ====== pbds ends ======

// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a,ll b) {return ((a%mod)-(b%mod)+mod)%mod;}
inline ll mul(ll a,ll b) {return ((a%mod)*(b%mod))%mod;}
ll pwr(ll x,ll n){
    if(!n) return 1;
    if(n&1) return mul(x, pwr(mul(x,x),(n-1)/2));
    else return pwr(mul(x,x),n/2);
}
ll modinv(ll n){ 
    return pwr(n,mod - 2); 
}
// ====== Useful functions end ======
 
// ====== Variables begin ======

// ====== Variables end ======

void speed_solve(){
    string s;
    cin >> s;
    if(s[2] == s[3] and s[4] == s[5]){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}
int main()
{
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////
ll N;

vector<string> ans;

void dfs(string S, ll a) {
	if (S.size() == N) { ans.push_back(S); return; }
	rep(i, a) {
		char c = i+'a';
		dfs(S + c, a);
	}

	char c = a + 'a';

	dfs(S + c, a + 1);
	return;
}


int main() {
	cin >> N;

	string S;

	dfs(S, 0);

	sort(ans.begin(), ans.end());

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

	system("PAUSE");

}





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

int main(){
  int b1,b2,b3;
  cin >> b1 >> b2 >> b3;
  if(b1==0 && b2==0 && b3==1){
    cout << "Open\n";
  }else if(b1==1 && b2==1 && b3==0){
    cout << "Open\n";
  }else{
    cout << "Close\n";
  }
  return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007 
#define pb push_back
//#define mp make_pair
#define INF 2000000011LL
#define INFLL 1000000000000000011LL
#define eps 1e-9
#define pp pair < pair<ll,ll> , ll> 
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define foll(i,j,k) for(ll i=j;i<=k;i++)
#define clr(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vll vector<ll>
#define sz(a) a.size()
#define len(a) a.length()
#define all(a) a.begin(),a.end()
#define io_file freopen("Contest/input_file.in", "r", stdin); freopen("Contest/output_file.in", "w", stdout)

const int MAXN = 2e5+5;
using namespace std;
ll power(ll x, ll y)
{
  ll res = 1;
  while(y>0)
  {
    if(y&1)
       {
         res = (res*x)%mod;
        }
     x = (x*x)%mod;
     y = y>>1;
  }
    return res;
}
// std::vector<ll> divi[100004];
// void divisor(int n)
// {
//    for(ll i=1;i<=n;i++)
//    {
//      for(ll j=i;j<=n;j+=i)
//      {
//        divi[j].pb(i);
//      }
//    }
// }
ll n,m,k;
ll fact[200005];
ll rev[200005];

ll ncr(ll n,ll r)
{
  if(n < r) return 0;
  return (((fact[n]*rev[n-r])%mod)*rev[r])%mod;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    fact[0] = 1;
    rev[0] = 1;
    for(ll i = 1;i<=200004;i++)
    {
      fact[i] = (fact[i-1]*i)%mod;
      rev[i] = (rev[i-1]*power(i,mod-2))%mod;
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
      for(ll j=1;j<=m;j++)
      {
        ll x = ((((i-1LL)*i)/2LL + ((n-i+1LL)*(n-i))/2LL)*m)%mod;
        ll y = ((((j-1LL)*j)/2LL + ((m-j+1LL)*(m-j))/2LL)*n)%mod;
        ans = (ans + x + y)%mod;
      }
    }
    ans = (ans*ncr(n*m-2LL,k-2LL))%mod;
    ans = (ans*power(2LL,mod-2LL))%mod;
    cout<<ans<<endl;
    return 0;

}



Measured memory_bytes: 3328
# ITP1_6_C_0002.rb

# data配列の初期化
data = Array.new(4).map{Array.new(3).map{Array.new(10,0)}}

# データ数を取り込み、nに代入
n = gets.to_i

# データを実際に取り込み、処理

n.times do
	b,f,r,v = gets.split.map(&:to_i)
	sample = data[b-1][f-1][r-1]
	sample += v
	data[b-1][f-1][r-1] = sample
end

=begin
# デバッグ用

p data
=end

# データ出力

4.times do |i1|
	3.times do |i2|
		print " ",data[i1][i2].join(" "),"\n"
	end

	unless i1 == 3
		puts '#'*20
	end
end

Measured memory_bytes: 6108
S = list(input())
T = list(input())


for i in S:
    if S == T:
        print("Yes")
        break
    else:
        S_pop = S.pop(len(S)-1)
        S.insert(0, S_pop)
        # S =S[-1:] + S[:len(S)-1]
if not S==T:
    print("No")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	int a[N];
	int Alice=0;
	int Bob=0;
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	sort(a,a+N);
	reverse(a,a+N);
	for(int l=0;l<N;l++){
		if(l%2==0){
			Alice+=a[l];
		}
		else{
			Bob+=a[l];
		}
	}
	cout<<Alice-Bob<<endl;
}


Measured memory_bytes: 256
/* 
区間DPをします
F(l, r) := [l,r)の中で叩き出せる個数
*/

#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int dp[400][400];

// [l, r)
/*
int rec(int l, int r, vector<int> &w) {
    if (dp[l][r] != -1) return dp[l][r];
    if (abs(l-r)<=1) return 0;

    int res = 0;
    if (abs(w[l]-w[r-1]) <= 1 && rec(l+1,r-1,w) == r-l-2) res = r-l;
    for (int mid = l+1; mid < r; ++mid) res=max(res,rec(l,mid,w)+rec(mid,r,w));
    return dp[l][r] = res;
}
*/

int calc(int n, vector<int> &w) {
    for (int W = 2; W <= n; ++W) {
        for (int l = 0; l < n; ++l) {
            int r = l+W-1;
            if (n <= r) continue;
            if (abs(w[l]-w[r])<=1 && dp[l+1][r-1]==W-2) dp[l][r] = W;
            for (int mid = l; mid <= r; ++mid) {
                dp[l][r] = max(dp[l][r],dp[l][mid]+dp[mid+1][r]);
            }
        }
    }
    return dp[0][n-1];
}

int main(int argc, char const *argv[]) {
    int n;
    while(cin>>n,n) {
        vector<int> w(n); rep(i,n) cin>>w[i];
        memset(dp,0,sizeof(dp));
        // cout << rec(0,n,w) << endl;
        cout << calc(n,w) << endl;
    }
    return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL

using namespace std;
lli dp[3002][3002];
lli ar[3002];
lli br[3002][3002];
int n;
lli func(int i,int j,int f)
{
    if(i>j)
        return dp[i][j] = 0LL;
    if(dp[i][j]!=-1)
        return dp[i][j];
 //   cout << i << " " << j << endl;
    lli x = 0;
    lli y = 0;
    lli d1=ar[i]+func(i+1,j,1),d2=ar[j]+func(i,j-1,1);

    x = max(d1,d2);
  //  cout << "d1 " << d1  << endl;
  //  cout << "d2 " << d2 << endl;
    if(f==0)
    {
        if(d1>d2)
        {
            return d1 - br[i+1][j];
        }
        else if(d1<d2)
        {
            return d2-br[i][j-1];
        }
        else
        {
            return d1-max(br[i][j-1],br[i+1][j]);
        }
    }
    br[i][j] = x;
    if(d1>d2)
    {
        return dp[i][j] = br[i+1][j];
    }
    else if(d1<d2)
    {
        return dp[i][j] = br[i][j-1];
    }
    else
    {
        return dp[i][j] = max(br[i][j-1],br[i+1][j]);
    }

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

    mem(dp,-1);
    cin >> n;

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

    lli ans = func(0,n-1,0);
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 120408
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize
    };
    if n == 2 {
        println!("1");
        return;
    }
    // c>0 の範囲でaとbは自由なので, n-1以下になる整数の組み合わせ総数が解
    let mut count = 0;
    for a in 1..=(n - 1) {
        count += (n - 1) / a;
    }
    println!("{}", count);
}


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

int main(){
  int N;
  cin>>N;
  vector<int> a(N+1);
  vector<bool> flg(N+1);
  for(int i=1;i<=N;i++){
    cin>>a.at(i);
  }
  
  int next=a.at(1);
  flg.at(1)=true;
  int count=1;
  while(1){
    if(next==2){
      break;
    }
    if(flg.at(next)==true){
      count=-1;
      break;
    }
    flg.at(next)=true;
    next=a.at(next);
    count++;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 640
array = gets.split.map(&:to_i)

def factorization (m)
ary = []
  s = Math.sqrt(m.to_f).to_i
for i in(2..s)
  r = 0
  while m%i==0
      m=m/i
      r +=1
    end
    unless r ==0
    ary.push([i,r])
  end
end
if (m>s)
  ary.push([m,1])
end
return ary
end

n= array[0]
p = array[1]

factor_s =factorization(p)
ans = 1
factor_s.each{|fs|
  while fs[1]>=n
    ans *=fs[0]
    fs[1] -=n
  end}
p ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define For(i, a, b)       for(int i = a; i <= b; ++i)
#define Ford(i, a, b)      for(int i = a; i >= b; --i)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define FileName           "test"
#define ll                 long long
#define ld                 long double
#define ull                unsigned long
#define Print(x)           cerr << #x << "is " << x << '\n';
#define pb                 push_back
#define ep                 emplace_back
#define X                  first
#define Y                  second
//#define Karma

using namespace std;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template<typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template<typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template<typename T, typename... Args> inline void Cin(T& a, Args&... args){Cin(a);Cin(args...);}
template<typename T, typename... Args> inline void Cout(T x, char c, Args... args){Cout(x, c);Cout(args...); }

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 207;
const int M = 1e5 + 7;

struct TVal{ll w, v;} t[N];
ll n, m, cnt = 0, f[M], g[M], w, v, k;

void Enter()
{
     Cin(n, m);
     For(i, 1, n) Cin(t[i].w, t[i].v);
}

void Solve()
{
     memset(&f, -1, sizeof f);
     memset(&g, -1, sizeof g);
     f[0] = g[0] = 0;
     For(i, 1, n)
     {
         For(j, 0, m)
         {
             if(g[j] == -1) continue;
             if(t[i].w + j <= m) f[j + t[i].w] = max(f[j + t[i].w], g[j] + t[i].v);
         }
         For(j, 0, m) g[j] = max(g[j], f[j]), f[j] = g[j];
     }
     ll res = 0;
     For(i, 0, m) res = max(res, g[i]);
     cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;
 
#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)

const int N=2e5+50; 

int n,a[N],f[N],p[N],ans; 

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin); 
	//freopen("my.out","w",stdout); 
#endif
	scanf("%d",&n); 
	rep(i,1,n){
		scanf("%d",a+i); 
		p[a[i]]=i;
	}
	rep(i,1,n){
		f[i]=1;
		if(a[i]&&p[a[i]-1]<i)f[i]=f[p[a[i]-1]]+1;
		cmax(ans,f[i]); 
	}
	printf("%d\n",n-ans);
	return 0; 
}

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

int main(void){
	int a,b,c,temp = 0;
	cin >> a >> b >> c;
	
	if( a > b){
		temp = a;
		a = b;
		b = temp;
	}
	if( b > c){
		temp = b;
		b = c;
		c = temp;
	}
	if( a > b){
		temp = a;
		a = b;
		b = temp;
	}
	cout << a <<" "<< b <<" "<< c << endl;
        return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
 
/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair 
 
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int
 
/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;
 
/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
 
/* func */
 
/*struct*/
struct aaa {
	aaa() {
		cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);
	};
}aaaaaaa;
 
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//Counterclockwise from the 9o'clock direction
//Take the x-axis downward and the y-axis right
 
//#define int ll
//#define int long long
 
 int a[200010];
signed main()
{
  int n, k;
  cin>>n>>k;
  for(int i = 0; i < n; ++i){
    int t;
    cin>>t;
    ++a[t];
  }
  sort(a, a+n+1);
  int ans = 0;
  for(int i = 0; i <= n-k; ++i)
    ans += a[i];
    cout<<ans;
 
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>vec;
ll vis[100009];

int main()
{
    ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
    scanf("%lld%lld%lld",&n,&x,&m);
    vis[x]=1;
    a=x;
    vec.push_back(a);
    while(1)
    {
        a=(a*a)%m;
        if(vis[a]==1)
        {
            break;
        }
        else
        {
            vis[a]=1;
            vec.push_back(a);
        }
    }

    l=vec.size();
    k=min(l,n);
    ll ans=0;
    for(i=0;i<k;i++)
    {
        ans+=vec[i];
    }
    n-=k;
    x=0;
    y=0;
    for(i=0;i<l;i++)
    {
        if(vec[i]==a)
        {
            for(k=i;k<l;k++)
            {
                x+=vec[k];
                y++;
            }
            j=i;
            break;
        }
    }
    a=n/y;
    b=n%y;
    ans+=(a*x);
    for(i=j;i<l;i++)
    {
        if(b>0)
        {
            ans+=vec[i];
            b--;
        }
        else
        {
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4692
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AMaximizeTheFormula {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b, c;
	    in >> a >> b >> c;
	    int mx = a;
	    int n1 = b, n2 = c;
	    if(mx < b){
	        n1 = mx;
	        mx = b;
	    }
	    if(mx < c){
	        n2 = mx;
	        mx = c;
	    }

	    out << 10*mx + n1 + n2 << endl;
	}
};


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


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int k;
  int sum;
  int card[3];
  while(scanf("%d %d %d",&card[0],&card[1],&card[2])!=EOF){
    sum = 0;
    for(k=1;k<=10;k++){
      if(k==card[0] || k==card[1] || k==card[2]) continue;
      if(card[0] + card[1] + k <= 20) sum++;
    }
    if(sum>=4) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 580
#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>;
#define INF 100000000
const int MOD = 1000000007;


int main(){
    /*A
    int a,b,c;
    cin>>a>>b>>c;
    int x = a-b;
    if(c-x>=0)
    {
        cout<<c-x<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    */
    /*
    int n;
    cin>>n;
    vector <int> h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    bool flag = true;
    for(int i=n-1;i>0;i--)
    {
       if(h[i]-h[i-1]>=0)
       {
           continue;
       }
       else if(h[i]-h[i-1]==-1)
       {
           h[i-1]=h[i-1]-1;
       }
       else
       {
           flag = false;
       }
    }
    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    */

    int n;
    string s;
    cin >> s;
    n = s.size();
    vector<int> ans(n);
    rep(ri,2) {
        // solve R
        int cnt = 0;
        rep(i,n) {
            if (s[i] == 'R') cnt++;
            else {
            ans[i] += cnt/2;
            ans[i-1] += (cnt+1)/2;
            cnt = 0;
            }
        }
   
 
        reverse(ans.begin(), ans.end());
        reverse(s.begin(), s.end());
        rep(i,n) {
        if (s[i] == 'L') s[i] = 'R';
        else s[i] = 'L';
        }
    }
 
    rep(i,n) {
        cout<<ans[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 3812
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long LL;
#define N 100005
LL a[N];

int main()
{
    int n, cnt = 0;
    LL ans = 1;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    sort(a + 1, a + 1 + n);
    for (int i = n; i > 0; i--)
    {
        if (cnt == 2) break;
        if (a[i - 1] == a[i])
        {
            ans *= a[i];
            i--;
            cnt++;
        }
    }
    if (cnt == 2)
        printf("%lld\n", ans);
    else
        printf("0\n");

    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
int main(){
  int tall[10];
  int i,j;
  for(i = 0; i<10;i++){
    scanf("%d",&tall[i]);
  }
  for(i = 0;i < 3;i++){
    for(j = 0; j < 9-i;j++){
      if(tall[j] > tall[j+1]){
	int temp = tall[j];
	tall[j] = tall[j+1];
	tall[j+1] = temp;
      }
    }
    printf("%d\n",tall[9-i]);
  }
  return(0);
}

Measured memory_bytes: 600
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = input()

x = 0
ans = 0
for s in S:
	if s == "I":
		x += 1
	else:
		x -= 1
	ans = max(ans, x)
print(ans)


Measured memory_bytes: 3888
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする
 
using namespace std;
typedef long long int ll;
typedef pair< double, int> P;

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

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

struct edge{int to;
double cost;};

 
int main(void){

	long long int n;
	long long int h[100001]={};
	long long int dp[100001]={};

	cin>>n;
	FOR(i,1,n){
		cin>>h[i];
	}

	FOR(i,0,n){
		dp[i]=LINF;
	}
	dp[1]=0;

	FOR(i,0,n){
		if(i+2<=n){
			dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
		}
		if(i+1<=n){
			dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
		}
	}

	cout<<dp[n]<<endl;

}



Measured memory_bytes: 1792
import scala.io.StdIn._
object Main extends App {
  def count(a: Long, b: Long): Long = a + b - 2

  val n = readLong
  var res = Long.MaxValue
  for (i <- 1 to math.sqrt(n).toInt if n % i == 0) {
    res = math.min(res, count(i, n / i))
  }

  println(res)
}


Measured memory_bytes: 36036
H, W, K= map(int, input().split())
c = [input() for i in range(H)]
true_cnt = 0
for j in range(2**H):
  bin_j = str(bin(j))[2:].zfill(H)
  for k in range(2**W):
    bin_k = str(bin(k))[2:].zfill(W)
    cnt = 0
    ##ここまでで切る列は決定 この後で解析
    for l in range(H):
      if bin_j[l] == "0":
        continue
      for m in range(W):
        if bin_k[m] == "0":
          continue
        elif c[l][m] == "#":
          cnt += 1
    if cnt == K:
      true_cnt += 1
print(true_cnt)

Measured memory_bytes: 9208
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

int main()
{
	int a,b;cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b))<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    while (in.hasNext()) {
      String S = in.next();
    
      int count = 0;
      int maxCount = 0;
      for (int i = 0; i < S.length(); ++i) {
        if (S.charAt(i) == 'A' || S.charAt(i) == 'T' || S.charAt(i) == 'G' || S.charAt(i) == 'C') {
          ++count;
          maxCount = Math.max(maxCount, count);
        } else {
          count = 0;
        }
      }

      System.out.println(maxCount);
    }
  }
}

Measured memory_bytes: 21716
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
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; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string s; cin>>s;
    string t; cin>>t;
    string ans = "~";
    int index=0;
    for(int i=0;i<s.size();i++){
        bool flag=true;
        int temp=i;
        for(int j=0;j<t.size();j++){
            if(temp+j>(int)s.size()-1){flag=false;break;}
            if(s[temp+j]=='?')continue;
            else if(s[temp+j]==t[j])continue;
            else flag=false;
        }
        
        if(!flag)continue;
        cmax(index,i);
        string foo;
        for(int j=0;j<s.size();j++){
            if(j==index){
                foo+=t;
                rep(i,(int)t.size()-1)j++;
            }else if(s[j]=='?')foo.push_back('a');
            else
                foo.push_back(s[j]);
        }
        ans = min(ans, foo);
    }
    if(ans[0] != '~')cout<<ans<<endl;
    else cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;

	string S;
	cin >> S;

	ll cnt_r = 0;
	ll cnt_g = 0;
	ll cnt_b = 0;

	for (int i=0; i<N; i++) {
		if (S[i] == 'R') cnt_r++;
		else if (S[i] == 'G') cnt_g++;
		else cnt_b++;
	}

	ll cnt_all_tri = cnt_r * cnt_g * cnt_b;

	ll cnt_exception = 0;
	for (int i=0; i<N; i++) {
		for (int j=1; i+j+j<N; j++) {
			if (S[i] != S[i+j] && S[i] != S[i+j+j] && S[i+j] != S[i+j+j]) {
				cnt_exception++;
			}
		}
	}

	ll ans = cnt_all_tri - cnt_exception;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int r, D, x;
    cin >> r >> D >> x;

    REP(0, i, 10) {
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

struct Position {
  int r, c, dir;
  bool operator<(const Position& p) const {
    if (r != p.r) return r < p.r;
    if (c != p.c) return c < p.c;
    return dir < p.dir;
  }
};

struct Cost {
  int strokes;
  int dist;
  bool operator<(const Cost& c) const {
    if (strokes != c.strokes) return strokes < c.strokes;
    return dist < c.dist;
  }
};

struct State {
  Position position;
  Cost cost;
  bool operator<(const State& s) const {
    return s.cost < cost;
  }
};

const int INF = 1 << 30;

int main() {
  in(int, h, w, k);
  in(int, x1, y1, x2, y2);
  --x1, --y1, --x2, --y2;
  vector<string> grid(h);
  rep(i, h) cin >> grid[i];

  vector<vector<vector<Cost>>> cost(h, vector(w, vector(4, Cost{INF, INF})));
  auto CostOf = [&](const Position& p)->Cost& { return cost[p.r][p.c][p.dir]; };
  priority_queue<State> que;
  auto push = [&](const State& s) {
    Cost& c = CostOf(s.position);
    if (!(s.cost < c)) return;
    c = s.cost;
    que.push(s);
  };
  rep(dir, 4) push(State{{x1, y1, dir}, {1, 0}});
  while (!que.empty()) {
    State here = que.top();
    que.pop();
    if (here.position.r == x2 && here.position.c == y2) {
      out(here.cost.strokes);
      return 0;
    }
    {
      int dr[] = {1, -1, 0, 0};
      int dc[] = {0, 0, 1, -1};
      State there(here);
      there.position.r += dr[there.position.dir];
      there.position.c += dc[there.position.dir];
      if (there.cost.dist < k) {
        ++there.cost.dist;
      } else {
        ++there.cost.strokes;
        there.cost.dist = 1;
      }
      if (int r = there.position.r, c = there.position.c;
          0 <= r && r < h && 0 <= c && c < w && grid[r][c] == '.') {
        push(there);
      }
    }
    rep(i, 4) {
      State there(here);
      there.position.dir = i;
      ++there.cost.strokes;
      there.cost.dist = 0;
      push(there);
    }
  }
  out(-1);
}


Measured memory_bytes: 144944
#include <iostream>
#include <vector>

using namespace std;



int main(int argc, char *argv[]) {
	long N, A, B;

	cin >> N >> A >> B;

	vector<long> X(N);
	for (int i = 0; i < N; i++) cin >> X[i];

	long sum = 0;
	for (int i = 1; i < N; i++) {
		sum += min((X[i] - X[i - 1]) * A, B);
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  auto check = [](int n) {
    int cnt = 0;
    while (n) n /= 10, cnt++;
    return bool(cnt & 1);
  };
  int ans = 0;
  for (int i = 1; i <= N; i++) ans += check(i);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	String n = scan.nextLine();
	while (!n.equals("-")) {
	    int m = scan.nextInt();
	    scan.nextLine();
	    String newN = n;
	    for (int i = 0; i < m; i++) {
		String hs = scan.nextLine();
		int h = Integer.valueOf(hs);
		newN = newN.substring(h, newN.length()) + newN.substring(0, h);
	    }
	    System.out.println(newN);
	    n = scan.nextLine();
	}
    }
}

Measured memory_bytes: 26320
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define  int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int m,x,y;vector<pair<int,int> > p[n];//int m;
    for(int i=0;i<n;i++)
    {
        cin>>m;
        for(int j=0;j<m;j++)
        {
            cin>>x>>y;
            p[i].pb(m1(x,y));
        }
    }
    int ans=0;
    for(int mask=1;mask<(1<<n);mask++)
    {
        int honest[n+1]={0};
        int j=1;int in=0;
        while(j<=mask)
        {
            if(j&mask)
            {
                honest[in]=1;
            }
            in++;
            j=j<<1;
        }
        int pos=1;
        for(int i=0;i<n;i++)
        {
            if(honest[i])
            {
                for(j=0;j<p[i].size();j++)
                {
                    x=p[i][j].first;
                    y=p[i][j].second;
                    x--;
                    if(y)
                    {
                        if(!honest[x])
                        {
                            pos=0;break;
                        }
                    }
                    else
                    {
                        if(honest[x])
                        {
                            pos=0;break;
                        }
                    }
                }
            }
            if(!pos)
                break;
        }
       // if(mask==3)
         //   cout<<pos<<endl;
        int cnt=0;
        if(pos)
        {
            for(int i=0;i<n;i++)
                if(honest[i])
                    cnt++;
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                // 整数の入力
                String y = sc.next();
                String j = sc.next();

                int result = 0;
                for (int i = 0; i < y.length(); i++) {
                        if (y.charAt(i) == j.charAt(i)) {
                                result += 1;
                        }
                }

                // 出力
                System.out.println(result);
        }
}

Measured memory_bytes: 23252
def gcd(a, b):
    if a > b:
        a, b = b, a
    while b > 0:
        a, b = b, a % b
    return a


def allgcd(d):
    if len(d) == 1:
        return d
    ret_gcd = d[0]
    for i in d:
        ret_gcd = gcd(ret_gcd, i)
    return ret_gcd


def maxNumVisitCity(N, X, x):
    if len(x) == 1:
        return abs(x[0] - X)

    d = []
    for i in x:
        d.append(abs(i - X))
    return allgcd(d)


def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    print(maxNumVisitCity(N, X, x))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14480
N, M = map(int, input().split())
if N == 1:
    cand = list(map(str, range(0, 10)))
if N == 2:
    cand = list(map(str, range(10, 100)))
if N == 3:
    cand = list(map(str, range(100, 1000)))
for _ in range(M):
    s, c = map(int, input().split())
    new = []
    for x in cand:
        if s <= len(x) and x[s-1] == str(c):
            new.append(x)
    cand = new
if len(cand) == 0:
    print(-1)
else:
    print(min(map(int, cand)))


Measured memory_bytes: 3064
t = gets.to_i
t.times{
    x, y, w, h = gets.chomp.split.map(&:to_i)
    cats = 0
    n = gets.to_i
    n.times{
        x2, y2 = gets.chomp.split.map(&:to_i)
        cats += 1 if x2.between?(x, x + w) && y2.between?(y, y + h)
    }
    puts cats
}


Measured memory_bytes: 6840
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

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

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 210000;

int n;
ll m;
int v;
int p;

ll a[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> m >> v >> p;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	sort(a, a + n);
	reverse(a, a + n);

	int ans = p;

	ll sum = 0;
	for (int i = p; i < n; ++i) {
		sum += a[i - 1];
		int cnt = i - p + 1;
		ll cs = sum - a[i] * cnt;
		int av = v - (p - 1) - (n - i);
		av = max(av, 0);
		av = cnt - av;
		if (m >= a[p - 1] - a[i] && av * m >= cs) {
			++ans;
		}
	}

	cout << ans << "\n";

	return 0;
}




Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	// Code for A - Addition and Subtraction Easy
	var A, B int
	var op string
	fmt.Scanf("%d %s %d", &A, &op, &B)

	if op[0] == '+' {
		fmt.Println(A + B)
	} else {
		fmt.Println(A - B)
	}
}


Measured memory_bytes: 1832
#include <vector>
#include <complex>
#include <iostream>
#include <cstdio>
using namespace std;

using D = double;
using P = complex<D>;
#define X real()
#define Y imag()
const D EPS = (1e-10), pi = acos(-1);

D dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}


int main(){
  int N;
  cin >> N;
  vector<P> V;
  for(int i = 0; i < N; ++i){
    D x, y;
    cin >> x >> y;
    V.emplace_back(x,y);
  }
  int T = 100000;
  D ans = 0;
  for(int i = 0; i < T; ++i){
    D theta = 2*pi*i/T;
    P d(cos(theta),sin(theta));
    P p = 0;
    for(int j = 0; j < N; ++j){
      if(dot(d,V[j]) > -EPS)
        p += V[j];
    }
    ans = max(ans,abs(p));
  }
  printf("%.12f\n",ans);
}


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

int dp[100000+1][3];

struct vacation {
	int a,b,c;
};

int solve(vector<vacation> &v , int i , int n ,int j){

 if(i>n)
 	return 0;

 if(dp[i][j]!=-1)
 	return dp[i][j];

 int sol=0;

 if(j==0)
 	dp[i][j] = max( v[i].b + solve(v,i+1,n,1) , v[i].c + solve(v,i+1,n,2) );
 else if(j==1)
     dp[i][j] = max( v[i].a + solve(v,i+1,n,0) , v[i].c + solve(v,i+1,n,2) );
 else
 	dp[i][j] = max( v[i].b + solve(v,i+1,n,1) , v[i].a + solve(v,i+1,n,0) );

 return dp[i][j];

}

int main()
{
    ll n;
  	cin>>n;

  	vector<vacation>v(n+1);
  	int x,y,z;

  	for(int i=1;i<=n;i++){

  		cin>>v[i].a;
  		cin>>v[i].b;
		cin>>v[i].c;

  	}

  	for(int i=0;i<=n;i++)
  		for(int j=0;j<3;j++)
  			dp[i][j]=-1;

  		dp[1][0] = v[1].a;
  		dp[1][1] = v[1].b;
  		dp[1][2] = v[1].c;

  int A = v[1].a + solve(v,2,n,0);

  int B = v[1].b + solve(v,2,n,1);

  int C = v[1].c + solve(v,2,n,2);
 
 cout<<max(A,max(B,C))<<endl;


return 0;

}

Measured memory_bytes: 10368
#include <stdio.h>
int main() {

  int N,i,j,c=0,b,minj;
  int A[100];

  scanf("%d",&N);
  for(i=0;i<N;i++) {
    scanf("%d",&A[i]);
  }

  for(i=0;i<N;i++) {
    minj = i;
    for(j=i;j<N;j++){	
      if(A[j] < A[minj]) minj = j;
    }
    if(minj != i) {
      b = A[i];
      A[i] = A[minj];
      A[minj] = b;
      c++;
    }
  }
  
  for(i=0;i<N;i++) {
    if(i>0) printf(" "); 
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",c);

  return 0;
}

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

int n;
int a[210000];

//素数判定関数 O(√N)
bool isDivisible(int x){

    double sqrtx = sqrt(x);

    if(x==1){
        if(upper_bound(a, a+n, 1) - lower_bound(a, a+n, 1) >=2){
            return true;
        }
        return false;
    }
    
    if(binary_search(a, a+n, 1)){
        return true;
    }
    if(binary_search(a, a+n, x)){
        if(upper_bound(a, a+n, x) - lower_bound(a, a+n, x) >=2){
            return true;
        }
    }

    for (int i = 2; i <= sqrtx; i++){
        if (x % i == 0){
            if(binary_search(a, a+n, i)){
                return true;
            }
            int y = x/i;
            if(binary_search(a, a+n, y)){
                return true;
            }
        }
    }

    return false;
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);

    int count = 0;

    for(int i=0; i<n; i++){
        if(!(isDivisible(a[i]))) count++;
    }
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 4412
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, a, b = MAP()
x = LIST()
ans = 0

for i in range(1, n):
    ans += min(( x[i] - x[i-1] ) * a, b )

print(ans)

Measured memory_bytes: 21884
// Created by arvybhatt

#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define p_b push_back
#define m_p make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
    fast;

    int n,k;cin>>n>>k;
    ll a[n];
    rep(i,n)cin>>a[i];

    ll dp[n];
    memset(dp,1e4+1,sizeof(dp));
    dp[0]=0;
    for(int i=0; i<n; i++)
    {
    	for(int j=i+1; j<=i+k && j<n; j++)
    	{
    		dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
    		
    	}
    }
    cout<<dp[n-1];
    return 0;
}


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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long a, b[200005];
int main()
{
    long long sum, n, i, j, t;
    scanf("%lld",&n);
    sum=t=0;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a);
        sum+=a;
        b[i]=sum;
        if(sum==0) t++;
    }
    sort(b,b+n);
    long long q=b[0], p=0;
    for(i=1;i<n;i++)
    {
        if(q==b[i])
            p++;
        else
        {
            if(p!=0) t+=p*(p+1)/2;
            p=0;
            q=b[i];
        }
    }
    if(p!=0) t+=p*(p+1)/2;
    printf("%lld\n",t);
}

Measured memory_bytes: 1664