akhauriyash/Code-Regression huggingface dataset:
/*
* @author:  codancer
* @createTime:  2020-04-04, 20:12:19
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int main(){
	ll n,k;
	cin>>n>>k;
	cout<<min(n%k,abs(k-n%k))<<endl;
	return 0;
}

Measured memory_bytes: 256
def max2(a, b, c, d):
    vals = sorted((a, b, c, d), reverse=True)
    return vals[0], vals[1]


n = int(input())
a = list(map(int, input().split()))

dp = [[0] * (1 << n) for i in range(n + 1)]
dq = [[0] * (1 << n) for i in range(n + 1)]
for i in range(1 << n):
    dp[0][i] = a[i]

for i in range(n):
    for bit_state in range(1 << n):
        if (1 << i) & bit_state:
            first, second = max2(dp[i][bit_state], dq[i][bit_state], dp[i][bit_state ^ (1 << i)], dq[i][bit_state ^ (1 << i)])
        else:
            first, second = dp[i][bit_state], dq[i][bit_state]
        dp[i + 1][bit_state], dq[i + 1][bit_state] = first, second

ans = 0
for i in range(1, 1 << n):
    ans = max(ans, dp[-1][i] + dq[-1][i])
    print(ans)

Measured memory_bytes: 126480
#include <bits/stdc++.h>
using namespace std;
int n,l,i,k,res;
long long dp[100009];
long long a[100009];
long long f(int x)
{
    if(x==0)return 0;
    if(dp[x]!=LONG_MAX)return dp[x];

    for(int j=1;j<=k && x-j>=0;j++)
             dp[x]=min(abs(a[x]-a[x-j])+f(x-j),dp[x]);

    return dp[x];
}

int main()
{   cin>>n>>k;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<100009;i++)
        dp[i]=LONG_MAX;

    cout << f(n-1) << endl;
    return 0;
}


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

int main() {
  int n;
    cin>>n;
  string s;
    cin>>s;
  
  vector<int>vec(n);
  vector<int>bec(n);
  
  if(s.at(0)=='#'){
    vec[0]=1;
  }
  else{
    vec[0]=-1;
    bec[0]=1;
  }
  for(int i=1;i<n;i++){
    if(s.at(i)=='#'){
      vec[i]+=1+vec[i-1];
      bec[i]=bec[i-1];
    }
    else{
      vec[i]+=vec[i-1]-1;
      bec[i]+=1+bec[i-1];
    }
  }
  if(vec[n-1]==n){
    cout<<0<<endl;
  }
  else{
   sort(vec.begin(),vec.end());
   cout<<min((vec[0]+bec[n-1]),bec[n-1])<<endl;
}
}

Measured memory_bytes: 2180
/*  Success may not come to me immediately,
 *  but it will come definitely....
 */
#include<bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li      int64_t
#define ld      double_t
#define ulli    uint64_t
//=====================================================================
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define repi(i,v)   for(i=v.begin();i!=v.end();i++)
#define repir(i,v)  for(i=v.rbegin();i!=v.rend();i++)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
#define nl          cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>   vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpl;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb  push_back
#define pob pop_back
#define pf  push_front
#define pof pop_front
#define all(v)  v.begin(),v.end()
#define itr iterator
#define rtr reverse_iterator
#define sz  size()
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define mp  make_pair
#define F   first
#define S   second
//=====================================================================
#define mod (li)(1e9+7)
#define inf (li)(1e18)
#define MX1 (li)(1e5+5)
#define MX2 (li)(1e6+5)
#define pi  acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return (1LL<<n);}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={-1,0,1,0},dy[]={0,-1,0,1};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

li n,a[105];

void solve(){
	li i;cin>>n;
	ld sum=0.0;
	rep(i,0,n) cin>>a[i],sum+=a[i];
	sum/=n*1.0;
	li x=floor(sum);
	li y=ceil(sum);
	li ans1,ans2;
	ans1=ans2=0;
	rep(i,0,n){
		ans1+=(x-a[i])*(x-a[i]);
		ans2+=(y-a[i])*(y-a[i]);
	}
	cout<<min(ans1,ans2);nl;
}

