akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
     long long n,k;
    cin>>n>>k;
    long long z;
    z=n%k;
    long long x=abs(z-k);
    if(x<z){
        cout<<x;
    }
    else{
        cout<<z;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int start,end,i,o,sum,temp;
    for(;sum=0,scanf("%d",&start),start;){
        scanf("%d",&end);
        for(i=start;i<=end;i++){
            temp=i;
            for(o=2;o!=7;o++)
                while(!(temp%o))temp/=o;
            if(temp==1)
                sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;
int h, w;
char s[2010][2010];
int xm[2010][2010];
int ym[2010][2010];

int ys(int i, int j){
  int i1=i, i2 = i, c;
  while(s[i1+1][j]!='#')++i1;
  while(s[i2-1][j]!='#')--i2;
  c = i1-i2+1;
  FOR(k, i2, i1+1) ym[k][j]=c;
  return c;
}
int xs(int i, int j){
  int j1=j, j2 = j, c;
  while(s[i][j1+1]!='#')++j1;
  while(s[i][j2-1]!='#')--j2;
  c =j1-j2+1;
  FOR(k, j2, j1+1) xm[i][k]=c;
  return c;
}

int main(){
  cin>>h>>w;
REP(i, h+2){
  REP(j, w+2){
    s[i][j]='#';
    xm[i][j]=0;
    ym[i][j]=0;
  }
}
  REP(i, h){
    REP(j, w){
      cin>>s[i+1][j+1];
    }
  }
  int ans=1, wx, wy;
  for(int i=1; i<=h; ++i){
    for(int j=1; j<=w; ++j){
      if(s[i][j]=='#')continue;
      if(xm[i][j]==0) wx = xs(i, j);
      else wx = xm[i][j];
      if(ym[i][j]==0) wy = ys(i, j);
      else wy = ym[i][j];
      if(ans<wx+wy-1){
        ans=wx+wy-1;
      }
    }
  }

  ECHO(ans);
  return 0;
}


Measured memory_bytes: 35712
#include <stdio.h>

bool isprime(int n)	{
	if (n == 1)	return false;
	for (int i = 2; i*i <= n; i++)	{
		if (n % i == 0)	return false;
	}
	return true;
}

int main(void)	{
	int n, cnt;
	
	while (true)	{
		
		scanf("%d", &n);
		if (n == 0)	break;
		
		cnt = 0;
		
		for (int i = n+1; i <= n*2; i++)	{
			if (isprime(i))	cnt++;
		}
		printf("%d\n", cnt);
	}
	
	return 0;
}


Measured memory_bytes: 2724
#include <vector>
#include <string.h>
#include<iostream>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string.h>
#include<algorithm>
#include <stdlib.h>
#include<math.h>
#include<queue>
using namespace std;

const int mod=1e9+7;
typedef long long ll;

#define out_vector(v) for(auto a:v)cout<<a<<" "; cout<<endl;

int h,w,k;
char r[900][900];
int dp[900][900];

int main()
{
    cin>>h>>w>>k;
    int sa,sb;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>r[i][j];
            if(r[i][j]=='S'){
                sa=i,sb=j;
            }
        }
    }
    queue<pair<pair<int,int>,int> >que;
    que.push(make_pair(make_pair(sa, sb),0));
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    int ans=900;
    set<pair<int,int> >se;
    while(que.size()){
        auto f=que.front();
        que.pop();
        int x=f.first.second,y=f.first.first;
        if(se.find(make_pair(x, y))!=se.end())continue;
        se.insert(make_pair(x, y));
        double mx=min(w-1-x,x);
        double my=min(h-1-y,y);
        if(mx==0||my==0)ans=1;
        else ans=min(ans,1+int(ceil(min(mx,my)/k)));
        if(f.second+1<=k){
            for(int i=0;i<4;i++){
                int nx=x+dx[i],ny=y+dy[i];
                if(nx>=0&&nx<w&&ny>=0&&ny<h&&r[ny][nx]=='.'){
                    que.push(make_pair(make_pair(ny, nx), f.second+1));
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  //ll a;cin>>a;
  //ll a,b;cin>>a>>b;
  ll a,b,c;cin>>a>>b>>c;
  //ll a,b,c,d;cin>>a>>b>>c>>d;
  //string s;cin>>s;
  //cout<<<<endl;
  ans(a+b+c>=22,"bust","win");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
   int n;
   cin>>n;
   if(n<1000)
    cout<<"ABC"<<endl;
   else
    cout<<"ABD"<<endl;

    return 0;
}


Measured memory_bytes: 3604
NM = input("").split()
A = list(map(int, input().strip().split()))

N = int(NM[0])
M = int(NM[1])
ALL = sum(A)
k = 0
c = ALL/(4*M)

for Ai in A:
    if Ai>=c:
        k += 1

if k >= M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n;
    cin>>n;
    int rem;
    rem=n%10;
    if(rem==2 || rem==4 || rem==5 || rem==7 || rem==9){cout<<"hon"<<endl;}
    else if(rem==0 || rem==1 || rem==6 || rem==8){cout<<"pon"<<endl;}
    else if(rem==3){cout<<"bon"<<endl;}
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int w,h,x,y,r;
  cin>>w>>h>>x>>y>>r;
  if((x<0) || (y<0) || (x+r<0 || y+r<0) || (x+r>w || y+r>h)){
    cout<<"No"<<'\n';
  }
  else{
    cout<<"Yes"<<'\n';
  }
  return(0);
}


Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int main(){
	k=read();n=read();m=read();
	if(k+n+m>=22)puts("bust");
	else puts("win");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

//container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

const int mod = 1e9 + 7;

bool arr[52+1];

ll m_pow(int a, int b){
	ll res = 1;
	REP(i,b){
		res *= a;
		res %= mod;
	}
	return res;
}

int main() {
	int n;
	string s1,s2;
	cin >> n >> s1 >> s2;
	int k=0;
	REP(i,n){
		arr[k] = s1[i]!=s2[i];
		if(arr[k])i++;
		k++;
	}
	ll ans=1;
	int cnt=0;
	bool flag = true;
	if(arr[k-1]){
		arr[k]=false;
		k++;
	}
	REP(i,k){
		if(arr[i]){
			cnt++;
		}else{
			if(cnt){
				ll t = m_pow(3, cnt-1);
				t*=2;
				t%=mod;
				if(flag){
					t *= 3;
					t %= mod;
					flag = false;
				}
				ans *= t;
				ans %= mod;
				cnt = 0;
			}else{
				int t = 2;
				if(flag){
					t = 3;
					flag = false;
				}
				ans *= t;
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[220][220];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(int i=0;i<=m+1;i++)
        a[0][i]=a[n+1][i]='#';
    for(int i=1;i<=n;i++)
        a[i][0]=a[i][m+1]='#';
    for(int i=0;i<=n+1;i++)
        puts(a[i]);
    return 0;

}


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

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll A, B, C, D;

ll gcd(ll x, ll y) {
    if (x % y == 0) return y;
    return gcd(y, x % y);
}

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

ll g(ll x, ll y) {
    return x / y;
}

ll f(ll x) {
    return x - g(x, C) - g(x, D) + g(x, lcm(C, D));
}

int main() {
    cin >> A >> B >> C >> D;

    cout << f(B) - f(A-1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
const int N = 1e5 + 5;
//const int INF = 1e9 + 5;
//int a[N];
void solve_test_case(){
	ll n;
	cin>>n;
	cout<<n + (n*n) + (n*n*n)<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	// cin>>t;
	for(int i = 0;i < t;++i){
		solve_test_case();
	}
}


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

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if( 0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

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

  cout << t/a*b << endl;

  return 0;
}

Measured memory_bytes: 256
function main(input){
  input = input.split("\n");
  var r = parseInt(input[0].split(" ")[0]);
  var d = parseInt(input[0].split(" ")[1]);
  var a = parseInt(input[0].split(" ")[2]);

  for (var i = 0; i < 10; i++) {
    a = r * a - d ;
    console.log(a);
  }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628
#include <iostream>
using namespace std;
int main(void){
  int H,W,i,j,n;
  cin >> H;
  cin >> W;
   
  while(H != 0 && W != 0){
      for(i = 0; i < H; i++){
          for(j = 0; j < W; j++){
              if((i + j) % 2 == 0){
                  cout << "#";
              }
              else{
                  cout << ".";
              }
          }
          cout << endl;
      }
      cin >> H;
      cin >> W;
      cout << endl;
  }
}


Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int geti(string s)
{
	for(int i=0;i<(int)s.size()-1;i++)
		if(s[i]!=s[i+1])
			return i+1;
	return -1;
}

lint cnt(string s)
{
	lint ret=0;
	for(int i=0;i<(int)s.size()-1;i++)
	{
		if(s[i]==s[i+1])
		{
			ret++;
			i++;
		}
	}
	return ret;
}

int main()
{
	string S;
	lint K;

	cin >> S >> K;
	int N=S.size();

	lint ans=0;
	int index=geti(S);
	if(index==-1)
		ans=(lint)S.size()*K/2;
	else
	{
		ans+=cnt(S.substr(0,index));
		ans+=(K-1)*cnt(S.substr(index)+S.substr(0,index));
		ans+=cnt(S.substr(index));
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin >>a >> b;
    string A="",B="";
    int a1=stoi(a);
    int b1=stoi(b);
    for(int i=0;i<a1;i++){
        B+=b;
    }
    for(int j=0;j<b1;j++){
        A+=a;
    }
    if(A>=B)cout << B << endl;
    else cout <<A << endl;
    return 0;
}

Measured memory_bytes: 256
//2018年  3月 23日 金曜日 03:09:08 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N; ll x;
int A[MAX_N];
int dp[4010][4010];

int loop(int a, int b) {
	if(dp[a][b] != -1) return dp[a][b];
	if(a == b) return A[a];
	return dp[a][b] = min(min(loop(a + 1, b), A[a]), min(loop(a, b - 1), A[b]));
}

void solve() {
	cin >> N >> x;
	rep(i, 0, N) {
		cin >> A[i];
		A[i + N] = A[i];
	}
	memset(dp, -1, sizeof(dp));
	ll res = linf;
	rep(i, 0, N) {
		ll tmp = 0;
		rep(j, N, 2 * N) {
			tmp += loop(j - i, j);
		}
		MIN(res, tmp + x * i);
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 63872
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

ifstream fin("file.in");
ofstream fout("file.out");

long long int nrnr, sum;

int vec[3005];
long long int ras[3005][3005];

int main()
{
    cin >> nrnr;
    for(int index = 0; index < nrnr; index++){
        cin >> vec[index];
    }
    for(int index = 0; index < nrnr; index++){
        ras[index][index] = vec[index] * (nrnr % 2);
        sum += vec[index];
    }
    for(int index = 1; index < nrnr; index++){
        for(int index2 = 0; index + index2 < nrnr; index2++){
            if((nrnr - index) % 2){
                ras[index2][index + index2] = max(vec[index2] + ras[index2 + 1][index + index2], vec[index + index2] + ras[index2][index + index2 - 1]);
            }
            else{
                ras[index2][index + index2] = min(ras[index2 + 1][index + index2], ras[index2][index + index2 - 1]);
            }
        }
    }
    cout << 2 * ras[0][nrnr - 1] - sum;
    return 0;
}


Measured memory_bytes: 70016
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    priority_queue<int> que;
    ll ans = 0;
    rep(i, N) {
        int A; cin >> A;
        que.push(A);
    }
    while(M--) {
        int tmp = que.top(); que.pop();
        tmp /= 2;
        que.push(tmp);
    }
    while(que.size()) {
        ans += que.top(); que.pop();
    }
    cout << ans << endl;


    return 0;
}


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

int main() {
  
    int N;
    string S;
    int sumP,sumW,sumG,sumY=0;
    
    cin>>N;
    
    for(int i=0;i<N;i++)
    {
     cin>>S;
        if(S=="P")
        {
            sumP++;
        }
         else if(S=="W")
          {
              sumW++;
         }
          else if(S=="G")
           {
               sumG++;
          }
               else if(S=="Y")
                {
                    sumY++;
               }
               
    }
        
    
    if (sumG!=0 && sumW!=0 && sumY!=0 &&sumP!=0)
    {
        cout << "Four"<< endl;
    }
    else
    {
        cout<<"Three"<<endl;
    }
    
       
}
    



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

int main()
{
  int a, b;
  cin >> a >> b;
  string as = "", bs = "";
  rep(i, b) as += to_string(a);
  rep(i, a) bs += to_string(b);
  string ans = as < bs ? as : bs;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*"You can do anything you set your mind to,man" - Eminem*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define llpow(a,b) (ll)(pow(a,b)+0.5)
#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))
#define f first
#define s second
#define INF 9223372036854775807
const  int mod = 1000000007;
void add(ll& a, ll b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
void mul(ll& a, ll b){a*=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}
int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}
void strrev(string& s){int n = (s.size());for(int i = 0 ; i < n/2; i++)swap(s[i],s[n-1-i]);}
int main()
{
	int n; cin>>n;
	vector<int> dp(3);
	for(int k = 0 ; k < n; k++){
		vector<int> new_dp(3,-1);
		vector<int> c(3);
		for(int i = 0 ; i < 3; i++)
			cin>>c[i];

		for(int i = 0 ; i < 3; i++)
			for(int j = 0; j < 3; j++)
				if(i!=j)
					new_dp[i] = max(new_dp[i], c[i]+dp[j]);
		dp = new_dp;
	}
	int ans = -1;
	for(int i = 0 ; i < 3; i++)
		ans = max(ans, dp[i]);
	cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define xmod int(1e9)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pi 3.14159265358
#define inf long long(1e18)
using namespace std;

int n,d,pt,ans; 
int main(){
	scanf("%d%d",&n,&d);
	for (int i=d+1;i<=n;i+=(d+1)*2-1){
		ans++;
		if (i+(d+1)*2-1 > n && i+d < n)
		ans++;
	//	printf("%d\n",i);
	}
	if (ans == 0)
	ans++;
	
	printf("%d\n",ans);
	return 0;
}
//4 11

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            int[] A = new int[N];
            for (int i = 0; i < N; i++){
                A[i] = cin.ReadInt;
            }

            int maxA = A.Max();
            int[] orderedA = new int[N];
            Array.Copy(A, orderedA, N);
            Array.Sort(orderedA);
            Array.Reverse(orderedA);
            var secondMaxA = orderedA[1];

            for (int i = 0; i < N; i++){
                if(A[i] == maxA) {
                    Console.WriteLine(secondMaxA);
                } else {
                    Console.WriteLine(maxA);
                }
            }
            return;
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define in(x, data) data.find(x) != data.end()

typedef long long ll;

bool c[51][51];

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

    int N, M; cin >> N >> M;
    rep(i,M) {
        int a, b; cin >> a >> b;
        c[a][b] = c[b][a] = true;
    }

    set<int> s = set<int>();
    REP(i,1,N+1) s.insert(i);

    int ans = 0;
    while (true) {
        bool changed = false;
        REP(i,1,N+1) {
            if(in(i,s)) {
                int cnt = 0, pos;
                REP(j,1,N+1) {
                    if(c[i][j]) {
                        cnt++; pos = j;
                    }
                }
                if(cnt==1) {
                    s.erase(i);
                    c[i][pos] = c[pos][i] = false;
                    changed = true;
                    ans++;
                }
            }
        }
        if(!changed || s.empty()) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
const main = input => {
    const [A, B] = input.split(' ').map(x => parseInt(x));
    console.log(Math.max(0, A - 2 * B));
};

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"));
// main(require("fs").readFileSync("input.txt", "utf8"));

Measured memory_bytes: 29556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		int mod = 1000000007;
		long total = power(2, n, mod);
		long ra = nCr(n, a, mod);
		long rb = nCr(n, b, mod);
		long ans = total - ra - rb - 1 + mod * 2;
		ans %= mod;
		System.out.println(ans);
	}

	static long power(long x, long n, int m) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2, m);
		val = val * val % m;
		if (n % 2 == 1) {
			val = val * x % m;
		}
		return val;
	}

	static long nCr(long n, long r, int m) {
		long val = 1;
		for (int i = 1; i <= r; i++) {
			val = val * (n - i + 1) % m;
			val = val * modinv(i, m) % m;
		}
		return val;
	}

	static long modinv(long a, int m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


Measured memory_bytes: 23892
#!/usr/bin/python3
# vim: set fileencoding=utf-8:
import sys
input = sys.stdin.readline

"""
H = int(input())
h = [int(ele) for ele in input().split()]
h = [0] + h
"""


def main():
    N, A, B = map(int, input().split())
    ans = 0
    for i in range(1, N+1):
        if isValid(i, A, B):
            ans += i

    print(ans)


def my_sum(n):
    sum_i = 0
    for j in str(n):
        sum_i += int(j)

    return sum_i


def isValid(i, A, B):
    ret = False
    if A <= my_sum(i) <= B:
        ret = True

    return ret


def bfs(queue):
    global yet, graph
    if len(queue) == 0:
        return
    yet.remove(queue[-1])

    for i, adjacency in enumerate(graph[queue[-1]]):
        if adjacency == 1 and (i in yet) and (i not in queue):  # 隣接かつ未探索であれば、stackにpush
            queue.appendleft(i)
    else:
        queue.pop()
        bfs(queue)


def dfs(stack):
    global yet, graph
    yet.remove(stack[-1])

    for i, adjacency in enumerate(graph[stack[-1]]):
        if adjacency == 1 and i in yet:  # 隣接かつ未探索であれば、stackにpush
            stack.append(i)
            dfs(stack)
    else:
        stack.pop()


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
        if i != n // i:
            divisors.append(n//i)
    return divisors


class Node():

    def __init__(self):
        self.idx = None
        self.left = None
        self.right = None
        self.parent = None
        return

    def pre_order(self):
        global pre_order_str
        pre_order_str += str(self.idx) + " "
        if self.left:
            self.left.pre_order()

        if self.right:
            self.right.pre_order()

    def in_order(self):
        global in_order_str

        if self.left:
            self.left.in_order()

        in_order_str += str(self.idx) + " "

        if self.right:
            self.right.in_order()

    def post_order(self):
        global post_order_str
        if self.left:
            self.left.post_order()

        if self.right:
            self.right.post_order()

        post_order_str += str(self.idx) + " "


class HeapHelper():
    """HeapContrler.
    完全二分木を二分ヒープで表現した配列 A に対して、
    HeapHelper.parent(idx) とするとそのノードの親の添字を返す
    存在しない場合は Falseを返す

    Returns:
        [type] -- [description]
    """

    def __init__(self):
        return

    @staticmethod
    def parent(i):
        if i == 1:
            return False

        return int(i/2)

    @staticmethod
    def left(i):
        l_idx = 2*i
        if H < l_idx:
            return False

        return l_idx

    @staticmethod
    def right(i):
        r_idx = 2*i + 1
        if H < r_idx:
            return False

        return r_idx


if __name__ == "__main__":
    main()


Measured memory_bytes: 3192
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    S = rl().rstrip()
    T = rl().rstrip()
    
    if S == T[:-1]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 61684
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int r = a + b;
    r = max(r, a - b);
    r = max(r, a * b);

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int num = 0;

    scanf("%d", &num);

    int top = num /100;
    int mid = (num - top * 100) / 10;
    int low = (num - top * 100 - mid * 10);

    if(top == 7 || mid == 7 || low == 7){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <cmath>

int main(){
    int n, k, y, i, j, a = -1, b = -1, c = -1;
    scanf("%d %d", &n, &y);

    k = y / 1000;

    for(i = 0; i <= std::ceil((k - n) / 9); ++i){
        j = (k - n) - (9 * i);
        if((j % 4 == 0) && (j >= 0) && (n - i - (j / 4) >= 0)){
            a = i;
            b = j / 4;
            c = n - a - b;
            break;
        }
    }

    printf("%d %d %d\n", a, b, c);

    return 0;
}

Measured memory_bytes: 128
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    ans = 0
    for a in range(1, N):
        ans += N // a
        if N % a == 0:
            ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9436
n = int(input())
L = [i for i in range(1,n+1)]
P = list(map(int,input().split()))
for i in range(n):
    if P[i] !=i+1:
        tmp = P[i]
        P[P[i]-1] = tmp
        P[i] = i+1
        break
if P == L:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
import 'dart:io';
main(List<String> args) {
	
  List aa = stdin.readLineSync().split(" ");
  var K = int.parse((stdin.readLineSync()));

//  red green blue
  int red = int.parse(aa[0]);
  int green = int.parse(aa[1]);
  int blue = int.parse(aa[2]);
  for (int i = 0; i < K; i++) {

    if (red >= green) { green = green * 2;}
    else { blue = blue * 2;};

	}
//     print ('${red} , ${green} ,${blue}');
  if ((red < green ) && (green < blue ))
    {print('Yes');}
    else 
    {print('No');}
}

Measured memory_bytes: 13192
$visit = 0
$visited = []
$stack = []
class Vertex
  @@index = 0
  def initialize(adjacent)
    @index = @@index += 1
    @adjacent = adjacent
    @discovery = nil
    @finishing = nil
  end

  def <=>(vertex)
    self.index <=> vertex.index
  end

  def to_s
    "#{index} #{discovery} #{finishing}"
  end

  attr_reader :index
  attr_accessor :adjacent, :finishing, :discovery
end

def dfs(vertex)
  return if vertex.nil?
  if vertex.discovery.nil?
    vertex.discovery = $visit += 1
    $visited << vertex.index
  end
  if vertex.adjacent.empty? || vertex.adjacent.all? { |x| !x.discovery.nil? }
    vertex.finishing = $visit += 1 if vertex.finishing.nil?
    dfs $stack.pop
  else
    $stack << vertex
    dfs vertex.adjacent.delete vertex.adjacent.find { |x| !$visited.include?(x.index) }
  end
end

n = gets.to_i
array = Array.new(n).map { Vertex.new([]) }
n.times do
  adjacent = []
  input = gets.split(' ').map(&:to_i)
  unless input[1].zero?
    input[2..-1].each do |index|
      adjacent << array.find { |vertex| vertex.index == index }
    end
    array[input[0] - 1].adjacent = adjacent
  end
end
# str =<<EOS
# 1 2 2 4
# 2 1 5
# 3 2 5 6
# 4 0
# 5 1 4
# 6 1 6
# EOS
# str.each_line do |a|
#   adjacent = []
#   input = a.split(' ').map(&:to_i)
#   unless input[1].zero?
#     input[2..-1].each do |index|
#       adjacent << array.find { |vertex| vertex.index == index }
#     end
#     array[input[0] - 1].adjacent = adjacent
#   end
# end
array.each do |val|
  dfs val if val.discovery.nil?
end
array.map { |vertex| puts vertex.to_s }


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

int main() {
  int n,q;
  string s;

  cin >> n >> q;
  cin >> s;

  vector<int>a(n);
  a[0] = 0;

  for (int i = 0; i < n-1; i++) {
    if (s[i]=='A'&& s[i+1] =='C') {
      a[i+1] = a[i]+1;
    }
    else {
      a[i+1] = a[i];
    }
  }
  int l,r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    cout << a[r-1] - a[l-1] << endl;
  }
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a; cin >> a;
    cout << 3*a*a << endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll N, K;
vector<ll> pos, neg;
ll z = 0;

ll count_neg(ll a){
	ll res = 0;
	REP(i, pos.size()){
		ll val = pos[i];
		ll tui = (a+(val-1))/val;
		ll tmp = neg.end() - lower_bound(neg.begin(), neg.end(), tui);
		res += tmp;
	}
	return res;
}

ll count_pos(ll a){
	ll res = 0;
	REP(i, pos.size()){
		ll val = pos[i];
		ll tui = a/val;
		ll tmp = upper_bound(pos.begin(), pos.begin()+i, tui) - (pos.begin());
		res += tmp;
	}

	REP(i, neg.size()){
		ll val = neg[i];
		ll tui = a/val;
		ll tmp = upper_bound(neg.begin(), neg.begin()+i, tui) - (neg.begin());
		res += tmp;
	}

	return res;
}

ll f(ll x){
	ll tot = 0;
	if(x<0){
		tot += count_neg(-x);
	}else if(x==0){
		tot += count_neg(1);
		tot += N*(N-1)/2 - (N-z)*(N-z-1)/2;
	}else{
		tot += count_neg(1);
		tot += N*(N-1)/2 - (N-z)*(N-z-1)/2;
		tot += count_pos(x);
	}
	return tot;
}

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

    
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    REP(i, N){
    	if(A[i]>0) pos.push_back(A[i]);
    	if(A[i]==0) z++;
    	if(A[i]<0) neg.push_back(-A[i]);
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    
    
    const ll INF = 1e18 + 1;
    ll ub = INF;
    ll lb = -INF;
    while(ub-lb>1){
    	ll md = (ub+lb)/2;
    	if(f(md)>=K) ub = md;
    	else lb = md; 
    }

    cout << ub << endl;
    
    return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long n;
    vector<long long> count(100003, 0);
    
    cin >> n;
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        count[temp]++;
        count[temp+1]++;
        count[temp+2]++;
    }
    
    long long max_value = 0; 
    for(int i = 0; i < 100003; i++)
        max_value = max(max_value, count[i]);
    
    cout << max_value << endl;
    
    return 0;
}

Measured memory_bytes: 1024
N, Y = map(int, input().split())
for x in range(N+1):
  for y in range(N-x+1):
    z = N - x - y
    if z>=0 and 10000*x+5000*y+1000*z == Y:
      print(x, y, z)
      exit()
print(*[-1]*3)

Measured memory_bytes: 2940
class Dice:
    def __init__(self):
        self.up = 1
        self.under = 6
        self.N = 5
        self.W = 4
        self.E = 3
        self.S = 2

    def roll(self, d):#d => direction
        if d == "N":
            tmp = self.up
            self.up = self.S
            self.S = self.under
            self.under = self.N
            self.N = tmp
        elif d == "W":
            tmp = self.up
            self.up = self.E
            self.E = self.under
            self.under = self.W
            self.W = tmp
        elif d == "E":
            tmp = self.up
            self.up = self.W
            self.W = self.under
            self.under = self.E
            self.E = tmp
        elif d == "S":
            tmp = self.up
            self.up = self.N
            self.N = self.under
            self.under = self.S
            self.S = tmp

    def getUpward(self):
        return self.up

    def setRoll(self,up,under,N,W,E,S):
        self.up = up
        self.under = under
        self.N = N
        self.W = W
        self.E = E
        self.S = S

myd = Dice()
myd.up, myd.S, myd.E, myd.W, myd.N, myd.under = map(int,input().split())
do = input()
for i in do:
        myd.roll(i)
print(myd.getUpward())

Measured memory_bytes: 7776
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
const int MAX_V = 100100;

int N,W;
ll w[110], v[110];

// dp[i+1][j]: 商品iまで，価値の和j以上として選ぶときの，重さの総和のmin
// ただし，価値の総和の最大 10^5 程度
ll dp[110][MAX_V];

int main()
{
  cin >> N >> W;
  REP(i,0,N) cin >> w[i] >> v[i];

  // Init:
  REP(i,0,N+10) REP(j,0,MAX_V) dp[i][j] = INF;
  dp[0][0] = 0;
  // Update:
  REP(i,0,N) {
    REP(j,0,MAX_V) {
      // 商品iを選ばない場合
      dp[i+1][j] = dp[i][j];
      // 選ぶ場合
      if (j >= v[i]) chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
    }
  }

  // 添字連れ
  // dp[N][j] の値がW以下であるようなjの最大値
  // jの大きい方から見て行き，値がW以下になるところ
  int res = -1;
  for(int j = MAX_V; j >= 0; --j) {
    if (dp[N][j] <= W) {
      res = j;
      break;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 86272
#include <stdio.h>

typedef struct a{
	int n;
	int rep;
}node;


node t[10000];

int unite(int x,int y){
	int repx=x,repy=y;
	do{
		repx=t[repx].rep;
		
	}while(repx!=t[repx].rep);
	do{
		repy=t[repy].rep;
	}while(repy!=t[repy].rep);
	t[repx].rep=repy;
}

void search(int x,int y){
	int repx=x,repy=y;
	do{
		repx=t[repx].rep;
	}while(repx!=t[repx].rep);
	do{
		repy=t[repy].rep;
	}while(repy!=t[repy].rep);
	if(repx==repy) printf("1\n");
	else printf("0\n");
}

int main(void){
	int n,q;
	int com,x,y;
	int i,j;
	node *work;
	scanf("%d%d",&n,&q);
	for(i=0;i<n;i++){
		t[i].n=i;
		t[i].rep=i; 
	}

	while(q--){
		scanf("%d%d%d",&com,&x,&y);
		if(com==0){
			unite(x,y);
		}
		else {
			search(x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 1088
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;




int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll x;
	cin >> x;
	for (ll a = -1000; a <= 1000; a++) {
		for (ll b = -1000; b <= 1000; b++) {
			if ((a*a*a*a*a - b*b*b*b*b) == x) {
				cout << a << " " << b;
				return 0;
			}
		}
	}
}

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

char getGlyph( int col, int row )
{
	if( col < 1 || col > 6 || row < 1 || row > 5 ){
		return '\0';
	}
	char glyph = '\0';
	if( col < 6 ){
		glyph = 'a' + ( col - 1 ) * 5 + ( row - 1 );
	}else{
		const char sign[] = { 'z', '.', '?', '!', ' ' };
		glyph = sign[ row - 1 ];
	}
	return glyph;
}

int main()
{
	char input[ 201 ];
	while( cin >> input ){
		bool failed = false;
		int len = strlen( input );
		int reader = 0;

		char output[ 201 ];
		int writer = 0;

		while( reader < len ){
			int col = input[ reader++ ] - '0';
			if( reader >= len ){
				failed = true;
				break;
			}
			int row = input[ reader++ ] - '0';
			char glyph = getGlyph( col, row );
			if( glyph == '\0' ){
				failed = true;
				break;
			}
			 output[ writer++ ] = glyph;
		}
		if( failed == true ){
			cout << "NA" << endl;
		}else{
			output[ writer ] = '\0';
			cout << output << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1136
#!/usr/bin/env python3

n, m = map(int, input().split())
high = list(map(int, input().split()))

graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)


ans = 0
for i in range(n):
    tmp = high[i]
    flg = True
    for nxt in graph[i]:
        if high[nxt] >= tmp:
            flg = False
            break
    if flg:
        ans += 1

print(ans)


Measured memory_bytes: 29436
import java.util.Scanner;
import java.math.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str1 = scan.next();
		
      	int r = Integer.parseInt(str1);
      
      	double round = 2 * r * Math.PI;
      	

        System.out.println(BigDecimal.valueOf(round).toPlainString());
        scan.close();
    }
}

Measured memory_bytes: 36256
#include <complex>
#include <cmath>
#include <cstdio>
using namespace std;

typedef complex<double> xy_t;

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }

int main(){
  double x1, y1, x2, y2, xq, yq;
  while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1,&y1,&x2,&y2,&xq,&yq)){
    xy_t P1(x1,y1), P2(x2,y2), Q(xq,yq);
    xy_t R = Q + xy_t(2, 0) * (projection(Q-P1, P2-P1) - (Q-P1));
    printf("%.6f %.6f\n", real(R), imag(R));
  }
}

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

using namespace std;

int main(void) {
	int N;
	int prev_t = 0;
	int prev_x = 0;
	int prev_y = 0;
	cin >> N;
	for(int i = 0; i < N; ++i) {
		int t, x, y;
		cin >> t >> x >> y;
		if(t - prev_t < abs(x - prev_x) + abs(y - prev_y)) {
			cout << "No\n";
			return 0;
		}
		if((abs(x - prev_x) + abs(y - prev_y) - (t - prev_t)) % 2 != 0) {
			cout << "No\n";
			return 0;
		}
		prev_t = t;
		prev_x = x;
		prev_y = y;
	}
	cout << "Yes\n";
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,k;
	cin>>n>>k;
	cout<<n-k+1;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int a[310][310];
int num[310];
int ans=1e9;
bool used[310];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		a[i][0]=1;
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[i][j]);
		}
		num[a[i][1]]++;
	}
	for(int i=m;i>=1;i--)
	{
		if((n+i-1)/i>ans)break;
		int res=0;
		for(int j=1;j<=m;j++)
		{
			res=max(res,num[j]);
		}
		ans=min(ans,res);
		int mx=0,id=0;
		for(int j=1;j<=m;j++)
		{
			if(num[j]>mx)
			{
				mx=num[j];
				id=j;
			}
		}
		used[id]=true;
		for(int j=1;j<=n;j++)
		{
			if(a[j][a[j][0]]==id)
			{
				num[id]--;
				while(a[j][0]<=m && used[a[j][a[j][0]]])a[j][0]++;
				num[a[j][a[j][0]]]++;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
int n;
  cin>>n;
  vector<int> vec;
  rep(i, n){
    int p;
  cin>>p;
  vec.push_back(p);}
  int ord[n+1];
  
    int num=1;
  while(vec.size()>=1){
    
  rep(i, vec.size()){
  
    if(vec[i]==i+1){
      ord[num]=vec[i];
      int ed=i;
      for(int j=i;j<vec.size();j++){
        if(vec[j]==j+1){
          ord[num]=vec[j];
          ed=j;}
      }
      num++;
      vec.erase(vec.begin() + ed);
      break;}
    
    if(i==vec.size()-1){
      cout<<-1<<endl;
      return 0;}
  }
  }
  
  for(int i=n;i>=1;i--){
    cout<<ord[i]<<endl;}
 return 0;
  
  
}


Measured memory_bytes: 256
def resolve():
    S = str(input())
    K = int(input())

    if S[0] != '1':
        print(S[0])
        return
    else:
        for i in range(1, K):
            if S[i] != '1':
                print(S[i])
                return
            else:
                continue
        print('1')

    return

resolve()

Measured memory_bytes: 9180