akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

static const int MAX = 100;
static const int NIL = -1;

struct Node
{
  int left;
  int right;

  Node():
    left(NIL),
    right(NIL)
  {}
};

Node tree[MAX];
int preorder[MAX];
int inorder[MAX];
int postorder[MAX];

int reconstruct(int n, int pre_begin, int in_begin)
{
  if (n <= 0)
    return -1;

  int root = preorder[pre_begin];

  int in_root_id = 0;
  for (int i = in_begin; i < in_begin + n; ++i)
  {
    if (inorder[i] == root)
    {
      in_root_id = i;
      break;
    }
  }

  tree[root].left = reconstruct(in_root_id - in_begin,
                                pre_begin + 1,
                                in_begin);
  tree[root].right = reconstruct(in_begin - in_root_id + n - 1,
                                 pre_begin - in_begin + in_root_id + 1,
                                 in_root_id + 1);

  return root;
}

void genaratePostorder(int id)
{
  static int i = 0;

  if (id == NIL)
    return;

  genaratePostorder(tree[id].left);
  genaratePostorder(tree[id].right);
  postorder[i] = id;
  ++i;
}

int main()
{
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; ++i)
    scanf("%d", &preorder[i]);
  for (int i = 0; i < n; ++i)
    scanf("%d", &inorder[i]);

  reconstruct(n, 0, 0);

  genaratePostorder(preorder[0]);

  for (int i = 0; i < n; ++i)
  {
    printf("%d", postorder[i]);
    if (i < n - 1)
      printf(" ");
  }
  printf("\n");

  return 0;
}


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

int main(){

    int m, f, r;

    for ( ;; ) {

        std::cin >> m >> f >> r;

        if ( m == -1 && f == -1 && r == -1 ) break;

        char grade;

        if ( m == -1 || f == -1 ) grade = 'F';

        else if ( m + f >= 80 ) grade = 'A';
        else if ( m + f >= 65 ) grade = 'B';
        else if ( m + f >= 50 ) grade = 'C';
        else if ( m + f >= 30 ) grade = r >= 50 ? 'C' : 'D';
        else                    grade = 'F';

        std::cout << grade << std::endl;
    }

    return 0;
}



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

#define pb push_back
#define ppp pop_back
#define fi first
#define se second
#define pii pair<int,int>

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
   freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    int a[n+5];
    for (int i=1; i<=n; i++) cin >> a[i];
    int ans = 0;
    int cur = 1;
    for (int i=2; i<=n; i++) {
        if (a[i] != a[i-1]) {
            ans += cur/2;
            cur = 1;
        }
        else {
            cur++;
        }
    }
    ans += cur/2;
    cout << ans;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
