akhauriyash/Code-Regression huggingface dataset:
import sys
import math
import bisect
import heapq
import copy
sys.setrecursionlimit(1000000)
from collections import deque
from itertools import permutations

def main():

    dy = [-2,-1,0,1,2,-1,0,1,0]
    rx = [1,1,1,1,1,2,2,2,3]
    lx = [-1,-1,-1,-1,-1,-2,-2,-2,-3]
    inf = 1000000007

    while True:
        m,n = map(int,input().split())
        if n == 0:break
        grid = []
        for _ in range(n):
            grid.append(list(input().split()))


        dp = [[[inf]*2 for _ in range(m)] for _ in range(n)]
        pq = []
        for i in range(n):
            for j in range(m):
                if grid[i][j]=='S':
                    pq.append([0,i,j,0])
                    dp[i][j][0] = 0
                    pq.append([0,i,j,1])
                    dp[i][j][1] = 0
        heapq.heapify(pq)

        res = inf

        while pq:
            cost,i,j,b = heapq.heappop(pq)
            if dp[i][j][b]<cost:continue

            if grid[i][j] == 'T':
                res = cost
                break

            for k in range(9):
                h = i+dy[k]
                if b:w = j+lx[k]
                else:w = j+rx[k]
                bb = (b+1)%2
                if not (0<=h and h<n and 0<=w and w<m):continue
                if grid[h][w]=='X':continue
                if '1'<=grid[i][j]  and grid[i][j]<='9':
                    ncost = cost+int(grid[i][j])
                else :
                    ncost = copy.copy(cost)
                if ncost<dp[h][w][bb]:
                    dp[h][w][bb] = ncost
                    heapq.heappush(pq,[ncost,h,w,bb])

        print (res if res!=inf else -1)

if __name__ == '__main__':
    main()




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

// 1 <= N <= 10^5
int N;
// ノードN番の色  white 0, black 1
int Color[100000+10]={0};
// 
bool Done[100000+10]={false};

// ノードN番からつながる複数のリンクの番号
// int Link[100000+10][100000+10];
vector<int> Link[100000+10]={};
// ノードN番からつながる複数のリンクの距離
//long long DisOfLink[100000+10][100000+10];
vector<long long> DisOfLink[100000+10]={};

int debug=0;

void dfs(int node, long long dis){
    if(debug){
        cout << "dfs(" << node << "," << dis << ")" << endl;
    }

    if(Done[node]) 
        return;
    else
        Done[node]=true;

    // Mark black
    if( dis % 2 != 0){
        // if dis is odd number , then mark as black
        Color[node]=1;
    }
    // Exist link?
    if(Link[node].size() ==0 )
        return;
    // 
    int i=0;
    for(int x:Link[node]){
        long long w;
        w = DisOfLink[node][i];
        dfs(x, dis+w);
        i++;
    }
}

int main(){
    cin >> N;
    for(int i=0; i< N-1;++i){
        int u,v,j;
        long long w;
        cin >> u >> v >> w;
        Link[u].push_back(v);
        DisOfLink[u].push_back(w);
        Link[v].push_back(u);
        DisOfLink[v].push_back(w);
    } 

    if(debug){
        for(int i=1;i<N;++i){
            cout << i << "...";
            for(int x: Link[i])
                cout << x << ",";
            cout << " w=";
            for(int x: DisOfLink[i])
                cout << x << ",";
            cout << endl;
            
        }

    }

    dfs(1,0);

    for(int i=1;i<N+1;++i){
        if(debug) cout << i << "...";
        cout << Color[i] << endl;
    }
}






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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

string way;

bool can(int s, int g){
  bool ok = true;
  for(int i = s; i < g; i++){
    if(way[i] == '#' && way[i+1] == '#') ok = false;
  }
  return ok;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--; b--; c--; d--;
  cin >> way;
  if(c > d){
    bool ok = false;
    for(int i = b-1; i < d; i++){
      if(way[i] == '.' && way[i+1] == '.' && way[i+2] == '.') ok = true;
    }
    if(!ok){
      cout << "No" << endl;
      return 0;
    }
  }
  YesorNo(can(a,c) && can(b,d));
}

