akhauriyash/Code-Regression huggingface dataset:
import random
import time

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    
    ans = []
    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][j]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)

    random.seed(20)
    while time.time() - start < 1.9:
        d = random.randint(1,D-1)
        if c[idx] == 0 or ans[d-1] == idx:
            continue
        tmp_d1 = ans[d]
        tmp_d2 = ans[d-1]
        ans[d] = tmp_d2
        ans[d-1] = tmp_d1
        last_d = [0 for i in range(26)]
        score2 = 0    
        for i in range(D):
            score2 += s[i][ans[i]-1]
            last_d[ans[i]-1] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans[d] = tmp_d1
            ans[d-1] = tmp_d2
        else:
            score1 = score2
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()


Measured memory_bytes: 9724
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
const LL kai_MAX = 400001;
vector<LL> kai(kai_MAX);
vector<LL> kai_inv(kai_MAX);

LL powMod(LL num, LL n, LL mod = (LL)MOD) {//(num**n)%mod
	num %= mod;//
	if (n == 0) {
		return (LL)1;
	}
	LL mul = num;
	LL ans = (LL)1;
	while (n) {
		if (n & 1) {
			ans = (ans * mul) % mod;
		}
		mul = (mul * mul) % mod;
		n >>= 1;
	}
	return ans;
}
LL mod_inverse(LL num, LL mod = MOD) {
	return powMod(num, MOD - 2, MOD);
}

LL nCk(LL N, LL k, LL mod = MOD) {
	LL ans = 1;
	if (k == 0 || k == N) {
		return 1;
	}
	ans = (kai[N] * kai_inv[N - k]) % mod;
	ans = (ans * kai_inv[k]) % mod;
	return ans;
}
void solve() {
	LL N, K;
	cin >> N >> K;

	kai[0] = 1; //kai_inv[0] = mod_inverse(1);
	kai[1] = 1; kai_inv[1] = mod_inverse(1);

	for (int i = 2; i < kai_MAX; ++i) {
		kai[i] = (kai[i - 1] * i) % MOD;
		kai_inv[i] = mod_inverse(kai[i]);
	}

	LL ans;
	if (K >= N) {
		K = N;
		ans = 1;
	}
	else {
		ans = 1;//0人
	}

	for (int k = 1; k <= K; ++k) {
		if (N - 1 < k) {
			continue;
		}
		ans += (nCk(N,k) *nCk((N-k-1)+k, k)) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 6528
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=201;
LL a[N];
int read(){
	int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch>'9'||ch<'0'))
		ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')
		data=data*10+ch-'0',ch=getchar();
	return data*w;
}
int main(){
	int n;
	n=read();a[0]=2;
	for(int i=1;i<=n;++i)
	    a[i]=a[i-1]*2+2;
	printf("%lld\n",a[n]);
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    vector<int> x(m);
    REP(i, m) cin >> x[i];
    sort(x.begin(), x.end());

    if (n >= m) cout << 0 << '\n';
    else {
        vector<int> diff(m - 1, 0);
        REP(i, m - 1)
            diff[i] = abs(x[i] - x[i + 1]);
        sort(diff.begin(), diff.end());

        ll sum = 0;
        REP(i, m - n)
            sum += diff[i];

        cout << sum << '\n';
    }
    return 0;
}


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