#include<set>
using namespace std;
typedef long long int ll;
const ll MOD=10007;
const ll INF=1000000000;
const int MAX=100001;
const double EPS=1e-10;
int main(){
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    for(int i=0;i<n;i++){
        if(c*(n-1-i)-d*i<=b-a&&b-a<=-c*i+(n-1-i)*d){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

                           


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdlib>
using namespace std;
int main()
{
	int n; 
	bool fl = false;
	cin >>n;
	if((n%100)%10==7) fl=true;
	if((n%100)/10==7) fl=true;
	if(n/100==7) fl=true;
	if(fl)cout<<"Yes"<<endl;
	else cout<<"No"<<endl ;
	return 0;
}

Measured memory_bytes: 3632
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int N, A[15], X[15][15], Y[15][15];

int check(const bitset<15> &bits){
	rp(i, 0, N)
		if(bits[i])
			rp(j, 0, A[i]) if(bits[X[i][j]] != Y[i][j]) return 0;
	return bits.count();
}

int main(){
	cin>>N;
	rp(i, 0, N){ cin>>A[i]; rp(j, 0, A[i]){ cin>>X[i][j]>>Y[i][j]; X[i][j]--; } }
	int ans = 0;
	rp(bits, 1, 1<<N) ans = max(ans, check(bits));
	cout<< ans <<endl;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    a = inpl()
    ans = [0 for _ in range(n)]
    for i in range(n-1):
        ans[a[i]-1] += 1
    for i in range(n):
        print(ans[i])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 105004
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int n; cin >> n;
  
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int t = 0;

  for (int i = 0; i < n; ++i) {
    t ^= a[i];
  }
  if (t == 0) {
    print("Yes");
  } else {
    print("No");
  }

  return 0;
}

Measured memory_bytes: 640
MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    B = []
    used = set()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            x = F(a, b)
            y = -F(b, a) % P
            cA[x] += 1
            if x not in used and y not in used:
                B.append((x, y))
                used.add(x)
                used.add(y)

    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in B:
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 214464
/**
 *   author: sahushivam
 *   created: 22 December 2019 (Sunday)  17:44:09
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

void solve(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++) 
		cin>>a[i];
	int j=1;
	for(int i=0;i<n;i++)
	{
		if(a[i]==j){
			j++;
		}
	}
	if(j==1) 
	{
		cout<<"-1"; return;
	}
	cout<<n-j+1;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

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

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

using namespace std;

const double PI=acos(-1);

template<class T>
vector<T> longest_increasing_subsequence(const vector<T> &a){
	vector<T> lis;
	for(const auto& x:a){
		auto it=lower_bound(lis.begin(),lis.end(),x);
		if(it!=lis.end()) *it=x;
		else lis.emplace_back(x);
	}
	return lis;
}

int main(){
	int sx,sy,gx,gy,n;
	scanf("%d%d%d%d%d",&sx,&sy,&gx,&gy,&n);
	vector<int> x(n),y(n);
	rep(i,n) scanf("%d%d",&x[i],&y[i]);

	if(sx>gx){
		sx*=-1;
		gx*=-1;
		rep(i,n) x[i]*=-1;
	}
	if(sy>gy){
		sy*=-1;
		gy*=-1;
		rep(i,n) y[i]*=-1;
	}

	vector<int> Y;
	{
		vector<pair<int,int>> p;
		rep(i,n) if(sx<=x[i] && x[i]<=gx && sy<=y[i] && y[i]<=gy) {
			p.emplace_back(x[i],y[i]);
		}
		sort(p.begin(),p.end(),[](const auto& a,const auto& b){
			return make_pair(a.first,-a.second)<make_pair(b.first,-b.second);
		});
		rep(i,p.size()) Y.emplace_back(p[i].second);
	}

	int m=longest_increasing_subsequence(Y).size();
	if(m<=min(gx-sx,gy-sy)) printf("%.15f\n",100.0*(gx-sx+gy-sy)+(5*PI-20)*m);
	else                    printf("%.15f\n",100.0*(gx-sx+gy-sy)+(5*PI-20)*(m-1)+(10*PI-20));

	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

const int MOD = 1e9+7;

int main() {
    string L; cin >> L;
    int s = L.size();
    vector<vector<ll>> dp(s+1, vector<ll>(2,0));
    dp[0][0] = 1;

    REP(i,s){
        if(L[i] == '1'){
            dp[i+1][0] += 2*dp[i][0];
            dp[i+1][1] += dp[i][0] + 3*dp[i][1];
        }else{
            dp[i+1][0] += dp[i][0];
            dp[i+1][1] += 3*dp[i][1];
        }
        dp[i+1][0] %= MOD;
        dp[i+1][1] %= MOD;
    }
    cout << (dp[s][0] + dp[s][1]) % MOD << endl;
    return 0;
}

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

int main() {
    int h, w;
    cin >> h >>w;
    string board[50];

    for(int i=0; i < h; ++i) cin >> board[i];

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

    for(int i=0; i<h; ++i) {
        for(int j=0; j < w; ++j) {
            if(board[i][j] == '#') continue;

            int num = 0;
            for(int d = 0; d < 8; ++d) {
                const int ni = i + dy[d];
                const int nj = j + dx[d];

                if(ni < 0 or h <= ni) continue;
                if(nj < 0 or w <= nj) continue;
                if(board[ni][nj] == '#') num++;
            }
            board[i][j] = char(num + '0');
        }
    }
    for(int i=0; i<h; ++i) cout << board[i] << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i].first;
    for (int i = 0; i < n; ++i) cin >> a[i].second;
    const int m = 1000000000;
    int ans = m;
    for (int i = 0; i < (1 << n); ++i) {
        vector<int> b;
        vector<pair<int, pair<int, int>>> c;
        int blue = 0;
        for (int j = 0; j < n; ++j) {
            if (i >> j & 1) {
                b.push_back(a[j].second);
                c.push_back(make_pair(a[j].second, make_pair(1, 0)));
                ++blue;
            }
            else {
                b.push_back(a[j].first);
                c.push_back(make_pair(a[j].first, make_pair(0, 0)));
            }
        }
        if (blue % 2 != 0) continue;
        sort(b.begin(), b.end());
        int res = 0;
        for (int j = 0; j < n; ++j) {
            bool find = false;
            for (int k = j; k < n; ++k) {
                if (c[k].first == b[j]) {
                    if ((c[k].second.second ^ ((k - j) % 2)) == c[k].second.first) {
                        int tmp = k;
                        find = true;
                        while (tmp != j) {
                            ++res;
                            swap(c[tmp - 1], c[tmp]);
                            c[tmp].second.second ^= 1;
                            c[tmp - 1].second.second ^= 1;
                            --tmp;
                        }
                        break;
                    }
                }
            }
            if (find == false) {
                res = m;
                break;
            }
        }
        ans = min(ans, res);
    }
    if (ans == m) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF INT_MAX
#define MAX_W 30
#define MAX_H 60
char field[MAX_H][MAX_W];

struct P
{
    int x,y,cost,w;
    bool operator >(const P &p) const{
        return cost>p.cost;
    }
};

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

int main() {
    int w, h;
    while(cin >> w >> h, w|h){
        fill_n((char *)field, MAX_W*MAX_H, 'X');

        priority_queue<P, vector<P>, greater<P> >que;

        REP(y,h)REP(x,w){
            cin >> field[y][x];
            if(field[y][x]=='S'){
                que.push({x, y, 0, 1});
                que.push({x, y, 0,-1});
            }
        }

        vvi GL(h, vi(w, INF));
        vvi GR(h, vi(w, INF));

        int res=-1;
        while(!que.empty()){
            P p=que.top(); que.pop();

            if(field[p.y][p.x]=='T'){
                res=p.cost;
                break;
            }

            REP(i, 9){
                int sx=p.x+dx[i]*p.w;
                int sy=p.y+dy[i];
                if(0<=sx&&sx<w&&0<=sy&&sy<h){
                    int cost=p.cost;
                    switch(field[sy][sx]){
                    case 'T':
                    case 'S':
                        break;
                    case 'X':
                        continue;
                    default:
                        cost+=field[sy][sx]-'0';
                        break;
                    }
                    bool t=true;
                    if(p.w>0&&GR[sy][sx]>cost){
                        GR[sy][sx]=cost;
                        t=false;
                    }else if(p.w<0&&GL[sy][sx]>cost){
                        GL[sy][sx]=cost;
                        t=false;
                    }
                    if(t)continue;
                    que.push({sx, sy, cost, -p.w});
                }
            }
        }

        cout << res << endl;
    }
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];

    vector<ll> Y = X;
    sort(all(Y));

    rep (i, N) {
        int lb = lower_bound(all(Y), X[i]) - Y.begin();
        int ub = upper_bound(all(Y), X[i]) - Y.begin();

        // [lb, ub) がX[i]
        int mid = Y.size() / 2;
        ll v = 0;
        if (ub - 1 < mid) {
            v = Y[mid];
        }
        else {
            v = Y[mid - 1];
        }

        put(v);
    }

    return 0;
}

Measured memory_bytes: 6316
#include<iostream>

using namespace std;

int main(){

    while(1){
        int n;
        cin>> n;
        if(n==0) break;

        int dp[31];
        fill(dp, dp+31, 0);
        dp[1]=1; dp[2]=2; dp[3]=4;
        for(int i=4; i<=n; i++){
            dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
        }

        cout<< (dp[n]+3650-1)/3650<< endl;
    }

    return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;	
  cin >> c;
  
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
  {
   cout << "vowel" << endl; 
  }
 else
 {
  cout << "consonant" << endl; 
 }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

int score[1000001];
// set<pii> S;
priority_queue<pii> Q;
int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  Q.push(MP(0,-1));
  while(q--){
    int a,v;
    scanf("%d%d",&a,&v);
    score[a] += v;
    Q.push(MP(score[a],-a));
    while(!Q.empty()){
      pii P = Q.top();
      if(score[-P.second]!=P.first)Q.pop();
      else{
        printf("%d %d\n",-P.second,P.first);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 5984
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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; }

class R
{
public:
    string s;
    int p;
    int i;

    R(string s, int p, int i)
    {
        this->s = s;
        this->p = p;
        this->i = i;
    }

    bool operator < (R& r)
    {
        if (this->s != r.s)
        {
            return this->s < r.s;
        }
        else
        {
            return this->p > r.p;
        }
    }
};

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

    int N;
    cin >> N;

    vector<R> v;
    rep(i, N)
    {
        string s;
        int p;
        cin >> s >> p;
        v.emplace_back(s, p, i + 1);
    }

    sort(all(v));

    for (auto x : v)
    {
        cout << x.i << endl;
    }

    return 0;
}

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

using namespace std;

using ll = long long;
const int MAXN = 5050;
const int MAXM = 220;
const ll INF = 1e18;

int N, M;
int A[MAXN];
int B[MAXN][MAXM];

ll tr[MAXN << 2];
ll lazy[MAXN << 2];

void build(int v, int l, int r) {
   tr[v] = -INF;
   if (l < r) {
      int md = (l + r) >> 1;
      build(v << 1, l, md);
      build(v << 1 | 1, md + 1, r);
   }
}

void push(int v, int l, int r) {
   if (lazy[v]) {
      tr[v] += lazy[v];
      if (l < r) {
         lazy[v << 1] += lazy[v];
         lazy[v << 1 | 1] += lazy[v];
      }
      lazy[v] = 0;
   }
}

void add(int v, int l, int r, int L, int R, ll val) {
   push(v, l, r);
   if (L > r || R < l) return;
   if (L <= l && r <= R) {
      lazy[v] = val;
      push(v, l, r);
      return;
   }
   int md = (l + r) >> 1;
   add(v << 1, l, md, L, R, val);
   add(v << 1 | 1, md + 1, r, L, R, val);
   tr[v] = max(tr[v << 1], tr[v << 1 | 1]);
}

void print(int v, int l, int r) {
   push(v, l, r);
   if (l == r) {
      cerr << tr[v] << "\n";
   } else {
      int md = (l + r) >> 1;
      print(v << 1, l, md);
      print(v << 1 | 1, md + 1, r);
   }
   if (v == 1) cerr << "\n";
}
vector<int> st[MAXM];

int main() {
   ios_base::sync_with_stdio(false);
   cin >> N >> M;
   for (int i = 1; i < N; ++i) cin >> A[i];
   for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= M; ++j) {
         cin >> B[i][j];
      }
   }
   for (int i = 1; i <= M; ++i) {
      st[i].emplace_back(0);
   }
   build(1, 1, N);
   ll ans = -INF;
   for (int i = 1; i <= N; ++i) {
      add(1, 1, N, i, i, INF);
      if (i > 1) add(1, 1, N, 1, i - 1, -ll(A[i - 1]));
      for (int z = 1; z <= M; ++z) {
         while (st[z].size() > 1 && B[st[z].back()][z] < B[i][z]) {
            add(1, 1, N, st[z][st[z].size() - 2] + 1, st[z].back(), -ll(B[st[z].back()][z]));
            st[z].pop_back();
         }
         add(1, 1, N, st[z].back() + 1, i, ll(B[i][z]));
         st[z].emplace_back(i);
      }
      ans = max(ans, tr[1]);
   }
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 4992
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_D
  * Structured Program I - Structured Programming
  */
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val result = " " + (1 to n).filter(i => i % 3 == 0 || i.toString.contains("3")).mkString(" ")
    println(result)
  }
}

Measured memory_bytes: 45632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,m,q;
    cin>>n>>k>>q;
    vector<long long>vc(n+10,k);

    for(i=0; i<q; i++)
    {
        cin>>l;
        vc[l]++;
    }

    for(i=1; i<=n; i++)
    {
        if((vc[i]-q)>0)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 305
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

const int inf=(int)1e9;

int i,j,m,n,p,k;
long long dis[N][N];

long long ans;

struct Node{
		int x,y,c;
}B[N*N];

int read()
{
	char c; int x;
	while (c=getchar(),c<'0'||c>'9');
	x=c-'0';
	while (c=getchar(),c>='0'&&c<='9') x=x*10+c-'0';
	return  x;
}

inline int cmp(Node a,Node b)
{
		return a.c<b.c;
}

int main()
{
		scanf("%d",&n);
		for (i=1;i<=n;++i)
			for (j=1;j<=n;++j) 
				dis[i][j]=inf+5;
		for (i=1;i<=n;++i) dis[i][i]=0;
		for (i=1;i<=n;++i)
			for (j=1;j<=n;++j)
				B[(i-1)*n+j]=(Node){i,j,read()};
		sort(B+1,B+n*n+1,cmp);
		for (i=1;i<=n*n;++i)
			if (dis[B[i].x][B[i].y]<B[i].c) break;
			else 
			if (dis[B[i].x][B[i].y]>B[i].c)
			{
					int x=B[i].x,y=B[i].y;
					dis[x][y]=dis[y][x]=B[i].c;
					for (j=1;j<=n;++j)
						for (k=1;k<=n;++k)
							dis[j][k]=min(dis[j][k],min(dis[j][x]+B[i].c+dis[y][k],
														dis[j][y]+B[i].c+dis[x][k]));
					ans+=B[i].c;	
			}
		if (i<=n*n) puts("-1");
		else 
		cout<<ans<<endl;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>


int main() {
	long long n;

	std::cin >> n;

	std::vector<long long> v(n);
	for (long long i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	std::sort(v.begin(), v.end());

	std::vector<long long> sub_sum(n);
	sub_sum[0] = v[0];
	for (long long i = 1; i < n; i++)
	{
		sub_sum[i] = sub_sum[i - 1] + v[i];
	}


	long long ans = n;
	for (long long i = n - 2; i >= 0; i--)
	{
		if (sub_sum[i] * 2 < v[i + 1]) {
			ans = n - (i + 1);
			break;
		}
	}

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

Measured memory_bytes: 1792
import sys, heapq
def input():
	return sys.stdin.readline()[:-1]

n, k, q = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
a = [0] + a + [0]
ans = 10**30
for x in b:
	removed = []
	que = []
	for i in range(n+2):
		if a[i] < x:
			que = []
		else:
			heapq.heappush(que, a[i])
			if len(que) == k:
				removed.append(heapq.heappop(que))
	if len(removed) < q:
		continue
	removed.sort()
	ans = min(ans, removed[q-1] - x)
print(ans)

Measured memory_bytes: 57304
D=int(input())
c=list(map(int,input().split()))
s=[0]
last=[0]*26
for i in range(D):
  s.append(list(map(int,input().split())))
#Donyoku
for i in range(1,D+1):
  score=0
  t=0
  score+=s[i][t]
  lasttemp=last[t]
  last[t]=i
  for j in range(26):
    score-=c[j]*(i-last[j])
  maxscore=score
  bestans=1
  last[t]=lasttemp
  for t in range(1,26):
    score=0
    score+=s[i][t]
    lasttemp=last[t]
    last[t]=i
    for j in range(26):
      score-=c[j]*(i-last[j])
    if maxscore<score:
      bestans=t+1
      maxscore=score
    last[t]=lasttemp
  print(bestans)
  last[bestans-1]=i

Measured memory_bytes: 69188
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	bool increase = true;
	bool sepalate = true;
	int ans = MOD;
	int subans = 1;
	for (int i = 0; i < N - 1; i++) {
		if (sepalate) {
			//if(i!=0)i++;
			while (v[i] == v[i + 1])
				i++;
			if (v[i] < v[i + 1]) {
				increase = true;
			}
			else {
				increase = false;
			}
			sepalate = false;
		}
		if (increase) {
			if (v[i] > v[i + 1]) {
				subans++;
				sepalate = true;
			}
		}
		else {
			if (v[i] < v[i + 1]) {
				subans++;
				sepalate = true;
			}
		}
	}
	cout << subans << endl;
	return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();

	int kotae = 0;
	int k = 0;
	int mae = 0;
	rep(i, N) {
		int A = getint();

		switch (k) {
		case 0:
			k = 1;
			kotae++;
			mae = A;
			break;
		case 1:
			if (A > mae) k = 2;
			else if (A < mae) k = 3;
			mae = A;
			break;
		case 2:
			if (A < mae) {
				k = 1;
				kotae++;
			}
			mae = A;
			break;
		case 3:
			if (A > mae) {
				k = 1;
				kotae++;
			}
			mae = A;
		}
	}

	co(kotae);

	Would you please return 0;
}

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

#define println(msg) cout << msg << endl

int main() {
  // 入力
  int N, D;
  cin >> N >> D;

  vector<vector<int>> vvi(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      int x;
      cin >> x;
      vvi.at(i).push_back(x);
    }
  }
  
  // 計算
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      if (i >= j) continue;
      
      auto p1 = vvi.at(i);
      auto p2 = vvi.at(j);
      
      double sum = 0.0;
      for (int k = 0; k < D; k++) {
        sum += pow(p1.at(k) - p2.at(k), 2);
      }
      double dis = sqrt(sum);
      if (floor(dis) == dis) {
        count++;
      }
    }
  }
  
  // 出力
  println(count);
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  V<lint> cb(n + 1);
  for (int i = 0; i < n; ++i) cb[i + 1] = cb[i] + (s[i] == 'B');
  lint res = 0;
  for (int i = 0; i < n; ++i) if (s[i] == 'W') {
    res += cb[i];
  }
  cout << res << '\n';
}

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

using namespace std;
using ll = long long;

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

int main() {
  int a;
  string s;
  cin >> a >> s;

  if (a < 3200)
    cout << "red" << endl;
  else
    cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int k; cin >> k;
    vector<int> v ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << v[k-1] << endl;
}


Measured memory_bytes: 764
#include<iostream>

using namespace std;

int main(){
  int n,max=0,cnt=0,h[150],i,j,flag=0;

  cin >> n;
  for(i=0;i<n;i++){
    cin >> h[i];
    if( max < h[i] ) max=h[i];
  }

  for(i=0;i<max;i++){
    flag = 0;
    for(j=0;j<n;j++){
      if(h[j]>0 && j==n-1)cnt++;
      if(h[j]>0) flag=1;
      if(flag==1 && h[j]<=0){
	cnt++;
	flag=0;
      }
      h[j]--;
    }
  }
  cout << cnt <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,ll> P;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(){
    int x,y;
    cin >> x >> y;
    int k = x+y;
    if(k%3!=0){
        cout << 0 << endl;
        return 0;
    }
    k/=3;
    int pos = x-k;
    combination com(k);
    // cout << "(k,pos) = "<< k << ";" << pos <<endl;
    mint ans = com(k,pos);
    cout<< ans.x<<endl;
    return 0;
}

Measured memory_bytes: 10752
#include<iostream>
using namespace std;
int main()
{
    int n,sum=0,arr[100000];
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    for(int i=1;i<=n;i++)
    {
        if(arr[i]==i)
        {
            int combo=0;
            for(int j=i;arr[j]==j;j++)
                combo++;
            if(combo%2==0)
                sum+=combo/2;
            else
                sum+=combo/2+1;
 
            i += combo-1;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = long.Parse(Console.ReadLine());
            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var dic = new Dictionary<long, bool>();

            foreach(var x in inputLongArray) {
                if(dic.ContainsKey(x)) {
                    Console.WriteLine("NO");
                    Console.Out.Flush();
                    return;
                }

                dic.Add(x, true);
            }

            Console.WriteLine("YES");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 46288
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        a:i64,b:i64,
    }
    println!("{}", max(a + b, max(a * b, a - b)));
}


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

bool graph[9][9];
int dfs(int v, int N, bool visited[]) {
  bool visited_all = true;
  REP(i,N+1) if (!visited[i]) visited_all = false;
  if (visited_all) return 1;

  int ret = 0;
  REP(i,N+1) {
    if (graph[v][i] == false) continue;
    if (visited[i]) continue;
    visited[i] = true;
    ret+=dfs(i,N,visited);
    visited[i] = false;
  }
  return ret;
}

int main() {
  int N,M; cin >> N >> M;
  bool visited[N+1];
  REP(i,N+1) visited[i] = false;
  visited[0] = true; // 0は存在しない
  visited[1] = true; // 1は始点

  int a,b;
  REP(i,M) {
    cin >> a >> b;
    graph[a][b] = true; graph[b][a] = true;
  }
  cout << dfs(1, N, visited) << endl;
}


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


bool isNumber(char c) {
  if(c >= '0' && c <= '9') return true;
  else                     return false;
}

int ctoi(char c) {
  return c-'0';
}

char itoc(int i) {
  return '0'+i;
}

int toInt(string s) {
  int ans = 0;
  int tmp = 1;
  for(int i = 0; i < s.length(); i++) {
    if(isNumber(s[i])) {
      tmp = ctoi(s[i]);
    } else {
      switch(s[i]) {
      case 'm': ans += tmp * 1000; break;
      case 'c': ans += tmp * 100;  break;
      case 'x': ans += tmp * 10;   break;
      case 'i': ans += tmp;        break;
      }
      tmp = 1;
    }
  }
  return ans;
}

string toMcxi(int x) {
  string ans = "";
  for(int i = 1000; i >= 1; i /= 10) {
    int tmp = x / i;
    if(tmp == 0) continue;
    if(tmp != 1) ans += itoc(tmp);
    switch(i) {
    case 1000: ans += 'm'; break;
    case 100:  ans += 'c'; break;
    case 10:   ans += 'x'; break;
    case 1:    ans += 'i'; break;
    }
    x %= i;
  }
  return ans;
}

main() {
  int N;
  string s1, s2;
  cin >> N;
  for(int t = 0; t < N; t++) {
    cin >> s1 >> s2;
    cout << toMcxi(toInt(s1)+toInt(s2)) << endl;
  }
}

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

int main(){
  int n,x;
  cin >> n >> x;
  priority_queue<int> q;
  rep(i,n){
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,x){
    int b = q.top();q.pop();
    q.push(b/2);
  }
  ll ans = 0;
  while(!q.empty()){
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 892
# -*- coding: utf-8 -*-
n = int(input())
if n == 111:
    print(999)
if n == 119:
    print(991)
if n == 191:
    print(919)
if n == 199:
    print(911)
if n == 911:
    print(199)
if n == 919:
    print(191)
if n == 991:
    print(119)
if n == 999:
    print(111)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<vector<ll>> dp(n, vector<ll>(n));
  for (int l = n-1; l >= 0; --l) {
    for (int r = l; r < n; ++r) {
      if (l == r) dp[l][r] = a[l];
      else {
        dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
      }
    }
  }

  cout << dp[0][n-1] << '\n';

  return 0;
}


Measured memory_bytes: 73708
import math
from decimal import Decimal as d

a,b,h,m=map(int,input().split())
tyousin=d((h+m/60)/6*math.pi)
tanshin=d(m/30*math.pi)
rad=abs(tyousin-tanshin)
x=a**2+b**2-2*a*b*math.cos(rad)
ans=d(math.sqrt(x))
print(abs(ans))


Measured memory_bytes: 10328
n,m=map(int,input().split())
l=[]
ans0=0
ans1=n
for i in range(m):
        l.append(list(map(int,input().split())))
for j in range(m):
        ans0=max(ans0,l[j][0])
        ans1=min(ans1,l[j][1])
if ans1-ans0+1<=0:
        print("0")
else:
        print(ans1-ans0+1)





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

int main(){
  int K;
  cin >> K;
  queue<ll> que;
  FOR(i, 1, 10) {
    que.push(i);
  }
  ll now = 0;
  rep(i, K) {
    now = que.front();
    que.pop();
    // 次の桁のなんとか数を入れる
    ll amari = now % 10;
    if (amari != 0) {
      que.push(10 * now + amari - 1);
    }
    que.push(10 * now + amari);
    if (amari != 9) {
      que.push(10 * now + amari + 1);
    }
  }
  cout << now << "\n";
}


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

int N, M = 0;
int A[2 * 100000];
int B[2 * 100000];

int main()
{
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = N-1; i >= 0; i--) {
    int sum = 0;
    for (int j = i; j < N; j += (i+1)) {
      sum += B[j];
    }
    if (sum % 2 != A[i]) {
      B[i] = 1;
      M++;
    }
  }
  cout << M << endl;
  bool first = true;
  for (int i = 0; i < N; i++) if (B[i]) {
    cout << (first ? "" : " ") << i+1;
    first = false;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<vector>
#include<queue>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define INF 1e6
#define P std::pair<int,int>
#define M std::vector<std::vector<int> >
#define V std::vector<int>

int dh[]={1,0,-1,0};
int dw[]={0,1,0,-1};
int h,w;

int bfs(P start, std::vector<std::string> &maze){
    M dist(h,V(w,INF));
    std::vector<std::vector<bool> > visited(h, std::vector<bool>(w,false));
    dist[start.first][start.second] = 0;
    std::queue<P> que; que.push(start);
    while(!que.empty()){
        P pos=que.front(); que.pop();
        rep(i,4){
            int hh=pos.first+dh[i];
            int ww=pos.second+dw[i];
            if(hh >= h || hh < 0 || ww >= w || ww < 0 || visited[hh][ww] || maze[hh][ww] == '#')
                continue;
            dist[hh][ww] = std::min(dist[pos.first][pos.second]+1, dist[hh][ww]);
            que.push(P(hh,ww));
            visited[hh][ww]=true;
        }
    }
    int ans=0;
    rep(i,h){
        rep(j,w){
            if(maze[i][j] == '.')
                ans = std::max(ans,dist[i][j]);
        }
    }
    return ans;
}

int main(){
    std::cin >> h >> w;
    std::vector<std::string> maze(h);
    rep(i,h) std::cin >> maze[i];
    int ans=-1;
    rep(hh,h){
        rep(ww,w){
            if(maze[hh][ww] == '#') continue;
            P start(hh,ww);
            ans = std::max(bfs(start, maze), ans);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3616
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
A,B,C=MI()
K=II()
i=0
while A>=B:
  B*=2
  i+=1
  if i>K:
    print('No')
    exit()
while B>=C:
  C*=2
  i+=1
  if i>K:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 9196
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int a[50], b[50], c[50], d[50];

void Search(vector<int>&v) {
	if (v.size() == N) {
		long long int ans = 0;
		for (int i = 0; i < K; i++) {
			if (v[b[i]] - v[a[i]] == c[i])ans += d[i];
		}
		L = max(L, ans);
		return;
	}
	int st = 1;
	if (v.size())st = v.back();
	for (int i = st; i <= M; i++) {
		v.push_back(i);
		Search(v);
		v.pop_back();
	}
}

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

	cin >> N >> M >> K;
	for (int i = 0; i < K; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--, b[i]--;
	}
	vector<int>v;
	Search(v);
	cout << L << endl;
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;

//ABC047-C-一次元リバーシ
//http://abc047.contest.atcoder.jp/tasks/arc063_a
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("BBBWW");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("WWWWWW");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("WBWBWBWBWB");
            //9
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];

        int Cnt = 0;
        char CurrSeqChar = '\0';
        foreach (char EachChar in S) {
            if (CurrSeqChar != EachChar) {
                Cnt++;
                CurrSeqChar = EachChar;
            }
        }
        Console.WriteLine(Cnt - 1);
    }
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

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

int n;
pair < pair < string , int > , int > a[N];

int main()
{
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i].st.st >> a[i].st.nd;
    a[i].st.nd *= -1;
    a[i].nd = i + 1;
  }
  sort(a, a + n);
  for(int i = 0; i < n; i++)
    cout << a[i].nd << "\n";
	return 0;
}


Measured memory_bytes: 23680
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int h, w, n; cin >> h >> w >> n;
    vector<vector<int>> c(h, vector<int>(w));
    int cnt=0;
    REP(i, n){
        int a; cin >> a;
        REP(j, a){
            int hh = cnt / w;
            int ww = cnt % w;
            if(hh%2) ww = w - ww - 1;
            c[hh][ww] = i+1;
            ++cnt;
        }
    }
    REP(i, h){
        REP(j, w){
            if(j) cout << " ";
            cout << c[i][j];
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)
	var ans int
	switch S {
	case "SAT":
		ans = 1
	case "FRI":
		ans = 2
	case "THU":
		ans = 3
	case "WED":
		ans = 4
	case "TUE":
		ans = 5
	case "MON":
		ans = 6
	case "SUN":
		ans = 7
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512