Measured memory_bytes: 592
# 1は除外
# ・N-1の約数は全て対象
# ・Nの約数で、sqrt(N)以下であればOK　ただしN自身は対象
# これを足し合わせる

N = int(input())

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
  
# N-1の約数の個数
ans = len(make_divisors(N-1)) - 1

def check(n,x):
  # xで割った余りがxの倍数でなくなるまでxで割る
  # xの倍数でなくなったときにxで割って1余ればOK
  while n % x == 0:
    n //= x
  return (n % x == 1)

# Nの約数で2以上sqrt(N)以下の数
for i in range(2,int(N ** 0.5) + 1):
  if N % i == 0:
    if check(N,i):
      ans += 1

# N自身も対象
ans += 1

print(ans)


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

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> pq;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    pq.push(A);
  }
  for (int i = 0; i < M; i++) {
    int A = pq.top();
    pq.pop();
    pq.push(A/2);
  }
  long long ans = 0;
  while (!pq.empty()) {
    int A = pq.top();
    ans += A;
    pq.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    ll int n;
    cin>>n;
    lld a[n];
    lld ans=0;
    ll int i,j;
    for(i=0;i<n;i++)
    {
    	cin>>a[i];
    }
    lld dp[n+1][n];lld z=1;
    for(i=0;i<=n;i++)
    {
    	for(j=0;j<n;j++)
    	{
    		if(i==0)
    		{
    			dp[i][j]=(lld)0;
    		}
    		else if(j==0 && i==1)
    		{
    			dp[i][j]=a[0];//cout<<dp[i][j]<<endl;
    			z=z*(1-a[j]);
    		}
    		else if(i>j+1)
    		{
    			dp[i][j]=(lld)0;
    		}
    		else if(i==1)
    		{//cout<<z<<endl;
    			dp[i][j]=a[j]*(z)+(1-a[j])*dp[i][j-1];
    			//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    			z=z*(1-a[j]);
    		}
    		else if(i>1)
    		{
    			dp[i][j]=dp[i][j-1]*(lld)((lld)1-a[j])+a[j]*dp[i-1][j-1];
    			//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    		}
    	}
    }
    ll int w=n/2+1;
    for(i=w;i<=n;i++)
    {
    	ans+=dp[i][n-1];
    }
    cout<<fixed<<setprecision(20)<<ans<<endl;
//cout<<dp[1][2]<<endl;
}

Measured memory_bytes: 144360
#include<stdio.h>
#define N 10000
#define M 25

int main(void){
  int i,num,j,k;
  int map[M][M];
  int curx,cury;
  int n,m;
  int x,y,l;
  char d[3];
  int count;
  int ans[N];

  for(i=0;;i++){
    scanf("%d",&n);
    if(n==0) break;
    count=0;
    for(j=0;j<=20;j++) for(k=0;k<=20;k++) map[j][k]=0;
    for(j=0;j<n;j++){
      scanf("%d%d",&x,&y);
      map[y][x]=1;
    }
    scanf("%d",&m);
    curx=10;
    cury=10;
    for(j=0;j<m;j++){
      scanf("%s%d",d,&l);
      if(d[0]=='N'){
        for(k=0;k<l;k++){
          cury++;
          if(map[cury][curx]==1){
            map[cury][curx]=0;
            count++;
          }
        }
      }
      if(d[0]=='E'){
        for(k=0;k<l;k++){
          curx++;
          if(map[cury][curx]==1){
            map[cury][curx]=0;
            count++;
          }
        }
      }
      if(d[0]=='S'){
        for(k=0;k<l;k++){
          cury--;
          if(map[cury][curx]==1){
            map[cury][curx]=0;
            count++;
          }
        }
      }
      if(d[0]=='W'){
        for(k=0;k<l;k++){
          curx--;
          if(map[cury][curx]==1){
            map[cury][curx]=0;
            count++;
          }
        }
      }
    }
    if(count==n) ans[i]=1;
    else ans[i]=0;
  }
  num=i;
  for(i=0;i<num;i++){
    if(ans[i]==1) printf("Yes\n");
    else if(ans[i]==0) printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VB=vector<bool>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}

#include <atcoder/convolution>

using namespace atcoder;
void Main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	vector<long long> a(n), b(m);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &(a[i]));
	}
	for (int i = 0; i < m; i++) {
		scanf("%lld", &(b[i]));
	}

	vector<long long> c = convolution(a, b);

	for (int i = 0; i < n + m - 1; i++) {
		printf("%lld ", c[i]);
	}
	printf("\n");

	return;
}

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