int main() {
  double N;
  cin>>N;
  vector<int>X(N);
  double T=0;
 for(int i=0;i<N;i++){
    cin>> X.at(i);
    T+=X.at(i);
 }
  double Y=0;
  int EX=T/N+0.5;

  for(int i=0;i<N;i++){
    Y+=(X.at(i)-EX)*(X.at(i)-EX);
  }
  cout<<Y<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int p[11],n,m,s,c;
int main()
{
	memset(p,-1,sizeof(p));
	cin>>n>>m;
	while(m--)
	{
		cin>>s>>c;
		if(p[s]!=c&&p[s]!=-1)
		{
			cout<<-1<<endl;
			return 0;
		}
		else p[s]=c;
	}
	if(n==1)
	{
		if(p[1]!=-1) cout<<p[1]<<endl;
		else cout<<0<<endl;
	}
	else
	{
		if(p[1]==0) cout<<-1<<endl;
		else
		{
			if(p[1]==-1) cout<<1;
			else cout<<p[1];
			for(int i=2;i<=n;i++)
			{
				if(p[i]==-1) cout<<0;
				else cout<<p[i];
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
#include<random>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
int d;
int c[30]={};
int s[370][30];
int num=100000;
int calc(vector<int>const& t,vector<vector<int>>& last_list){
  int res=0;
  vector<int> last(30,0);
  rep1(i,d){
    res+=s[i][t[i]];
    last[t[i]]=i;
    last_list[i]=last;
    int buf=0;
    rep1(j,26){
      buf+=c[j]*(i-last[j]);
    }
    res-=buf;
    //cout<<res<<"\n";
  }
  return res;
}
int change(int nd,int nq,int& res,vector<int>& t,vector<vector<int>>& last_list){
  int flag_t=false;
  int flag_q=false;
  int x=t[nd];
  t[nd]=0;
  res+=s[nd][nq];res-=s[nd][x];
  for(int i=nd;i<=d;++i){
    if(flag_t&&flag_q)break;
    if(t[i]==x||flag_t)flag_t=true;
    else{
      res+=c[x]*(i-last_list[i][x]);
      last_list[i][x]=last_list[i-1][x];
      res-=c[x]*(i-last_list[i][x]);
    }
    if(t[i]==nq||flag_q)flag_q=true;
    else{
      res+=c[nq]*(i-last_list[i][nq]);
      last_list[i][nq]=nd;
      res-=c[nq]*(i-last_list[i][nq]);
    }
  }
  t[nd]=nq;
  return res;
}
vector<int> greedy(int d){
  vector<int> res(d+1,0);
  vector<int> last(30,0);
  rep1(i,d){
    int mx=-inf;
    int mx_ind=0;
    rep1(j,26){
      int tmp=s[i][j];
      rep1(k,26){
        if(k==j)continue;
        tmp-=c[k]*(i-last[k]);
      }
      if(mx<tmp){
        mx=tmp;
        mx_ind=j;
      }
    }
    last[mx_ind]=i;
    res[i]=mx_ind;
  }
  return res;
}
signed main(){
  cin>>d;
  rep1(i,26)cin>>c[i];
  rep1(i,d){
    rep1(j,26)cin>>s[i][j];
  }
  vector<int> t=greedy(d);
  vector<vector<int>> last_list(d+1,vector<int>(30,0));
  int res=calc(t,last_list);
  //cout<<res<<"\n";
  int param=2;
  rep(xx,num){
    random_device rand;
    mt19937 mt(rand());
    vector<int> nd(param);rep(i,param)nd[i]=mt()%d+1;
    vector<int> nq(param);rep(i,param)nq[i]=mt()%26+1;
    vector<int> bq(param);rep(i,param)bq[i]=t[nd[i]];
    int bval=res;
    rep(i,param){
      change(nd[i],nq[i],res,t,last_list);
    }
    int yakinamasi=mt()%100;
    if(yakinamasi<20&&res+res/10>bval)continue;
    if(bval>res){
      rep(i,param){
        change(nd[i],bq[i],res,t,last_list);
      }
    }
  }
  rep(xx,num){
    random_device rnd;
    mt19937 mt(rnd());
    int nd=mt()%d+1;
    int nq=mt()%26+1;
    int bq=t[nd];
    int bval=res;
    int hoge=change(nd,nq,res,t,last_list);
    if(hoge<bval){
      change(nd,bq,res,t,last_list);
    }
  }
  rep1(i,d){
    cout<<t[i]<<"\n";
  }
  //cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 3812
#include <iostream>

using ll = long long int;

ll n, k;

int main()
{

    std::cin >> n >> k;

    ll m = n % k;

    if (m <= k / 2)
        std::cout << m << std::endl;
    else
    {
        std::cout << k - m << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ",debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os,pair<T,S>a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}

//char inv(char c){
//    return c^32;
//}
//string inv(string &a){
//    auto res = a;
//    for(auto &x:res) x^=32;
//    reverse(res.begin(),res.end());
//    return res;
//}
//string product(const string &a,const string &b){
//    auto res = a;
//    for(auto x:b){
//        if(res.size() and inv(x) == res.back())res.erase(res.begin()+res.size()-1);
//        else res.push_back(x);
//    }
//    return res;
//    
//}

vector<int> id(const int n){
    vector<int> res(n);
    rep(i,n)res[i] = i;
    return res;
}
vector<int> inv(const vector<int> &a){
    vector<int> res(a.size());
    rep(i,a.size()){
        res[a[i]] = i;
    }
    return res;
}
vector<int> product(const vector<int> &a, const vector<int> &b){
    vector<int> res(a.size());
    rep(i,a.size()){
        res[i] = a[b[i]];
    }
    return res;
}
vector<int> power(const vector<int> &a, ll p){
    if(p == 0)return id((int)a.size());
    auto res = a;
    auto temp = a;
    p--;
    for(int i = 0; i < 28; i++){
        if(p >> i & 1){
            res = product(res, temp);
        }
        temp = product(temp, temp);
    }
    return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int>p(n),q(n);
    rep(i,n)cin >> p[i],p[i]--;
    rep(i,n)cin >> q[i],q[i]--;
    auto g = product(q,product(inv(p),product(inv(q),p)));
    g = power(g,(k-1)/6);
    auto a = product(g,product(p,inv(g)));
    auto b = product(g,product(q,inv(g)));
    int now = 1 + (k-1)/6*6;
    while(now != k){
        auto c = product(b, inv(a));
        a = b;
        b = c;
        now++;
    }
    rep(i,n)cout << a[i] + 1 << " \n"[i==n-1];
}


Measured memory_bytes: 3544
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int n,sum;
	int a[205];
	while(~scanf("%d",&n)){
		sum=0;
		for(int i=0;i<2*n;i++)
		scanf("%d",&a[i]);
		sort(a,a+2*n);
		for(int i=0;i<2*n;i=i+2)
		sum+=a[i];
		printf("%d\n",sum);
	}
	return 0;
} 

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

typedef long long ll;

int A[2333333], B[2333333];
ll suma[233333], sumb[233333];

int main()
{
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> A[i];
        suma[i] = suma[i - 1] + A[i];
    }
    for (int i = 1; i <= m; i++)
        cin >> B[i], sumb[i] = sumb[i - 1] + B[i];
    int ans = 0;
    for (int i = 0; i <= n; i++)
    {
        if (suma[i] > k)
            break;
        int ls = upper_bound(sumb + 1, sumb + m + 1, k - suma[i]) - sumb;
        ans = max(ans, i + ls - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8392
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <deque>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int t1[3333],t2[3333];
int main(void){
  double a,b,c,d,e,f;
  vector<int> mizu,satou;
  int tmp;
  cin>>a>>b>>c>>d>>e>>f;
  t1[0]=t2[0]=1;
  for(int i=0;(100*a*i)<=f;i++){
    for(int j=0;(100*a*i + 100*b*j)<=f;j++){
      tmp=100*a*i+100*b*j;
      if(t1[tmp]==0){
        mizu.pb(tmp);
        t1[tmp]=1;
      }
    }
  }
 
  for(int i=0;(c*i)<=f;i++){
    for(int j=0;(c*i + d*j)<=f;j++){
      tmp=c*i+d*j;
      if(t2[tmp]==0){
 
        satou.pb(tmp);
        t2[tmp]=1;
      }
    }
  }
  sort(all(mizu));
  sort(all(satou));
  int res1,res2;
  double res,s,ss;
  res=0.0;
  res1=mizu[0];
  res2=0;
  ss=100*e/(100+e);
  for(int i=0;i<mizu.size();i++){
    for(int j=0;j<satou.size();j++){
      if(mizu[i]+satou[j]>f) continue;
      s=(100*(double)satou[j]/(mizu[i]+(double)satou[j]));
      if(s>ss) continue;
      if(res<s){
        res=s;
        res1=mizu[i];
        res2=satou[j];
      }
    }
  }
  cout<<res1+res2<<" "<<res2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 2);
    a[0] = a[n + 1] = 0;
    rep(i, n)
    {
        cin >> a[i + 1];
    }

    vector<int> psum(n + 2), rpsum(n + 2);
    irep(i, n + 1)
    {
        if (i == 0) {
            psum[i] = rpsum[n + 1 - i] = 0;
        } else {
            psum[i] = psum[i - 1] + abs(a[i] - a[i - 1]);
            rpsum[n + 1 - i] = rpsum[n + 1 - i + 1] + abs(a[n + 1 - i] - a[n + 1 - i + 1]);
        }
    }

    rep(i, n)
    {
        int cost = psum[i] + rpsum[i + 2] + abs(a[i + 2] - a[i]);
        cout << cost << endl;
    }

    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,c;
  cin >> a >> b >> c;
  if(a<b){
  	cout << (a<c&&c<b ? "Yes" : "No") << endl;
  }else{
    cout << (b<c&&c<a ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

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

	/* 入力 */
	int n = scan.nextInt();
	int m = scan.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	int[] c = new int[m];
	int[] d = new int[m];
	for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt();
	    b[i] = scan.nextInt();
	}
	for(int i = 0; i < m; i++){
	    c[i] = scan.nextInt();
	    d[i] = scan.nextInt();
	}

	for(int i = 0; i < n; i++){
	    int min = Integer.MAX_VALUE;
	    int index = -1;
	    for(int j = 0; j < m; j++){		
		if(min > Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j])){
		    min = Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]);
		    index = j;
		}
	    }
	    System.out.println(index+1);
	}
    }
}
	    


Measured memory_bytes: 21712
def nCr(n, r, p): 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,p - 2, p)) % p 

s=int(input())
mod=pow(10,9)+7
ans=0
for i in range(3,s+1,3):
	ans=(ans+nCr(s-i+i//3-1,i//3-1,mod))%mod
print(ans)

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

int main() {
    int M, D;
    cin >> M >> D;

    int res = 0;
    for (int i = 1; i <= M; i++) {
        for (int j = 10; j <= D; j++) {
            int m = i;
            int d10 = j / 10;
            int d1 = j % 10;
            if (d10 >= 2 && d1 >= 2 && d10 * d1 == m)
                res++;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  vector<int> a(4);
  for (int i = 0; i < 4; i++) {
    a[i] = s[i]-'0';
  }
  for (int bit = 0; bit < (1 << 3); bit++) {
    int sum = a[0];
    for (int i =0; i < 3; i++) {
      if ((1<<i)&bit) {
        sum += a[i+1];
      }
      else {
        sum -= a[i+1];
      }
    }
    if (sum == 7) {
      cout << a[0];
      for (int i =0; i < 3; i++) {
        if ((1<<i)&bit) {
          cout << '+' << a[i+1];
        }
        else {
          cout << '-' << a[i+1];
        }
      }
      cout << '=' << 7 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3604
N=int(input())
a=list(map(int,input().split()))
ans=[]
b=0
if N==1:
    print(0)
else:
    for i in range(min(a),max(a)+1):
        for k in range(N):
            b+=(a[k]-i)**2
        ans.append(b)
        b=0
    print(min(ans))

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

template<typename T, int get_digit(T, int)>
void LSD_RadixSort(::std::vector<T>& v, int maximum, int max_digit){
	::std::vector<::std::vector<int>> bucket(maximum+1);
	::std::vector<T> tmp;
	int digit = 0;
	for(int digit = 0;digit < max_digit;digit++){
		for(int i = 0;i < v.size();i++){
			int x = get_digit(v[i], digit);
			bucket[x].push_back(i);
		}
		for(int i = 0;i <= maximum;i++){
			for(int j = 0;j < bucket[i].size();j++){
				tmp.push_back(v[bucket[i][j]]);
			}
			bucket[i].clear();
		}

		swap(v, tmp);
		tmp.clear();
	}
}

int get(int x, int dig){
	return x >> dig & 1;
}

int main(void){
	int n;
	::std::vector<int> v;
	std::cin >> n;
	v.resize(n);
	for(int i = 0;i < n;i++) std::cin >> v[i];

	LSD_RadixSort<int, get>(v, 2, 32);
	std::reverse(v.begin(), v.end());
	int res = 0;
	for(int i = 0;i < n;i++) res = res + v[i] * (i%2 ? -1 : 1);
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        int a[] = new int[1000000];
        
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        
        for(int i = 0; i < n; i++) {
            a[i] = scan.nextInt();
        }
        shellSort(a, n);
        for(int i = 0; i < n; i++) {
            System.out.println(a[i]);
        }
    }
    
    public static void shellSort(int a[], int n) {
        List<Integer> width = new ArrayList<>();
        
        int i = 0;
        
        //shellSort????????¨??????????????????????????????(A i+1 = 3A * i + 1)
        while(3 * i + 1 < n) {
            width.add(3 * i + 1);
            
            i = 3 * i + 1;
        }
        //????´?????\????????°?????????¨??????????????§???1?????????
        if(width.isEmpty()) {
            width.add(1);
        }
        
        //count?????\???????????°???????????????
        int count = 0;
        int m = width.size();
        for(int j = 0; j < m; j++) {
         //width???????°?????????????????¢??????????????????§?????????????????¨???
         //ex. width = {1, 4, 13, ....} <- ???????????????
         count += insertionSort(a, n, width.get((m - 1) - j));   
        }
        
        System.out.println(m);
        
        for(int k = 0; k < m; k++) {
            if(k > 0) {
               System.out.print(" ");
            }
            System.out.print(width.get((m - 1) - k));
        }
        System.out.println();
        System.out.println(count);
    }
    
    public static int insertionSort(int a[], int n, int width) {
        int count = 0;
        for(int i = width; i < n; i++) {
            int v = a[i];
            int j = i - width;
            while(j >= 0 && a[j] > v) {
                a[j + width]= a[j];
                j -= width;
                count++;
            }
            a[j + width] = v;
        }
        return count;
    }
    
}

Measured memory_bytes: 299248
/*
Author:Fuad Ashraful Mehmet
University of Asia Pacific
Date:23 Feb 2020
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N=1e5+5;
int n;

void Solve()
{
   deque<char>dq;

   string s;
   cin>>s;
   int turn=0;

   for(char c:s)dq.push_back(c);

   int q;
   cin>>q;
   char c;
   int cmd,f;
   while(q--)
   {
       cin>>cmd;
       if(cmd==1)
       {
           turn=1-turn;
       }
       else
       {
           cin>>f;
           cin>>c;

           if(f==1)
           {
               if(turn==0)
               dq.push_front(c);
               else dq.push_back(c);
           }
           else
           {
              if(turn==1)
               dq.push_front(c);
               else dq.push_back(c);
           }
           
       }
       
   }

  if(turn==0)
   while(!dq.empty())
   {
       cout<<dq.front();
       dq.pop_front();
   }
   else
      while(!dq.empty())
   {
       cout<<dq.back();
       dq.pop_back();
   }
   cout<<endl;
}
int main()
{
 ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    
  Solve();
 
 return 0;
}

Measured memory_bytes: 976
def kaibun(s):
    N=len(s)
    f=1
    if N%2 == 0:
        for i in range(int(N/2)):
            if s[i] != s[N -i -1]:
                f=0
    else:
        for i in range(int((N+1)/2)):
            if s[i]!=s[N-1-i]:
                f=0
    return f


s=input()
N=len(s)
c = 1
'''
for i in range(int((N-1)/2)):
    if s[i]!=s[N-1-i]:
        c=0
d = 1
f = (N-1)/2 % 2

if f == 0:
    for i in range(int((N-1)/4)):
        if s[i]!=s[int((N-1)/2)-1-i]:
            d=0
else:
     for i in range(int(((N-1)/2 -1)/2)):
        if s[i]!=s[int(((N-1)/2 -1)/2-i)]:
            d=0

if c*d == 0:
    print("No")
else:
    print("Yes")
'''

if kaibun(s)*kaibun(s[0:int((N-1)/2)]) == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <set>
#include<cmath>
#include <stdio.h>
#include <cstdio>
#include<string.h>
using namespace std;
int main()
{
set<long long int> num1;
set<long long int> num2;
set<long long int> num3;
set<long long int> num4;
long long int num,n;
long long int maxn1=0,maxn2=0;
set<long long int>::iterator it;
scanf ("%lld",&n);
while(n--)
{
scanf ("%lld",&num);
     it =num1.find(num);
	 if(it!=num1.end())
	 {
	     it=num2.find(num);
	     if(it!=num2.end())
	     {
	         it=num3.find(num);
	         if(it!=num3.end())
	         {
	             it=num4.find(num);
	             if(it!=num4.end())
	              {
	                  
	              }
	              else
	              {
	                  num4.insert(num);
	                  if (num>maxn1)
	                  {
	                       maxn1=num;
	                       maxn2=num;
	                   }
	                   else if (num>maxn2)
	                   {
	                       maxn2=num;
	                   }
	              }
	         }
	         else
	         {
	             num3.insert(num);
	         }
	     }
	     else
	     {
	         num2.insert(num);
	         if (num>maxn1)
	         {
	             maxn2=maxn1;
	             maxn1=num;
	         }
	         else if (num>maxn2)
	         {
	             maxn2=num;
	         }
	     }
	 }
	 else
	 {
	     num1.insert(num);
	 }
}
printf("%lld",maxn1*maxn2);
return 0;
}



Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
const int inf=0x3f3f3f3f;
struct Node{
    int l,r;
    bool operator <(Node p){
        return l<p.l;
    }
}p[max_n];
int n;
int pre[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d%d",&p[i].l,&p[i].r);
    int x=1,y=1;
    for(int i=1;i<=n;i++)if(p[i].l>p[x].l)x=i;
    for(int i=1;i<=n;i++){
        if(i==x)continue;
        if(p[i].r<p[y].r)y=i;
    }
    int tx=p[x].r-p[x].l+1,ty=p[y].r-p[y].l+1;
    int ans=0;
    int res=min(p[x].r,p[y].r)-max(p[x].l,p[y].l)+1;
    res=max(res,0);
    int tmp=0;
    for(int i=1;i<=n;i++){
        if(i==x||i==y)continue;
        tmp=max(tmp,p[i].r-p[i].l+1);
    }
    if(tmp!=0)ans=max(ans,tmp+res);
    //cout<<ans<<endl;
    int tl=p[x].l,tr=p[y].r;
    int tot=0;
    for(int i=1;i<=n;i++){
        if(i==x||i==y)continue;
        p[++tot]=p[i];
    }
    n=tot;
    for(int i=1;i<=n;i++){
        int l=p[i].l,r=p[i].r;
        p[i].l=max(r-tl+1,0);
        p[i].r=max(tr-l+1,0);
    }
    sort(p+1,p+n+1);
    pre[0]=inf;
    for(int i=1;i<=n;i++)pre[i]=min(pre[i-1],p[i].r);
    res=0;
    for(int i=1;i<=n;i++){
        int tmp=pre[i-1];
        int nx=min(tx,p[i].l),ny=min(ty,pre[i-1]);
        res=max(res,nx+ny);
    }
    int nx=tx,ny=min(ty,pre[n]);
    res=max(res,nx+ny);
    ans=max(ans,res);
    if(n==0)ans=max(ans,tx+ty);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
void ii(ll &x){ cin >> x; }
void is(string &x){ cin >> x; }
void oi(ll &x){ cout << x; }
void os(string &x){ cout << x; }
void oie(ll &x){ cout << x << endl; }
void ose(string &x){ cout << x << endl; }
 
int main(){
    ll A,B,M;
    ii(A);ii(B);ii(M);
    vector<ll> a, b;
    REP(i,0,A){
        ll aa;
        ii(aa);
        a.push_back(aa); 
    }
    REP(i,0,B){
        ll bb;
        ii(bb);
        b.push_back(bb);
    }

    ll ret=10E10;
    map<pii,ll> table;
    REP(i,0,M){
        ll x,y,c;
        ii(x);ii(y);ii(c);
        table.insert(make_pair(make_pair(x-1,y-1),c));
        ret=min(ret,a[x-1]+b[y-1]-c);
    }
    ll ai=0, bi=0;

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    while(true){
        if(table.find(make_pair(ai,bi))!=table.end()){
            if(ai==A-1&&bi==B-1){
                break;
            }else if(ai==A-1){
                bi++;
            }else if(bi==B-1){
                ai++;
            }else if(a[ai+1]-a[ai]<b[bi+1]-b[bi]){
                ai++;
            }else{
                bi++;
            }
        }else{          
            ret=min(a[ai]+b[bi], ret);
            break;
        }
    }


    oie(ret);
    return 0;
}

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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<ll>> dp(n, vector<ll>(21));
    dp[0][0] = 1;
    for(int i = 0; i < n - 1; ++i) {
        for(int j = 0; j <= 20; ++j) {
            if(i != 0 && j - a[i] >= 0) {
                dp[i + 1][j - a[i]] += dp[i][j];
            }
            if(j + a[i] <= 20) {
                dp[i + 1][j + a[i]] += dp[i][j];
            }
        }
    }
    cout << dp[n - 1][a.back()] << endl;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int H, W, N; cin >> H >> W >> N;
  vector<int> a(N); REP(i, N) cin >> a[i];
  vector<int> c; REP(i, N) REP(j, a[i]) c.push_back(i+1);

  REP(i, H) {
    REP(j, W) printf("%d ", (i%2==0 ? c[i*W+j] : c[i*W+W-(j+1)]));
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define abs(x) ((x) < 0 ? (-(x)) : (x))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
using namespace std;
/*
#ifdef JUDGE
#include <fstream>
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#else
#include <iostream>
using std::cin;
using std::cout;
#endif
*/
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
long double eps = 1.0E-14;
long long MOD = 1000000007;
/*
bool comparator(const MyStruct& lhs, const MyStruct& rhs) {
   return lhs.key < rhs.key;
}
*/
int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t,T, n;
    long long sum = 0;
	cin >> n >> T;	
	for(t = 1; t <= T; ++ t){
        cin >> a;
        sum += a;
		
		//cerr << t << "/" << T << " = " << ((double)clock () / CLOCKS_PER_SEC) << " | " << (((double)clock () / t * T) / CLOCKS_PER_SEC) << endl;
	}
    if (sum > n) {
        cout << -1 << endl;
        return 0;
    } 
    cout << n - sum << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

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

    if(N >= 10){
        cout << R << endl;
    }else{
        int p = 100 * ( 10 - N );
        cout << R + p << endl;
    }

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

using namespace std;
typedef unsigned long long ll;
typedef pair<int,int>P;
const ll MOD=1e9+7;

int main()
{
	ll N,K;
	cin>>N>>K;
	vector<ll>nn;
	ll res=0;
	for(ll i=0;i<N;i++)
	{
		int t;
		cin>>t;
		nn.push_back(t);
	}
	//1
	ll t=0;
	for(ll i=1;i<N;i++)
		for(int j=0;j<i;j++)
		{
			if(nn[j]>nn[i])
			{
				t++;
			}
		}
	//2~
	ll tt=0;
	for(ll i=0;i<N;i++)
		for(ll j=0;j<N;j++)
		{
			if(nn[i]>nn[j])
			{
				tt++;
			}
		}
	//res=t;
	//for(ll p=K-1;p>0;p--)
	//	res=(res+t+tt*p)%MOD;
	ll a=(t*K)%MOD;
	ll b=((K))*(K-1)/2%MOD;
	ll c=(tt*b)%MOD;
	res=(a+c)%MOD;
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pb push_back
set<int > se;

int main(){
	string a,b;
	cin >> a >> b;
	int len = a.length();
	
	int count=0;
	for(int i=0; i<len; ++i){
		if(a[i] != b[i]) count++;

	}
	cout << count << endl;
}

Measured memory_bytes: 3900
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

int main(){
  ll ans = 0;

  ll N, A, B;

  cin >> N >> A >> B;

  if(N >= 3){
    ans += ((B - A) + 1) + (N - 3) *  (B - A);
  } else if(N == 2){
    ans = 1;
  } else if (N == 1){
    if(A == B){
      ans = 1;
    } else {
      ans = 0;
    }
  }

  if(A > B){
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


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

using namespace std;

int main() {

	int n,t;
	cin >> n >> t;

	int c, t1;
	int minn=10000;

	for (int i = 0; i < n; i++) {
		cin >> c >> t1;
		if(t >= t1) {
			if (minn > c) {
				minn = c;
			}
		}

	}
	if (minn ==10000) {
		cout << "TLE" << endl;
		return 0;
	}
	cout << minn << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<tuple>
#include<algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<tuple<string, int, int>> a;
    for (int i = 1; i <= N; ++i) {
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.push_back(tie(s, p, i));
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < N; ++i) {
        cout << get<2>(a[i]) << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

/*bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}*/
int dp[100010][3];
int a[100010], b[100010], c[100010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    for (int i = 0; i < N; ++i)
    {
        dp[i + 1][0] = max({dp[i + 1][0], dp[i][1] + a[i], dp[i][2] + a[i]});
        dp[i + 1][1] = max({dp[i + 1][1], dp[i][0] + b[i], dp[i][2] + b[i]});
        dp[i + 1][2] = max({dp[i + 1][2], dp[i][0] + c[i], dp[i][1] + c[i]});
    }
    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
    return 0;
}

Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int n, m, l; cin >> n >> m >> l;
	vector<VL> a(101, VL(101)), b(101, VL(101));
	rep(i, n)rep(j, m)cin >> a[i][j];
	rep(i, m)rep(j, l)cin >> b[i][j];

	vector<VL> c(101, VL(101));
	rep(i, n)rep(j, l) {
		rep(k, m)c[i][j] += a[i][k] * b[k][j];
	}
	rep(i, n) rep(j, l) {
		cout << c[i][j];
		printf(j == l - 1 ? "\n" : " ");
	}
}


Measured memory_bytes: 3432
N = int(input())
*C, = input()

nw = C.count('W')

ans = 0
for _ in range(N):
    if nw == 0:
        break
    tmp = C.pop()
    if tmp == 'W':
        nw -= 1
    else:
        ans += 1
        nw -= 1
print(ans)

Measured memory_bytes: 87088
#include<stdio.h>
int main(){
int a,b;
scanf("%d%d", &a,&b);
if(a%3==0){ printf("Possible\n");}
else if(b%3==0){ printf("Possible\n");}
else if((a+b)%3==0){ printf("Possible\n");}
else printf("Impossible\n");
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <deque>
#include <algorithm>
#include <math.h>
#include <random>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
#define double long double
#define Matrix vector<vector<int> >
#define kektor vector
#define pp pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;

int RandInt(int min, int max) {
    if (max < min) {
        swap(min, max);
    }
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<int> dist(min, max);
    return dist(mt);
}

struct Node {
	int l, r, x; 
	Node(int _l, int _r, int _x) : l(_l), r(_r), x(_x) {} 
	Node() : l(-1), r(-1), x(0) {} 
};

const int maxn = 2e5 + 1, mod = 1e9;
bool debug = false;
int gr[3][3];

void solve() {
	for (int i = 0; i < 3; ++i)	{
		for (int j = 0; j < 3; ++j) {
			cin >> gr[i][j];
		}
	}
	for (int i = 0; i <= 100; ++i) {
		for (int j = 0; j <= 100; ++j) {
			for (int k = 0; k <= 100; ++k) {
				int b1 = gr[0][0] - i; 
				int b2 = gr[0][1] - i; 
				int b3 = gr[0][2] - i; 
				if (b1 >= 0 && b2 >= 0 && b3 >= 0) {
					if (j + b1 == gr[1][0] && j + b2 == gr[1][1] && j + b3 == gr[1][2] && k + b1 == gr[2][0] && k + b2 == gr[2][1] && k + b3 == gr[2][2])  {
						cout << "Yes";
						return;
					} 
				}
			}
		}
	}
	cout << "No";
}            

signed main() {
    /*!

    !*/
    cout.precision(10);
    cout << fixed;
    if (!debug) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
 //   freopen("TASK.in", "r", stdin);
  // freopen("TASK.out", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main( void )
{
	int N; // f[^ZbgÌÂ
	cin >> N;

	for ( int lpc = 0; lpc < N; lpc++ )
	{
		int a = 0;
		int b = 0;
		int cnt = 0;
		for ( int i = 0; i < 10; i++ )
		{
			int c;
			cin >> c;

			bool ok = false;
			if ( a < c )
			{
				if ( b < c && b > a )
					b = c;
				else
					a = c;
				ok = true;
			}
			else if ( b < c )
			{
				if ( a < c && a > b )
					a = c;
				else
					b = c;
				ok = true;
			}

			if ( ok == false )
			{
				while ( i+1 < 10 )
				{
					cin >> c;
					i++;
				}
				break;
			}

			cnt++;

		}

		if ( cnt == 10 )
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a, b;
    cin >> a >> b;
    cout << max(a * b, max(a + b, a - b)) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll f(ll x){
	int i;
	ll ret=0ll;
	for(i=0; i<60; ++i){
		ret += (1ll<<i)*(((1ll<<i)*(x/(1ll<<(i+1)))+max(0ll,x%((1ll<<(i+1)))-(1ll<<i)))%2);
	}
	return ret;
}

int main(void){
	ll a,b;
	cin >> a >> b;
	cout << (f(a)^f(b+1)) << endl;
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



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

    rep(i, n+1) {
        rep(j, n+1-i) {
            if(i*10000+j*5000+(n-i-j)*1000 == y) {
                cout << i << ' ' << j << ' ' << n-i-j << endl;
                return 0;
            }
        }
    }

    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A , B ;
    char S;
    cin>>A>>S>>B;
    switch(S)
    {
        case '+':
            cout<<A+B;
            break;
        case'-':
            cout<<A-B;
            break;
    }

    return 0;
}


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

int cnt = 0;

void insertionSort(vector<int> &A,int g){
	int n = A.size();
	for(int i = g; i < n; i++){
		int v = A[i];
		int j = i - g;
		while(j >= 0 and A[j] > v){
			A[j+g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(vector<int> &A){
	cnt = 0;
	int n = A.size(),i;
	vector<int> G;
	for(i = 1; i <= n; i = 3*i+1) G.push_back(i);
	reverse(G.begin(),G.end());
	int m = G.size();
	cout << m << endl;
	for(i = 0; i < m; i++) printf(i < m-1 ? "%d ":"%d\n",G[i]);
	for(i = 0; i < m; i++) insertionSort(A,G[i]);
}

int main(){
	int n;
	cin >> n;
	vector<int> A(n);
	for(auto &a:A) cin >> a;
	shellSort(A);
	cout << cnt << endl;
	for(auto a:A){
		cout << a << endl;
	}
	return 0;
}		

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
int const nax = 2e5 + 10;
int const N = 3005;

int n, m;

int x[nax], y[nax];
int top_x, top_y, nx, ny;



inline void upd_min(int &a, int b) {
    a = min(a, b);
}

inline void upd_max(int &a, int b) {
    a = max(a, b);
}

int a[N];
int b[N];
int c[N];
int d[N];
int e[N];
int f[N];

bool U[N][N];
bool D[N][N];
bool L[N][N];
bool R[N][N];
bool vis[N][N];



int find_x (int x) {
    return lower_bound(::x + 1, ::x + ::nx + 1, x) - ::x;
}

int find_y (int y) {
    return lower_bound(::y + 1, ::y + ::ny + 1, y) - ::y;
}

int min_x, max_x;
int min_y,  max_y;

long long sum;


void BFS(int u, int v) {

    queue<pair <int, int> > q;
    q.emplace(u, v);

    vis[u][v] = 1;
    while (!q.empty()) {

        u = q.front().first, v = q.front().second;
        q.pop();

        upd_min(min_x, u), upd_max(max_x, u);
        upd_min(min_y, v), upd_max(max_y, v);

        sum += 1LL * (x[u + 1] - x[u]) * (y[v + 1] - y[v]);

        if (!L[u][v] && !vis[u - 1][v] && u > 1) {
            vis[u - 1][v] = true;
            q.emplace(u - 1, v);
        }

        if (!R[u][v] && !vis[u + 1][v] && u + 1 <= nx) {
            vis[u + 1][v] = true;
            q.emplace(u + 1, v);
        }

        if (!U[u][v] && !vis[u][v - 1] && v > 1) {
            vis[u][v - 1] = true;
            q.emplace(u, v - 1);
        }

        if (!D[u][v] && !vis[u][v + 1] &&v + 1 <= ny) {
            vis[u][v + 1] = true;
            q.emplace(u, v + 1);
        }
    }


}


int main () {

    /// hell not x, y coordinate...

    scanf("%d %d", &n, &m);

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

        scanf("%d %d %d", a + i, b + i, c + i);
        /// connect (a, c) to (b, c)
        /// xy coordinate in this problem
        x[++ top_x] = a[i];
        x[++ top_x] = b[i];
        y[++ top_y] = c[i];
    }

    const int lim = 1e9 + 7;
    x[++ top_x] = lim; x[++ top_x] = - lim, x[++ top_x] = 0;

    y[++ top_y] = lim ; y [++ top_y] = - lim, y[++ top_y] = 0;

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

        scanf("%d %d %d", d + i, e + i, f + i);

        /// connect (d, e) to (d, f)
        x[++ top_x] = d[i];
        y[++ top_y] = e[i];
        y[++ top_y] = f[i];
    }

    sort(x + 1, x + top_x + 1);
    sort(y + 1, y + top_y + 1);

    nx = unique(x + 1, x + top_x + 1) - x - 1;
    ny = unique(y + 1, y + top_y + 1) - y - 1;

    for (int i = 1 ; i <= n ; ++ i) {
        int x1 = find_x(a[i]);
        int x2 = find_x(b[i]);
        int y = find_y(c[i]);

        for (int j = x1 ; j < x2 ; ++ j) {
            U[j][y] = D[j][y - 1] = true;
        }
    }

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

        int x = find_x(d[i]);
        int y1 = find_y(e[i]);
        int y2 = find_y(f[i]);

        for (int j = y1 ; j < y2 ; ++ j) {
            L[x][j] = R[x - 1][j] = true;
        }
    }

    int sx = find_x(0), sy = find_y(0);

    min_x = nx + 1, max_x = 0;
    min_y = ny + 1, min_y = 0;

    BFS(sx, sy);


    if (min_x == 1 || max_x == nx || min_y == 1 || max_y == ny) {
        puts("INF");
    } else {
        printf("%lld\n", sum);
    }
}
/*
    Good Luck
        -Lucina
*/


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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    string s = to_string(i);
    if (s.size() % 2 == 1) {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
#include <complex>
using namespace std;
int main()
{
    long long n,i,ans=1,cnt=1;
    cin>>n;
    for(i=1;i<10;i++) cnt*=10;
    cnt+=7;
    for(i=2;i<=n;i++) 
    {
        ans*=i;
        if(ans>cnt) ans%=cnt;
    }
    cout<<ans;
    system ("pause"); 
    return 0;
}

Measured memory_bytes: 504
X,Y = map(int, input().split())

if X%Y == 0:
    print(-1)
else:
    i = 1
    while 1:
        if X*i > 10**18:
            print(-1)
            break
        elif X*i%Y!=0:
            print(X*i)
            break
        else:
            i+= 1

Measured memory_bytes: 9156
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

		final Scanner stdin = new Scanner( System.in );

		while ( true ) {

			final int n = stdin.nextInt();
			if ( n == 0 ) break;

			int[][] vals = new int[ 2 ][ 12 ];
			for ( int i = 0; i < 12; i++ ) {
				vals[ 0 ][ i ] = stdin.nextInt();
				vals[ 1 ][ i ] = stdin.nextInt();
			}
			int sum = 0;
			boolean success = false;
			for ( int i = 0; i < 12; i++ ) {
				sum += vals[ 0 ][ i ] - vals[ 1 ][ i ];
				if ( sum >= n ) {
					System.out.println( i + 1 );
					success = true;
					break;
				}
			}
			if ( !success ) {
				System.out.println( "NA" );
			}
		}	
    }    
}

Measured memory_bytes: 32884
import math

n = input()
a = input().split()
N = int(n)

ans_list = []
ann = []
ana = 1
for j in range(N):
    ana = ana * int(a[j])
ana = ana -1
ans = 0
for k in range(N):
    ans += int(ana % int(a[k]))
ans_list.append(ans)

ans_list.sort()
ans_list.reverse()
print(str(ans_list[0]))







Measured memory_bytes: 3188