int main(){
	opt
	li t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  int N , x , ans = 0 , i;
  cin >> N;
  for(i=1;i<=N;i++)
      {
        cin >> x;
        ans = ans + x%2;
      }
  if(ans%2 && N != 1)
    cout << "NO\n";
  else cout << "YES\n";
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

int hungarian(vector<vector<int> > a) {
  int n=a.size(),p,q,INF=1<<29;
  vector<int> fx(n,INF),fy(n,0);
  vector<int> x(n,-1),y(n,-1);
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      fx[i]=max(fx[i],a[i][j]);
  for(int i=0;i<n;) {
    vector<int> t(n,-1),s(n+1,i);
    for(p=q=0;p<=q&&x[i]<0;p++)
      for(int k=s[p],j=0;j<n&&x[i]<0;j++)
        if(fx[k]+fy[j]==a[k][j]&&t[j]<0) {
          s[++q]=y[j],t[j]=k;
          if(s[q]<0)for(p=j;p>=0;j=p) y[j]=k=t[j],p=x[k],x[k]=j;
        }
    if(x[i]<0) {
      int d=INF;
      for(int k=0;k<=q;k++)
        for(int j=0;j<n;j++)
          if(t[j]<0) d=min(d,fx[s[k]]+fy[j]-a[s[k]][j]);
      for(int j=0;j<n;j++) fy[j]+=(t[j]<0?0:d);
      for(int k=0;k<=q;k++) fx[s[k]]-=d;
    } else i++;
  }
  int ret=0;
  for(int i=0;i<n;i++) ret+=a[i][x[i]];
  return ret;
}

void Main() {
  int n,m;
  while(cin >> n >> m && n) {
    vector<int> a(n),b(m);
    rep(i,n) R a[i];
    rep(i,m) R b[i];
    if(n<m) swap(a,b),swap(n,m);
    vector<vector<int> > v;
    rep(i,n) {
      vector<int> w;
      rep(j,m) {
        int d=abs(a[i]-b[j]);
        w.pb(d*(d-30)*(d-30));
      }
      REP(j,m,n) w.pb(0);
      v.pb(w);
    }
    pr(hungarian(v));
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    vector<int64_t> V;
    int64_t v=0,i=0;
    while(v<N){
        i++;
        v+=i;
        V.push_back(i);
    }

    rep(i,0,V.size()){
        if(v==N) break;
        if(v-N<V.at(i)){
            V.at(i)-=v-N;
            v-=v-N;
        }else{
            v-=V.at(i);
            V.at(i)=0;
        }
    }

    for(auto v:V)if(v)cout<<v<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/ped_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
//#define ordered_set ped<ll , null_type, less<ll>, rb_ped_tag, ped_order_statistics_node_update>

typedef long long ll;


int main()
{
   run;
   ll n;
   cin>>n;
   string s;
   cin>>s;
   fr(i,0,s.length())
   {
       ll o=s[i]-'A';
       o+=n;
       o%=26;
       s[i]=o+'A';
   }
   cout<<s;










    return 0;
}


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

bool div_by_two(vector<int>& data) {
	bool ret = true;
	for (int i = 0; i < data.size(); i++) {
		ret = (data.at(i) % 2 != 1);
		if (!ret) break;
		data.at(i) /= 2;
	}
	return ret;
}

void Main() {
	int N;
	cin >> N;
	vector<int> data(N);
	for (int i = 0; i < N; i++) {
		cin >> data.at(i);
	}

	int ans = 0;
	while (div_by_two(data)) {
		ans++;
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;

int main(int argc, const char * argv[]) {


    int a, b, h, m;
    cin >> a >> b >> h >> m;
    
    int min;
    
    double thetaA, thetaB, theta, ans;
    
    min = h * 60 + m;
    
    thetaA = min * 0.5;
    thetaB = min % 60 * 6;
    
    theta = abs(thetaA - thetaB);
    
   // if(theta > 180) theta = theta - 180;
    
    ans = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(theta * M_PI / 180));
    
    //cout << cos(theta) << endl;
    
    cout << fixed << setprecision (10) << ans << endl;

    return 0;
    
    
}


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

#define M 1046527
#define NIL -1
#define L 14

string H[M];

int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

long long getKey(string str){
  long long sum = 0, p = 1;
  for(int i = 0; i < str.size(); i++){
    sum += p * getChar(str[i]);
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(string str){
  long long key, h;
  key = getKey(str);
  for(int i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(H[h] == str) return 1;
    else if(H[h].size() == 0) return 0;
  }
  return 0;
}

int insert(string str){
  long long key, h;
  key = getKey(str);
  for(int i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(H[h] == str) return 1;
    else if(H[h].size() == 0){
      H[h] = str;
      return 0;
    }
  }
  return 0;
}

int main(void){
  int n, h;
  string str, com;
  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> com >> str;
    if(com[0] == 'i'){
      insert(str);
    }else{
      if(find(str)){
        cout << "yes" << endl;
      }else{
        cout << "no" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 25872
#include<bits/stdc++.h>
using namespace std;
void PDF(double r)
{
    double pi = 3.1416;
    double area;
    area = 2 * pi * r;
    cout << area << endl;
}
int main()
{
    double n;
    cin >> n;
    PDF(n);
    return 0;
}


Measured memory_bytes: 3788
#include <stdio.h>
int main(){
    int n;
    int v[21],c[21];
    int i,ans=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&v[i]);
    for(i=0;i<n;i++)scanf("%d",&c[i]);
    for(i=0;i<n;i++){
        if(v[i]-c[i]>0)ans+=(v[i]-c[i]);
    }
    printf("%d\n",ans);
    return 0;
}

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

int main(){
    int a,b;
    cin >> a>>b;
    string ans="";
    if(a<b) ans = "a < b";
    else if(a>b) ans="a > b";
    else ans="a == b";
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define str string
#define deb_arr(arr,n) for(ll i=0;i<(n);i++){ cout << (arr)[i] << " ";}
#define in_arr0(arr,n) for(ll i=0;i<(n);i++){ cin >> (arr)[i]; }
#define in_arr1(arr,n) for(ll i=1;i<=(n);i++){ cin >> (arr)[i];}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define vll vector<ll> 
#define fr(n) for(i=0;i<(n);i++)
#define fr1(n) for(i=1;i<=(n);i++)
#define pll pair<ll,ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define IN(a,b) ((a).find(b)!=(a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) if(ON) cout << #x <<" : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL),cout.tie(NULL)
#define ON !false
ll dx[]={0,-1,0,1};
ll dy[]={1,0,-1,0};
const ll mod=1e9+7;
inline ll add(ll a,ll b){
    return  ((a%mod)+(b%mod)+mod)%mod;
}
inline ll mul(ll a,ll b){
    return ((a%mod)*(b%mod)+mod)%mod;
}
void pause(ll id){
    cout << "Waiting " << id << endl;
    cin >> id;
}

const int mxn=1e5+10;


void init(){

    return ;
}


signed main(){
    fast;
    io;
    if(!true){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    }
    init();
    ll i,j;
    str s;
    cin >> s;
    ll n=s.size();
    vll arr(n+1,0);
    arr[0]=0;
    ll rem=0;
    for(i=1;i<=n;i++){
        rem=rem*10 + (s[i-1]-'0');
        rem%=2019;
        arr[i]=rem;
    }
    ll ten=1ll;
    for(i=n;i>=1;i--){
        arr[i]*=ten;
        arr[i]%=2019;
        ten*=10;
        ten%=2019;
    }
    map<ll,ll> mp;
    mp[0]=1;
    for(i=1;i<=n;i++){
        mp[arr[i]]++;
    }
    ll ans=0;
    for(auto c:mp){
        ans+=(c.s*(c.s-1))/2;
    }
    cout << ans << endl;
   
    return 0;
}


Measured memory_bytes: 5136
#include<stdio.h>
#include<limits.h>
int smaller(int a,int b){
	if(a<=b)
		return a;
	else return b;
}
	int main(){
		int c[200][200],t[200][200],a,b,C,T,p,q,r,k,v[200],g[200],x,now,nex,n,m,i,j,min;
		while(scanf("%d %d",&n,&m),n||m){
			for(i=0;i<m;i++)
				for(j=0;j<m;j++){
					c[i][j]=INT_MAX;
					t[i][j]=INT_MAX;
			}
			while(n-->0){
				scanf("%d %d %d %d",&a,&b,&C,&T);
				c[a-1][b-1]=C;
				c[b-1][a-1]=C;
				t[a-1][b-1]=T;
				t[b-1][a-1]=T;
			}
			scanf("%d",&k);
			while(k-->0){
				for(i=0;i<m;i++){
						v[i]=-1;
						g[i]=INT_MAX;
					}
				scanf("%d %d %d",&p,&q,&r);
				g[p-1]=0;
				if(r==0){
					
					
					while(v[q-1]==-1){
						min=INT_MAX;
						for(i=0;i<m;i++)
							if(v[i]==-1&&g[i]<min){
								min=g[i];
								x=i;
						}
						v[x]=0;
						for(i=0;i<m;i++){
							if(v[i]==-1&&c[x][i]!=INT_MAX)
								g[i]=smaller(g[i],g[x]+c[x][i]);
						}
					}
					printf("%d\n",g[q-1]);
				}
				else {
					
					
					
					while(v[q-1]==-1){
						min=INT_MAX;
						for(i=0;i<m;i++)
							if(v[i]==-1&&g[i]<min){
								min=g[i];
								x=i;
						}
						v[x]=0;
						for(i=0;i<m;i++){
							if(v[i]==-1&&t[x][i]!=INT_MAX)
								g[i]=smaller(g[i],g[x]+t[x][i]);
						}
					}
					printf("%d\n",g[q-1]);
				}
			}
		}
		return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair 
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define For(I,N) for(int I=0;I<N;I++)
typedef unsigned long long ull;
using namespace std;
int n,a[105];

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	int ans=1;
	rep(n)
	{
		cin>>a[i];
		ans*=3;
	}
	int s=1;
	rep(n)
	{
		if(a[i]%2==0) s*=2;
	}
	cout<<ans-s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int main()
{
	int N,D,X,i,b=0,sum=0;
    int A[101];
    cin>>N;
    cin>>D>>X;
    for(i=1;i<=N;i++)
    {
    	b=0;
    	cin>>A[i];
    	while(b*A[i]+1<=D) 
		{
			b++;
			sum++;
		}
	}
	cout<<sum+X;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL S (LL n){
  LL sum = 0;
  while (n > 0)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  double fu=std::numeric_limits<double>::infinity();
  vector<LL> snuke(0);
  for (LL j = 10000000000000; j >= 1; j /= 10)
  {
    for (LL k = 10000; k >= 1001; --k)
    {
      LL i = k * j - 1;
      double hoge = (double)i / (double)S(i);
      if (hoge <= fu)
      {
        snuke.push_back(i);
      //  cout << i << ":" << (double)i / (double)S(i) << endl;
        fu = hoge;
      }
    }
  }
  for (LL i = 999; i >= 1;--i){
       double hoge = (double)i / (double)S(i);
      if (hoge <= fu)
      {
        snuke.push_back(i);
        //cout << i << ":" << (double)i / (double)S(i) << endl;
        fu = hoge;
      }
  }
    LL K;
  cin >> K;
  REP(i, K)
  {
    cout << snuke[snuke.size() - 1 - i] << endl;

  }
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn increment(num: &mut Vec<u64>) {
    let mut i = 0usize;
    let mut flag = false;
    while i < num.len() {
        if num[i] < 9 {
            if i == num.len() - 1 {
                num[i] += 1;
                // set lower digit to minimum
                for j in (0..i).rev() {
                    if num[j + 1] == 0 {
                        num[j] = 0;
                    } else {
                        num[j] = num[j + 1] - 1;
                    }
                }
                return;
            } else {
                if num[i+1] + 1 == num[i] {
                    i += 1;
                } else {
                    num[i] += 1;
                    // set lower digit to minimum
                    for j in (0..i).rev() {
                        if num[j + 1] == 0 {
                            num[j] = 0;
                        } else {
                            num[j] = num[j + 1] - 1;
                        }
                    }
                    return;
                }
            }
        } else {
           i += 1;
       }
    }
    if i == num.len() {
        for i in 0..num.len() {
            num[i] = 0;
        }
        num.push(1);
    }
}

fn main() {
    let k: u64 = input();
    let mut num: Vec<u64> = Vec::new();
    num.push(0);
    let mut count = 0;

    for i in 0..k {
        increment(&mut num);
    }
    num.reverse();
    for n in num {
        print!("{}", n);
    }
    println!();
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

long int digitSum[50][2];

int getMaxDigit(long int N) {
    return N == 0 ? 1 : floor(log2((double) N)) + 1;
}

int getKthDigit(long int N, int K) {
    return (N % (long int) pow(2, K + 1)) / (long int) pow(2, K);
}

long int getMaxLastK(int j) {
    long int sum = 0;
    for (int i = j - 1; i >= 0; i++) {
        sum += max(digitSum[i][0], digitSum[i][1]);
    }
    return sum;
}

int main() {
    int N;
    long int K;
    scanf("%d %ld", &N, &K);
    long int A[N];
    for (int i = 0; i < N; i++) {
        scanf("%ld", &A[i]);
    }
    int maxDigit = getMaxDigit(K + 1);
    for (int i = 0; i < N; i++) {
        maxDigit = max(maxDigit, getMaxDigit(A[i]));
    }
    int digitCount[maxDigit];
    for (int j = 0; j < maxDigit; j++) {
        digitCount[j] = 0;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < maxDigit; j++) {
            digitCount[j] += getKthDigit(A[i], j);
        }
    }

    for (int j = 0; j < maxDigit; j++) {
        digitSum[j][0] = digitCount[j] * (long int) pow(2, j);
        digitSum[j][1] = (N - digitCount[j]) * (long int) pow(2, j);
    }

    int targetDigit[maxDigit];
    long int maximum = 0;
    for (int j = 0; j < maxDigit; j++) {
        targetDigit[j] = getKthDigit(K + 1, j);
        maximum += digitSum[j][0];
    }
    for (int j = 0; j < maxDigit; j++) {
        if (targetDigit[j] == 1) {
            long int sum = 0;
            for (int k = 0; k < maxDigit; k++) {
                if (k > j) sum += digitSum[k][targetDigit[k]];
                else if (k == j) sum += digitSum[k][0];
                else sum += max(digitSum[k][0], digitSum[k][1]);
            }
            maximum = max(maximum, sum);
        }
    }

    printf("%ld\n", maximum);

    return 0;
}

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

int main(){
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if (a1+a2+a3 > 21){
        cout << "bust"<<endl;
    }else{
        cout << "win" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main(){
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for(int i = 0; i < n; ++i){
    std::cin >> v[i];
  }
  std::vector<int> c(n);
  for(int i = 0; i < n; ++i){
    std::cin >> c[i];
  }
  int ans = 0;
  for(int i = 0; i < n; ++i){
    if(v[i] > c[i]){
      ans += v[i] - c[i];
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


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


int main() {
    int N;
    cin >> N;
    int a[N], b[N], c[N], a_sel[N]={}, b_sel[N]={}, c_sel[N]={};
    for (int i=0; i<N; i++) scanf("%d %d %d", &a[i], &b[i], &c[i]);

    a_sel[0] = a[0];
    b_sel[0] = b[0];
    c_sel[0] = c[0];
    for (int i=0; i<N-1; i++) {
        a_sel[i+1] = max(b_sel[i], c_sel[i]) + a[i+1];
        b_sel[i+1] = max(c_sel[i], a_sel[i]) + b[i+1];
        c_sel[i+1] = max(a_sel[i], b_sel[i]) + c[i+1];
    }

    cout << max({a_sel[N-1], b_sel[N-1], c_sel[N-1]}) << endl;

    return 0;
}



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

int main() {
  vector<int> sides(3);
  for (int i = 0; i < 3; i++) {
    cin >> sides.at(i);
  }
  sort(sides.begin(), sides.end());
  cout << sides.at(0) * sides.at(1) / 2 << endl;
}

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

static const int N_MAX = 110, INF = 10000;

int main(void){
  //入力
  int N, T;
  int c[N_MAX], t[N_MAX];
  cin >> N >> T;
  for(int i = 0; i < N ;i++){
    cin >> c[i] >> t[i];
  }
  int ans = INF;
  for(int i = 0; i < N; i++){
    if(T >= t[i]){
      if(ans > c[i]) ans = c[i];
    }
  }
  if(ans == INF) cout << "TLE" << endl;
  else cout << ans << endl;
  return 0;
}


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

typedef long long ll;
int H, W;
ll ans;
int main() {
    scanf("%d %d", &H, &W);
    ans = (H % 3 == 0 || W % 3 == 0? 0 : min(H, W));
    for(int i = 1; i < W; i++) {
        ll mn = min((ll)i*H, (ll)(W - i)*(H/2));
        ll mx = max((ll)i*H, (ll)(W - i)*(H - H/2));
        ans = min(ans, mx - mn);
    }
    for(int i = 1; i < H; i++) {
        ll mn = min((ll)i*W, (ll)(H - i)*(W/2));
        ll mx = max((ll)i*W, (ll)(H - i)*(W - W/2));
        ans = min(ans, mx - mn);
    }
    printf("%lld", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int N, W[101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> W[i];
	rep(i, 1, N) W[i] += W[i - 1];

	int ans = inf;
	rep(T, 0, N - 1) {
		int s1 = W[T];
		int s2 = W[N - 1] - s1;
		chmin(ans, abs(s1 - s2));
	}

	cout << ans << endl;
}







Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr


n, p = map(int, input().split())
pf = factorization(p)
ans = 1
for i in pf:
    if i[1] >= n:
        ans *= i[0] ** (i[1]//n)
print(ans)

Measured memory_bytes: 3064
#![allow(unused_imports)]
#![allow(unused_macros)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;


//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}


//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}


//
// Main
//

fn main() {
    input! {
        n: isize,
    }

    let ans = if n <= 9 {
        n
    } else if n <= 99 {
        9
    } else if n <= 999 {
        9 + (n - 99)
    } else if n <= 9999 {
        9 + (999 - 99)
    } else if n <= 99999 {
        9 + (999 - 99) + (n - 9999)
    } else if n <= 999999 {
        9 + (999 - 99) + (99999 - 9999)
    } else {
        panic!();
    };
    println!("{}", ans);
}


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

void Main() {
  int N, M;
  cin >> N >> M;
  int H[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  vector<set<int>> edge(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    edge[A - 1].insert(B - 1);
    edge[B - 1].insert(A - 1);
  }

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    bool good = true;
    for (auto j: edge[i]) {
      if (H[i] <= H[j]) {
        good = false;
        break;
      }
    }
    if (good) ans++;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 17720
import sys
def solve():
    person = 0
    for i in range(0,H):
        for j in range(0,W):
            if geo[i][j] is not "_":
                search(i,j)
                person += 1
    print(person)
 
def search(i,j):
    temp = geo[i][j]
    geo[i][j] = "_"
    for a in range(0,4):
        idx, jdy = i + dx[a], j + dy[a]
        if(isOnMap(idx, jdy)):
            if(isNeededToSolve(temp, idx, jdy)):
                search(idx,jdy)
 
def isOnMap(i,j): return (0<=i and 0<=j and i<H and j<W)
 
def isNeededToSolve(temp,i,j):
    target = geo[i][j]
    return (target is not "_" and temp is target)
 
limit = 10**7
sys.setrecursionlimit(limit)
 
H, W, tempH = -1, -1, 0
dx = [-1,0,1,0]
dy = [0,-1,0,1]
geo = [[0 for i in range(1)]for j in range(1)]
while True:
    line = input()
    if H is -1 and W is -1:
        p = line.split(" ")
        H, W = int(p[0]), int(p[1])
        geo = [[0 for i in range(W)] for j in range(H)]
    else:
        geo[tempH] = list(line)
        tempH+=1
    if H is 0 and W is 0:break
    if tempH is H:
        solve()
        H, W, tempH = -1, -1, 0

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

const int MAX_X = 2000;
const int MAX_Y = 2000;

//sはグローバル変数なので 宣言時に0に初期化される
int s[MAX_X][MAX_Y];

int main() {

    int x, y, w, h;
    for ( int k=0; k<2; ++k ) {
	cin >> x >> y >> w >> h;
	for ( int i=x; i<x+w; ++i ) 
	    for ( int j=y; j<y+h; ++j ) ++s[i][j];
    }
    
    int c = 0;
    for ( int i=0; i<MAX_X; ++i ) 
	for ( int j=0; j<MAX_Y; ++j ) 
	    if ( s[i][j] == 1 ) ++c;

    cout << c << endl;

    return 0;
}



Measured memory_bytes: 18716
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

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

	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	vector<int> l(N), r(N);
	l[0] = A[0];
	r[N - 1] = A[N - 1];
	FOR(i, 1, N) l[i] = gcd(l[i - 1], A[i]);
	FOR(i, 1, N) r[N - 1 - i] = gcd(r[N - i], A[N - 1 - i]);
	int res;
	REP(i, N) {
		if (i == 0) res = r[1];
		else if (i == N - 1) res = max(res, l[N - 2]);
		else res = max(res, gcd(l[i - 1], r[i + 1]));
	}
	cout << res << "\n";

	return 0;
}


Measured memory_bytes: 1408
N = int(input())
p = list(map(int, input().split()))
answer = 0
streak = 0
for i in range(1, N+1):
    if i == p[i-1]:
        answer += 1
        if i-1 == p[i-2]:
            answer -= 1
            temp = p[i-1]
            p[i-1] = p[i-2]
            p[i-2] = temp

print(answer)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define all(a) a.begin(),a.end()
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){x=x>y?y:x;}
template<class T> inline void gmax(T &x,const T &y){x=x<y?y:x;}
template<class T> inline bool Gmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T> inline bool Gmax(T &x,const T &y){return x<y?x=y,1:0;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int main(){
#ifdef rqgao2014
	assert(freopen("input.txt","r",stdin));
#endif
	int n,m;cin>>n>>m;
	if(n==1&&m==1){cout<<1<<endl;return 0;}
	if(n==1||m==1){cout<<n+m-3<<endl;return 0;}
	cout<<(ll)(n-2)*(m-2)<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 


x,y = [int(i) for i in readline().split()]
#n = int(input())

ans = 0
if x == 3:
    ans += 1
elif x == 2:
    ans += 2
elif x == 1:
    ans += 3

if y == 3:
    ans += 1
elif y == 2:
    ans += 2
elif y == 1:
    ans += 3

if x == y == 1:
    ans += 4
    
print(ans * 100000)    
    
    
    
    







Measured memory_bytes: 3316
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2018-10-6 21:02:02
# Powered by Visual Studio Code
#

n, l = gets.chomp.split(" ").map{|i| i.to_i}
ans = 1000000
n.times{
  c, t = gets.chomp.split(" ").map{|i| i.to_i}
  if t <= l
    ans = [ans, c].min
  end
}
if ans == 1000000
  puts "TLE"
else
  puts ans
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  long long ans;
  cin >> S >> T;
  
  ans = 0;
  for ( long long i = 0; i < S.length(); i++ ) {
    if ( S[i] != T[i] ) {
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll cnt[10000001];


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;


   
    for(ll i=1; i<=N; i++)
    {
        for(ll j=0; j<N; j++)
        {
            if(i+i*j<=N)
            {
                cnt[i+i*j]++;
            }
            else
            {
                break;
            }
            
        }
    }

    ll ans =0;
    rep(i, N+1)
    {
        ans += i*cnt[i];
    }

    cout << ans << endl;



    return 0;

}



Measured memory_bytes: 81748
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    int N;
    cin >> N;
    auto A = vc(int, N);
    auto B = vc(int, N);
    auto C = vc(int, N-1);
    fa(i, A) { cin >> i; i--; }
    fa(i, B) cin >> i;
    fa(i, C) cin >> i;
    int ans = B[A[0]];
    lpsb(i, 1, N) ans += B[A[i]] + (A[i-1]+1 == A[i] ? C[A[i-1]] : 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var H1, H2, M1, M2, K int
	fmt.Scan(&H1)
	fmt.Scan(&M1)
	fmt.Scan(&H2)
	fmt.Scan(&M2)
	fmt.Scan(&K)
	ans := (H2-H1)*60 + (M2 - M1) - K
	fmt.Println(ans)
}


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

const int XD = 1e5 + 2;
int dp[ XD ][ 3 ];

int main()
{
    ios_base::sync_with_stdio( false );
    int n; cin >> n;
    for( int i = 1; i <= n; i++ )
    {
        for( int j = 0; j < 3; j++ )
            cin >> dp[ i ][ j ];
        dp[ i ][ 0 ] += max( dp[ i - 1 ][ 1 ], dp[ i - 1 ][ 2 ] );
        dp[ i ][ 1 ] += max( dp[ i - 1 ][ 0 ], dp[ i - 1 ][ 2 ] );
        dp[ i ][ 2 ] += max( dp[ i - 1 ][ 0 ], dp[ i - 1 ][ 1 ] );
    }
    cout << max( dp[ n ][ 0 ], max( dp[ n ][ 1 ], dp[ n ][ 2 ] ) );
    return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  int ans=0;
  rep(i,k){
    ans+=p[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

int Stuck[100];
int p;

void init(){p = 0;}

void push(int x)
{
    if (p ==100){
        printf("stuck over flow");
        exit(0);
    }
    Stuck[p++] = x;
}

int pop()
{
    if (p == 0){
        printf("stuck under flow");
        exit(0);
    }
    return (Stuck[--p]);
}

int main()
{
    int x, a, b;
    char c[100];

    while(scanf("%s", c) != EOF){
        if(isdigit(c[0])){
            x = atoi(c);
            push(x);
        } else if (c[0] == '+'){
            b = pop();
            a = pop();
            push(a + b);
        } else if (c[0] == '-'){
            b = pop();
            a = pop();
            push(a - b);
        } else if (c[0] == '*'){
            b = pop();
            a = pop();
            push(a * b);
        } else {
            printf("error");
            exit(0);
        }
    }
    
    
    printf("%d\n",pop());
    return 0;
}


Measured memory_bytes: 2720
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);
function main(){
  var s = next(1);
  return Array(s.length).fill("x").join("");
}

Measured memory_bytes: 21192
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
ll a[100005];
int main() {
  int n;
  cin >> n;
  ll cur = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long double x = 1;
  for (int i = 0; i < n; i++) {
    x *= a[i];
  }
  if (x > 1e18) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cur *= a[i];
    if (cur > 1000000000000000000LL || cur < 0LL) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << cur << endl;
}

Measured memory_bytes: 4420
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

template<class T>
inline bool chmin(T &a, const T b) { return a > b && (a = b, true); }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H, W;
	cin >> H >> W;

	vector<vector<int>> A(H, vector<int>(W));
	vector<vector<int>> B(H, vector<int>(W));
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> A[i][j];
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> B[i][j];

	const int offset = 6500;
	auto dp = make_vec(H + 1, W + 1, offset * 2 + 1, char(0));
	dp[0][0][offset] = 1;
	for (int i = 0; i < H; i++) {

		for (int j = 0; j < W; j++) {

			for (int k = 0; k <= 2 * offset; k++) {

				if (0 <= k + A[i][j] - B[i][j] && k + A[i][j] - B[i][j] <= 2 * offset) {
					dp[i][j + 1][k] |= dp[i][j][k + A[i][j] - B[i][j]];
				}
				if (0 <= k - A[i][j] + B[i][j] && k - A[i][j] + B[i][j] <= 2 * offset) {
					dp[i][j + 1][k] |= dp[i][j][k - A[i][j] + B[i][j]];
				}
				
			}

		}
		DMP(dp);

		if (i == H - 1) break;
		for (int j = 1; j <= W; j++) {
			for (int k = 0; k <= 2 * offset; k++) {
				if (0 <= k + A[i + 1][j - 1] - B[i + 1][j - 1] && k + A[i + 1][j - 1] - B[i + 1][j - 1] <= 2 * offset) {
					dp[i+1][j][k] |= dp[i][j][k + A[i + 1][j - 1] - B[i + 1][j - 1]];
				}
				if (0 <= k - A[i + 1][j - 1] + B[i + 1][j - 1] && k - A[i + 1][j - 1] + B[i + 1][j - 1] <= 2 * offset) {
					dp[i+1][j][k] |= dp[i][j][k - A[i + 1][j - 1] + B[i + 1][j - 1]];
				}
			}
		}

		DMP(dp);

	}

	int ans = INF;
	for (int i = 0; i <= 2 * offset; i++) {
		if(dp[H - 1][W][i]) chmin(ans, abs(i - offset));
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 84992
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(f.readLine());
        double a = Double.parseDouble(st.nextToken());
        double b = Double.parseDouble(st.nextToken());
        double h = Double.parseDouble(st.nextToken());
        double m = Double.parseDouble(st.nextToken());
        double minAngle = 2.0*Math.PI*(m/60.0);
        double hAngle = 2.0*Math.PI*((60.0*h+m)/720.0);
        double dist = Math.sqrt(Math.pow(a*Math.sin(hAngle)-b*Math.sin(minAngle), 2.0) + Math.pow(a*Math.cos(hAngle)-b*Math.cos(minAngle), 2));
        out.println(dist);



        out.close();
    }
}


Measured memory_bytes: 33372
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

const int N = 100000 + 5;

int n;
long long ans;
long long a[N], b[N];

void solve()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; ++ i) {
        cin >> a[i] >> b[i];
    }
    long long ans = 0;
    for(int i = n - 1; i >= 0; -- i) {
        a[i] += ans;
        if (a[i] % b[i]) {
            ans += b[i] - a[i] % b[i];
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1792
from bisect import bisect_left

def get_prime_list(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


X = int(input())
primes = get_prime_list(100100)
print(primes[bisect_left(primes, X)])

Measured memory_bytes: 4192
from copy import copy
from time import time
import random
t0 = time()
import math
import sys
input = sys.stdin.readline
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
    ps = [0]*26
    for j in range(26):
        pl = copy(last)
        pl[j] = i+1
        ps[j] += s[i][j]
        for k in range(26):
            ps[j] -= c[k]*(i+1-pl[k])
    idx = ps.index(max(ps))
    last[idx] = i+1
    ans[i] = idx+1
    score += max(ps)
now = time()
lim = 1.85
T = 1000
while now-t0<lim:
    na = copy(ans)
    x = random.randint(1,365)
    y = random.randint(1,365)
    na[x-1] = na[y-1]
    last = [0]*26
    ns = 0
    for i in range(D):
        last[na[i]-1] = i+1
        ns += s[i][na[i]-1]
        for j in range(26):
            ns -= c[j]*(i+1-last[j])
    now = time()
    T = 1000+(-998)*(now-t0)/lim
    p = pow(math.e,-abs(ns-score)/T)
    if ns > score or random.random() < p:
        ans = na
        score = ns
for a in ans:
    print(a)

Measured memory_bytes: 87588