Measured memory_bytes: 27300
n = int(input())
a = [int(s) for s in input().split()]
avg = sum(a) / len(a)

min_abs = 100
index = 0
for i in range(len(a)):
    if abs(avg - a[i]) < min_abs:
        min_abs = abs(avg - a[i])
        index = i
print(index)

Measured memory_bytes: 9108
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cassert>
#include <functional>
#include <set>
#include <cmath>

using namespace std;
#define get(x) if (DEBUG) cout << #x << " : " << x << endl;
#define print(x) if (DEBUG) cout << x << endl;
#define int long long
#define double long double

void fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}

const int MAX = (int)1e6;
const double INF = 1e9;

signed main() {
    fast();
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout.precision(30);
    int n;
    cin >> n;
    int dp[n];
    int h[n];
    for (int i = 0; i < n; ++i) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1];

    return 0;
}

Measured memory_bytes: 1792
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int n;
int a[100][100];
int r[100], c[100];

int main(){
  while (cin >> n, n){
    rep(i, n) rep(j, n) cin >> a[i][j];
    rep(i, n) r[i] = inf;
    rep(i, n) c[i] = 0;
    rep(i, n) rep(j, n) chmin(r[i], a[i][j]);
    rep(i, n) rep(j, n) chmax(c[j], a[i][j]);
    bool f = true;
    rep(i, n) rep(j, n){
      if (f && r[i] == a[i][j] && c[j] == a[i][j]){
        cout << a[i][j] << endl;
        f = false;
      }
    }
    if (f) cout << 0 << endl;
  }
}

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

int main () {
  int n; cin >> n;
  int ans = 0;
  
  for (int mask = 0; mask < (1 << 18); mask++) {
    int num = 0;
    
    for (int i = 0; i < 18; i += 2) {
      int digit = i / 2;
      if (mask & (1 << i) && mask & (1 << i + 1)) num += 7 * pow(10, digit);
      else if (mask & (1 << i + 1)) num += 5 * pow(10, digit);
      else if (mask & (1 << i)) num += 3 * pow(10, digit);
    }
    
    if (num > n) {
      break;
    } else {
      vector<bool> fit(10, false);
      while(num) {
        fit[num % 10] = true;
        num /= 10;
      }
      if (!fit[0] && fit[3] && fit[5] && fit[7]) ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#define MAX 10000
#define NIL -1

void setDepth(int,int);
int setHeight(int);
int getSibling(int u);
void print(int u);

typedef struct{
  int parent;
  int left;
  int right;
} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

int main(){
  
  int i, v, l, r, root=0;
  scanf("%d",&n);

  for(i=0;i<n;i++) T[i].parent=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent=v;
    if(r != NIL) T[r].parent=v;
    
  }

  for(i=0;i<n;i++){
    if(T[i].parent==NIL) root=i;
  }
  
    setDepth(root,0);
    setHeight(root);

    for(i=0;i<n;i++) print(i);

    return 0;
    
  }


void setDepth(int u, int d){
  
  if(u==NIL) return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
  
}


int setHeight(int u){

  int h1=0, h2=0;
  if(T[u].left != NIL){
    h1 = setHeight(T[u].left)+1;
  }
  if(T[u].right != NIL){
    h2 = setHeight(T[u].right)+1;
  }
    return H[u] = (h1>h2 ? h1:h2);

}


int getSibling(int u){
  
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL) return T[T[u].parent].right;
  return NIL;

}


void print(int u){
  
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));

  int deg=0;

  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }

}

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

int a, b, c;

void prians(bool answer) {
  if(answer)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

int main() {
  bool ans = 0;
  cin >> a >> b >> c;
  if(b - a == c - b) ans = 1;
  prians(ans);
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char s[200050];
int main(){
	int n,i,res=0;
	long long ans=0;
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=1;i<=n;++i)if(s[i]=='A')++res;
	else if(s[i]=='B'&&i<n&&s[i+1]=='C'){
		ans+=res;
		++i;
	}else res=0;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
//
//Created by BLUEBUFF 2016/1/9
//Copyright (c) 2016 BLUEBUFF.All Rights Reserved
//

#pragma comment(linker,"/STACK:102400000,102400000")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <time.h>
#include <cstdlib>
#include <cstring>
#include <sstream> //isstringstream
#include <iostream>
#include <algorithm>
using namespace std;
//using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, LL> pp;
#define REP1(i, a, b) for(int i = a; i < b; i++)
#define REP2(i, a, b) for(int i = a; i <= b; i++)
#define REP3(i, a, b) for(int i = a; i >= b; i--)
#define CLR(a, b)     memset(a, b, sizeof(a))
#define MP(x, y)      make_pair(x,y)
template <class T1, class T2>inline void getmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void getmin(T1 &a, T2 b) { if (b<a)a = b; }
const int maxn = 200010;
const int maxm = 100010;
const int maxs = 10;
const int maxp = 1e3 + 10;
const int INF  = 1e9;
const int UNF  = -1e9;
const int mod  = 1e9 + 7;
//int gcd(int x, int y) {return y == 0 ? x : gcd(y, x % y);}
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>order_set;
//head

map <LL, LL> mp;
LL f(LL n)
{
    return mp[n] ? mp[n] : ((mp[n] = (f(n / 2) + f((n - 1)/ 2)) % mod + f((n - 2) / 2) % mod) % mod);
}
int main()
{
    LL n;
    mp[0] = 1;
    mp[1] = 2;
    scanf("%lld", &n);
    printf("%lld\n", f(n));
}


Measured memory_bytes: 256
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll cn=0;
    while((a>0)&&(c>0)){
        if(cn%2==0) c-=b;
        else a-=d;
        cn++;
    }
    if(cn%2!=0) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3636
while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break
    for h in range(H):
        for w in range(W):
            if h == 0 or h == H - 1 or w == 0 or w == W - 1:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()

Measured memory_bytes: 9076
#include<iostream>
#include<string>

using namespace std;

int main()
{
	char array[30]={'X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'};
	string str;
	
	for(;cin >> str;)
	{
	}
	for(int i=0;i<str.size();i++)
	{
		cout << array[str[i]-'A'] ;
	}
	cout << endl;
}

Measured memory_bytes: 0
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val S = rd.readInt()

    val dp = LongArray(2005){0}
    for (i in 0 .. 2) {
        dp[i] = 0
    }
    for (i in 3 .. 5) {
        dp[i] = 1
    }

    var sum = 0L
    for (i in 6 .. S) {
        sum += dp[i-3]
        sum %= MOD

        dp[i] = sum
        dp[i] %= MOD

        dp[i] += 1L
        dp[i] %= MOD
    }

    val ans = dp[S]
    println(ans)
}


//val rd = debug.Reader("abc", "178", "d", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readDouble: () -> Double = { br.readLine().toDouble() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readIntArray: () -> IntArray = { readListInt().toIntArray() }
    val readLongArray: () -> LongArray = { readListLong().toLongArray() }
    val readListStringCol: (Int) -> List<String> = { N -> (0 until N).map { readString() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { readListInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { readListLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 34712
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll n,m; cin >> n >> m;
		if(!n && !m) break;
		vb v(n,false);
		v[0] = true;
		vector<pair<ll,P>> query(m);
		rep(i,m) cin >> query[i].first >> query[i].second.first >> query[i].second.second;
		sort(all(query));
		rep(i,m){
			P p = query[i].second;
			if(v[p.first-1]) v[p.second-1] = true;
		}
		ll ans = 0;
		rep(i,n) if(v[i]) ans++;
		cout << ans << "\n";
	}
}


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


using namespace std;
long long n;
long long k;
vector<long long> vec;

long long meme[100007];

long long solve(long long index){

    if(index==n-1){
        return 0;
    }
    
    if(meme[index]!=-1){
        return meme[index];
    }
    
    long long ret = 10000000000000000;
    long long sol = 10000000000000000;
    for(long long i = 1 ;i<=k ; i++){
        if(index+i<n){
            ret = abs (vec[index]- vec[index+i]) + solve(index+i); 
        }
        sol = min(sol,ret);
    }

    return meme[index] = sol;
}

int main(){
    cin>>n;
    cin>>k;
    memset(meme,-1,sizeof(meme));
    long long num;
    for(long long i = 0 ; i<n ; i++){
        cin>>num;
        vec.push_back(num);
    }
    cout<<solve(0)<<endl;
    return 0;
}

Measured memory_bytes: 11064
package main

import "fmt"

type station struct {
	c, s, f int
}

func main() {
	var n int
	fmt.Scan(&n)

	n--

	stations := make([]station, n)
	for i := range stations {
		fmt.Scan(&stations[i].c, &stations[i].s, &stations[i].f)
	}

	for i := 0; i <= n; i++ {
		if i == n {
			fmt.Println(0)
			break
		}

		time := 0
		for j := i; j < n; j++ {
			s := stations[j]
			switch {
			case time < s.s:
				time = s.s
			case time%s.f != 0:
				time += s.f - (time % s.f)
			}
			time += s.c
		}
		fmt.Println(time)
	}
}


Measured memory_bytes: 512
#include <stdio.h>

int debtHell(int money){
	double interest = money;
	interest = interest * 1.05 / 1000;
	money = interest;
	if((interest - money) * 1000 > 0){
		money = money * 1000 + 1000;
	}else{
		money = money * 1000;
	}
	return money;
}

int main(){
	int n, i, money = 100000; scanf("%d", &n);
	for(i = 0; i < n; i++){
		money = debtHell(money);
	}
	printf("%d\n", money);
	return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)
vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

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

using namespace std;


 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

//5
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){

ios::sync_with_stdio(false);
cin.tie(0);
int n,k;

cin>>n>>k;//n人k菓子

int d[n]={};//人


for(int i=0;i<k;i++){
int dd=0;
cin>>dd;
for(int j=0;j<dd;j++){
int aa=0;
cin>>aa;
d[aa-1]++;
}

}
int res=0;
for(int i=0;i<n;i++){
if(d[i]==0)res++;
}

cout<<res<<endl;



}



//cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
 
int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a) cout<<k<<endl;
  else if (a<k && k<=a+b) cout<<a<<endl;
  else cout << a-(k-a-b)<<endl;
  return 0;
}

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

using namespace std;

template <typename T>
using vec1 = vector<T>;

constexpr auto cin2line([] {
    string s;
    getline(cin, s);
    return s;
});

vec1<string> Split(const string& str, char sep)
{
    vec1<string> v;
    stringstream ss(str + sep);
    string       line;
    while (getline(ss, line, sep)) {
        v.push_back(line);
    }
    return v;
}

int main()
{
    while (true) {
        const string S(cin2line());
        if (S == "END OF INPUT") break;
        const auto strs(Split(S, ' '));
        for (const auto& str : strs) {
            cout << str.size();
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

using ll = long long;
template <ll MOD = 1000000007>
struct Mint{
    ll x;

    Mint() : x(0) {}
    Mint(ll t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(ll n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator *= (Mint a){
        x = 1LL * x * a.x % MOD;
        return *this;
    }
    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        ll t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

#define MAX_N 100000

signed main(){
    int n;
    cin >> n;
    int a[n];
    REP(i,n){
        cin >> a[i];
    }
    Mint<1000000007LL> ans = 1;
    ll cnt[MAX_N + 1] = {};
    if(a[0] == 0){
        cnt[0] = 3;
    }else{
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        ans *= cnt[a[i]];
        cnt[a[i]]--;
        cnt[a[i] + 1]++;
    }
    cout << ans << endl;
    return 0;
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int n, k;
	sf("%d %d", &n, &k);
	int a[n];
	for (int i = 0; i < n; ++i) {
		sf("%d", &a[i]);
	}

	sort(a, a + n);
	int ans = 0;
	for (int i = 0; i < k; ++i) {
		ans += a[i];
	}
	printf("%d\n", ans);

	return 0;
}


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

int main()
{
	int N;
	while(cin>>N && N){
	
		vector<int> n(N), dp(N);
		for(int i=0;i<N;i++){
			cin>>n[i];
		}
		int ans = -1<<29;
		for(int i=0;i<N;i++){
			if(i-1 >= 0 && dp[i-1]>0){
				dp[i] += dp[i-1] + n[i];
			}else{
				dp[i] = n[i];
			}
			ans = max(ans, dp[i]);
		}
		
		cout<<ans<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 1216
from collections import deque

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

for i in range(n):
  a, b=ab[i]
  ab[i].append(a+b)
ab.sort(key=lambda x:x[2], reverse=True)
ab=deque(ab)
count = 0
ans=0
while len(ab)>0:
  a, b, dif = ab.popleft()
  if count%2==0:
    ans+=a
  else:
    ans-=b
  count+=1
print(ans)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),Q=in();
	queue<pair<string,int>> Queue;
	
	REP(i,N){
		string s = in<string>();
		int v = in();
		Queue.emplace(s,v);
	}

	int time = 0;
	while(!Queue.empty()){
		auto P = Queue.front();
		Queue.pop();
		if(P.second-Q<=0){
			out(P.first,time+P.second);
			time += P.second;
		}
		else{
			P.second -= Q;
			Queue.push(P);
			time += Q;
		}
	}

	return 0;
}



Measured memory_bytes: 6288
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int x, y; cin >> x >> y;
	bool f=0;
	REP(i,x+1){
		if(2*i+4*(x-i)==y)
			f=1;
	}
	if(f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
char a[5][5];
int i,j;
int main()
{
	for(i=1;i<=2;i++)
	{
    for(j=1;j<=3;j++)
	{			
		scanf(" %c",&a[i][j]);
	}
	}
	if((a[1][1]==a[2][3])&&(a[1][2]==a[2][2])&&(a[1][3]==a[2][1]))
		printf("YES");
	else
		printf("NO");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long fact[21000000];
long long finv[21000000];
long long inv[21000000];
int main(){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<21000000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<21000000;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	long long ret=c;
	ret=(ret+(a+b)*inv[a+b]%mod*d2%mod*c%mod*(c+1))%mod;
//	printf("%lld\n",ret);
	long long tmp=0;
	for(int i=0;i<=c-2;i++){
		tmp=(tmp+fact[i+2]*finv[i])%mod;
	}
	ret=(ret+tmp*fact[a+b-2]%mod*finv[a+b]%mod*(a)%mod*(b))%mod;
//	printf("%lld\n",ret);
	ret=ret*fact[a+b]%mod*finv[a+b-c]%mod;
	printf("%lld\n",ret);
}


Measured memory_bytes: 492416
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int w,a,b;w=sc.nextInt();a=sc.nextInt();b=sc.nextInt();
  System.out.println((Math.abs(a-b)<=w)?0:Math.abs(a-b)-w);
}
}

Measured memory_bytes: 23124
#include<iostream>
#include<vector>
using namespace std;
int main() {
	long long int N, K;
	cin >> N >> K;
	int count = 0;
	long long int memo1 = (N%K);
	long long int memo2 = 0;
	long long int memo3 = 0;
	while (count == 0) {
		memo3 = memo1;
		memo1 = abs(memo1 - K);
		memo2 = abs(memo1 - K);
		if (memo2 == memo3) {
			count++;
		}
	}
	if (memo1 > memo2) {
		cout << memo2 << endl;
	}
	else {
		cout << memo1 << endl;
	}
	return 0;
}

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

int main() {
  string S;
  cin >> S;

  int words_size = 4;
  vector<string> words = {"dreamer", "dream", "eraser", "erase"};

  // 左右反転
  reverse(S.begin(), S.end());
  for (int i = 0; i < words_size; i++) {
    reverse(words[i].begin(), words[i].end());
  }

  bool match = false;
  for (int i = 0; i < S.size();) {
    match = false;
    for (int j = 0; j < words_size; j++) {
      string word = words[j];
      if (S.substr(i, word.size()) == word) {
        match = true;
        i += word.size();
      }
    }

    if (match == false || i == S.size()) {
      break;
    }
  }

  cout << (match ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int D = in.nextInt();
		int D2 = in.nextInt();
		int A = in.nextInt();
		int[]B = new int [N+1];
		for(int i = 0;i < N;i++){
			B[i] = in.nextInt();
		}
		int max = A / D;
		int cng;
		for(int i = 0;i < N;i++){
			D += D2;
			B[N] = 0;
			for(int j = 0;j < N;j++){
				if(B[N] < B[j]){
					if(B[N] == B[j]){
						B[j] = 0;
					}
					cng = B[j];
					B[j] = B[N];
					B[N] = cng;
				}
			}
			A += B[N];
			if(max < A / D){
				max = A / D;
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 18120
if __name__ == '__main__':
    N = int(input())

    if N == 0:
        print(0)
        exit()

    ans = []
    cnt = 0
    while abs(N) >= 1:
        mod_val = N % ((-2) ** (cnt + 1))
        if mod_val == 0:
            ans.append(0)
        else:
            ans.append(1)
            N -= (-2) ** cnt
        cnt += 1

    print(''.join([str(val) for val in ans[::-1]]))


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdbool.h>

int A[110];
int cnt = 0;

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

void bubbleSort(int *A, int N) {
    bool flag = true;
    while (flag) {
        flag = false;
        for (int j = N - 1; j >= 1; --j) {
            if (A[j] < A[j - 1]) {
                int tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
                flag = 1;
                cnt++;
            }
        }
    }
}

int main(void){
    int n;
    scanf("%i", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%i", &A[i]);
    }
    bubbleSort(A, n);
    for (int i = 0; i < n; ++i) {
        if (i != n - 1) printf("%i ", A[i]);
        else printf("%i\n", A[i]);
    }
    printf("%i\n", cnt);
}


Measured memory_bytes: 2108
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  string A, B, C;
  cin >> A >> B >> C;
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    vector<char> a = {A[i], B[i], C[i]};
    sort(a.begin(), a.end());
    if (a[0] == a[2]) continue;
    if (a[0] == a[1] || a[1] == a[2]) {
      ret += 1;
    } else {
      ret += 2;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
/* ex 9_1
series2 */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
//条件　文字列を格納するスタックを定義、push,pop
typedef struct stack {
    int size;
    int count;        //現在格納されている文字数
    char data[SIZE];  //データ内容そのもの
    char *top;  //外部からのアクセス部はdata配列の一番後ろの番地のアドレスをさす
} stack;

void init_stack(stack *stk) {
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}
void push(stack *stk, char data) {
    if (stk->count <
        stk->size) {  //用意したstackの要領未満の時、入力文字をトップアドレスに追加する
        stk->top--;
        *(stk->top) = data;
        stk->count++;
    }
}
char pop(stack *stk) {
    char latest;
    if (stk->count > 0) {  //文字が残っている時
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    } else {
        latest = '\0';  //文字が残っていない時null文字を返す
    }
    return latest;
}

// stackなので、再帰的に呼び出すことで正しい順にする。(直接呼び出すのは、stackとしての設計に反する)
void printout(stack *stk) {
    char out = pop(stk);
    if (out) {  // outがnull文字でない時
        printout(stk);
        printf("%c", out);
    }
}

int main(void) {
    stack stk;
    init_stack(&stk);
    char inp = ' ';
    while (inp != '\n') {
        scanf("%c", &inp);
        if (inp == 'B') {
            pop(&stk);
        } else if (inp != '\n') {
            push(&stk, inp);
        }
    }
    printout(&stk);
    printf("\n");

    return 0;
}

Measured memory_bytes: 1596
main(n,a,b,c){for(;scanf("%d",&n),n;)for(;n--;printf("%c\n",!(a-100&&b-100&&c-100)||a+b>179||a+b+c>239?65:a+b+c>209||(a+b+c>149&&(a>79||b>79))?66:67))scanf("%d%d%d",&a,&b,&c);}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string> 
#include<map>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<utility>
#include<cstdio>
#include<cstring>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qui queue<int>
#define vit vector<int>
#define ll long long
#define pb push_back
using namespace std;
int main()
{int a,b;cin>>a>>b;
if(a>b)cout<<a-1;
else cout<<a;
system("pause");
return 0;
}

Measured memory_bytes: 504
import math

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

threshold = math.ceil(sum(sequence) / (4*m))

sequence.sort(reverse = True)
index = 0

while m > 0:
	if sequence[index] >= threshold:
		m -= 1
		index += 1
	else:
		break

if m == 0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    scanf("%d %d", &a,&b);
    int digit=0;
    int x=b;
    while(b!=0){
        digit+=1;
        b/=10;
    }
    for(int i=0;i<digit;i++){
        a*=10;
    }
    a+=x;
    for(int i=0;i*i<=a;i++){
        if(i*i==a){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;
const int MOD = 1000000007;

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

    string S;
    cin >> S;
    ll n = S.size();

    vector<vector<ll>> dp(n+1, vector<ll>(4, 0));
    dp[0][0] = 1;
    Rep (i, n) {
        Rep (j, 4) {
            if (S[i] != '?') dp[i+1][j] += dp[i][j];
            else dp[i+1][j] += 3 * dp[i][j];
            dp[i+1][j] %= MOD;
        }
        Rep (j, 3) {
            if (S[i] == 'A'+j || S[i] == '?') {
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= MOD;
            }
        }
    }

    cout << dp[n][3] << endl;

}

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


int main() {
 int n,A,B;
  string s;
  cin >>n>>A>>B>>s;
  int wa =0;
  int kai =0;
  for(int i=0;i<n;i++){
   if(s[i] =='a' && wa <A+B){
    wa++;
     cout <<"Yes"<<endl;
   }
    else if(s[i] =='b' && wa <A+B && kai <B){
     wa++;
      kai++;
      cout << "Yes" <<endl;
    }
    else cout <<"No" <<endl;
  }
}
  


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, T;
    cin >> N >> T;
    int ans = 1001;
    for (int i = 0; i < N; i++)
    {
        int c, t;
        cin >> c >> t;
        if (t <= T)
        {
            ans = min(ans, c);
        }
    }
    if (ans <= 1000)
    {
        cout << ans << endl;
    }
    else
    {
        cout << "TLE" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>   //setprecision(10) 

using namespace std;

int main() {
    int A, B, C;

    cin >> A >> B >> C;
    
    if (A == B && A != C) {
        cout << "Yes" << endl;
    }
    else if (A==C && A != B) {
        cout << "Yes" << endl;
    }
    else if (B == C && A != B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int64_t kRem = 1000000007;

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

	int64_t n, k; cin >> n >> k;
	int64_t ans = 0;
	for (int64_t i = k; i <= n + 1; i++) {
		int64_t minv = i * (i - 1) / 2;
		int64_t maxv = (n * (n + 1)) / 2 - ((n - i) * (n - i + 1) / 2);

		ans += (maxv - minv) + 1;
		ans %= kRem;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 3652